From 49cffc1e68554da2b497535e7a1359d58b9333ca Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Thu, 13 Feb 2020 07:19:11 -0500 Subject: [PATCH] rpc: Add thread_get_io_channels RPC Add an new JSON RPC thread_get_io_channels to retrieve IO channels of the threads. IO channel don't have its own name and so get the name of the corresponding IO device instead. Signed-off-by: Shuhei Matsumoto Change-Id: Id8fbb328ffba09e1eace35994cdbf36b24832b82 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/887 Tested-by: SPDK CI Jenkins Reviewed-by: Aleksey Marchuk Reviewed-by: Jim Harris Reviewed-by: Ben Walker --- doc/jsonrpc.md | 44 ++++++++++++++++++++++++++++++++++++++ module/event/rpc/app_rpc.c | 43 +++++++++++++++++++++++++++++++++++++ scripts/rpc.py | 7 ++++++ scripts/rpc/app.py | 9 ++++++++ 4 files changed, 103 insertions(+) diff --git a/doc/jsonrpc.md b/doc/jsonrpc.md index 54b331b68..019497d8d 100644 --- a/doc/jsonrpc.md +++ b/doc/jsonrpc.md @@ -663,6 +663,50 @@ Example response: } ~~~ +## thread_get_io_channels {#rpc_thread_get_io_channels} + +Retrieve current IO channels of all the threads. + +### Parameters + +This method has no parameters. + +### Response + +The response is an array of objects containing IO channels of all the threads. + +### Example + +Example request: +~~~ +{ + "jsonrpc": "2.0", + "method": "thread_get_io_channels", + "id": 1 +} +~~~ + +Example response: +~~~ +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "tick_rate": 2500000000, + "threads": [ + { + "name": "app_thread", + "io_channels": [ + { + "name": "nvmf_tgt", + "ref": 1 + } + ] + } + ] + } +} +~~~ # Block Device Abstraction Layer {#jsonrpc_components_bdev} ## bdev_set_options {#rpc_bdev_set_options} diff --git a/module/event/rpc/app_rpc.c b/module/event/rpc/app_rpc.c index 3e25aaa62..9e225f982 100644 --- a/module/event/rpc/app_rpc.c +++ b/module/event/rpc/app_rpc.c @@ -284,6 +284,49 @@ spdk_rpc_thread_get_pollers(struct spdk_jsonrpc_request *request, SPDK_RPC_REGISTER("thread_get_pollers", spdk_rpc_thread_get_pollers, SPDK_RPC_RUNTIME) +static void +rpc_get_io_channel(struct spdk_io_channel *ch, struct spdk_json_write_ctx *w) +{ + spdk_json_write_object_begin(w); + spdk_json_write_named_string(w, "name", spdk_io_device_get_name(ch->dev)); + spdk_json_write_named_uint32(w, "ref", ch->ref); + spdk_json_write_object_end(w); +} + +static void +rpc_thread_get_io_channels(void *arg) +{ + struct rpc_get_stats_ctx *ctx = arg; + struct spdk_thread *thread = spdk_get_thread(); + struct spdk_io_channel *ch; + + spdk_json_write_object_begin(ctx->w); + spdk_json_write_named_string(ctx->w, "name", spdk_thread_get_name(thread)); + + spdk_json_write_named_array_begin(ctx->w, "io_channels"); + TAILQ_FOREACH(ch, &thread->io_channels, tailq) { + rpc_get_io_channel(ch, ctx->w); + } + spdk_json_write_array_end(ctx->w); + + spdk_json_write_object_end(ctx->w); +} + +static void +spdk_rpc_thread_get_io_channels(struct spdk_jsonrpc_request *request, + const struct spdk_json_val *params) +{ + if (params) { + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + "'thread_get_io_channels' requires no arguments"); + return; + } + + rpc_thread_get_stats_for_each(request, rpc_thread_get_io_channels); +} + +SPDK_RPC_REGISTER("thread_get_io_channels", spdk_rpc_thread_get_io_channels, SPDK_RPC_RUNTIME); + static void rpc_framework_get_reactors_done(void *arg1, void *arg2) { diff --git a/scripts/rpc.py b/scripts/rpc.py index 18b5dbcdf..44870d36b 100755 --- a/scripts/rpc.py +++ b/scripts/rpc.py @@ -2290,6 +2290,13 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse 'thread_get_pollers', help='Display current pollers of all the threads') p.set_defaults(func=thread_get_pollers) + def thread_get_io_channels(args): + print_dict(rpc.app.thread_get_io_channels(args.client)) + + p = subparsers.add_parser( + 'thread_get_io_channels', help='Display current IO channels of all the threads') + p.set_defaults(func=thread_get_io_channels) + def env_dpdk_get_mem_stats(args): print_dict(rpc.env_dpdk.env_dpdk_get_mem_stats(args.client)) diff --git a/scripts/rpc/app.py b/scripts/rpc/app.py index 64b21322b..9412de17d 100644 --- a/scripts/rpc/app.py +++ b/scripts/rpc/app.py @@ -67,3 +67,12 @@ def thread_get_pollers(client): Current pollers. """ return client.call('thread_get_pollers') + + +def thread_get_io_channels(client): + """Query current IO channels. + + Returns: + Current IO channels. + """ + return client.call('thread_get_io_channels')