From 3e7356580b2de51e75375c0188342e1356b1f4d9 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Fri, 31 Aug 2018 14:02:11 -0700 Subject: [PATCH] trace: inline tpoint_mask checking This reduces overhead of spdk_trace_record calls when tracing is not enabled. While here, remove a couple of unit test stubs for spdk_trace_record that weren't needed anymore. Signed-off-by: Jim Harris Change-Id: I2cbb91e7d3311d95444d663f466d846676d2dcce Reviewed-on: https://review.gerrithub.io/424276 Tested-by: SPDK CI Jenkins Chandler-Test-Pool: SPDK Automated Test System Reviewed-by: Changpeng Liu Reviewed-by: Shuhei Matsumoto Reviewed-by: Ben Walker --- include/spdk/trace.h | 20 ++++++++++++++++++- lib/trace/trace.c | 16 +++------------ .../lib/nvmf/ctrlr_bdev.c/ctrlr_bdev_ut.c | 6 ------ test/unit/lib/nvmf/request.c/request_ut.c | 5 ----- test/unit/lib/scsi/lun.c/lun_ut.c | 5 +++-- 5 files changed, 25 insertions(+), 27 deletions(-) diff --git a/include/spdk/trace.h b/include/spdk/trace.h index b897383eb..906a143cf 100644 --- a/include/spdk/trace.h +++ b/include/spdk/trace.h @@ -122,6 +122,7 @@ struct spdk_trace_flags { struct spdk_trace_tpoint tpoint[SPDK_TRACE_MAX_TPOINT_ID]; }; extern struct spdk_trace_flags *g_trace_flags; +extern struct spdk_trace_histories *g_trace_histories; struct spdk_trace_histories { @@ -129,6 +130,9 @@ struct spdk_trace_histories { struct spdk_trace_history per_lcore_history[SPDK_TRACE_MAX_LCORE]; }; +void _spdk_trace_record(uint16_t tpoint_id, uint16_t poller_id, + uint32_t size, uint64_t object_id, uint64_t arg1); + /** * Record the current trace state for tracing tpoints. Debug tool can read the * information from shared memory to post-process the tpoint entries and display @@ -140,8 +144,22 @@ struct spdk_trace_histories { * \param object_id Object id to record. * \param arg1 Argument to record. */ +static inline void spdk_trace_record(uint16_t tpoint_id, uint16_t poller_id, uint32_t size, - uint64_t object_id, uint64_t arg1); + uint64_t object_id, uint64_t arg1) +{ + /* + * Tracepoint group ID is encoded in the tpoint_id. Lower 6 bits determine the tracepoint + * within the group, the remaining upper bits determine the tracepoint group. Each + * tracepoint group has its own tracepoint mask. + */ + if (g_trace_histories == NULL || + !((1ULL << (tpoint_id & 0x3F)) & g_trace_histories->flags.tpoint_mask[tpoint_id >> 6])) { + return; + } + + _spdk_trace_record(tpoint_id, poller_id, size, object_id, arg1); +} /** * Get the current tpoint mask of the given tpoint group. diff --git a/lib/trace/trace.c b/lib/trace/trace.c index fe180032d..0cfeea831 100644 --- a/lib/trace/trace.c +++ b/lib/trace/trace.c @@ -40,27 +40,17 @@ static int g_trace_fd = -1; static char g_shm_name[64]; -static struct spdk_trace_histories *g_trace_histories; +struct spdk_trace_histories *g_trace_histories; void -spdk_trace_record(uint16_t tpoint_id, uint16_t poller_id, uint32_t size, - uint64_t object_id, uint64_t arg1) +_spdk_trace_record(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; uint64_t tsc; unsigned lcore; - /* - * Tracepoint group ID is encoded in the tpoint_id. Lower 6 bits determine the tracepoint - * within the group, the remaining upper bits determine the tracepoint group. Each - * tracepoint group has its own tracepoint mask. - */ - if (g_trace_histories == NULL || - !((1ULL << (tpoint_id & 0x3F)) & g_trace_histories->flags.tpoint_mask[tpoint_id >> 6])) { - return; - } - lcore = spdk_env_get_current_core(); if (lcore >= SPDK_TRACE_MAX_LCORE) { return; diff --git a/test/unit/lib/nvmf/ctrlr_bdev.c/ctrlr_bdev_ut.c b/test/unit/lib/nvmf/ctrlr_bdev.c/ctrlr_bdev_ut.c index 8d77de893..1085e4d7d 100644 --- a/test/unit/lib/nvmf/ctrlr_bdev.c/ctrlr_bdev_ut.c +++ b/test/unit/lib/nvmf/ctrlr_bdev.c/ctrlr_bdev_ut.c @@ -95,12 +95,6 @@ spdk_bdev_unmap_blocks(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch, return 0; } -void -spdk_trace_record(uint16_t tpoint_id, uint16_t poller_id, uint32_t size, uint64_t object_id, - uint64_t arg1) -{ -} - bool spdk_bdev_io_type_supported(struct spdk_bdev *bdev, enum spdk_bdev_io_type io_type) { diff --git a/test/unit/lib/nvmf/request.c/request_ut.c b/test/unit/lib/nvmf/request.c/request_ut.c index c37e917b0..bd21fa634 100644 --- a/test/unit/lib/nvmf/request.c/request_ut.c +++ b/test/unit/lib/nvmf/request.c/request_ut.c @@ -39,11 +39,6 @@ SPDK_LOG_REGISTER_COMPONENT("nvmf", SPDK_LOG_NVMF) -void spdk_trace_record(uint16_t tpoint_id, uint16_t poller_id, uint32_t size, - uint64_t object_id, uint64_t arg1) -{ -} - int spdk_nvmf_transport_req_free(struct spdk_nvmf_request *req) { diff --git a/test/unit/lib/scsi/lun.c/lun_ut.c b/test/unit/lib/scsi/lun.c/lun_ut.c index 1381013ab..d8a431f44 100644 --- a/test/unit/lib/scsi/lun.c/lun_ut.c +++ b/test/unit/lib/scsi/lun.c/lun_ut.c @@ -71,8 +71,9 @@ spdk_thread_send_msg(const struct spdk_thread *thread, spdk_thread_fn fn, void * { } -void spdk_trace_record(uint16_t tpoint_id, uint16_t poller_id, uint32_t size, - uint64_t object_id, uint64_t arg1) +struct spdk_trace_histories *g_trace_histories; +void _spdk_trace_record(uint16_t tpoint_id, uint16_t poller_id, + uint32_t size, uint64_t object_id, uint64_t arg1) { }