summaryrefslogtreecommitdiffstats
path: root/src/spdk/lib/trace
diff options
context:
space:
mode:
Diffstat (limited to 'src/spdk/lib/trace')
-rw-r--r--src/spdk/lib/trace/Makefile45
-rw-r--r--src/spdk/lib/trace/spdk_trace.map29
-rw-r--r--src/spdk/lib/trace/trace.c201
-rw-r--r--src/spdk/lib/trace/trace_flags.c323
-rw-r--r--src/spdk/lib/trace/trace_rpc.c170
5 files changed, 768 insertions, 0 deletions
diff --git a/src/spdk/lib/trace/Makefile b/src/spdk/lib/trace/Makefile
new file mode 100644
index 000000000..9102c320a
--- /dev/null
+++ b/src/spdk/lib/trace/Makefile
@@ -0,0 +1,45 @@
+#
+# BSD LICENSE
+#
+# Copyright (c) Intel Corporation.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Intel Corporation nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
+include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
+
+SO_VER := 2
+SO_MINOR := 0
+
+C_SRCS = trace.c trace_flags.c trace_rpc.c
+LIBNAME = trace
+
+SPDK_MAP_FILE = $(abspath $(CURDIR)/spdk_trace.map)
+
+include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk
diff --git a/src/spdk/lib/trace/spdk_trace.map b/src/spdk/lib/trace/spdk_trace.map
new file mode 100644
index 000000000..14a03b337
--- /dev/null
+++ b/src/spdk/lib/trace/spdk_trace.map
@@ -0,0 +1,29 @@
+{
+ global:
+
+ # public functions
+ _spdk_trace_record;
+ spdk_trace_get_tpoint_mask;
+ spdk_trace_set_tpoints;
+ spdk_trace_clear_tpoints;
+ spdk_trace_get_tpoint_group_mask;
+ spdk_trace_set_tpoint_group_mask;
+ spdk_trace_clear_tpoint_group_mask;
+ spdk_trace_init;
+ spdk_trace_cleanup;
+ spdk_trace_flags_init;
+ spdk_trace_register_owner;
+ spdk_trace_register_object;
+ spdk_trace_register_description;
+ spdk_trace_get_first_register_fn;
+ spdk_trace_get_next_register_fn;
+ spdk_trace_enable_tpoint_group;
+ spdk_trace_disable_tpoint_group;
+ spdk_trace_mask_usage;
+ spdk_trace_add_register_fn;
+
+ # public variables
+ g_trace_histories;
+
+ local: *;
+};
diff --git a/src/spdk/lib/trace/trace.c b/src/spdk/lib/trace/trace.c
new file mode 100644
index 000000000..621c52aae
--- /dev/null
+++ b/src/spdk/lib/trace/trace.c
@@ -0,0 +1,201 @@
+/*-
+ * BSD LICENSE
+ *
+ * Copyright (c) Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "spdk/stdinc.h"
+
+#include "spdk/env.h"
+#include "spdk/string.h"
+#include "spdk/trace.h"
+#include "spdk/util.h"
+#include "spdk/barrier.h"
+#include "spdk/log.h"
+
+static int g_trace_fd = -1;
+static char g_shm_name[64];
+
+struct spdk_trace_histories *g_trace_histories;
+
+void
+_spdk_trace_record(uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id, uint32_t size,
+ uint64_t object_id, uint64_t arg1)
+{
+ struct spdk_trace_history *lcore_history;
+ struct spdk_trace_entry *next_entry;
+ unsigned lcore;
+ uint64_t next_circular_entry;
+
+ lcore = spdk_env_get_current_core();
+ if (lcore >= SPDK_TRACE_MAX_LCORE) {
+ return;
+ }
+
+ lcore_history = spdk_get_per_lcore_history(g_trace_histories, lcore);
+ if (tsc == 0) {
+ tsc = spdk_get_ticks();
+ }
+
+ lcore_history->tpoint_count[tpoint_id]++;
+
+ /* Get next entry index in the circular buffer */
+ next_circular_entry = lcore_history->next_entry & (lcore_history->num_entries - 1);
+ next_entry = &lcore_history->entries[next_circular_entry];
+ next_entry->tsc = tsc;
+ next_entry->tpoint_id = tpoint_id;
+ next_entry->poller_id = poller_id;
+ next_entry->size = size;
+ next_entry->object_id = object_id;
+ next_entry->arg1 = arg1;
+
+ /* Ensure all elements of the trace entry are visible to outside trace tools */
+ spdk_smp_wmb();
+ lcore_history->next_entry++;
+}
+
+int
+spdk_trace_init(const char *shm_name, uint64_t num_entries)
+{
+ int i = 0;
+ int histories_size;
+ uint64_t lcore_offsets[SPDK_TRACE_MAX_LCORE + 1];
+
+ /* 0 entries requested - skip trace initialization */
+ if (num_entries == 0) {
+ return 0;
+ }
+
+ lcore_offsets[0] = sizeof(struct spdk_trace_flags);
+ for (i = 1; i < (int)SPDK_COUNTOF(lcore_offsets); i++) {
+ lcore_offsets[i] = spdk_get_trace_history_size(num_entries) + lcore_offsets[i - 1];
+ }
+ histories_size = lcore_offsets[SPDK_TRACE_MAX_LCORE];
+
+ snprintf(g_shm_name, sizeof(g_shm_name), "%s", shm_name);
+
+ g_trace_fd = shm_open(shm_name, O_RDWR | O_CREAT, 0600);
+ if (g_trace_fd == -1) {
+ SPDK_ERRLOG("could not shm_open spdk_trace\n");
+ SPDK_ERRLOG("errno=%d %s\n", errno, spdk_strerror(errno));
+ return 1;
+ }
+
+ if (ftruncate(g_trace_fd, histories_size) != 0) {
+ SPDK_ERRLOG("could not truncate shm\n");
+ goto trace_init_err;
+ }
+
+ g_trace_histories = mmap(NULL, histories_size, PROT_READ | PROT_WRITE,
+ MAP_SHARED, g_trace_fd, 0);
+ if (g_trace_histories == MAP_FAILED) {
+ SPDK_ERRLOG("could not mmap shm\n");
+ goto trace_init_err;
+ }
+
+ /* TODO: On FreeBSD, mlock on shm_open'd memory doesn't seem to work. Docs say that kern.ipc.shm_use_phys=1
+ * should allow it, but forcing that doesn't seem to work either. So for now just skip mlock on FreeBSD
+ * altogether.
+ */
+#if defined(__linux__)
+ if (mlock(g_trace_histories, histories_size) != 0) {
+ SPDK_ERRLOG("Could not mlock shm for tracing - %s.\n", spdk_strerror(errno));
+ if (errno == ENOMEM) {
+ SPDK_ERRLOG("Check /dev/shm for old tracing files that can be deleted.\n");
+ }
+ goto trace_init_err;
+ }
+#endif
+
+ memset(g_trace_histories, 0, histories_size);
+
+ g_trace_flags = &g_trace_histories->flags;
+
+ g_trace_flags->tsc_rate = spdk_get_ticks_hz();
+
+ for (i = 0; i < SPDK_TRACE_MAX_LCORE; i++) {
+ struct spdk_trace_history *lcore_history;
+
+ g_trace_flags->lcore_history_offsets[i] = lcore_offsets[i];
+ lcore_history = spdk_get_per_lcore_history(g_trace_histories, i);
+ lcore_history->lcore = i;
+ lcore_history->num_entries = num_entries;
+ }
+ g_trace_flags->lcore_history_offsets[SPDK_TRACE_MAX_LCORE] = lcore_offsets[SPDK_TRACE_MAX_LCORE];
+
+ spdk_trace_flags_init();
+
+ return 0;
+
+trace_init_err:
+ if (g_trace_histories != MAP_FAILED) {
+ munmap(g_trace_histories, histories_size);
+ }
+ close(g_trace_fd);
+ g_trace_fd = -1;
+ shm_unlink(shm_name);
+ g_trace_histories = NULL;
+
+ return 1;
+
+}
+
+void
+spdk_trace_cleanup(void)
+{
+ bool unlink;
+ int i;
+ struct spdk_trace_history *lcore_history;
+
+ if (g_trace_histories == NULL) {
+ return;
+ }
+
+ /*
+ * Only unlink the shm if there were no trace_entry recorded. This ensures the file
+ * can be used after this process exits/crashes for debugging.
+ * Note that we have to calculate this value before g_trace_histories gets unmapped.
+ */
+ for (i = 0; i < SPDK_TRACE_MAX_LCORE; i++) {
+ lcore_history = spdk_get_per_lcore_history(g_trace_histories, i);
+ unlink = lcore_history->entries[0].tsc == 0;
+ if (!unlink) {
+ break;
+ }
+ }
+
+ munmap(g_trace_histories, sizeof(struct spdk_trace_histories));
+ g_trace_histories = NULL;
+ close(g_trace_fd);
+
+ if (unlink) {
+ shm_unlink(g_shm_name);
+ }
+}
diff --git a/src/spdk/lib/trace/trace_flags.c b/src/spdk/lib/trace/trace_flags.c
new file mode 100644
index 000000000..615afe355
--- /dev/null
+++ b/src/spdk/lib/trace/trace_flags.c
@@ -0,0 +1,323 @@
+/*-
+ * BSD LICENSE
+ *
+ * Copyright (c) Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "spdk/stdinc.h"
+
+#include "spdk/env.h"
+#include "spdk/trace.h"
+#include "spdk/log.h"
+#include "spdk_internal/log.h"
+
+struct spdk_trace_flags *g_trace_flags = NULL;
+static struct spdk_trace_register_fn *g_reg_fn_head = NULL;
+
+SPDK_LOG_REGISTER_COMPONENT("trace", SPDK_LOG_TRACE)
+
+uint64_t
+spdk_trace_get_tpoint_mask(uint32_t group_id)
+{
+ if (group_id >= SPDK_TRACE_MAX_GROUP_ID) {
+ SPDK_ERRLOG("invalid group ID %d\n", group_id);
+ return 0ULL;
+ }
+
+ return g_trace_flags->tpoint_mask[group_id];
+}
+
+void
+spdk_trace_set_tpoints(uint32_t group_id, uint64_t tpoint_mask)
+{
+ if (group_id >= SPDK_TRACE_MAX_GROUP_ID) {
+ SPDK_ERRLOG("invalid group ID %d\n", group_id);
+ return;
+ }
+
+ g_trace_flags->tpoint_mask[group_id] |= tpoint_mask;
+}
+
+void
+spdk_trace_clear_tpoints(uint32_t group_id, uint64_t tpoint_mask)
+{
+ if (group_id >= SPDK_TRACE_MAX_GROUP_ID) {
+ SPDK_ERRLOG("invalid group ID %d\n", group_id);
+ return;
+ }
+
+ g_trace_flags->tpoint_mask[group_id] &= ~tpoint_mask;
+}
+
+uint64_t
+spdk_trace_get_tpoint_group_mask(void)
+{
+ uint64_t mask = 0x0;
+ int i;
+
+ for (i = 0; i < SPDK_TRACE_MAX_GROUP_ID; i++) {
+ if (spdk_trace_get_tpoint_mask(i) != 0) {
+ mask |= (1ULL << i);
+ }
+ }
+
+ return mask;
+}
+
+void
+spdk_trace_set_tpoint_group_mask(uint64_t tpoint_group_mask)
+{
+ int i;
+
+ for (i = 0; i < SPDK_TRACE_MAX_GROUP_ID; i++) {
+ if (tpoint_group_mask & (1ULL << i)) {
+ spdk_trace_set_tpoints(i, -1ULL);
+ }
+ }
+}
+
+void
+spdk_trace_clear_tpoint_group_mask(uint64_t tpoint_group_mask)
+{
+ int i;
+
+ for (i = 0; i < SPDK_TRACE_MAX_GROUP_ID; i++) {
+ if (tpoint_group_mask & (1ULL << i)) {
+ spdk_trace_clear_tpoints(i, -1ULL);
+ }
+ }
+}
+
+struct spdk_trace_register_fn *
+spdk_trace_get_first_register_fn(void)
+{
+ return g_reg_fn_head;
+}
+
+struct spdk_trace_register_fn *
+spdk_trace_get_next_register_fn(struct spdk_trace_register_fn *register_fn)
+{
+ return register_fn->next;
+}
+
+static uint64_t
+trace_create_tpoint_group_mask(const char *group_name)
+{
+ uint64_t tpoint_group_mask = 0;
+ struct spdk_trace_register_fn *register_fn;
+
+ register_fn = spdk_trace_get_first_register_fn();
+ if (strcmp(group_name, "all") == 0) {
+ while (register_fn) {
+ tpoint_group_mask |= (1UL << register_fn->tgroup_id);
+
+ register_fn = spdk_trace_get_next_register_fn(register_fn);
+ }
+ } else {
+ while (register_fn) {
+ if (strcmp(group_name, register_fn->name) == 0) {
+ break;
+ }
+
+ register_fn = spdk_trace_get_next_register_fn(register_fn);
+ }
+
+ if (register_fn != NULL) {
+ tpoint_group_mask |= (1UL << register_fn->tgroup_id);
+ }
+ }
+
+ return tpoint_group_mask;
+}
+
+int
+spdk_trace_enable_tpoint_group(const char *group_name)
+{
+ uint64_t tpoint_group_mask = 0;
+
+ tpoint_group_mask = trace_create_tpoint_group_mask(group_name);
+ if (tpoint_group_mask == 0) {
+ return -1;
+ }
+
+ spdk_trace_set_tpoint_group_mask(tpoint_group_mask);
+ return 0;
+}
+
+int
+spdk_trace_disable_tpoint_group(const char *group_name)
+{
+ uint64_t tpoint_group_mask = 0;
+
+ tpoint_group_mask = trace_create_tpoint_group_mask(group_name);
+ if (tpoint_group_mask == 0) {
+ return -1;
+ }
+
+ spdk_trace_clear_tpoint_group_mask(tpoint_group_mask);
+ return 0;
+}
+
+void
+spdk_trace_mask_usage(FILE *f, const char *tmask_arg)
+{
+ struct spdk_trace_register_fn *register_fn;
+
+ fprintf(f, " %s, --tpoint-group-mask <mask>\n", tmask_arg);
+ fprintf(f, " tracepoint group mask for spdk trace buffers (default 0x0");
+
+ register_fn = g_reg_fn_head;
+ while (register_fn) {
+ fprintf(f, ", %s 0x%x", register_fn->name, 1 << register_fn->tgroup_id);
+ register_fn = register_fn->next;
+ }
+
+ fprintf(f, ", all 0xffff)\n");
+}
+
+void
+spdk_trace_register_owner(uint8_t type, char id_prefix)
+{
+ struct spdk_trace_owner *owner;
+
+ assert(type != OWNER_NONE);
+
+ /* 'owner' has 256 entries and since 'type' is a uint8_t, it
+ * can't overrun the array.
+ */
+ owner = &g_trace_flags->owner[type];
+ assert(owner->type == 0);
+
+ owner->type = type;
+ owner->id_prefix = id_prefix;
+}
+
+void
+spdk_trace_register_object(uint8_t type, char id_prefix)
+{
+ struct spdk_trace_object *object;
+
+ assert(type != OBJECT_NONE);
+
+ /* 'object' has 256 entries and since 'type' is a uint8_t, it
+ * can't overrun the array.
+ */
+ object = &g_trace_flags->object[type];
+ assert(object->type == 0);
+
+ object->type = type;
+ object->id_prefix = id_prefix;
+}
+
+void
+spdk_trace_register_description(const char *name, uint16_t tpoint_id, uint8_t owner_type,
+ uint8_t object_type, uint8_t new_object,
+ uint8_t arg1_type, const char *arg1_name)
+{
+ struct spdk_trace_tpoint *tpoint;
+
+ assert(tpoint_id != 0);
+ assert(tpoint_id < SPDK_TRACE_MAX_TPOINT_ID);
+
+ if (strnlen(name, sizeof(tpoint->name)) == sizeof(tpoint->name)) {
+ SPDK_ERRLOG("name (%s) too long\n", name);
+ }
+
+ tpoint = &g_trace_flags->tpoint[tpoint_id];
+ assert(tpoint->tpoint_id == 0);
+
+ snprintf(tpoint->name, sizeof(tpoint->name), "%s", name);
+ tpoint->tpoint_id = tpoint_id;
+ tpoint->object_type = object_type;
+ tpoint->owner_type = owner_type;
+ tpoint->new_object = new_object;
+ tpoint->arg1_type = arg1_type;
+ snprintf(tpoint->arg1_name, sizeof(tpoint->arg1_name), "%s", arg1_name);
+}
+
+void
+spdk_trace_add_register_fn(struct spdk_trace_register_fn *reg_fn)
+{
+ struct spdk_trace_register_fn *_reg_fn;
+
+ if (reg_fn->name == NULL) {
+ SPDK_ERRLOG("missing name for registering spdk trace tpoint group\n");
+ assert(false);
+ return;
+ }
+
+ if (strcmp(reg_fn->name, "all") == 0) {
+ SPDK_ERRLOG("illegal name (%s) for tpoint group\n", reg_fn->name);
+ assert(false);
+ return;
+ }
+
+ /* Ensure that no trace point group IDs and names are ever duplicated */
+ for (_reg_fn = g_reg_fn_head; _reg_fn; _reg_fn = _reg_fn->next) {
+ if (reg_fn->tgroup_id == _reg_fn->tgroup_id) {
+ SPDK_ERRLOG("duplicate tgroup_id (%d) with %s\n", _reg_fn->tgroup_id, _reg_fn->name);
+ assert(false);
+ return;
+ }
+
+ if (strcmp(reg_fn->name, _reg_fn->name) == 0) {
+ SPDK_ERRLOG("duplicate name with %s\n", _reg_fn->name);
+ assert(false);
+ return;
+ }
+ }
+
+ /* Arrange trace registration in order on tgroup_id */
+ if (g_reg_fn_head == NULL || reg_fn->tgroup_id < g_reg_fn_head->tgroup_id) {
+ reg_fn->next = g_reg_fn_head;
+ g_reg_fn_head = reg_fn;
+ return;
+ }
+
+ for (_reg_fn = g_reg_fn_head; _reg_fn; _reg_fn = _reg_fn->next) {
+ if (_reg_fn->next == NULL || reg_fn->tgroup_id < _reg_fn->next->tgroup_id) {
+ reg_fn->next = _reg_fn->next;
+ _reg_fn->next = reg_fn;
+ return;
+ }
+ }
+}
+
+void
+spdk_trace_flags_init(void)
+{
+ struct spdk_trace_register_fn *reg_fn;
+
+ reg_fn = g_reg_fn_head;
+ while (reg_fn) {
+ reg_fn->reg_fn();
+ reg_fn = reg_fn->next;
+ }
+}
diff --git a/src/spdk/lib/trace/trace_rpc.c b/src/spdk/lib/trace/trace_rpc.c
new file mode 100644
index 000000000..90dbfbc60
--- /dev/null
+++ b/src/spdk/lib/trace/trace_rpc.c
@@ -0,0 +1,170 @@
+/*-
+ * BSD LICENSE
+ *
+ * Copyright (c) Intel Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "spdk/rpc.h"
+#include "spdk/util.h"
+#include "spdk/trace.h"
+#include "spdk_internal/log.h"
+
+struct rpc_tpoint_group {
+ char *name;
+};
+
+static void
+free_rpc_tpoint_group(struct rpc_tpoint_group *p)
+{
+ free(p->name);
+}
+
+static const struct spdk_json_object_decoder rpc_tpoint_group_decoders[] = {
+ {"name", offsetof(struct rpc_tpoint_group, name), spdk_json_decode_string},
+};
+
+static void
+rpc_trace_enable_tpoint_group(struct spdk_jsonrpc_request *request,
+ const struct spdk_json_val *params)
+{
+ struct rpc_tpoint_group req = {};
+ struct spdk_json_write_ctx *w;
+
+ if (spdk_json_decode_object(params, rpc_tpoint_group_decoders,
+ SPDK_COUNTOF(rpc_tpoint_group_decoders), &req)) {
+ SPDK_DEBUGLOG(SPDK_LOG_TRACE, "spdk_json_decode_object failed\n");
+ goto invalid;
+ }
+
+ if (req.name == NULL) {
+ SPDK_DEBUGLOG(SPDK_LOG_TRACE, "flag was NULL\n");
+ goto invalid;
+ }
+
+ if (spdk_trace_enable_tpoint_group(req.name)) {
+ goto invalid;
+ }
+
+ free_rpc_tpoint_group(&req);
+
+ w = spdk_jsonrpc_begin_result(request);
+ spdk_json_write_bool(w, true);
+ spdk_jsonrpc_end_result(request, w);
+ return;
+
+invalid:
+ spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
+ free_rpc_tpoint_group(&req);
+}
+SPDK_RPC_REGISTER("trace_enable_tpoint_group", rpc_trace_enable_tpoint_group,
+ SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME)
+SPDK_RPC_REGISTER_ALIAS_DEPRECATED(trace_enable_tpoint_group, enable_tpoint_group)
+
+static void
+rpc_trace_disable_tpoint_group(struct spdk_jsonrpc_request *request,
+ const struct spdk_json_val *params)
+{
+ struct rpc_tpoint_group req = {};
+ struct spdk_json_write_ctx *w;
+
+ if (spdk_json_decode_object(params, rpc_tpoint_group_decoders,
+ SPDK_COUNTOF(rpc_tpoint_group_decoders), &req)) {
+ SPDK_DEBUGLOG(SPDK_LOG_TRACE, "spdk_json_decode_object failed\n");
+ goto invalid;
+ }
+
+ if (req.name == NULL) {
+ SPDK_DEBUGLOG(SPDK_LOG_TRACE, "flag was NULL\n");
+ goto invalid;
+ }
+
+ if (spdk_trace_disable_tpoint_group(req.name)) {
+ goto invalid;
+ }
+
+ free_rpc_tpoint_group(&req);
+
+ w = spdk_jsonrpc_begin_result(request);
+ spdk_json_write_bool(w, true);
+ spdk_jsonrpc_end_result(request, w);
+ return;
+
+invalid:
+ spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
+ free_rpc_tpoint_group(&req);
+}
+SPDK_RPC_REGISTER("trace_disable_tpoint_group", rpc_trace_disable_tpoint_group,
+ SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME)
+SPDK_RPC_REGISTER_ALIAS_DEPRECATED(trace_disable_tpoint_group, disable_tpoint_group)
+
+static void
+rpc_trace_get_tpoint_group_mask(struct spdk_jsonrpc_request *request,
+ const struct spdk_json_val *params)
+{
+ uint64_t tpoint_group_mask;
+ char mask_str[7];
+ bool enabled;
+ struct spdk_json_write_ctx *w;
+ struct spdk_trace_register_fn *register_fn;
+
+ if (params != NULL) {
+ spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
+ "trace_get_tpoint_group_mask requires no parameters");
+ return;
+ }
+
+ w = spdk_jsonrpc_begin_result(request);
+ tpoint_group_mask = spdk_trace_get_tpoint_group_mask();
+
+ spdk_json_write_object_begin(w);
+
+ snprintf(mask_str, sizeof(mask_str), "0x%lx", tpoint_group_mask);
+ spdk_json_write_named_string(w, "tpoint_group_mask", mask_str);
+
+ register_fn = spdk_trace_get_first_register_fn();
+ while (register_fn) {
+ enabled = spdk_trace_get_tpoint_mask(register_fn->tgroup_id) != 0;
+
+ spdk_json_write_named_object_begin(w, register_fn->name);
+ spdk_json_write_named_bool(w, "enabled", enabled);
+
+ snprintf(mask_str, sizeof(mask_str), "0x%lx", (1UL << register_fn->tgroup_id));
+ spdk_json_write_named_string(w, "mask", mask_str);
+ spdk_json_write_object_end(w);
+
+ register_fn = spdk_trace_get_next_register_fn(register_fn);
+ }
+
+ spdk_json_write_object_end(w);
+ spdk_jsonrpc_end_result(request, w);
+}
+SPDK_RPC_REGISTER("trace_get_tpoint_group_mask", rpc_trace_get_tpoint_group_mask,
+ SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME)
+SPDK_RPC_REGISTER_ALIAS_DEPRECATED(trace_get_tpoint_group_mask, get_tpoint_group_mask)