Commit 5cb084bb1f3fd4dcdaf7e4cf564994346ec8f783

Authored by Jiri Olsa
Committed by Ingo Molnar
1 parent 756d17ee7e

tracing: Enable records during the module load

I was debuging some module using "function" and "function_graph"
tracers and noticed, that if you load module after you enabled
tracing, the module's hooks will convert only to NOP instructions.

The attached patch enables modules' hooks if there's function trace
allready on, thus allowing to trace module functions.

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <20091013203425.896285120@goodmis.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>

Showing 1 changed file with 30 additions and 8 deletions Side-by-side Diff

kernel/trace/ftrace.c
... ... @@ -1270,12 +1270,34 @@
1270 1270 ftrace_new_addrs = p->newlist;
1271 1271 p->flags = 0L;
1272 1272  
1273   - /* convert record (i.e, patch mcount-call with NOP) */
1274   - if (ftrace_code_disable(mod, p)) {
1275   - p->flags |= FTRACE_FL_CONVERTED;
1276   - ftrace_update_cnt++;
1277   - } else
  1273 + /*
  1274 + * Do the initial record convertion from mcount jump
  1275 + * to the NOP instructions.
  1276 + */
  1277 + if (!ftrace_code_disable(mod, p)) {
1278 1278 ftrace_free_rec(p);
  1279 + continue;
  1280 + }
  1281 +
  1282 + p->flags |= FTRACE_FL_CONVERTED;
  1283 + ftrace_update_cnt++;
  1284 +
  1285 + /*
  1286 + * If the tracing is enabled, go ahead and enable the record.
  1287 + *
  1288 + * The reason not to enable the record immediatelly is the
  1289 + * inherent check of ftrace_make_nop/ftrace_make_call for
  1290 + * correct previous instructions. Making first the NOP
  1291 + * conversion puts the module to the correct state, thus
  1292 + * passing the ftrace_make_call check.
  1293 + */
  1294 + if (ftrace_start_up) {
  1295 + int failed = __ftrace_replace_code(p, 1);
  1296 + if (failed) {
  1297 + ftrace_bug(failed, p->ip);
  1298 + ftrace_free_rec(p);
  1299 + }
  1300 + }
1279 1301 }
1280 1302  
1281 1303 stop = ftrace_now(raw_smp_processor_id());
... ... @@ -2609,7 +2631,7 @@
2609 2631 return 0;
2610 2632 }
2611 2633  
2612   -static int ftrace_convert_nops(struct module *mod,
  2634 +static int ftrace_process_locs(struct module *mod,
2613 2635 unsigned long *start,
2614 2636 unsigned long *end)
2615 2637 {
... ... @@ -2669,7 +2691,7 @@
2669 2691 {
2670 2692 if (ftrace_disabled || start == end)
2671 2693 return;
2672   - ftrace_convert_nops(mod, start, end);
  2694 + ftrace_process_locs(mod, start, end);
2673 2695 }
2674 2696  
2675 2697 static int ftrace_module_notify(struct notifier_block *self,
... ... @@ -2730,7 +2752,7 @@
2730 2752  
2731 2753 last_ftrace_enabled = ftrace_enabled = 1;
2732 2754  
2733   - ret = ftrace_convert_nops(NULL,
  2755 + ret = ftrace_process_locs(NULL,
2734 2756 __start_mcount_loc,
2735 2757 __stop_mcount_loc);
2736 2758