Skip to contentSkip to conversation

tracing: Let tracepoints have data passed to tracepoint callbacks

RFC PATCH Steven Rostedt 2 participants 7 messages May 7, 2010

lore
Share & tools
lore
#0 lore raw
Quoted 140 lines · Frederic Weisbecker
Quoted 139 lines · Steven Rostedt

From: Steven Rostedt <[email protected]>

This patch allows data to be passed to the tracepoint callbacks if the tracepoint was created to do so.

The DECLARE_TRACE() now adds two new functions:

register_trace_mytracepoint_data()
unregister_trace_mytracepoint_data()

These two are the same as the original

register_trace_mytracepoint()
unregister_trace_mytracepoint()

But now allow you to pass a private data pointer that will be passed to the callback handle. For example:

DECLARE_TRACE(mytracepoint, int value, value);

will create a function called trace_mytracepoint()

	void trace_mytracepoint(int value);

If the user wants to pass data to register a function to this tracepoint and have data also passed to this callback, they can use:

	int mycallback(int value, void *data);

	register_trace_mytracepoint_data(mycallback, mydata);

Then the mycallback() will receive the "mydata" as the parameter after the args.

A more detailed example:

  DECLARE_TRACE(mytracepoint, TP_PROTO(int status), TP_ARGS(status));

/* In the C file */

  DEFINE_TRACE(mytracepoint, TP_PROTO(int status), TP_ARGS(status));

[...]

       trace_mytacepoint(status);

/* In a file registering this tracepoint */

int my_callback(int status, void *data)

  {
	struct my_struct my_data = data;
	[...]

}

[...]

	my_data = kmalloc(sizeof(*my_data), GFP_KERNEL);
	init_my_data(my_data);
	register_trace_mytracepoint_data(my_callback, my_data);

The same callback can also be registered to the same tracepoint as long as the data registered is the different. Note, the data must also be used to unregister the callback:

	unregister_trace_mytracepoint_data(my_callback, my_data);

Because of the data parameter, tracepoints declared this way can not have no args. That is:

  DECLARE_TRACE(mytracepoint, TP_PROTO(void), TP_ARGS());

will cause an error.

If no arguments are needed, a new macro can be used instead:

  DECLARE_TRACE_NOARGS(mytracepoint);

Since there are no arguments, the proto and args fields are left out.

This is part of a series to make the tracepoint footprint smaller:

text data bss dec hex filename
5788186 1337252 9351592 16477030 fb6b66 vmlinux.orig
5792282 1333796 9351592 16477670 fb6de6 vmlinux.class
5793448 1333780 9351592 16478820 fb7264 vmlinux.tracepoint

Again, this patch also increases the size of the kernel, but lays the ground work for decreasing it.

v2: Made the DECLARE_TRACE() have the ability to pass arguments
and added a new DECLARE_TRACE_NOARGS() for tracepoints that do not need any arguments.

Cc Mathieu Desnoyers <[email protected]>
---
 include/linux/tracepoint.h             |   94 +++++++++++++++++++++++++-------
 kernel/tracepoint.c                    |   91 +++++++++++++++++--------------
 samples/tracepoints/tp-samples-trace.h |    4 +-
 3 files changed, 126 insertions(+), 63 deletions(-)
include/linux/tracepoint.h +11 -5
index 78b4bd3..ee8059a 100644
@@ -20,12 +20,17 @@
 struct module;
 struct tracepoint;
 
