[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <2a0d1fbc53e153d9ee8299740b643207f6fc0dc7.1621414942.git.bristot@redhat.com>
Date: Wed, 19 May 2021 13:36:26 +0200
From: Daniel Bristot de Oliveira <bristot@...hat.com>
To: linux-kernel@...r.kernel.org, Steven Rostedt <rostedt@...dmis.org>
Cc: Tommaso Cucinotta <tommaso.cucinotta@...tannapisa.it>,
Kate Carcia <kcarcia@...hat.com>,
Daniel Bristot de Oliveira <bristot@...hat.com>,
Jonathan Corbet <corbet@....net>,
Ingo Molnar <mingo@...hat.com>,
Mauro Carvalho Chehab <mchehab@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>,
Peter Zijlstra <peterz@...radead.org>,
Will Deacon <will@...nel.org>,
Catalin Marinas <catalin.marinas@....com>,
"Paul E. McKenney" <paulmck@...nel.org>,
Joel Fernandes <joel@...lfernandes.org>,
Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
Gabriele Paoloni <gabriele.paoloni@...el.com>,
Juri Lelli <juri.lelli@...hat.com>,
Clark Williams <williams@...hat.com>, linux-doc@...r.kernel.org
Subject: [RFC PATCH 05/16] rv/include: Add tracing helper functions
Tracing helper functions to facilitate the instrumentation of
auto-generated RV monitors create by dot2k.
Cc: Jonathan Corbet <corbet@....net>
Cc: Steven Rostedt <rostedt@...dmis.org>
Cc: Ingo Molnar <mingo@...hat.com>
Cc: Mauro Carvalho Chehab <mchehab@...nel.org>
Cc: Thomas Gleixner <tglx@...utronix.de>
Cc: Peter Zijlstra <peterz@...radead.org>
Cc: Will Deacon <will@...nel.org>
Cc: Catalin Marinas <catalin.marinas@....com>
Cc: "Paul E. McKenney" <paulmck@...nel.org>
Cc: Joel Fernandes <joel@...lfernandes.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@...icios.com>
Cc: Gabriele Paoloni <gabriele.paoloni@...el.com>
Cc: Juri Lelli <juri.lelli@...hat.com>
Cc: Clark Williams <williams@...hat.com>
Cc: linux-doc@...r.kernel.org
Cc: linux-kernel@...r.kernel.org
Signed-off-by: Daniel Bristot de Oliveira <bristot@...hat.com>
---
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..1a8b6f246d0d
--- /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-2021 Daniel Bristot de Oliveira <bristot@...hat.com>
+ */
+
+#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.26.2
Powered by blists - more mailing lists