[RFC V2 05/21] rv/include: Add tracing helper functions

From: Daniel Bristot de Oliveira
Date: Mon Feb 14 2022 - 06:16:29 EST


Tracing helper functions to facilitate the instrumentation of
auto-generated RV monitors create by dot2k.

Cc: Jonathan Corbet <corbet@xxxxxxx>
Cc: Steven Rostedt <rostedt@xxxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Will Deacon <will@xxxxxxxxxx>
Cc: Catalin Marinas <catalin.marinas@xxxxxxx>
Cc: Marco Elver <elver@xxxxxxxxxx>
Cc: Dmitry Vyukov <dvyukov@xxxxxxxxxx>
Cc: "Paul E. McKenney" <paulmck@xxxxxxxxxx>
Cc: Shuah Khan <skhan@xxxxxxxxxxxxxxxxxxx>
Cc: Gabriele Paoloni <gpaoloni@xxxxxxxxxx>
Cc: Juri Lelli <juri.lelli@xxxxxxxxxx>
Cc: Clark Williams <williams@xxxxxxxxxx>
Cc: linux-doc@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
Cc: linux-trace-devel@xxxxxxxxxxxxxxx
Signed-off-by: Daniel Bristot de Oliveira <bristot@xxxxxxxxxx>
---
include/rv/trace_helpers.h | 69 ++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+)
create mode 100644 include/rv/trace_helpers.h

diff --git a/include/rv/trace_helpers.h b/include/rv/trace_helpers.h
new file mode 100644
index 000000000000..440c681148a8
--- /dev/null
+++ b/include/rv/trace_helpers.h
@@ -0,0 +1,69 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Helper functions to facilitate the instrumentation of auto-generated
+ * RV monitors create by dot2k.
+ *
+ * The dot2k tool is available at tools/tracing/rv/dot2/
+ *
+ * Copyright (C) 2019-2022 Daniel Bristot de Oliveira <bristot@xxxxxxxxxx>
+ */
+
+#include <linux/ftrace.h>
+
+struct tracepoint_hook_helper {
+ struct tracepoint *tp;
+ void *probe;
+ int registered;
+ char *name;
+};
+
+static inline void thh_compare_name(struct tracepoint *tp, void *priv)
+{
+ struct tracepoint_hook_helper *thh = priv;
+
+ if (!strcmp(thh->name, tp->name))
+ thh->tp = tp;
+}
+
+static inline bool thh_fill_struct_tracepoint(struct tracepoint_hook_helper *thh)
+{
+ for_each_kernel_tracepoint(thh_compare_name, thh);
+
+ return !!thh->tp;
+}
+
+static inline void thh_unhook_probes(struct tracepoint_hook_helper *thh, int helpers_count)
+{
+ int i;
+
+ for (i = 0; i < helpers_count; i++) {
+ if (!thh[i].registered)
+ continue;
+
+ tracepoint_probe_unregister(thh[i].tp, thh[i].probe, NULL);
+ }
+}
+
+static inline int thh_hook_probes(struct tracepoint_hook_helper *thh, int helpers_count)
+{
+ int retval;
+ int i;
+
+ for (i = 0; i < helpers_count; i++) {
+ retval = thh_fill_struct_tracepoint(&thh[i]);
+ if (!retval)
+ goto out_err;
+
+ retval = tracepoint_probe_register(thh[i].tp, thh[i].probe, NULL);
+
+ if (retval)
+ goto out_err;
+
+ thh[i].registered = 1;
+ }
+ return 0;
+
+out_err:
+ thh_unhook_probes(thh, helpers_count);
+ return -EINVAL;
+}
--
2.33.1