Skip to contentSkip to conversation

Define tracepoint callback only if TRACEPOINT_DEFINE defined

PATCH Mathieu Desnoyers 2 participants 2 messages Mar 13, 2014 – Mar 14, 2014 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

----- Original Message -----

Quoted 26 lines

From: "Zifei Tong" <[email protected]>
To: "mathieu desnoyers" <[email protected]>
Cc: [email protected], "Zifei Tong" <[email protected]>
Sent: Wednesday, March 12, 2014 5:40:37 AM
Subject: [PATCH] Define tracepoint callback only if TRACEPOINT_DEFINE defined

Compiling tracepoint providers in clang will result in 'Wunused-function' warning, since tracepoint callbacks are defined but never called.

lttng-gen-tp is also updated to not put TRACEPOINT_DEFINE in generated headers.

Fixes #760

---
 doc/examples/gen-tp/sample.c |  1 +
 include/lttng/tracepoint.h   | 13 ++++++++++---
 tools/lttng-gen-tp           |  1 -
 3 files changed, 11 insertions(+), 4 deletions(-)
doc/examples/gen-tp/sample.c +0 -0
index dab6e7d..ae22f28 100644

doc/examples/gen-tp/sample.c line 26

Quoted 4 lines
doc/examples/gen-tp/sample.c +1 -0
@@ -23,6 +23,7 @@
 
 #include <unistd.h>
 
+#define TRACEPOINT_DEFINE

Hrm, so this requires end users to change the way to use lttng-gen-tp. I'm not sure I like that at all. This means changes in the way people do instrumentation, and I'm trying really hard not to break that.

Quoted 8 lines
doc/examples/gen-tp/sample.c +0 -0
 #include "sample_tracepoint.h"
 int main(int argc, char **argv)
 {
include/lttng/tracepoint.h +0 -0
index 66e2abd..462a0fc 100644

include/lttng/tracepoint.h extern "C" { · line 153

Quoted 6 lines
include/lttng/tracepoint.h +1 -2
@@ -150,8 +150,8 @@ extern "C" {
  * between caller's ip addresses within the probe using the return
  * address.
  */
-#define _DECLARE_TRACEPOINT(_provider, _name, ...)			 		\
-extern struct tracepoint __tracepoint_##_provider##___##_name;				\
+#if defined(TRACEPOINT_DEFINE)

So you are adding a ifdef conditional to skip creation of a macro that defines static inline functions. What is it achieving really other than silencing a compiler warning ? Anyway the compiler will optimize those static inline away if they are not used.

I think this is a case where we might want to use __attribute__((unused)) to just shut up the clang warning.

Thoughts ?

Thanks,

Mathieu

Quoted 38 lines
include/lttng/tracepoint.h +1 -0
+#define _DECLARE_TRACEPOINT_CB(_provider, _name, ...)			 		\
 static inline __attribute__((always_inline)) lttng_ust_notrace				\
 void __tracepoint_cb_##_provider##___##_name(_TP_ARGS_PROTO(__VA_ARGS__));
 		\

static \

include/lttng/tracepoint.h +8 -1
@@ -174,7 +174,14 @@ void
 __tracepoint_cb_##_provider##___##_name(_TP_ARGS_PROTO(__VA_ARGS__))		\
 	} while ((++__tp_probe)->func);							\
 end:											\
 	tp_rcu_read_unlock_bp();							\
-}											\
+}
+#else
+#define _DECLARE_TRACEPOINT_CB(_provider, _name, ...)
+#endif
+
+#define _DECLARE_TRACEPOINT(_provider, _name, ...)			 		\
+extern struct tracepoint __tracepoint_##_provider##___##_name;				\
+_DECLARE_TRACEPOINT_CB(_provider, _name, __VA_ARGS__)			 		\
 static inline lttng_ust_notrace								\
 void __tracepoint_register_##_provider##___##_name(char *name,				\
include/lttng/tracepoint.h +0 -0
 		void (*func)(void), void *data);					\
tools/lttng-gen-tp +0 -2
index c49e8a5..ff8c22d 100755
@@ -69,7 +69,6 @@ class CFile:
 /*
  * The header containing our TRACEPOINT_EVENTs.
  */
