@@ -1153,17 +1153,36 @@ static void remove_event_file_dir(struct trace_event_file *file)
11531153 */
11541154static int
11551155__ftrace_set_clr_event_nolock (struct trace_array * tr , const char * match ,
1156- const char * sub , const char * event , int set )
1156+ const char * sub , const char * event , int set ,
1157+ const char * mod )
11571158{
11581159 struct trace_event_file * file ;
11591160 struct trace_event_call * call ;
1161+ char * module __free (kfree ) = NULL ;
11601162 const char * name ;
11611163 int ret = - EINVAL ;
11621164 int eret = 0 ;
11631165
1166+ if (mod ) {
1167+ char * p ;
1168+
1169+ module = kstrdup (mod , GFP_KERNEL );
1170+ if (!module )
1171+ return - ENOMEM ;
1172+
1173+ /* Replace all '-' with '_' as that's what modules do */
1174+ for (p = strchr (module , '-' ); p ; p = strchr (p + 1 , '-' ))
1175+ * p = '_' ;
1176+ }
1177+
11641178 list_for_each_entry (file , & tr -> events , list ) {
11651179
11661180 call = file -> event_call ;
1181+
1182+ /* If a module is specified, skip events that are not that module */
1183+ if (module && (!call -> module || strcmp (module_name (call -> module ), module )))
1184+ continue ;
1185+
11671186 name = trace_event_name (call );
11681187
11691188 if (!name || !call -> class || !call -> class -> reg )
@@ -1200,24 +1219,34 @@ __ftrace_set_clr_event_nolock(struct trace_array *tr, const char *match,
12001219}
12011220
12021221static int __ftrace_set_clr_event (struct trace_array * tr , const char * match ,
1203- const char * sub , const char * event , int set )
1222+ const char * sub , const char * event , int set ,
1223+ const char * mod )
12041224{
12051225 int ret ;
12061226
12071227 mutex_lock (& event_mutex );
1208- ret = __ftrace_set_clr_event_nolock (tr , match , sub , event , set );
1228+ ret = __ftrace_set_clr_event_nolock (tr , match , sub , event , set , mod );
12091229 mutex_unlock (& event_mutex );
12101230
12111231 return ret ;
12121232}
12131233
12141234int ftrace_set_clr_event (struct trace_array * tr , char * buf , int set )
12151235{
1216- char * event = NULL , * sub = NULL , * match ;
1236+ char * event = NULL , * sub = NULL , * match , * mod ;
12171237 int ret ;
12181238
12191239 if (!tr )
12201240 return - ENOENT ;
1241+
1242+ /* Modules events can be appened with :mod:<module> */
1243+ mod = strstr (buf , ":mod:" );
1244+ if (mod ) {
1245+ * mod = '\0' ;
1246+ /* move to the module name */
1247+ mod += 5 ;
1248+ }
1249+
12211250 /*
12221251 * The buf format can be <subsystem>:<event-name>
12231252 * *:<event-name> means any event by that name.
@@ -1240,9 +1269,13 @@ int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set)
12401269 sub = NULL ;
12411270 if (!strlen (event ) || strcmp (event , "*" ) == 0 )
12421271 event = NULL ;
1272+ } else if (mod ) {
1273+ /* Allow wildcard for no length or star */
1274+ if (!strlen (match ) || strcmp (match , "*" ) == 0 )
1275+ match = NULL ;
12431276 }
12441277
1245- ret = __ftrace_set_clr_event (tr , match , sub , event , set );
1278+ ret = __ftrace_set_clr_event (tr , match , sub , event , set , mod );
12461279
12471280 /* Put back the colon to allow this to be called again */
12481281 if (buf )
@@ -1270,7 +1303,7 @@ int trace_set_clr_event(const char *system, const char *event, int set)
12701303 if (!tr )
12711304 return - ENODEV ;
12721305
1273- return __ftrace_set_clr_event (tr , NULL , system , event , set );
1306+ return __ftrace_set_clr_event (tr , NULL , system , event , set , NULL );
12741307}
12751308EXPORT_SYMBOL_GPL (trace_set_clr_event );
12761309
@@ -1296,7 +1329,7 @@ int trace_array_set_clr_event(struct trace_array *tr, const char *system,
12961329 return - ENOENT ;
12971330
12981331 set = (enable == true) ? 1 : 0 ;
1299- return __ftrace_set_clr_event (tr , NULL , system , event , set );
1332+ return __ftrace_set_clr_event (tr , NULL , system , event , set , NULL );
13001333}
13011334EXPORT_SYMBOL_GPL (trace_array_set_clr_event );
13021335
@@ -1646,7 +1679,7 @@ system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
16461679 if (system )
16471680 name = system -> name ;
16481681
1649- ret = __ftrace_set_clr_event (dir -> tr , NULL , name , NULL , val );
1682+ ret = __ftrace_set_clr_event (dir -> tr , NULL , name , NULL , val , NULL );
16501683 if (ret )
16511684 goto out ;
16521685
@@ -4094,7 +4127,7 @@ int event_trace_del_tracer(struct trace_array *tr)
40944127 __ftrace_clear_event_pids (tr , TRACE_PIDS | TRACE_NO_PIDS );
40954128
40964129 /* Disable any running events */
4097- __ftrace_set_clr_event_nolock (tr , NULL , NULL , NULL , 0 );
4130+ __ftrace_set_clr_event_nolock (tr , NULL , NULL , NULL , 0 , NULL );
40984131
40994132 /* Make sure no more events are being executed */
41004133 tracepoint_synchronize_unregister ();
@@ -4378,7 +4411,7 @@ static __init void event_trace_self_tests(void)
43784411
43794412 pr_info ("Testing event system %s: " , system -> name );
43804413
4381- ret = __ftrace_set_clr_event (tr , NULL , system -> name , NULL , 1 );
4414+ ret = __ftrace_set_clr_event (tr , NULL , system -> name , NULL , 1 , NULL );
43824415 if (WARN_ON_ONCE (ret )) {
43834416 pr_warn ("error enabling system %s\n" ,
43844417 system -> name );
@@ -4387,7 +4420,7 @@ static __init void event_trace_self_tests(void)
43874420
43884421 event_test_stuff ();
43894422
4390- ret = __ftrace_set_clr_event (tr , NULL , system -> name , NULL , 0 );
4423+ ret = __ftrace_set_clr_event (tr , NULL , system -> name , NULL , 0 , NULL );
43914424 if (WARN_ON_ONCE (ret )) {
43924425 pr_warn ("error disabling system %s\n" ,
43934426 system -> name );
@@ -4402,7 +4435,7 @@ static __init void event_trace_self_tests(void)
44024435 pr_info ("Running tests on all trace events:\n" );
44034436 pr_info ("Testing all events: " );
44044437
4405- ret = __ftrace_set_clr_event (tr , NULL , NULL , NULL , 1 );
4438+ ret = __ftrace_set_clr_event (tr , NULL , NULL , NULL , 1 , NULL );
44064439 if (WARN_ON_ONCE (ret )) {
44074440 pr_warn ("error enabling all events\n" );
44084441 return ;
@@ -4411,7 +4444,7 @@ static __init void event_trace_self_tests(void)
44114444 event_test_stuff ();
44124445
44134446 /* reset sysname */
4414- ret = __ftrace_set_clr_event (tr , NULL , NULL , NULL , 0 );
4447+ ret = __ftrace_set_clr_event (tr , NULL , NULL , NULL , 0 , NULL );
44154448 if (WARN_ON_ONCE (ret )) {
44164449 pr_warn ("error disabling all events\n" );
44174450 return ;
0 commit comments