[v6,13/33] eal/trace: implement registration payload

Message ID 20200419100133.3232316-14-jerinj@marvell.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series DPDK Trace support |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK

Commit Message

Jerin Jacob Kollanukkaran April 19, 2020, 10:01 a.m. UTC
  From: Jerin Jacob <jerinj@marvell.com>

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 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 <jerinj@marvell.com>
Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
 lib/librte_eal/common/eal_common_trace.c      | 19 +++++++++++++++++++
 lib/librte_eal/include/rte_trace_point.h      | 19 +++++++++++++++++++
 .../include/rte_trace_point_register.h        | 19 +++++++++++++++++++
 lib/librte_eal/rte_eal_version.map            |  1 +
 4 files changed, 58 insertions(+)
  

Patch

diff --git a/lib/librte_eal/common/eal_common_trace.c b/lib/librte_eal/common/eal_common_trace.c
index e8e1bc693..d55a23df1 100644
--- a/lib/librte_eal/common/eal_common_trace.c
+++ b/lib/librte_eal/common/eal_common_trace.c
@@ -385,6 +385,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 8e37f971e..f4e6d7e42 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 b21302c3d..3f61f8346 100644
--- a/lib/librte_eal/include/rte_trace_point_register.h
+++ b/lib/librte_eal/include/rte_trace_point_register.h
@@ -17,4 +17,23 @@  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 b4b3a92e5..8b51c8a5b 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;