-#define TRACEPOINT_DEFINE
 #include "{headerFilename}"
 """
     def __init__(self, filename, template):
--

1.9.0

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 22 lines · Mathieu Desnoyers

----- Original Message -----

Quoted 21 lines

From: "Zifei Tong" <[email protected]>
To: "mathieu desnoyers" <[email protected]>
Cc: [email protected], "Zifei Tong" <[email protected]>
Sent: Wednesday, March 12, 2014 5:40:37 AM
Subject: [PATCH] Define tracepoint callback only if TRACEPOINT_DEFINE defined

Compiling tracepoint providers in clang will result in 'Wunused-function' warning, since tracepoint callbacks are defined but never called.

lttng-gen-tp is also updated to not put TRACEPOINT_DEFINE in generated headers.

Fixes #760

---
 doc/examples/gen-tp/sample.c |  1 +
 include/lttng/tracepoint.h   | 13 ++++++++++---
 tools/lttng-gen-tp           |  1 -
 3 files changed, 11 insertions(+), 4 deletions(-)
Quoted 16 lines

include/lttng/tracepoint.h extern "C" { · line 153

Quoted 11 lines
include/lttng/tracepoint.h +1 -2
index 66e2abd..462a0fc 100644
@@ -150,8 +150,8 @@ extern "C" {
  * between caller's ip addresses within the probe using the return
  * address.
  */
-#define _DECLARE_TRACEPOINT(_provider, _name, ...)                                   \
-extern struct tracepoint __tracepoint_##_provider##___##_name;                               \
+#if defined(TRACEPOINT_DEFINE)

So you are adding a ifdef conditional to skip creation of a macro that defines static inline functions. What is it achieving really other than silencing a compiler warning ? Anyway the compiler will optimize those static inline away if they are not used.

I just want to get rid of these warnings (I am little bit paranoid for compiler warnings especially for clang's colorful ones :D). I think these warnings result from compiling a simple 'hello-world' tracepoint provider are annoying and confusing.

Quoted 2 lines

I think this is a case where we might want to use __attribute__((unused)) to just shut up the clang warning.

Yes, with __attribute__((unused)), a one-line patch would be enough to silence these warnings.
And I've tested with clang, __attribute__((unused)) works well.

Quoted 6 lines
Quoted 6 lines
doc/examples/gen-tp/sample.c +0 -0
index dab6e7d..ae22f28 100644
@@ -23,6 +23,7 @@
 
Quoted 11 lines

doc/examples/gen-tp/sample.c line 26

Quoted 3 lines
doc/examples/gen-tp/sample.c +1 -0
 #include <unistd.h>
 
+#define TRACEPOINT_DEFINE

Hrm, so this requires end users to change the way to use lttng-gen-tp. I'm not sure I like that at all. This means changes in the way people do instrumentation, and I'm trying really hard not to break that.

Quoted 3 lines
doc/examples/gen-tp/sample.c +0 -0
 #include "sample_tracepoint.h"
 int main(int argc, char **argv)
 {

There is no need to change lttng-gen-tp anymore.

I'll send a new simple patch for your review.

Thank you!
Zifei Tong

Quoted 49 lines

Thoughts ?

Thanks,

Mathieu

Quoted 35 lines
doc/examples/gen-tp/sample.c +9 -1
+#define _DECLARE_TRACEPOINT_CB(_provider, _name, ...)                                        \
 static inline __attribute__((always_inline)) lttng_ust_notrace                               \
 void __tracepoint_cb_##_provider##___##_name(_TP_ARGS_PROTO(__VA_ARGS__));
              \
 static                                                                                       \
@@ -174,7 +174,14 @@ void
 __tracepoint_cb_##_provider##___##_name(_TP_ARGS_PROTO(__VA_ARGS__))          \
      } while ((++__tp_probe)->func);                                                 \
 end:                                                                                 \
      tp_rcu_read_unlock_bp();                                                        \
-}                                                                                    \
+}
+#else
+#define _DECLARE_TRACEPOINT_CB(_provider, _name, ...)
+#endif
+
+#define _DECLARE_TRACEPOINT(_provider, _name, ...)                                   \
+extern struct tracepoint __tracepoint_##_provider##___##_name;                               \
+_DECLARE_TRACEPOINT_CB(_provider, _name, __VA_ARGS__)                                        \
 static inline lttng_ust_notrace                                                              \
 void __tracepoint_register_##_provider##___##_name(char *name,                               \
              void (*func)(void), void *data);                                        \
tools/lttng-gen-tp +0 -2
index c49e8a5..ff8c22d 100755
@@ -69,7 +69,6 @@ class CFile:
 /*
  * The header containing our TRACEPOINT_EVENTs.
  */
-#define TRACEPOINT_DEFINE
 #include "{headerFilename}"
 """
     def __init__(self, filename, template):
--
Quoted 3 lines

1.9.0

--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com