From 0cd4ea043f3eb77a15e7a0a4c10977d203297149 Mon Sep 17 00:00:00 2001 From: Jerin Jacob Date: Thu, 23 Apr 2020 00:33:29 +0530 Subject: [PATCH] trace: implement registration payload The trace function payloads such as rte_trace_point_emit_* have dual functions. The first to emit the payload for the registration function and the second one to act as trace memory emitters. When it is used as registration payload, it will do the following to fulfill the registration job. - Find out the size of the event, - Generate metadata field string using __rte_trace_point_emit_field(). Signed-off-by: Jerin Jacob Signed-off-by: Sunil Kumar Kori Acked-by: David Marchand --- lib/librte_eal/common/eal_common_trace.c | 19 ++++++++++++++++++ lib/librte_eal/include/rte_trace_point.h | 19 ++++++++++++++++++ .../include/rte_trace_point_register.h | 20 +++++++++++++++++++ lib/librte_eal/rte_eal_version.map | 1 + 4 files changed, 59 insertions(+) diff --git a/lib/librte_eal/common/eal_common_trace.c b/lib/librte_eal/common/eal_common_trace.c index e82bb9e30f..da269debeb 100644 --- a/lib/librte_eal/common/eal_common_trace.c +++ b/lib/librte_eal/common/eal_common_trace.c @@ -378,6 +378,25 @@ trace_mem_per_thread_free(void) rte_spinlock_unlock(&trace->lock); } +void +__rte_trace_point_emit_field(size_t sz, const char *in, const char *datatype) +{ + char *field = RTE_PER_LCORE(ctf_field); + int count = RTE_PER_LCORE(ctf_count); + size_t size; + int rc; + + size = RTE_MAX(0, TRACE_CTF_FIELD_SIZE - 1 - count); + RTE_PER_LCORE(trace_point_sz) += sz; + rc = snprintf(RTE_PTR_ADD(field, count), size, "%s %s;", datatype, in); + if (rc <= 0 || (size_t)rc >= size) { + RTE_PER_LCORE(trace_point_sz) = 0; + trace_crit("CTF field is too long"); + return; + } + RTE_PER_LCORE(ctf_count) += rc; +} + int __rte_trace_point_register(rte_trace_point_t *handle, const char *name, void (*register_fn)(void)) diff --git a/lib/librte_eal/include/rte_trace_point.h b/lib/librte_eal/include/rte_trace_point.h index fc3d9c4f5d..34dcba3a63 100644 --- a/lib/librte_eal/include/rte_trace_point.h +++ b/lib/librte_eal/include/rte_trace_point.h @@ -236,6 +236,25 @@ __rte_trace_point_fp_is_enabled(void) __rte_experimental void __rte_trace_mem_per_thread_alloc(void); +/** + * @internal + * + * Helper function to emit field. + * + * @param sz + * The tracepoint size. + * @param field + * The name of the trace event. + * @param type + * The datatype of the trace event as string. + * @return + * - 0: Success. + * - <0: Failure. + */ +__rte_experimental +void __rte_trace_point_emit_field(size_t sz, const char *field, + const char *type); + /** * @internal * diff --git a/lib/librte_eal/include/rte_trace_point_register.h b/lib/librte_eal/include/rte_trace_point_register.h index 6c5872a3e6..4e2306f1af 100644 --- a/lib/librte_eal/include/rte_trace_point_register.h +++ b/lib/librte_eal/include/rte_trace_point_register.h @@ -17,4 +17,24 @@ RTE_DECLARE_PER_LCORE(volatile int, trace_point_sz); __rte_trace_point_register(&__##trace, RTE_STR(name), \ (void (*)(void)) trace) +#define __rte_trace_point_emit_header_generic(t) \ + RTE_PER_LCORE(trace_point_sz) = __RTE_TRACE_EVENT_HEADER_SZ + +#define __rte_trace_point_emit_header_fp(t) \ + __rte_trace_point_emit_header_generic(t) + +#define __rte_trace_point_emit(in, type) \ +do { \ + RTE_BUILD_BUG_ON(sizeof(type) != sizeof(typeof(in))); \ + __rte_trace_point_emit_field(sizeof(type), RTE_STR(in), \ + RTE_STR(type)); \ +} while (0) + +#define rte_trace_point_emit_string(in) \ +do { \ + RTE_SET_USED(in); \ + __rte_trace_point_emit_field(__RTE_TRACE_EMIT_STRING_LEN_MAX, \ + RTE_STR(in)"[32]", "string_bounded_t"); \ +} while (0) + #endif /* _RTE_TRACE_POINT_REGISTER_H_ */ diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index b4b3a92e5c..8b51c8a5b1 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -338,6 +338,7 @@ EXPERIMENTAL { # added in 20.05 __rte_trace_mem_per_thread_alloc; + __rte_trace_point_emit_field; __rte_trace_point_register; per_lcore_trace_mem; per_lcore_trace_point_sz; -- 2.20.1