Skip to content

Commit a06263a

Browse files
author
Rafal Stefanowski
committed
Implement statistics
Change-Id: I70e3d6470dc3f0c7a6a493472746ccdc3bd3c6e7 Signed-off-by: Rafal Stefanowski <[email protected]>
1 parent 7088916 commit a06263a

File tree

7 files changed

+281
-57
lines changed

7 files changed

+281
-57
lines changed

module/bdev/ocf/stats.c

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,33 @@
11
/* SPDX-License-Identifier: BSD-3-Clause
22
* Copyright (C) 2018 Intel Corporation.
3+
* Copyright (C) 2025 Huawei Technologies
34
* All rights reserved.
45
*/
56

6-
#include "ctx.h"
77
#include "stats.h"
88

99
int
10-
vbdev_ocf_stats_get(ocf_cache_t cache, char *core_name, struct vbdev_ocf_stats *stats)
10+
vbdev_ocf_stats_cache_get(ocf_cache_t cache, struct vbdev_ocf_stats *stats)
1111
{
12-
int status;
13-
ocf_core_t core;
14-
15-
status = ocf_core_get_by_name(cache, core_name, strlen(core_name), &core);
16-
if (status) {
17-
return status;
18-
}
19-
20-
return ocf_stats_collect_core(core, &stats->usage, &stats->reqs, &stats->blocks, &stats->errors);
12+
return ocf_stats_collect_cache(cache, &stats->usage, &stats->req, &stats->blocks, &stats->errors);
2113
}
2214

2315
int
24-
vbdev_ocf_stats_reset(ocf_cache_t cache, char *core_name)
16+
vbdev_ocf_stats_core_get(ocf_core_t core, struct vbdev_ocf_stats *stats)
2517
{
26-
int status;
27-
ocf_core_t core;
18+
return ocf_stats_collect_core(core, &stats->usage, &stats->req, &stats->blocks, &stats->errors);
19+
}
2820

29-
status = ocf_core_get_by_name(cache, core_name, strlen(core_name), &core);
30-
if (status) {
31-
return status;
32-
}
21+
int
22+
vbdev_ocf_stats_cache_reset(ocf_cache_t cache)
23+
{
24+
return ocf_core_stats_initialize_all(cache);
25+
}
3326

27+
int
28+
vbdev_ocf_stats_core_reset(ocf_core_t core)
29+
{
3430
ocf_core_stats_initialize(core);
35-
3631
return 0;
3732
}
3833

