From f7fb9c9182dc874e5d1f1b0c4adc7398b763216d Mon Sep 17 00:00:00 2001 From: William Cohen Date: Thu, 7 Mar 2019 09:37:53 -0500 Subject: [PATCH] Do the search save_stack_trace_regs() in the stap module's initialization Previously, the search for save_stack_trace_regs() was done the first time the _stp_stack_print_fallback was called. However, want to avoid calling kallsyms_lookup_name() in some arbitrary probe handler as it may take a signficant amount of time to search for save_stack_trace_regs(). Moving this search to where other initialization operations are done and there are fewer contraints on runninging it. --- runtime/stack.c | 18 ++++++++++-------- translate.cxx | 9 +++++++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/runtime/stack.c b/runtime/stack.c index 3539dd352..90ad8b56e 100644 --- a/runtime/stack.c +++ b/runtime/stack.c @@ -47,10 +47,19 @@ #include #endif -static int checked_stack_trace_fns; static void (*(save_stack_trace_regs_fn))(struct pt_regs *regs, struct stack_trace *trace); +static int +_stp_init_stack(void) +{ + /* check for save_stack_trace_regs function for fallback stack print */ + save_stack_trace_regs_fn = (void *)kallsyms_lookup_name("save_stack_trace_regs"); + dbug_unwind(1, "save_stack_trace_regs_fn=%lx for _stp_stack_print_fallback().\n", + (unsigned long) save_stack_trace_regs_fn); + return 0; +} + static void _stp_stack_print_fallback(unsigned long, struct pt_regs*, int, int, int); #ifdef STP_USE_DWARF_UNWINDER @@ -162,13 +171,6 @@ static void _stp_stack_print_fallback(unsigned long sp, struct pt_regs *regs, struct stack_trace trace; int i; - /* One time check for save_stack_trace_regs */ - if (!checked_stack_trace_fns) { - dbug_unwind(1, "fallback kernel stacktrace search for save_stack_trace_regs\n"); - save_stack_trace_regs_fn = (void *)kallsyms_lookup_name("save_stack_trace_regs"); - checked_stack_trace_fns = 1; - } - /* If don't have save_stack_trace_regs unwinder, just give up. */ if (!save_stack_trace_regs_fn) { dbug_unwind(1, "no fallback kernel stacktrace (giving up)\n"); diff --git a/translate.cxx b/translate.cxx index b15cbc2fb..2524f4ea3 100644 --- a/translate.cxx +++ b/translate.cxx @@ -1918,6 +1918,15 @@ c_unparser::emit_module_init () o->newline(-1) << "}"; o->newline() << "#endif"; + // initialize stack setup (if needed) + o->newline() << "#ifdef STP_NEED_UNWIND_DATA"; + o->newline() << "rc = _stp_init_stack();"; + o->newline() << "if (rc) {"; + o->newline(1) << "_stp_error (\"couldn't initialize stack support\");"; + o->newline() << "goto out;"; + o->newline(-1) << "}"; + o->newline() << "#endif"; + // NB: we don't need per-_stp_module task_finders, since a single common one // set up in runtime/sym.c's _stp_sym_init() will scan through all _stp_modules. XXX - check this! o->newline() << "(void) probe_point;"; -- 2.43.5