From 63bf022b9309fc6541e6fb7b03119dd100855f40 Mon Sep 17 00:00:00 2001 From: Ed Rodriguez Date: Tue, 12 Sep 2017 10:50:24 -0400 Subject: [PATCH] trace: Move trace flags to separate implementation file Change-Id: Ibe31b961fec36644cf64716c512429d68e873e88 Signed-off-by: Ed rodriguez Reviewed-on: https://review.gerrithub.io/386170 Tested-by: SPDK Automated Test System Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- app/trace/trace.cpp | 12 +-- include/spdk/trace.h | 10 ++- lib/trace/Makefile | 2 +- lib/trace/trace.c | 141 ++---------------------------- lib/trace/trace_flags.c | 184 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 204 insertions(+), 145 deletions(-) create mode 100644 lib/trace/trace_flags.c diff --git a/app/trace/trace.cpp b/app/trace/trace.cpp index bc6ed6555..a31be6200 100644 --- a/app/trace/trace.cpp +++ b/app/trace/trace.cpp @@ -123,7 +123,7 @@ print_size(uint32_t size) static void print_object_id(uint8_t type, uint64_t id) { - printf("id: %c%-15jd ", g_histories->object[type].id_prefix, id); + printf("id: %c%-15jd ", g_histories->flags.object[type].id_prefix, id); } static void @@ -152,7 +152,7 @@ print_event(struct spdk_trace_entry *e, uint64_t tsc_rate, struct object_stats *stats; float us; - d = &g_histories->tpoint[e->tpoint_id]; + d = &g_histories->flags.tpoint[e->tpoint_id]; stats = &g_stats[d->object_type]; if (d->new_object) { @@ -171,8 +171,8 @@ print_event(struct spdk_trace_entry *e, uint64_t tsc_rate, us = get_us_from_tsc(e->tsc - tsc_offset, tsc_rate); printf("%2d: %10.3f (%9ju) ", lcore, us, e->tsc - tsc_offset); - if (g_histories->owner[d->owner_type].id_prefix) { - printf("%c%02d ", g_histories->owner[d->owner_type].id_prefix, e->poller_id); + if (g_histories->flags.owner[d->owner_type].id_prefix) { + printf("%c%02d ", g_histories->flags.owner[d->owner_type].id_prefix, e->poller_id); } else { printf("%4s", " "); } @@ -191,7 +191,7 @@ print_event(struct spdk_trace_entry *e, uint64_t tsc_rate, tsc_rate); print_object_id(d->object_type, stats->index[e->object_id]); print_float("time:", us); - start_description = &g_histories->tpoint[stats->tpoint_id[e->object_id]]; + start_description = &g_histories->flags.tpoint[stats->tpoint_id[e->object_id]]; if (start_description->short_name[0] != 0) { printf(" (%.4s)", start_description->short_name); } @@ -364,7 +364,7 @@ int main(int argc, char **argv) g_histories = (struct spdk_trace_histories *)history_ptr; - tsc_rate = g_histories->tsc_rate; + tsc_rate = g_histories->flags.tsc_rate; if (tsc_rate == 0) { fprintf(stderr, "Invalid tsc_rate %ju\n", tsc_rate); usage(); diff --git a/include/spdk/trace.h b/include/spdk/trace.h index a017498d6..518297f0b 100644 --- a/include/spdk/trace.h +++ b/include/spdk/trace.h @@ -114,16 +114,21 @@ struct spdk_trace_history { #define SPDK_TRACE_MAX_LCORE 128 -struct spdk_trace_histories { +struct spdk_trace_flags { uint64_t tsc_rate; uint64_t tpoint_mask[SPDK_TRACE_MAX_GROUP_ID]; - struct spdk_trace_history per_lcore_history[SPDK_TRACE_MAX_LCORE]; struct spdk_trace_owner owner[UCHAR_MAX + 1]; struct spdk_trace_object object[UCHAR_MAX + 1]; struct spdk_trace_tpoint tpoint[SPDK_TRACE_MAX_TPOINT_ID]; }; +extern struct spdk_trace_flags *g_trace_flags; +struct spdk_trace_histories { + struct spdk_trace_flags flags; + 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); @@ -144,6 +149,7 @@ void spdk_trace_set_tpoint_group_mask(uint64_t tpoint_group_mask); void spdk_trace_init(const char *shm_name); void spdk_trace_cleanup(void); +void spdk_trace_flags_init(void); #define OWNER_NONE 0 #define OBJECT_NONE 0 diff --git a/lib/trace/Makefile b/lib/trace/Makefile index 1cbdfbad4..507ffee95 100644 --- a/lib/trace/Makefile +++ b/lib/trace/Makefile @@ -35,7 +35,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..) include $(SPDK_ROOT_DIR)/mk/spdk.common.mk CFLAGS += $(ENV_CFLAGS) -C_SRCS = trace.c +C_SRCS = trace.c trace_flags.c LIBNAME = trace include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk diff --git a/lib/trace/trace.c b/lib/trace/trace.c index 0f076444e..70de1e0cf 100644 --- a/lib/trace/trace.c +++ b/lib/trace/trace.c @@ -43,7 +43,6 @@ static char g_shm_name[64]; static struct spdk_trace_histories *g_trace_histories; -static struct spdk_trace_register_fn *g_reg_fn_head = NULL; void spdk_trace_record(uint16_t tpoint_id, uint16_t poller_id, uint32_t size, @@ -60,7 +59,7 @@ spdk_trace_record(uint16_t tpoint_id, uint16_t poller_id, uint32_t size, * tracepoint group has its own tracepoint mask. */ if (g_trace_histories == NULL || - !((1ULL << (tpoint_id & 0x3F)) & g_trace_histories->tpoint_mask[tpoint_id >> 6])) { + !((1ULL << (tpoint_id & 0x3F)) & g_trace_histories->flags.tpoint_mask[tpoint_id >> 6])) { return; } @@ -87,70 +86,9 @@ spdk_trace_record(uint16_t tpoint_id, uint16_t poller_id, uint32_t size, lcore_history->next_entry = 0; } -uint64_t -spdk_trace_get_tpoint_mask(uint32_t group_id) -{ - if (group_id >= SPDK_TRACE_MAX_GROUP_ID) { - fprintf(stderr, "%s: invalid group ID %d\n", __func__, group_id); - return 0ULL; - } - - return g_trace_histories->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) { - fprintf(stderr, "%s: invalid group ID %d\n", __func__, group_id); - return; - } - - g_trace_histories->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) { - fprintf(stderr, "%s: invalid group ID %d\n", __func__, group_id); - return; - } - - g_trace_histories->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 < 64; 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 < 64; i++) { - if (tpoint_group_mask & (1ULL << i)) { - spdk_trace_set_tpoints(i, -1ULL); - } - } -} - void spdk_trace_init(const char *shm_name) { - struct spdk_trace_register_fn *reg_fn; int trace_fd; int i = 0; char buf[64]; @@ -179,17 +117,15 @@ spdk_trace_init(const char *shm_name) memset(g_trace_histories, 0, sizeof(*g_trace_histories)); - g_trace_histories->tsc_rate = spdk_get_ticks_hz(); + 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++) { g_trace_histories->per_lcore_history[i].lcore = i; } - reg_fn = g_reg_fn_head; - while (reg_fn) { - reg_fn->reg_fn(); - reg_fn = reg_fn->next; - } + spdk_trace_flags_init(); } void @@ -198,70 +134,3 @@ spdk_trace_cleanup(void) munmap(g_trace_histories, sizeof(struct spdk_trace_histories)); shm_unlink(g_shm_name); } - -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_histories->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_histories->object[type]; - assert(object->type == 0); - - object->type = type; - object->id_prefix = id_prefix; -} - -void -spdk_trace_register_description(const char *name, const char *short_name, - uint16_t tpoint_id, uint8_t owner_type, - uint8_t object_type, uint8_t new_object, - uint8_t arg1_is_ptr, uint8_t arg1_is_alias, - const char *arg1_name) -{ - struct spdk_trace_tpoint *tpoint; - - assert(tpoint_id != 0); - assert(tpoint_id < SPDK_TRACE_MAX_TPOINT_ID); - - tpoint = &g_trace_histories->tpoint[tpoint_id]; - assert(tpoint->tpoint_id == 0); - - snprintf(tpoint->name, sizeof(tpoint->name), "%s", name); - snprintf(tpoint->short_name, sizeof(tpoint->short_name), "%s", short_name); - tpoint->tpoint_id = tpoint_id; - tpoint->object_type = object_type; - tpoint->owner_type = owner_type; - tpoint->new_object = new_object; - tpoint->arg1_is_ptr = arg1_is_ptr; - tpoint->arg1_is_alias = arg1_is_alias; - snprintf(tpoint->arg1_name, sizeof(tpoint->arg1_name), "%s", arg1_name); -} - -void -spdk_trace_add_register_fn(struct spdk_trace_register_fn *reg_fn) -{ - reg_fn->next = g_reg_fn_head; - g_reg_fn_head = reg_fn; -} diff --git a/lib/trace/trace_flags.c b/lib/trace/trace_flags.c new file mode 100644 index 000000000..03f58a805 --- /dev/null +++ b/lib/trace/trace_flags.c @@ -0,0 +1,184 @@ +/*- + * 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 +#include + +struct spdk_trace_flags *g_trace_flags = NULL; +static struct spdk_trace_register_fn *g_reg_fn_head = NULL; + +uint64_t +spdk_trace_get_tpoint_mask(uint32_t group_id) +{ + if (group_id >= SPDK_TRACE_MAX_GROUP_ID) { + SPDK_ERRLOG("%s: invalid group ID %d\n", __func__, 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("%s: invalid group ID %d\n", __func__, 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("%s: invalid group ID %d\n", __func__, 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 < 64; 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 < 64; i++) { + if (tpoint_group_mask & (1ULL << i)) { + spdk_trace_set_tpoints(i, -1ULL); + } + } +} + +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, const char *short_name, + uint16_t tpoint_id, uint8_t owner_type, + uint8_t object_type, uint8_t new_object, + uint8_t arg1_is_ptr, uint8_t arg1_is_alias, + const char *arg1_name) +{ + struct spdk_trace_tpoint *tpoint; + + assert(tpoint_id != 0); + assert(tpoint_id < SPDK_TRACE_MAX_TPOINT_ID); + + tpoint = &g_trace_flags->tpoint[tpoint_id]; + assert(tpoint->tpoint_id == 0); + + snprintf(tpoint->name, sizeof(tpoint->name), "%s", name); + snprintf(tpoint->short_name, sizeof(tpoint->short_name), "%s", short_name); + tpoint->tpoint_id = tpoint_id; + tpoint->object_type = object_type; + tpoint->owner_type = owner_type; + tpoint->new_object = new_object; + tpoint->arg1_is_ptr = arg1_is_ptr; + tpoint->arg1_is_alias = arg1_is_alias; + snprintf(tpoint->arg1_name, sizeof(tpoint->arg1_name), "%s", arg1_name); +} + +void +spdk_trace_add_register_fn(struct spdk_trace_register_fn *reg_fn) +{ + reg_fn->next = g_reg_fn_head; + g_reg_fn_head = reg_fn; +} + + +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; + } +}