+struct tracepoint_func {
+	void *func;
+	void *data;
+};
+
 struct tracepoint {
 	const char *name;		/* Tracepoint name */
 	int state;			/* State. */
 	void (*regfunc)(void);
 	void (*unregfunc)(void);
-	void **funcs;
+	struct tracepoint_func *funcs;
 } __attribute__((aligned(32)));		/*
 					 * Aligned on 32 bytes because it is
 					 * globally visible and gcc happily
@@ -46,14 +51,18 @@ struct tracepoint {
  */
 #define __DO_TRACE(tp, proto, args)					\
 	do {								\
-		void **it_func;						\
+		struct tracepoint_func *it_func_ptr;			\
+		void *it_func;						\
+		void *__data;						\
 									\
 		rcu_read_lock_sched_notrace();				\
-		it_func = rcu_dereference_sched((tp)->funcs);		\
-		if (it_func) {						\
+		it_func_ptr = rcu_dereference_sched((tp)->funcs);	\
+		if (it_func_ptr) {					\
 			do {						\
-				((void(*)(proto))(*it_func))(args);	\
Quoted 9 lines

include/linux/tracepoint.h struct tracepoint { · line 64

Quoted 4 lines
include/linux/tracepoint.h +3 -1
-			} while (*(++it_func));				\
+				it_func = (it_func_ptr)->func;		\
+				__data = (it_func_ptr)->data;		\
+				((void(*)(proto))(it_func))(args);	\

So, we had a talk about this and we concluded that it is probably fine on every archs to push one more argument than needed in a function.

Yeah, I'm hoping it's fine.

Quoted 5 lines

But I think it would be nice to add a comment about this. Firstly because this line breaks all the self-explanation of the code, I mean I tried hard to find how the non-data callback case was handled :) Secondly to also to avoid people asking what happens here.

OK I'll add a bit of comments to the macros. So much for my job security ;-)

Quoted 50 lines
Quoted 50 lines
include/linux/tracepoint.h +23 -5
+			} while ((++it_func_ptr)->func);		\
 		}							\
 		rcu_read_unlock_sched_notrace();			\
 	} while (0)
@@ -63,23 +72,47 @@ struct tracepoint {
  * not add unwanted padding between the beginning of the section and the
  * structure. Force alignment to the same alignment as the section start.
  */
-#define DECLARE_TRACE(name, proto, args)				\
+#define __DECLARE_TRACE(name, proto, args, data_proto, data_args)	\
 	extern struct tracepoint __tracepoint_##name;			\
 	static inline void trace_##name(proto)				\
 	{								\
 		if (unlikely(__tracepoint_##name.state))		\
 			__DO_TRACE(&__tracepoint_##name,		\
-				TP_PROTO(proto), TP_ARGS(args));	\
+				TP_PROTO(data_proto),			\
+				TP_ARGS(data_args));			\
 	}								\
 	static inline int register_trace_##name(void (*probe)(proto))	\
 	{								\
-		return tracepoint_probe_register(#name, (void *)probe);	\
+		return tracepoint_probe_register(#name, (void *)probe,	\
+						 NULL);			\
+	}								\
+	static inline int unregister_trace_##name(void (*probe)(proto)) \
+	{								\
+		return tracepoint_probe_unregister(#name, (void *)probe,\
+						   NULL);		\
 	}								\
-	static inline int unregister_trace_##name(void (*probe)(proto))	\
+	static inline int						\
+	register_trace_##name##_data(void (*probe)(data_proto),		\
+				     void *data)			\
 	{								\
-		return tracepoint_probe_unregister(#name, (void *)probe);\
+		return tracepoint_probe_register(#name, (void *)probe,	\
+						 data);			\
+	}								\
+	static inline int						\
+	unregister_trace_##name##_data(void (*probe)(data_proto),	\
+				       void *data)			\
+	{								\
+		return tracepoint_probe_unregister(#name, (void *)probe,\
+						   data);		\
 	}
 
Quoted 6 lines

include/linux/tracepoint.h struct tracepoint { · line 110

Quoted 2 lines
include/linux/tracepoint.h +2 -0
+#define DECLARE_TRACE_NOARGS(name)					\
+		__DECLARE_TRACE(name, void, , void *__data, __data)

That too, may be, deserves a small comment :)

OK

Quoted 50 lines
Quoted 50 lines
include/linux/tracepoint.h +27 -5
+
+#define DECLARE_TRACE(name, proto, args)				\
+		__DECLARE_TRACE(name, PARAMS(proto), PARAMS(args),	\
+				PARAMS(proto, void *__data),		\
+				PARAMS(args, __data))
 
 #define DEFINE_TRACE_FN(name, reg, unreg)				\
 	static const char __tpstrtab_##name[]				\
@@ -100,19 +133,37 @@ extern void tracepoint_update_probe_range(struct tracepoint *begin,
 	struct tracepoint *end);
 
 #else /* !CONFIG_TRACEPOINTS */
-#define DECLARE_TRACE(name, proto, args)				\
-	static inline void _do_trace_##name(struct tracepoint *tp, proto) \
-	{ }								\
+#define __DECLARE_TRACE(name, proto, args, data_proto, data_args)	\
 	static inline void trace_##name(proto)				\
-	{ }								\
+	{								\
+	}								\
 	static inline int register_trace_##name(void (*probe)(proto))	\
 	{								\
 		return -ENOSYS;						\
 	}								\
-	static inline int unregister_trace_##name(void (*probe)(proto))	\
+	static inline int unregister_trace_##name(void (*probe)(proto)) \
+	{								\
+		return -ENOSYS;						\
+	}								\
+	static inline int						\
+	register_trace_##name##_data(void (*probe)(data_proto),		\
+				     void *data)			\
+	{								\
+		return -ENOSYS;						\
+	}								\
+	static inline int						\
+	unregister_trace_##name##_data(void (*probe)(data_proto),	\
+				       void *data)			\
 	{								\
 		return -ENOSYS;						\
 	}
