From 4c2732a1dad1de295c9219ee3afac007b2d7ba05 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 28 Jan 2009 14:36:08 -0800 Subject: Use 'static' as much as possible This change just inserts 'static' on runtime, tapset, and generated C functions and globals, so the compiler can do a better job of optimizing. My tests with small scripts show ~10% reduction in compile time and ~20% reduction in module size. Larger scripts may show less benefit, but I expect purely positive results. --- runtime/stack.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'runtime/stack.c') diff --git a/runtime/stack.c b/runtime/stack.c index 23ac2edc..7ca0e316 100644 --- a/runtime/stack.c +++ b/runtime/stack.c @@ -47,7 +47,7 @@ * @param regs A pointer to the struct pt_regs. */ -void _stp_stack_print(struct pt_regs *regs, int verbose, struct kretprobe_instance *pi, int levels) +static void _stp_stack_print(struct pt_regs *regs, int verbose, struct kretprobe_instance *pi, int levels) { if (verbose) { /* print the current address */ @@ -75,7 +75,7 @@ void _stp_stack_print(struct pt_regs *regs, int verbose, struct kretprobe_instan * @param regs A pointer to the struct pt_regs. * @returns void */ -void _stp_stack_snprint(char *str, int size, struct pt_regs *regs, int verbose, struct kretprobe_instance *pi, int levels) +static void _stp_stack_snprint(char *str, int size, struct pt_regs *regs, int verbose, struct kretprobe_instance *pi, int levels) { /* To get a string, we use a simple trick. First flush the print buffer, */ /* then call _stp_stack_print, then copy the result into the output string */ @@ -93,7 +93,7 @@ void _stp_stack_snprint(char *str, int size, struct pt_regs *regs, int verbose, * @note Currently limited to a depth of two. Works from jprobes and kprobes. */ #if 0 -void _stp_ustack_print(char *str) +static void _stp_ustack_print(char *str) { struct pt_regs *nregs = ((struct pt_regs *)(THREAD_SIZE + (unsigned long)current->thread_info)) - 1; _stp_printf("%p : [user]\n", (int64_t) REG_IP(nregs)); -- cgit From bbc46bf643491173b9086907cf0820b3fd2c1fe3 Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Mon, 2 Feb 2009 15:58:53 +0100 Subject: Use kernel stack backtrace support when available Define new functions that use the kernel support to do a backtrace of other tasks than current. --- runtime/stack.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) (limited to 'runtime/stack.c') diff --git a/runtime/stack.c b/runtime/stack.c index 7ca0e316..25d0817d 100644 --- a/runtime/stack.c +++ b/runtime/stack.c @@ -27,6 +27,11 @@ #define MAXBACKTRACE 20 +#include +#include + +static void _stp_stack_print_fallback(unsigned long, int, int); + #if defined (__x86_64__) #include "stack-x86_64.c" #elif defined (__ia64__) @@ -43,6 +48,53 @@ #error "Unsupported architecture" #endif +#ifdef CONFIG_STACKTRACE + +struct print_stack_data +{ + int verbose; + int max_level; + int level; +}; + +static void print_stack_warning(void *data, char *msg) +{ +} + +static void +print_stack_warning_symbol(void *data, char *msg, unsigned long symbol) +{ +} + +static int print_stack_stack(void *data, char *name) +{ + return -1; +} + +static void print_stack_address(void *data, unsigned long addr, int reliable) +{ + struct print_stack_data *sdata = data; + if (sdata->level++ < sdata->max_level) + _stp_func_print(addr,sdata->verbose, 0); +} + +static const struct stacktrace_ops print_stack_ops = { + .warning = print_stack_warning, + .warning_symbol = print_stack_warning_symbol, + .stack = print_stack_stack, + .address = print_stack_address, +}; + +static void _stp_stack_print_fallback(unsigned long stack, int verbose, int levels) +{ + struct print_stack_data print_data; + print_data.verbose = verbose; + print_data.max_level = levels; + print_data.level = 0; + dump_trace(current, NULL, (long *)stack, 0, &print_stack_ops, + &print_data); +} +#endif /** Prints the stack backtrace * @param regs A pointer to the struct pt_regs. */ @@ -103,4 +155,39 @@ static void _stp_ustack_print(char *str) #endif /* 0 */ /** @} */ + +void _stp_stack_print_tsk(struct task_struct *tsk, int verbose, int levels) +{ +#ifdef CONFIG_STACKTRACE + int i; + unsigned long backtrace[MAXBACKTRACE]; + struct stack_trace trace; + int maxLevels = min(levels, MAXBACKTRACE); + memset(&trace, 0, sizeof(trace)); + trace.entries = &backtrace[0]; + trace.max_entries = maxLevels; + trace.skip = 0; + save_stack_trace_tsk(tsk, &trace); + for (i = 0; i < maxLevels; ++i) { + if (backtrace[i] == 0 || backtrace[i] == ULONG_MAX) + break; + _stp_printf("%lx ", backtrace[i]); + } +#endif +} + +/** Writes a task stack backtrace to a string + * + * @param str string + * @param tsk A pointer to the task_struct + * @returns void + */ +void _stp_stack_snprint_tsk(char *str, int size, struct task_struct *tsk, int verbose, int levels) +{ + _stp_pbuf *pb = per_cpu_ptr(Stp_pbuf, smp_processor_id()); + _stp_print_flush(); + _stp_stack_print_tsk(tsk, verbose, levels); + strlcpy(str, pb->buf, size < (int)pb->len ? size : (int)pb->len); + pb->len = 0; +} #endif /* _STACK_C_ */ -- cgit From 8c06f971cc14dab53e279e85519f34c57c783338 Mon Sep 17 00:00:00 2001 From: David Smith Date: Fri, 13 Feb 2009 12:51:05 -0600 Subject: Fixed stack.c compile problems on systems with older kernels (like RHEL4). 2009-02-13 David Smith * stack.c: Fixed compile problems on systems with older kernels (like RHEL4). --- runtime/stack.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'runtime/stack.c') diff --git a/runtime/stack.c b/runtime/stack.c index 25d0817d..2a133398 100644 --- a/runtime/stack.c +++ b/runtime/stack.c @@ -27,8 +27,10 @@ #define MAXBACKTRACE 20 +#ifdef CONFIG_STACKTRACE #include #include +#endif static void _stp_stack_print_fallback(unsigned long, int, int); -- cgit From 8aaa6e11f666ad372107299b5b17602011125c7d Mon Sep 17 00:00:00 2001 From: "Frank Ch. Eigler" Date: Wed, 18 Feb 2009 19:33:06 -0500 Subject: PR9866 band-aid: deactivate new CONFIG_STACKTRACE code for older kernels --- runtime/stack.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'runtime/stack.c') diff --git a/runtime/stack.c b/runtime/stack.c index 2a133398..aa0e6d65 100644 --- a/runtime/stack.c +++ b/runtime/stack.c @@ -27,7 +27,8 @@ #define MAXBACKTRACE 20 -#ifdef CONFIG_STACKTRACE +#if defined(CONFIG_STACKTRACE) && LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26) +// XXX: PR9866: hacky temporarily restriction to recent kernels #include #include #endif @@ -50,7 +51,7 @@ static void _stp_stack_print_fallback(unsigned long, int, int); #error "Unsupported architecture" #endif -#ifdef CONFIG_STACKTRACE +#if defined(CONFIG_STACKTRACE) && LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26) struct print_stack_data { @@ -160,7 +161,7 @@ static void _stp_ustack_print(char *str) void _stp_stack_print_tsk(struct task_struct *tsk, int verbose, int levels) { -#ifdef CONFIG_STACKTRACE +#if defined(CONFIG_STACKTRACE) && LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26) int i; unsigned long backtrace[MAXBACKTRACE]; struct stack_trace trace; -- cgit