Skip to content

Commit 4e37958

Browse files
committed
init, tracing: Have printk come through the trace events for initcall_debug
With trace events set before and after the initcall function calls, instead of having a separate routine for printing out the initcalls when initcall_debug is specified on the kernel command line, have the code register a callback to the tracepoints where the initcall trace events are. This removes the need for having a separate function to do the initcalls as the tracepoint callbacks can handle the printk. It also includes other initcalls that are not called by the do_one_initcall() which includes console and security initcalls. Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 58eacff commit 4e37958

File tree

1 file changed

+35
-16
lines changed

1 file changed

+35
-16
lines changed

init/main.c

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,10 @@ void __init __weak thread_stack_cache_init(void)
494494

495495
void __init __weak mem_encrypt_init(void) { }
496496

497+
bool initcall_debug;
498+
core_param(initcall_debug, initcall_debug, bool, 0644);
499+
static void __init initcall_debug_enable(void);
500+
497501
/*
498502
* Set up kernel memory allocators
499503
*/
@@ -615,6 +619,9 @@ asmlinkage __visible void __init start_kernel(void)
615619
/* Trace events are available after this */
616620
trace_init();
617621

622+
if (initcall_debug)
623+
initcall_debug_enable();
624+
618625
context_tracking_init();
619626
/* init some links before init_ISA_irqs() */
620627
early_irq_init();
@@ -731,9 +738,6 @@ static void __init do_ctors(void)
731738
#endif
732739
}
733740

734-
bool initcall_debug;
735-
core_param(initcall_debug, initcall_debug, bool, 0644);
736-
737741
#ifdef CONFIG_KALLSYMS
738742
struct blacklist_entry {
739743
struct list_head next;
@@ -803,38 +807,53 @@ static bool __init_or_module initcall_blacklisted(initcall_t fn)
803807
#endif
804808
__setup("initcall_blacklist=", initcall_blacklist);
805809

806-
static int __init_or_module do_one_initcall_debug(initcall_t fn)
810+
static __init_or_module void
811+
trace_initcall_start_cb(void *data, initcall_t fn)
807812
{
808-
ktime_t calltime, delta, rettime;
809-
unsigned long long duration;
810-
int ret;
813+
ktime_t *calltime = (ktime_t *)data;
811814

812815
printk(KERN_DEBUG "calling %pF @ %i\n", fn, task_pid_nr(current));
813-
calltime = ktime_get();
814-
ret = fn();
816+
*calltime = ktime_get();
817+
}
818+
819+
static __init_or_module void
820+
trace_initcall_finish_cb(void *data, initcall_t fn, int ret)
821+
{
822+
ktime_t *calltime = (ktime_t *)data;
823+
ktime_t delta, rettime;
824+
unsigned long long duration;
825+
815826
rettime = ktime_get();
816-
delta = ktime_sub(rettime, calltime);
827+
delta = ktime_sub(rettime, *calltime);
817828
duration = (unsigned long long) ktime_to_ns(delta) >> 10;
818829
printk(KERN_DEBUG "initcall %pF returned %d after %lld usecs\n",
819830
fn, ret, duration);
831+
}
820832

821-
return ret;
833+
static ktime_t initcall_calltime;
834+
835+
static void __init initcall_debug_enable(void)
836+
{
837+
int ret;
838+
839+
ret = register_trace_initcall_start(trace_initcall_start_cb,
840+
&initcall_calltime);
841+
ret |= register_trace_initcall_finish(trace_initcall_finish_cb,
842+
&initcall_calltime);
843+
WARN(ret, "Failed to register initcall tracepoints\n");
822844
}
823845

824846
int __init_or_module do_one_initcall(initcall_t fn)
825847
{
826848
int count = preempt_count();
827-
int ret;
828849
char msgbuf[64];
850+
int ret;
829851

830852
if (initcall_blacklisted(fn))
831853
return -EPERM;
832854

833855
trace_initcall_start(fn);
834-
if (initcall_debug)
835-
ret = do_one_initcall_debug(fn);
836-
else
837-
ret = fn();
856+
ret = fn();
838857
trace_initcall_finish(fn, ret);
839858

840859
msgbuf[0] = 0;

0 commit comments

Comments
 (0)