From cdb0726b95631d46eaf4f2e39ddb6533f150fd27 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Thu, 11 Aug 2022 05:34:47 +0000 Subject: [PATCH] trace, trace_parser: support 4-byte INT/PTR arguments This allows us to pack more arguments into the same amount of shared memory, for cases where those arguments don't need a full 8 bytes. 1- and 2-byte sizes not supported for now, variadic args do automatic promotion of types smaller than int, so support for those may need more work. Signed-off-by: Jim Harris Change-Id: Iec56cfa851b408a77d7995126d2111b0bf3d7f95 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13999 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Shuhei Matsumoto Reviewed-by: Ben Walker Reviewed-by: Dong Yi Reviewed-by: Jacek Kalwas Reviewed-by: Tomasz Zawadzki Reviewed-by: Aleksey Marchuk --- lib/trace/trace.c | 8 ++++++-- lib/trace/trace_flags.c | 4 ++-- lib/trace_parser/trace.cpp | 4 ++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/trace/trace.c b/lib/trace/trace.c index 3bc925471..f1fe8c019 100644 --- a/lib/trace/trace.c +++ b/lib/trace/trace.c @@ -82,9 +82,13 @@ _spdk_trace_record(uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id, uint32_ break; case SPDK_TRACE_ARG_TYPE_INT: case SPDK_TRACE_ARG_TYPE_PTR: - intval = va_arg(vl, uint64_t); + if (argument->size == 8) { + intval = va_arg(vl, uint64_t); + } else { + intval = va_arg(vl, uint32_t); + } argval = &intval; - arglen = sizeof(uint64_t); + arglen = argument->size; break; default: assert(0 && "Invalid trace argument type"); diff --git a/lib/trace/trace_flags.c b/lib/trace/trace_flags.c index 473bee5c1..cd3ea302d 100644 --- a/lib/trace/trace_flags.c +++ b/lib/trace/trace_flags.c @@ -289,8 +289,8 @@ trace_register_description(const struct spdk_trace_tpoint_opts *opts) switch (opts->args[i].type) { case SPDK_TRACE_ARG_TYPE_INT: case SPDK_TRACE_ARG_TYPE_PTR: - /* The integers and pointers have to be exactly 64b long */ - assert(opts->args[i].size == sizeof(uint64_t)); + /* The integers and pointers have to be exactly 4 or 8 bytes */ + assert(opts->args[i].size == 4 || opts->args[i].size == 8); break; case SPDK_TRACE_ARG_TYPE_STR: /* Strings need to have at least one byte for the NULL terminator */ diff --git a/lib/trace_parser/trace.cpp b/lib/trace_parser/trace.cpp index d3b4dc316..64b97122c 100644 --- a/lib/trace_parser/trace.cpp +++ b/lib/trace_parser/trace.cpp @@ -127,6 +127,10 @@ spdk_trace_parser::build_arg(argument_context *argctx, const spdk_trace_argument size_t curlen, argoff; argoff = 0; + /* Make sure that if we only copy a 4-byte integer, that the upper bytes have already been + * zeroed. + */ + pe->args[argid].integer = 0; while (argoff < arg->size) { if (argctx->offset == sizeof(buffer->data)) { buffer = get_next_buffer(buffer, argctx->lcore);