Skip to contentSkip to conversation

tracing: introduce for_each_token macro

PATCH In review Yuanhan Liu 4 participants 18 messages Nov 9, 2010 – Nov 11, 2010

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 tracing: introduce for_each_token macro

Introduce for_each_token macro to parse the trace event list.

---
 kernel/trace/trace_events.c |   14 ++++++--------
 1 files changed, 6 insertions(+), 8 deletions(-)
kernel/trace/trace_events.c +6 -8
index 0725eea..fe15b7c 100644
@@ -1218,6 +1218,11 @@ void trace_remove_event_call(struct ftrace_event_call *call)
 	mutex_unlock(&event_mutex);
 }
 
+#define for_each_token(token, buf) 				\
+	for (token = strsep(&buf, ","); 			\
+	     token && *token; 					\
+	     token = strsep(&buf, ","))
+
 #define for_each_event(event, start, end)			\
 	for (event = start;					\
 	     (unsigned long)event < (unsigned long)end;		\
@@ -1430,14 +1435,7 @@ static __init int event_trace_init(void)
 				       &ftrace_event_format_fops);
 	}
 
-	while (true) {
-		token = strsep(&buf, ",");
-
-		if (!token)
-			break;
-		if (!*token)
-			continue;
-
+	for_each_token(token, buf) {
 		ret = ftrace_set_clr_event(token, 1);
 		if (ret)
 			pr_warning("Failed to enable trace event: %s\n", token);
Signature · 1 line
1.7.2.3
#1 lore raw

PATCH 2/4 tracing: introduce trace_set_clr_module_event

Trace events belong to a module does exist only when that module is loaded. While, when the module loaded, we may miss some trace event happened at the module load time.

This is so true for gpu driver: when X(or shell) is started, you would be going to miss lots of events. This would be worse when the KMS is failed.

So, introduce trace_set_clr_module_event function, and do export it. Trace event then can be enabled on module load by doing something like follows at your module init function:

char *xxx_trace = NULL; module_param_named(trace, xxx_trace, charp, 0400);

xxx_init()

{
	....
	if (xxx_trace)
		ret = trace_set_clr_module_event(THIS_MODULE, xxx_trace, 1);
	....
}

where, xxx_trace is a comm separated event list, * for all event in that module, NO subsystem is needed.

---
 include/linux/ftrace_event.h |    3 ++
 kernel/trace/trace_events.c  |   45 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 0 deletions(-)
include/linux/ftrace_event.h +3 -0
index 8beabb9..8fbdbbd 100644
@@ -226,6 +226,9 @@ extern void trace_remove_event_call(struct ftrace_event_call *call);
 
 int trace_set_clr_event(const char *system, const char *event, int set);
 
+int trace_set_clr_module_event(struct module *mod, 
+			       const char *event_list, int set);
+
 /*
  * The double __builtin_constant_p is because gcc will give us an error
  * if we try to allocate the static variable to fmt if it is not a
kernel/trace/trace_events.c +45 -0

51 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#2 lore raw

Re: [PATCH 2/4] tracing: introduce trace_set_clr_module_event

On Tue, Nov 09, 2010 at 05:12:45PM +0800, Yuanhan Liu wrote:

[ snip ]

kernel/trace/trace_events.c static int trace_module_notify(struct notifier_block *self, · line 1391

Quoted 8 lines
kernel/trace/trace_events.c +8 -0
+	for_each_token(token, p) {
+		for_each_event(call, start, end) {
+			if (strcmp(token, "*") == 0 ||
+			    strcmp(token, call->name) == 0) 
+				ftrace_event_enable_disable(call, set);
+			else
+				pr_warning("Failed to find trace event: %s "
+					   "in module %s\n", token, mod->name);

Oops, sorry for this obvious error, will fix it.

Besides that, any comments?

Thanks.

--
Yuanhan Liu

Quoted 14 lines
kernel/trace/trace_events.c +9 -0
+		
+		}
+	}
+	kfree(buf);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(trace_set_clr_module_event);
+
+
 #else
 static int trace_module_notify(struct notifier_block *self,
 			       unsigned long val, void *data)
Signature · 1 line
1.7.2.3
#3 lore raw

Re: [PATCH 2/4] tracing: introduce trace_set_clr_module_event

Quoted 1 line · Yuanhan Liu

Besides that, any comments?

I've not looked closely at this yet, but it seems like we should be able to hook into a trace_module_notify and implement a generic option parser from within trace/ as opposed to each individual module. -Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#4 lore raw

Re: [PATCH 2/4] tracing: introduce trace_set_clr_module_event

Quoted 2 lines · Chris Wilson

I've not looked closely at this yet, but it seems like we should be able to hook into a trace_module_notify

But there should be someplace to enable these events, right? And how do you tell trace_module_notify to just enable one or several specific event?

Quoted 2 lines

and implement a generic option parser
from within trace/ as opposed to each individual module.

Nope, this patch does implement a generic option parser within trace/, and we just call this function from a module.

Thanks.

--
Yuanhan Liu

#5 lore raw

Re: [PATCH 2/4] tracing: introduce trace_set_clr_module_event

Quoted 7 lines · Yuanhan Liu
Quoted 2 lines · Chris Wilson

I've not looked closely at this yet, but it seems like we should be able to hook into a trace_module_notify

But there should be someplace to enable these events, right? And how do you tell trace_module_notify to just enable one or several specific event?

Yes, I was thinking of extending the module loader to permit core to hook into parse_args() and so the trace= facility could work with any module without exporting any new functions.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
maintainer
#6 lore raw

Re: [PATCH 2/4] tracing: introduce trace_set_clr_module_event

Quoted 5 lines · Chris Wilson
Quoted 4 lines · Yuanhan Liu
Quoted 2 lines · Chris Wilson

I've not looked closely at this yet, but it seems like we should be able to hook into a trace_module_notify

Quoted 7 lines
Quoted 3 lines

But there should be someplace to enable these events, right? And how do you tell trace_module_notify to just enable one or several specific event?

Yes, I was thinking of extending the module loader to permit core to hook into parse_args() and so the trace= facility could work with any module without exporting any new functions.

Exactly, if you want, I probably could whip up a patch.

-- Steve

#7 lore raw

Re: [PATCH 2/4] tracing: introduce trace_set_clr_module_event

Quoted 10 lines · Steven Rostedt
Quoted 9 lines · Chris Wilson
Quoted 7 lines · Yuanhan Liu
Quoted 2 lines · Chris Wilson

I've not looked closely at this yet, but it seems like we should be able to hook into a trace_module_notify

But there should be someplace to enable these events, right? And how do you tell trace_module_notify to just enable one or several specific event?

Quoted 5 lines
Quoted 3 lines

Yes, I was thinking of extending the module loader to permit core to hook into parse_args() and so the trace= facility could work with any module without exporting any new functions.

Exactly, if you want, I probably could whip up a patch.

Yes, please if you are free;)

Thanks.

--
Yuanhan Liu

Quoted 1 line
#8 lore raw

Re: [PATCH 2/4] tracing: introduce trace_set_clr_module_event

In reply to Chris Wilson
Quoted 5 lines · Chris Wilson
Quoted 4 lines · Yuanhan Liu
Quoted 2 lines · Chris Wilson

I've not looked closely at this yet, but it seems like we should be able to hook into a trace_module_notify

Quoted 7 lines
Quoted 3 lines

But there should be someplace to enable these events, right? And how do you tell trace_module_notify to just enable one or several specific event?

Yes, I was thinking of extending the module loader to permit core to hook into parse_args() and so the trace= facility could work with any module without exporting any new functions.

Got your idea. But is it OK?

Thanks.

--
Yuanhan Liu

maintainer
#9 lore raw

Re: [PATCH 2/4] tracing: introduce trace_set_clr_module_event

Quoted 10 lines · Yuanhan Liu
Quoted 9 lines · Chris Wilson
Quoted 7 lines · Yuanhan Liu
Quoted 2 lines · Chris Wilson

I've not looked closely at this yet, but it seems like we should be able to hook into a trace_module_notify

But there should be someplace to enable these events, right? And how do you tell trace_module_notify to just enable one or several specific event?

Quoted 5 lines
Quoted 3 lines

Yes, I was thinking of extending the module loader to permit core to hook into parse_args() and so the trace= facility could work with any module without exporting any new functions.

Got your idea. But is it OK?

Of course it is. It's the one that makes the most sense.

-- Steve

#10 lore raw

PATCH 1/1 Delegate unknown module parameters to interested parties

In reply to Chris Wilson

This is a sketch of what I had in mind for trace to do the event initialisation on the modules behalf.

---
 include/linux/module.h      |    8 ++++++++
 include/linux/moduleparam.h |    3 ++-
 init/main.c                 |    8 ++++----
 kernel/module.c             |   21 ++++++++++++++++++++-
 kernel/params.c             |   10 ++++++----
 kernel/trace/trace_events.c |   15 ++++++++++++++-
 6 files changed, 54 insertions(+), 11 deletions(-)
include/linux/module.h +8 -0
index b29e745..84daad8 100644
@@ -241,6 +241,14 @@ enum module_state
 	MODULE_STATE_GOING,
 };
 
+#define MODULE_UNKNOWN_PARAM (MODULE_STATE_GOING + 1)
+
+struct module_unknown_param {
+	struct module *mod;
+	char *param;
+	char *val;
+};
+
 struct module
 {
 	enum module_state state;
include/linux/moduleparam.h +2 -1
index 112adf8..5e24ec1 100644
@@ -265,7 +265,8 @@ extern int parse_args(const char *name,
 		      char *args,
 		      const struct kernel_param *params,
 		      unsigned num,
-		      int (*unknown)(char *param, char *val));
+		      int (*unknown)(char *param, char *val, void *data),
+		      void *data);
 
 /* Called by module remove. */
 #ifdef CONFIG_SYSFS
init/main.c +4 -4
index e59af24..782780e 100644
@@ -267,7 +267,7 @@ early_param("loglevel", loglevel);
  * Unknown boot options get handed to init, unless they look like
  * unused parameters (modprobe will find them in /proc/cmdline).
  */
-static int __init unknown_bootoption(char *param, char *val)
+static int __init unknown_bootoption(char *param, char *val, void *data)
 {
 	/* Change NUL term back to "=", to make "param" the whole string. */
 	if (val) {
@@ -455,7 +455,7 @@ static noinline void __init_refok rest_init(void)
 }
 
 /* Check for early params. */
-static int __init do_early_param(char *param, char *val)
+static int __init do_early_param(char *param, char *val, void *data)
 {
 	const struct obs_kernel_param *p;
 
@@ -475,7 +475,7 @@ static int __init do_early_param(char *param, char *val)
 
 void __init parse_early_options(char *cmdline)
 {
-	parse_args("early options", cmdline, NULL, 0, do_early_param);
+	parse_args("early options", cmdline, NULL, 0, do_early_param, NULL);
 }
 
 /* Arch code calls this early on, or if not, just before other parsing. */
@@ -578,7 +578,7 @@ asmlinkage void __init start_kernel(void)
 	parse_early_param();
 	parse_args("Booting kernel", static_command_line, __start___param,
 		   __stop___param - __start___param,
-		   &unknown_bootoption);
+		   &unknown_bootoption, NULL);
 	/*
 	 * These use large bootmem allocations and must precede
 	 * kmem_cache_init()
kernel/module.c +20 -1
index 2df4630..87ce541 100644
@@ -2544,6 +2544,24 @@ static int post_relocation(struct module *mod, const struct load_info *info)
 	return module_finalize(info->hdr, info->sechdrs, mod);
 }
 
+static int unknown_param(char *param, char *val, void *data)
+{
+	struct module_unknown_param arg;
+	int ret;
+
+	arg.mod = data;
+	arg.param = param;
+	arg.val = val;
+
+	ret = blocking_notifier_call_chain(&module_notify_list,
+					  MODULE_UNKNOWN_PARAM,
+					  &arg);
+	if (ret & NOTIFY_STOP_MASK)
+		return notifier_to_errno(ret);
+
+	return -ENOENT;
+}
+
 /* Allocate and load the module: note that size of section 0 is always
    zero, and we rely on this for optional sections. */
 static struct module *load_module(void __user *umod,
@@ -2637,7 +2655,8 @@ static struct module *load_module(void __user *umod,
 	mutex_unlock(&module_mutex);
 
 	/* Module is ready to execute: parsing args may do that. */
-	err = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, NULL);
+	err = parse_args(mod->name, mod->args, mod->kp, mod->num_kp,
+			 unknown_param, mod);
 	if (err < 0)
 		goto unlink;
 
kernel/params.c +6 -4
index 08107d1..d8c707c 100644
@@ -87,7 +87,8 @@ static int parse_one(char *param,
 		     char *val,
 		     const struct kernel_param *params,
 		     unsigned num_params,
-		     int (*handle_unknown)(char *param, char *val))
+		     int (*handle_unknown)(char *param, char *val, void *data),
+		     void *data)
 {
 	unsigned int i;
 	int err;
@@ -109,7 +110,7 @@ static int parse_one(char *param,
 
 	if (handle_unknown) {
 		DEBUGP("Unknown argument: calling %p\n", handle_unknown);
-		return handle_unknown(param, val);
+		return handle_unknown(param, val, data);
 	}
 
 	DEBUGP("Unknown argument `%s'\n", param);
@@ -173,7 +174,8 @@ int parse_args(const char *name,
 	       char *args,
 	       const struct kernel_param *params,
 	       unsigned num,
-	       int (*unknown)(char *param, char *val))
+	       int (*unknown)(char *param, char *val, void *data),
+	       void *data)
 {
 	char *param, *val;
 
@@ -188,7 +190,7 @@ int parse_args(const char *name,
 
 		args = next_arg(args, &param, &val);
 		irq_was_disabled = irqs_disabled();
-		ret = parse_one(param, val, params, num, unknown);
+		ret = parse_one(param, val, params, num, unknown, data);
 		if (irq_was_disabled && !irqs_disabled()) {
 			printk(KERN_WARNING "parse_args(): option '%s' enabled "
 					"irq's!\n", param);
kernel/trace/trace_events.c +14 -1
index 0725eea..d23cbf3 100644
@@ -1330,10 +1330,21 @@ static void trace_module_remove_events(struct module *mod)
 	up_write(&trace_event_mutex);
 }
 
+static int trace_module_unknown_param(struct module_unknown_param *arg)
+{
+	if (strcmp(arg->param, "trace") == 0) {
+		int ret = trace_set_clr_module_event(arg->mod, arg->val, 1);
+		return NOTIFY_STOP_MASK | (NOTIFY_OK - ret);
+	}
+
+	return NOTIFY_OK;
+}
+
 static int trace_module_notify(struct notifier_block *self,
 			       unsigned long val, void *data)
 {
 	struct module *mod = data;
+	int ret = 0;
 
 	mutex_lock(&event_mutex);
 	switch (val) {
@@ -1343,10 +1354,12 @@ static int trace_module_notify(struct notifier_block *self,
 	case MODULE_STATE_GOING:
 		trace_module_remove_events(mod);
 		break;
+	case MODULE_UNKNOWN_PARAM:
+		ret = trace_module_unknown_param(data);
 	}
 	mutex_unlock(&event_mutex);
 
-	return 0;
+	return ret;
 }
 #else
 static int trace_module_notify(struct notifier_block *self,
Signature · 1 line
1.7.2.3
maintainer
#11 lore raw

Re: [PATCH] Delegate unknown module parameters to interested parties

[ Added Rusty "Module God" Russell ]

Quoted 171 lines · Chris Wilson

This is a sketch of what I had in mind for trace to do the event initialisation on the modules behalf.

---
 include/linux/module.h      |    8 ++++++++
 include/linux/moduleparam.h |    3 ++-
 init/main.c                 |    8 ++++----
 kernel/module.c             |   21 ++++++++++++++++++++-
 kernel/params.c             |   10 ++++++----
 kernel/trace/trace_events.c |   15 ++++++++++++++-
 6 files changed, 54 insertions(+), 11 deletions(-)
include/linux/module.h +8 -0
index b29e745..84daad8 100644
@@ -241,6 +241,14 @@ enum module_state
 	MODULE_STATE_GOING,
 };
 
+#define MODULE_UNKNOWN_PARAM (MODULE_STATE_GOING + 1)
+
+struct module_unknown_param {
+	struct module *mod;
+	char *param;
+	char *val;
+};
+
 struct module
 {
 	enum module_state state;
include/linux/moduleparam.h +2 -1
index 112adf8..5e24ec1 100644
@@ -265,7 +265,8 @@ extern int parse_args(const char *name,
 		      char *args,
 		      const struct kernel_param *params,
 		      unsigned num,
-		      int (*unknown)(char *param, char *val));
+		      int (*unknown)(char *param, char *val, void *data),
+		      void *data);
 
 /* Called by module remove. */
 #ifdef CONFIG_SYSFS
init/main.c +4 -4
index e59af24..782780e 100644
@@ -267,7 +267,7 @@ early_param("loglevel", loglevel);
  * Unknown boot options get handed to init, unless they look like
  * unused parameters (modprobe will find them in /proc/cmdline).
  */
-static int __init unknown_bootoption(char *param, char *val)
+static int __init unknown_bootoption(char *param, char *val, void *data)
 {
 	/* Change NUL term back to "=", to make "param" the whole string. */
 	if (val) {
@@ -455,7 +455,7 @@ static noinline void __init_refok rest_init(void)
 }
 
 /* Check for early params. */
-static int __init do_early_param(char *param, char *val)
+static int __init do_early_param(char *param, char *val, void *data)
 {
 	const struct obs_kernel_param *p;
 
@@ -475,7 +475,7 @@ static int __init do_early_param(char *param, char *val)
 
 void __init parse_early_options(char *cmdline)
 {
-	parse_args("early options", cmdline, NULL, 0, do_early_param);
+	parse_args("early options", cmdline, NULL, 0, do_early_param, NULL);
 }
 
 /* Arch code calls this early on, or if not, just before other parsing. */
@@ -578,7 +578,7 @@ asmlinkage void __init start_kernel(void)
 	parse_early_param();
 	parse_args("Booting kernel", static_command_line, __start___param,
 		   __stop___param - __start___param,
-		   &unknown_bootoption);
+		   &unknown_bootoption, NULL);
 	/*
 	 * These use large bootmem allocations and must precede
 	 * kmem_cache_init()
kernel/module.c +20 -1
index 2df4630..87ce541 100644
@@ -2544,6 +2544,24 @@ static int post_relocation(struct module *mod, const struct load_info *info)
 	return module_finalize(info->hdr, info->sechdrs, mod);
 }
 
+static int unknown_param(char *param, char *val, void *data)
+{
+	struct module_unknown_param arg;
+	int ret;
+
+	arg.mod = data;
+	arg.param = param;
+	arg.val = val;
+
+	ret = blocking_notifier_call_chain(&module_notify_list,
+					  MODULE_UNKNOWN_PARAM,
+					  &arg);
+	if (ret & NOTIFY_STOP_MASK)
+		return notifier_to_errno(ret);
+
+	return -ENOENT;
+}
+
 /* Allocate and load the module: note that size of section 0 is always
    zero, and we rely on this for optional sections. */
 static struct module *load_module(void __user *umod,
@@ -2637,7 +2655,8 @@ static struct module *load_module(void __user *umod,
 	mutex_unlock(&module_mutex);
 
 	/* Module is ready to execute: parsing args may do that. */
-	err = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, NULL);
+	err = parse_args(mod->name, mod->args, mod->kp, mod->num_kp,
+			 unknown_param, mod);
 	if (err < 0)
 		goto unlink;
 
kernel/params.c +6 -4
index 08107d1..d8c707c 100644
@@ -87,7 +87,8 @@ static int parse_one(char *param,
 		     char *val,
 		     const struct kernel_param *params,
 		     unsigned num_params,
-		     int (*handle_unknown)(char *param, char *val))
+		     int (*handle_unknown)(char *param, char *val, void *data),
+		     void *data)
 {
 	unsigned int i;
 	int err;
@@ -109,7 +110,7 @@ static int parse_one(char *param,
 
 	if (handle_unknown) {
 		DEBUGP("Unknown argument: calling %p\n", handle_unknown);
-		return handle_unknown(param, val);
+		return handle_unknown(param, val, data);
 	}
 
 	DEBUGP("Unknown argument `%s'\n", param);
@@ -173,7 +174,8 @@ int parse_args(const char *name,
 	       char *args,
 	       const struct kernel_param *params,
 	       unsigned num,
-	       int (*unknown)(char *param, char *val))
+	       int (*unknown)(char *param, char *val, void *data),
+	       void *data)
 {
 	char *param, *val;
 
@@ -188,7 +190,7 @@ int parse_args(const char *name,
 
 		args = next_arg(args, &param, &val);
 		irq_was_disabled = irqs_disabled();
-		ret = parse_one(param, val, params, num, unknown);
+		ret = parse_one(param, val, params, num, unknown, data);
 		if (irq_was_disabled && !irqs_disabled()) {
 			printk(KERN_WARNING "parse_args(): option '%s' enabled "
 					"irq's!\n", param);
kernel/trace/trace_events.c +0 -0
index 0725eea..d23cbf3 100644

kernel/trace/trace_events.c static void trace_module_remove_events(struct module *mod) · line 1336

Quoted 7 lines
kernel/trace/trace_events.c +4 -0
@@ -1330,10 +1330,21 @@ static void trace_module_remove_events(struct module *mod)
 	up_write(&trace_event_mutex);
 }
 
+static int trace_module_unknown_param(struct module_unknown_param *arg)
+{
+	if (strcmp(arg->param, "trace") == 0) {
+		int ret = trace_set_clr_module_event(arg->mod, arg->val, 1);

This of course assumes that arg->mod is the system. Perhaps I could rewrite this to only enable events in this module.

kernel/trace/trace_events.c static void trace_module_remove_events(struct module *mod) · line 1341

Quoted 5 lines
kernel/trace/trace_events.c +5 -0
+		return NOTIFY_STOP_MASK | (NOTIFY_OK - ret);
+	}
+
+	return NOTIFY_OK;
+}

Wow! I was just going to add a direct hook into the module code, but this is much more generic!

-- Steve

Quoted 23 lines
kernel/trace/trace_events.c +5 -1
+
 static int trace_module_notify(struct notifier_block *self,
 			       unsigned long val, void *data)
 {
 	struct module *mod = data;
+	int ret = 0;
 
 	mutex_lock(&event_mutex);
 	switch (val) {
@@ -1343,10 +1354,12 @@ static int trace_module_notify(struct notifier_block *self,
 	case MODULE_STATE_GOING:
 		trace_module_remove_events(mod);
 		break;
+	case MODULE_UNKNOWN_PARAM:
+		ret = trace_module_unknown_param(data);
 	}
 	mutex_unlock(&event_mutex);
 
-	return 0;
+	return ret;
 }
 #else
 static int trace_module_notify(struct notifier_block *self,
#12 lore raw

Re: [PATCH] Delegate unknown module parameters to interested parties

Quoted 1 line · Steven Rostedt

[ Added Rusty "Module God" Russell ]

And I also wrote the parameter parsing code, so sending to me is probably a good idea.

So, what's this for? You want trace= as a standard module parameter or something? If this is a once-off I'd prefer a custom hack I think. If you can think of other users, this might be a good idea; though don't use "void *data" use an explicit struct module *...

Cheers,
Rusty.

maintainer
#13 lore raw

Re: [PATCH] Delegate unknown module parameters to interested parties

Quoted 7 lines · Rusty Russell
Quoted 1 line · Steven Rostedt

[ Added Rusty "Module God" Russell ]

And I also wrote the parameter parsing code, so sending to me is probably a good idea.

So, what's this for? You want trace= as a standard module parameter

Yep, this way we could even enable tracepoints that are in the init section.

Quoted 3 lines

or something? If this is a once-off I'd prefer a custom hack I think. If you can think of other users, this might be a good idea; though don't use "void *data" use an explicit struct module *...

If I wrote the code, it would have been a once-off custom hack. But, personally, I like the generic addition. Perhaps others will hook into it without fear of having to hack the module code, which can be quite intimidating to some.

I also agree to not use the void *data.

-- Steve

#14 lore raw

Re: [PATCH] Delegate unknown module parameters to interested parties

Quoted 11 lines · Steven Rostedt
Quoted 7 lines · Rusty Russell
Quoted 1 line · Steven Rostedt

[ Added Rusty "Module God" Russell ]

And I also wrote the parameter parsing code, so sending to me is probably a good idea.

So, what's this for? You want trace= as a standard module parameter

Yep, this way we could even enable tracepoints that are in the init section.

*Exactly* how would it be used though? Please provide a synopsis for someone unaware of what tracing does these days?

Because we could compile an extra module_parm() into the module using modpost, for example, at a cost of an extra 16/32 bytes per module.

Quoted 3 lines

But, personally, I like the generic addition. Perhaps others will hook into it without fear of having to hack the module code, which can be quite intimidating to some.

We *all* want to build infrastructure; when other coders are forced to use it we rise up the kernel dominance hierarchy. Ook ook! (Every Unix app has its own config language for the same reason: the author distils the mental sweat of the users into some kind of Elixer of Coder Hubris).

Yet abstractions obfuscate: let's resist our primal urges to add another speed hump on the lengthening road to kernel expertese.

And this one's classicly easy: in single uses cases we always get the infrastructure wrong for future users anyway, so let's not do it until we have more than one user.

Cheers,
Rusty.

maintainer
#15 lore raw

Re: [PATCH] Delegate unknown module parameters to interested parties

Quoted 6 lines · Rusty Russell
Quoted 3 lines

Yep, this way we could even enable tracepoints that are in the init section.

*Exactly* how would it be used though? Please provide a synopsis for someone unaware of what tracing does these days?

Well, if you have a tracepoint in the module, and you want to enable it as soon as the module is loaded, it would be nice to have that ability.

Quoted 4 lines

Because we could compile an extra module_parm() into the module using modpost, for example, at a cost of an extra 16/32 bytes per module.

Quoted 8 lines
Quoted 3 lines

But, personally, I like the generic addition. Perhaps others will hook into it without fear of having to hack the module code, which can be quite intimidating to some.

We *all* want to build infrastructure; when other coders are forced to use it we rise up the kernel dominance hierarchy. Ook ook! (Every Unix app has its own config language for the same reason: the author distils the mental sweat of the users into some kind of Elixer of Coder Hubris).

Note, I would have just done the hack, but I liked Chris's generic approach. /me ook ooks Chris!

Quoted 3 lines

Yet abstractions obfuscate: let's resist our primal urges to add another speed hump on the lengthening road to kernel expertese.

Adding a generic way to do global module options is a primal urge?

Quoted 4 lines

And this one's classicly easy: in single uses cases we always get the infrastructure wrong for future users anyway, so let's not do it until we have more than one user.

OK, we can add the hack for now. But perhaps have an archive of this patch (maybe even sneak a link to it in the change log).

Hmm, we can just add:

LKML-Reference: <[email protected]>

-- Steve

#16 lore raw

PATCH 3/4 tracing: update trace-events-sample.c

In reply to Yuanhan Liu

Update the samples/trace_events/trace-events-sample.c to show how to use trace_set_clr_module_event to enable some events at module load time.

---
 samples/trace_events/trace-events-sample.c |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)
samples/trace_events/trace-events-sample.c +13 -3
index aabc4e9..b7212e1 100644
@@ -9,7 +9,10 @@
  */
 #define CREATE_TRACE_POINTS
 #include "trace-events-sample.h"
+#include <linux/ftrace_event.h>
 
+char *sample_trace = NULL;
+module_param_named(trace, sample_trace, charp, 0400);
 
 static void simple_thread_func(int cnt)
 {
@@ -32,11 +35,18 @@ static struct task_struct *simple_tsk;
 
 static int __init trace_event_init(void)
 {
+	int ret = 0;
+
+        if (sample_trace) {
+                ret = trace_set_clr_module_event(THIS_MODULE, sample_trace, 1);
+		if (ret)
+			return ret;
+	}
+
 	simple_tsk = kthread_run(simple_thread, NULL, "event-sample");
-	if (IS_ERR(simple_tsk))
-		return -1;
+	ret = PTR_ERR(simple_tsk);
 
-	return 0;
+	return ret;
 }
 
 static void __exit trace_event_exit(void)
Signature · 1 line
1.7.2.3
#17 lore raw

PATCH 4/4 tracing: update the trace/events.txt documentation

In reply to Yuanhan Liu

Describe the usage of trace_set_clr_module_event in events.txt

---
 Documentation/trace/events.txt |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)
Documentation/trace/events.txt +25 -0
index 09bd8e9..120c1fe 100644
@@ -93,6 +93,31 @@ In order to facilitate early boot debugging, use boot option:
 event-list is a comma separated list of events. See section 2.1 for event
 format.
 
+2.4 Module load option
+----------------------
+
+In order to track the events at the early module load phase, add the
+following codes in your module:
+
+    char *xxx_trace = NULL;
+    module_param_named(trace, xxx_trace, charp, 0400);
+
+
+    /* Your module init function */
+    xxx_init()
+    {
+        ....
+        if (xxx_trace)
+                trace_set_clr_module_event(THIS_MODULE, xxx_trace, 1);
+        ....
+    }
+
+where the xxx_trace is same as event-list described above, besides DO
+NOT include the subsystem.
+
+You can check the sample code for more information.
+
+
 3. Defining an event-enabled tracepoint
 =======================================
 
Signature · 1 line
1.7.2.3