From c681d76fb4159167b45447d7a1c3fd121ac15990 Mon Sep 17 00:00:00 2001 From: Konrad Sztyber Date: Mon, 14 Jun 2021 14:04:01 +0200 Subject: [PATCH] lib/trace: extract getting next entry to a helper function It allows us to get rid of the `next_circual_entry` variable and will make it easier to retrieve multiple trace entries, which will be needed in subsequent patches. Signed-off-by: Konrad Sztyber Change-Id: I4666c9da518c2ac0b376e10aa73d1c58cff91f13 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8403 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Shuhei Matsumoto Reviewed-by: Tomasz Zawadzki Reviewed-by: Jim Harris Reviewed-by: Krzysztof Karas --- lib/trace/trace.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/trace/trace.c b/lib/trace/trace.c index bbc8154db..4ec53e85c 100644 --- a/lib/trace/trace.c +++ b/lib/trace/trace.c @@ -45,6 +45,12 @@ static char g_shm_name[64]; struct spdk_trace_histories *g_trace_histories; +static inline struct spdk_trace_entry * +get_trace_entry(struct spdk_trace_history *history, uint64_t offset) +{ + return &history->entries[offset & (history->num_entries - 1)]; +} + void _spdk_trace_record(uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id, uint32_t size, uint64_t object_id, int num_args, ...) @@ -54,7 +60,7 @@ _spdk_trace_record(uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id, uint32_ struct spdk_trace_tpoint *tpoint; const char *strval; unsigned lcore, i, offset; - uint64_t intval, next_circular_entry; + uint64_t intval; va_list vl; lcore = spdk_env_get_current_core(); @@ -70,8 +76,7 @@ _spdk_trace_record(uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id, uint32_ 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 = get_trace_entry(lcore_history, lcore_history->next_entry); next_entry->tsc = tsc; next_entry->tpoint_id = tpoint_id; next_entry->poller_id = poller_id;