@@ -47,8 +42,6 @@ vbdev_ocf_stats_reset(ocf_cache_t cache, char *core_name)
4742
void
4843
vbdev_ocf_stats_write_json(struct spdk_json_write_ctx *w, struct vbdev_ocf_stats *stats)
4944
{
50-
spdk_json_write_object_begin(w);
51-
5245
spdk_json_write_named_object_begin(w, "usage");
5346
WJSON_STAT(w, stats, usage, occupancy, "4KiB blocks");
5447
WJSON_STAT(w, stats, usage, free, "4KiB blocks");
@@ -57,18 +50,18 @@ vbdev_ocf_stats_write_json(struct spdk_json_write_ctx *w, struct vbdev_ocf_stats
5750
spdk_json_write_object_end(w);
5851

5952
spdk_json_write_named_object_begin(w, "requests");
60-
WJSON_STAT(w, stats, reqs, rd_hits, "Requests");
61-
WJSON_STAT(w, stats, reqs, rd_partial_misses, "Requests");
62-
WJSON_STAT(w, stats, reqs, rd_full_misses, "Requests");
63-
WJSON_STAT(w, stats, reqs, rd_total, "Requests");
64-
WJSON_STAT(w, stats, reqs, wr_hits, "Requests");
65-
WJSON_STAT(w, stats, reqs, wr_partial_misses, "Requests");
66-
WJSON_STAT(w, stats, reqs, wr_full_misses, "Requests");
67-
WJSON_STAT(w, stats, reqs, wr_total, "Requests");
68-
WJSON_STAT(w, stats, reqs, rd_pt, "Requests");
69-
WJSON_STAT(w, stats, reqs, wr_pt, "Requests");
70-
WJSON_STAT(w, stats, reqs, serviced, "Requests");
71-
WJSON_STAT(w, stats, reqs, total, "Requests");
53+
WJSON_STAT(w, stats, req, rd_hits, "Requests");
54+
WJSON_STAT(w, stats, req, rd_partial_misses, "Requests");
55+
WJSON_STAT(w, stats, req, rd_full_misses, "Requests");
56+
WJSON_STAT(w, stats, req, rd_total, "Requests");
57+
WJSON_STAT(w, stats, req, wr_hits, "Requests");
58+
WJSON_STAT(w, stats, req, wr_partial_misses, "Requests");
59+
WJSON_STAT(w, stats, req, wr_full_misses, "Requests");
60+
WJSON_STAT(w, stats, req, wr_total, "Requests");
61+
WJSON_STAT(w, stats, req, rd_pt, "Requests");
62+
WJSON_STAT(w, stats, req, wr_pt, "Requests");
63+
WJSON_STAT(w, stats, req, serviced, "Requests");
64+
WJSON_STAT(w, stats, req, total, "Requests");
7265
spdk_json_write_object_end(w);
7366

7467
spdk_json_write_named_object_begin(w, "blocks");
@@ -92,6 +85,4 @@ vbdev_ocf_stats_write_json(struct spdk_json_write_ctx *w, struct vbdev_ocf_stats
9285
WJSON_STAT(w, stats, errors, cache_volume_total, "Requests");
9386
WJSON_STAT(w, stats, errors, total, "Requests");
9487
spdk_json_write_object_end(w);
95-
96-
spdk_json_write_object_end(w);
9788
}

module/bdev/ocf/stats.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* SPDX-License-Identifier: BSD-3-Clause
22
* Copyright (C) 2018 Intel Corporation.
3+
* Copyright (C) 2025 Huawei Technologies
34
* All rights reserved.
45
*/
56

@@ -11,13 +12,15 @@
1112

1213
struct vbdev_ocf_stats {
1314
struct ocf_stats_usage usage;
14-
struct ocf_stats_requests reqs;
15+
struct ocf_stats_requests req;
1516
struct ocf_stats_blocks blocks;
1617
struct ocf_stats_errors errors;
1718
};
1819

19-
int vbdev_ocf_stats_get(ocf_cache_t cache, char *core_name, struct vbdev_ocf_stats *stats);
20-
int vbdev_ocf_stats_reset(ocf_cache_t cache, char *core_name);
20+
int vbdev_ocf_stats_cache_get(ocf_cache_t cache, struct vbdev_ocf_stats *stats);
21+
int vbdev_ocf_stats_core_get(ocf_core_t core, struct vbdev_ocf_stats *stats);
22+
int vbdev_ocf_stats_cache_reset(ocf_cache_t cache);
23+
int vbdev_ocf_stats_core_reset(ocf_core_t core);
2124

2225
void vbdev_ocf_stats_write_json(struct spdk_json_write_ctx *w, struct vbdev_ocf_stats *stats);
2326

module/bdev/ocf/vbdev_ocf.c

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "vbdev_ocf.h"
1212
#include "ctx.h"
1313
#include "data.h"
14+
#include "stats.h"
1415
#include "utils.h"
1516
#include "volume.h"
1617

@@ -2351,6 +2352,142 @@ vbdev_ocf_flush_start(const char *bdev_name, vbdev_ocf_rpc_mngt_cb rpc_cb_fn, vo
23512352
_flush_lock_cb, mngt_ctx);
23522353
}
23532354

2355+
// TODO: read lock cache
2356+
/* RPC entry point. */
2357+
void
2358+
vbdev_ocf_get_stats(const char *bdev_name, vbdev_ocf_get_bdevs_cb rpc_cb_fn,
2359+
void *rpc_cb_arg1, void *rpc_cb_arg2)
2360+
{
2361+
struct spdk_json_write_ctx *w = rpc_cb_arg1;
2362+
ocf_cache_t cache;
2363+
ocf_core_t core;
2364+
struct vbdev_ocf_mngt_ctx *mngt_ctx;
2365+
struct vbdev_ocf_stats stats;
2366+
int rc;
2367+
2368+
SPDK_DEBUGLOG(vbdev_ocf, "OCF '%s': getting statistics\n", bdev_name);
2369+
2370+
mngt_ctx = calloc(1, sizeof(struct vbdev_ocf_mngt_ctx));
2371+
if (!mngt_ctx) {
2372+
SPDK_ERRLOG("OCF '%s': failed to allocate memory for getting statistics context\n",
2373+
bdev_name);
2374+
goto end;
2375+
}
2376+
mngt_ctx->bdev_name = bdev_name;
2377+
/* Cache or core will be set using vbdev_ocf_bdev_resolve(). */
2378+
mngt_ctx->cache = NULL;
2379+
mngt_ctx->core = NULL;
2380+
2381+
if ((rc = vbdev_ocf_bdev_resolve(mngt_ctx))) {
2382+
SPDK_ERRLOG("OCF '%s': failed to find cache or core of that name: %s\n",
2383+
bdev_name, spdk_strerror(-rc));
2384+
free(mngt_ctx);
2385+
goto end;
2386+
}
2387+
cache = mngt_ctx->cache;
2388+
core = mngt_ctx->core;
2389+
free(mngt_ctx);
2390+
2391+
if (core) {
2392+
SPDK_DEBUGLOG(vbdev_ocf, "OCF core '%s': collecting statistics\n", ocf_core_get_name(core));
2393+
2394+
if ((rc = vbdev_ocf_stats_core_get(core, &stats))) {
2395+
SPDK_ERRLOG("OCF core '%s': failed to collect statistics (OCF error: %d)\n",
2396+
ocf_core_get_name(core), rc);
2397+
goto end;
2398+
}
2399+
} else {
2400+
SPDK_DEBUGLOG(vbdev_ocf, "OCF cache '%s': collecting statistics\n", ocf_cache_get_name(cache));
2401+
2402+
if ((rc = vbdev_ocf_stats_cache_get(cache, &stats))) {
2403+
SPDK_ERRLOG("OCF cache '%s': failed to collect statistics (OCF error: %d)\n",
2404+
ocf_cache_get_name(cache), rc);
2405+
goto end;
2406+
}
2407+
}
2408+
2409+
vbdev_ocf_stats_write_json(w, &stats);
2410+
2411+
end:
2412+
rpc_cb_fn(rpc_cb_arg1, rpc_cb_arg2);
2413+
}
2414+
2415+
static void
2416+
_reset_stats_lock_cb(ocf_cache_t cache, void *cb_arg, int error)
2417+
{
2418+
struct vbdev_ocf_mngt_ctx *mngt_ctx = cb_arg;
2419+
ocf_core_t core = mngt_ctx->core;
2420+
int rc;
2421+
2422+
if ((rc = error)) {
2423+
SPDK_ERRLOG("OCF cache '%s': failed to acquire OCF cache lock (OCF error: %d)\n",
2424+
ocf_cache_get_name(cache), error);
2425+
goto end;
2426+
}
2427+
2428+
if (core) {
2429+
SPDK_DEBUGLOG(vbdev_ocf, "OCF core '%s': stats reset\n", ocf_core_get_name(core));
2430+
2431+
if ((rc = vbdev_ocf_stats_core_reset(core))) {
2432+
SPDK_ERRLOG("OCF core '%s': failed to reset statistics (OCF error: %d)\n",
2433+
ocf_core_get_name(core), rc);
2434+
}
2435+
} else {
2436+
SPDK_DEBUGLOG(vbdev_ocf, "OCF cache '%s': stats reset\n", ocf_cache_get_name(cache));
2437+
2438+
if ((rc = vbdev_ocf_stats_cache_reset(cache))) {
2439+
SPDK_ERRLOG("OCF cache '%s': failed to reset statistics (OCF error: %d)\n",
2440+
ocf_cache_get_name(cache), rc);
2441+
}
2442+
}
2443+
2444+
ocf_mngt_cache_unlock(cache);
2445+
2446+
end:
2447+
mngt_ctx->rpc_cb_fn(mngt_ctx->bdev_name, mngt_ctx->rpc_cb_arg, rc);
2448+
free(mngt_ctx);
2449+
}
2450+
2451+
/* RPC entry point. */
2452+
void
2453+
vbdev_ocf_reset_stats(const char *bdev_name, vbdev_ocf_rpc_mngt_cb rpc_cb_fn, void *rpc_cb_arg)
2454+
{
2455+
struct vbdev_ocf_mngt_ctx *mngt_ctx;
2456+
int rc;
2457+
2458+
SPDK_DEBUGLOG(vbdev_ocf, "OCF '%s': resetting statistics\n", bdev_name);
2459+
2460+
mngt_ctx = calloc(1, sizeof(struct vbdev_ocf_mngt_ctx));
2461+
if (!mngt_ctx) {
2462+
SPDK_ERRLOG("OCF '%s': failed to allocate memory for resetting statistics context\n",
2463+
bdev_name);
2464+
rc = -ENOMEM;
2465+
goto err_alloc;
2466+
}
2467+
mngt_ctx->rpc_cb_fn = rpc_cb_fn;
2468+
mngt_ctx->rpc_cb_arg = rpc_cb_arg;
2469+
mngt_ctx->bdev_name = bdev_name;
2470+
/* Cache or core will be set using vbdev_ocf_bdev_resolve(). */
2471+
mngt_ctx->cache = NULL;
2472+
mngt_ctx->core = NULL;
2473+
2474+
if ((rc = vbdev_ocf_bdev_resolve(mngt_ctx))) {
2475+
SPDK_ERRLOG("OCF '%s': failed to find cache or core of that name: %s\n",
2476+
bdev_name, spdk_strerror(-rc));
2477+
goto err_resolve;
2478+
}
2479+
2480+
ocf_mngt_cache_lock(mngt_ctx->cache ? : ocf_core_get_cache(mngt_ctx->core),
2481+
_reset_stats_lock_cb, mngt_ctx);
2482+
2483+
return;
2484+
2485+
err_resolve:
2486+
free(mngt_ctx);
2487+
err_alloc:
2488+
rpc_cb_fn(bdev_name, rpc_cb_arg, rc);
2489+
}
2490+
23542491
static int
23552492
dump_promotion_info(struct spdk_json_write_ctx *w, ocf_cache_t cache)
23562493
{
@@ -2615,6 +2752,7 @@ _get_bdevs_cache_visitor(ocf_cache_t cache, void *cb_arg)
26152752
return rc;
26162753
}
26172754

2755+
// TODO: read lock cache ?
26182756
/* RPC entry point. */
26192757
void
26202758
vbdev_ocf_get_bdevs(const char *bdev_name, vbdev_ocf_get_bdevs_cb rpc_cb_fn, void *rpc_cb_arg1, void *rpc_cb_arg2)

module/bdev/ocf/vbdev_ocf.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ void vbdev_ocf_flush_start(const char *bdev_name,
7474
vbdev_ocf_rpc_mngt_cb rpc_cb_fn,
7575
void *rpc_cb_arg);
7676

77+
void vbdev_ocf_get_stats(const char *bdev_name,
78+
vbdev_ocf_get_bdevs_cb rpc_cb_fn,
79+
void *rpc_cb_arg1,
80+
void *rpc_cb_arg2);
81+
82+
void vbdev_ocf_reset_stats(const char *bdev_name,
83+
vbdev_ocf_rpc_mngt_cb rpc_cb_fn,
84+
void *rpc_cb_arg);
85+
7786
void vbdev_ocf_get_bdevs(const char *bdev_name,
7887
vbdev_ocf_get_bdevs_cb rpc_cb_fn,
7988
void *rpc_cb_arg1,

0 commit comments

Comments
 (0)