+#define DECLARE_TRACE_NOARGS(name)					\
+		__DECLARE_TRACE(name, void, , void *__data, __data)
+
+#define DECLARE_TRACE(name, proto, args)				\
+		__DECLARE_TRACE(name, PARAMS(proto), PARAMS(args),	\
+				PARAMS(proto, void *__data),		\
Quoted 9 lines

include/linux/tracepoint.h extern void tracepoint_update_probe_range(struct tracepoint *begin, · line 166

Quoted 1 line
include/linux/tracepoint.h +1 -0
+				PARAMS(args, __data))

It seems that the on and off cases are exactly the same for DECLARE_TRACE*(), you could provide a single version and let the __DECLARE_TRACE() do the on/off trick.

I don't know what you mean here?

-- Steve

Quoted 2 lines

Thanks.

Signature · 1 line
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
#1 lore raw

Re: [PATCH 2/9 - v2][RFC] tracing: Let tracepoints have data?passed to tracepoint callbacks

Quoted 5 lines · * Steven Rostedt ([email protected]) wrote:
Quoted 1 line · Frederic Weisbecker

On Mon, May 03, 2010 at 11:40:47PM -0400, Steven Rostedt wrote:

[...]

Quoted 50 lines
Quoted 40 lines
Quoted 40 lines
include/linux/tracepoint.h +11 -5
index 78b4bd3..ee8059a 100644
@@ -20,12 +20,17 @@
 struct module;
 struct tracepoint;
 
+struct tracepoint_func {
+	void *func;
+	void *data;
+};
+
 struct tracepoint {
 	const char *name;		/* Tracepoint name */
 	int state;			/* State. */
 	void (*regfunc)(void);
 	void (*unregfunc)(void);
-	void **funcs;
+	struct tracepoint_func *funcs;
 } __attribute__((aligned(32)));		/*
 					 * Aligned on 32 bytes because it is
 					 * globally visible and gcc happily
@@ -46,14 +51,18 @@ struct tracepoint {
  */
 #define __DO_TRACE(tp, proto, args)					\
 	do {								\
-		void **it_func;						\
+		struct tracepoint_func *it_func_ptr;			\
+		void *it_func;						\
+		void *__data;						\
 									\
 		rcu_read_lock_sched_notrace();				\
-		it_func = rcu_dereference_sched((tp)->funcs);		\
-		if (it_func) {						\
+		it_func_ptr = rcu_dereference_sched((tp)->funcs);	\
+		if (it_func_ptr) {					\
 			do {						\
-				((void(*)(proto))(*it_func))(args);	\
Quoted 9 lines

include/linux/tracepoint.h struct tracepoint { · line 64

Quoted 4 lines
include/linux/tracepoint.h +3 -1
-			} while (*(++it_func));				\
+				it_func = (it_func_ptr)->func;		\
+				__data = (it_func_ptr)->data;		\
+				((void(*)(proto))(it_func))(args);	\

So, we had a talk about this and we concluded that it is probably fine on every archs to push one more argument than needed in a function.

Quoted 1 line

Yeah, I'm hoping it's fine.

How about changing the callback prototypes to match the call arguments (changing the type expected in register/unregister_trace, as well as an additional "check type" that I proposed for Ftrace) ?

Otherwise, you basically expect here that:

void fct(void *foo, void *bar, etc etc) (N parameters expected) {

}

called by:

fct(foo, bar, etc etc, foobar) (N + 1 parameters)

will always work.

Can you show me where the C standard says it is safe to do so ?

Thanks,

Mathieu

Quoted 82 lines
Quoted 6 lines

But I think it would be nice to add a comment about this. Firstly because this line breaks all the self-explanation of the code, I mean I tried hard to find how the non-data callback case was handled :) Secondly to also to avoid people asking what happens here.

OK I'll add a bit of comments to the macros. So much for my job security ;-)

Quoted 50 lines
Quoted 50 lines
include/linux/tracepoint.h +23 -5
+			} while ((++it_func_ptr)->func);		\
 		}							\
 		rcu_read_unlock_sched_notrace();			\
 	} while (0)
@@ -63,23 +72,47 @@ struct tracepoint {
  * not add unwanted padding between the beginning of the section and the
  * structure. Force alignment to the same alignment as the section start.
  */
-#define DECLARE_TRACE(name, proto, args)				\
+#define __DECLARE_TRACE(name, proto, args, data_proto, data_args)	\
 	extern struct tracepoint __tracepoint_##name;			\
 	static inline void trace_##name(proto)				\
 	{								\
 		if (unlikely(__tracepoint_##name.state))		\
 			__DO_TRACE(&__tracepoint_##name,		\
-				TP_PROTO(proto), TP_ARGS(args));	\
+				TP_PROTO(data_proto),			\
+				TP_ARGS(data_args));			\
 	}								\
 	static inline int register_trace_##name(void (*probe)(proto))	\
 	{								\
-		return tracepoint_probe_register(#name, (void *)probe);	\
+		return tracepoint_probe_register(#name, (void *)probe,	\
+						 NULL);			\
+	}								\
+	static inline int unregister_trace_##name(void (*probe)(proto)) \
+	{								\
+		return tracepoint_probe_unregister(#name, (void *)probe,\
+						   NULL);		\
 	}								\
-	static inline int unregister_trace_##name(void (*probe)(proto))	\
+	static inline int						\
+	register_trace_##name##_data(void (*probe)(data_proto),		\
+				     void *data)			\
 	{								\
-		return tracepoint_probe_unregister(#name, (void *)probe);\
+		return tracepoint_probe_register(#name, (void *)probe,	\
+						 data);			\
+	}								\
+	static inline int						\
+	unregister_trace_##name##_data(void (*probe)(data_proto),	\
+				       void *data)			\
+	{								\
+		return tracepoint_probe_unregister(#name, (void *)probe,\
+						   data);		\
 	}
 
Quoted 6 lines

include/linux/tracepoint.h struct tracepoint { · line 110

Quoted 2 lines
include/linux/tracepoint.h +2 -0
+#define DECLARE_TRACE_NOARGS(name)					\
+		__DECLARE_TRACE(name, void, , void *__data, __data)

That too, may be, deserves a small comment :)

OK

Quoted 14 lines
Quoted 14 lines
include/linux/tracepoint.h +5 -0
+
+#define DECLARE_TRACE(name, proto, args)				\
+		__DECLARE_TRACE(name, PARAMS(proto), PARAMS(args),	\
+				PARAMS(proto, void *__data),		\
+				PARAMS(args, __data))
 
 #define DEFINE_TRACE_FN(name, reg, unreg)				\
 	static const char __tpstrtab_##name[]				\
@@ -100,19 +133,37 @@ extern void tracepoint_update_probe_range(struct tracepoint *begin,
 	struct tracepoint *end);
 

[...]

Signature · 4 lines
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
#2 lore raw

Re: [PATCH 2/9 - v2][RFC] tracing: Let tracepoints have data?passed to tracepoint callbacks

Quoted 57 lines · Mathieu Desnoyers
Quoted 5 lines · * Steven Rostedt ([email protected]) wrote:
Quoted 1 line · Frederic Weisbecker

On Mon, May 03, 2010 at 11:40:47PM -0400, Steven Rostedt wrote:

[...]

Quoted 50 lines
Quoted 49 lines
Quoted 34 lines
include/linux/tracepoint.h +9 -2
index 78b4bd3..ee8059a 100644
@@ -20,12 +20,17 @@
 struct module;
 struct tracepoint;
 
+struct tracepoint_func {
+	void *func;
+	void *data;
+};
+
 struct tracepoint {
 	const char *name;		/* Tracepoint name */
 	int state;			/* State. */
 	void (*regfunc)(void);
 	void (*unregfunc)(void);
-	void **funcs;
+	struct tracepoint_func *funcs;
 } __attribute__((aligned(32)));		/*
 					 * Aligned on 32 bytes because it is
 					 * globally visible and gcc happily
@@ -46,14 +51,18 @@ struct tracepoint {
  */
 #define __DO_TRACE(tp, proto, args)					\
 	do {								\
-		void **it_func;						\
+		struct tracepoint_func *it_func_ptr;			\
+		void *it_func;						\
+		void *__data;						\
 									\
 		rcu_read_lock_sched_notrace();				\

include/linux/tracepoint.h struct tracepoint { · line 64

Quoted 10 lines
include/linux/tracepoint.h +5 -4
-		it_func = rcu_dereference_sched((tp)->funcs);		\
-		if (it_func) {						\
+		it_func_ptr = rcu_dereference_sched((tp)->funcs);	\
+		if (it_func_ptr) {					\
 			do {						\
-				((void(*)(proto))(*it_func))(args);	\
-			} while (*(++it_func));				\
+				it_func = (it_func_ptr)->func;		\
+				__data = (it_func_ptr)->data;		\
+				((void(*)(proto))(it_func))(args);	\

So, we had a talk about this and we concluded that it is probably fine on every archs to push one more argument than needed in a function.

Quoted 5 lines
Quoted 1 line

Yeah, I'm hoping it's fine.

How about changing the callback prototypes to match the call arguments (changing the type expected in register/unregister_trace, as well as an additional "check type" that I proposed for Ftrace) ?

This can not happen!!!! As I said before, the register is done in C, there is no macro that will help here. We create the call back with the macro, but the registering is in kernel/trace/trace_events.c. One register for ___ALL___ events!!!

Thus there is no check.

Understand this yet?

Quoted 8 lines

Otherwise, you basically expect here that:

void fct(void *foo, void *bar, etc etc) (N parameters expected) {

}

Quoted 7 lines

called by:

fct(foo, bar, etc etc, foobar) (N + 1 parameters)

will always work.

Can you show me where the C standard says it is safe to do so ?

No, but it seems safe in the kernel ;-)

But that said. There is another option that will conform to this, and that is to add flags to registering tracepoints. I already wrote a patch for this in trying to do some other work (that I threw away).

So here's the proposal.

Change struct tracepoint_func to...

struct tracepoint_func {
	void *func;
	void *data;
	unsigned int flags;
};

The flags is set when registered. If a function is registered with data, then the flags field will be set. Then the calling of the function can be:

	if ((it_func_ptr)->flags & TP_FL_DATA)
		((void(*)(proto, void *))(it_func)(args, __data);
	else
		((void(*)(proto))(it_func)(args);

This would comply with the C standard.

-- Steve

#3 lore raw

Re: [PATCH 2/9 - v2][RFC] tracing: Let tracepoints have data?passed to tracepoint callbacks

Quoted 64 lines · * Steven Rostedt ([email protected]) wrote:
Quoted 57 lines · Mathieu Desnoyers
Quoted 5 lines · * Steven Rostedt ([email protected]) wrote:
Quoted 1 line · Frederic Weisbecker

On Mon, May 03, 2010 at 11:40:47PM -0400, Steven Rostedt wrote:

[...]

Quoted 50 lines
Quoted 49 lines
Quoted 34 lines
include/linux/tracepoint.h +9 -2
index 78b4bd3..ee8059a 100644
@@ -20,12 +20,17 @@
 struct module;
 struct tracepoint;
 
+struct tracepoint_func {
+	void *func;
+	void *data;
+};
+
 struct tracepoint {
 	const char *name;		/* Tracepoint name */
 	int state;			/* State. */
 	void (*regfunc)(void);
 	void (*unregfunc)(void);
-	void **funcs;
+	struct tracepoint_func *funcs;
 } __attribute__((aligned(32)));		/*
 					 * Aligned on 32 bytes because it is
 					 * globally visible and gcc happily
@@ -46,14 +51,18 @@ struct tracepoint {
  */
 #define __DO_TRACE(tp, proto, args)					\
 	do {								\
-		void **it_func;						\
+		struct tracepoint_func *it_func_ptr;			\
+		void *it_func;						\
+		void *__data;						\
 									\
 		rcu_read_lock_sched_notrace();				\

include/linux/tracepoint.h struct tracepoint { · line 64

Quoted 10 lines
include/linux/tracepoint.h +5 -4
-		it_func = rcu_dereference_sched((tp)->funcs);		\
-		if (it_func) {						\
+		it_func_ptr = rcu_dereference_sched((tp)->funcs);	\
+		if (it_func_ptr) {					\
 			do {						\
-				((void(*)(proto))(*it_func))(args);	\
-			} while (*(++it_func));				\
+				it_func = (it_func_ptr)->func;		\
+				__data = (it_func_ptr)->data;		\
+				((void(*)(proto))(it_func))(args);	\

So, we had a talk about this and we concluded that it is probably fine on every archs to push one more argument than needed in a function.

Quoted 5 lines
Quoted 1 line

Yeah, I'm hoping it's fine.

How about changing the callback prototypes to match the call arguments (changing the type expected in register/unregister_trace, as well as an additional "check type" that I proposed for Ftrace) ?

Quoted 8 lines

This can not happen!!!! As I said before, the register is done in C, there is no macro that will help here. We create the call back with the macro, but the registering is in kernel/trace/trace_events.c. One register for ___ALL___ events!!!

Thus there is no check.

Understand this yet?

Clearly understood. I was referring to add a static inline check_trace_##name##_callback_type(...) { } call within the callbacks you generate. It generates no code and adds compiler type-checking (rather than relying on CPP macro correctness for type-correctness).

Quoted 12 lines
Quoted 12 lines

Otherwise, you basically expect here that:

void fct(void *foo, void *bar, etc etc) (N parameters expected) {

}

called by:

Quoted 7 lines
Quoted 5 lines

fct(foo, bar, etc etc, foobar) (N + 1 parameters)

will always work.

Can you show me where the C standard says it is safe to do so ?

No, but it seems safe in the kernel ;-)

The use of "seems" here does not give me a warm feeling of safety. ;)

Quoted 21 lines

But that said. There is another option that will conform to this, and that is to add flags to registering tracepoints. I already wrote a patch for this in trying to do some other work (that I threw away).

So here's the proposal.

Change struct tracepoint_func to...

struct tracepoint_func {
	void *func;
	void *data;
	unsigned int flags;
};

The flags is set when registered. If a function is registered with data, then the flags field will be set. Then the calling of the function can be:

Quoted 6 lines
	if ((it_func_ptr)->flags & TP_FL_DATA)
		((void(*)(proto, void *))(it_func)(args, __data);
	else
		((void(*)(proto))(it_func)(args);

This would comply with the C standard.

This would also add a branch on the tracing fast path, which I would like to avoid. Why can't we simply change all prototypes to take an extra void *__data parameter instead ?

Thanks,

Mathieu

Quoted 4 lines

-- Steve

Signature · 4 lines
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
#4 lore raw

Re: [PATCH 2/9 - v2][RFC] tracing: Let tracepoints have data?passed to tracepoint callbacks

Quoted 5 lines · Mathieu Desnoyers
Quoted 3 lines
Quoted 1 line

Can you show me where the C standard says it is safe to do so ?

No, but it seems safe in the kernel ;-)

The use of "seems" here does not give me a warm feeling of safety. ;)

Right, which is why I added the below.

Quoted 27 lines
Quoted 27 lines

But that said. There is another option that will conform to this, and that is to add flags to registering tracepoints. I already wrote a patch for this in trying to do some other work (that I threw away).

So here's the proposal.

Change struct tracepoint_func to...

struct tracepoint_func {
	void *func;
	void *data;
	unsigned int flags;
};

The flags is set when registered. If a function is registered with data, then the flags field will be set. Then the calling of the function can be:

	if ((it_func_ptr)->flags & TP_FL_DATA)
		((void(*)(proto, void *))(it_func)(args, __data);
	else
		((void(*)(proto))(it_func)(args);
Quoted 5 lines
Quoted 1 line

This would comply with the C standard.

This would also add a branch on the tracing fast path, which I would like to avoid. Why can't we simply change all prototypes to take an extra void *__data parameter instead ?

I'm fine with making the data parameter mandatory with all tracers. Thus the call back must require it. I would then move the data parameter from the end to the beginning.

So a tracepoint with proto, will have a callback:

	void callback(void *data, proto);

I'm fine with forcing all callbacks to include a data parameter if you are. This would also make the changes simpler.

-- Steve

#5 lore raw

Re: [PATCH 2/9 - v2][RFC] tracing: Let tracepoints have data?passed to tracepoint callbacks

Quoted 47 lines · * Steven Rostedt ([email protected]) wrote:
Quoted 5 lines · Mathieu Desnoyers
Quoted 3 lines
Quoted 1 line

Can you show me where the C standard says it is safe to do so ?

No, but it seems safe in the kernel ;-)

The use of "seems" here does not give me a warm feeling of safety. ;)

Right, which is why I added the below.

Quoted 27 lines
Quoted 27 lines

But that said. There is another option that will conform to this, and that is to add flags to registering tracepoints. I already wrote a patch for this in trying to do some other work (that I threw away).

So here's the proposal.

Change struct tracepoint_func to...

struct tracepoint_func {
	void *func;
	void *data;
	unsigned int flags;
};

The flags is set when registered. If a function is registered with data, then the flags field will be set. Then the calling of the function can be:

	if ((it_func_ptr)->flags & TP_FL_DATA)
		((void(*)(proto, void *))(it_func)(args, __data);
	else
		((void(*)(proto))(it_func)(args);
Quoted 5 lines
Quoted 1 line

This would comply with the C standard.

This would also add a branch on the tracing fast path, which I would like to avoid. Why can't we simply change all prototypes to take an extra void *__data parameter instead ?

I'm fine with making the data parameter mandatory with all tracers. Thus the call back must require it. I would then move the data parameter from the end to the beginning.

Quoted 6 lines

So a tracepoint with proto, will have a callback:

	void callback(void *data, proto);

I'm fine with forcing all callbacks to include a data parameter if you are. This would also make the changes simpler.

Yes, I am all for it.

As for the extra type checking, it is basically just trying to force you to generate matching caller-callee prototypes in your CPP macros. The goal is really to check that the data parameter type match in both the caller and callee. I see that as a mean to make sure nobody is going to try to take shortcuts by playing with the callback types in the "undefined behavior" zone of the C standard in future TRACE_EVENT() modifications.

Thanks,

Mathieu

Quoted 4 lines

-- Steve

Signature · 4 lines
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
#6 lore raw

Re: [PATCH 2/9 - v2][RFC] tracing: Let tracepoints have data?passed to tracepoint callbacks

Quoted 6 lines · Mathieu Desnoyers
Quoted 2 lines · * Steven Rostedt ([email protected]) wrote:

I'm fine with forcing all callbacks to include a data parameter if you are. This would also make the changes simpler.

Yes, I am all for it.

Great! I'm making the changes now.

Quoted 7 lines

As for the extra type checking, it is basically just trying to force you to generate matching caller-callee prototypes in your CPP macros. The goal is really to check that the data parameter type match in both the caller and callee. I see that as a mean to make sure nobody is going to try to take shortcuts by playing with the callback types in the "undefined behavior" zone of the C standard in future TRACE_EVENT() modifications.

OK, I'll wait for your patch. As my favorite saying goes...

"When people ask me what language my mother tongue is, I simply reply 'C'."

-- Steve