-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
libbpf-tools/offcputime: Add -P option to post unwind user stack backtrace using dwarf unwind via libunwind #4463
base: master
Are you sure you want to change the base?
Conversation
@davemarchevsky could you also take a look at this patch? |
I think this could be a useful feature. In most bcc tools, the user space gets stack_id and a list of addresses for the stack and then reconstruct the symbolized stack strace based recorded pid. If the application compiled with omitting frame pointer, it would be hard from the kernel to figure out the correct stack trace. In these cases, having a backup using user space libunwind seems a reasonable alternative. So please go ahead to finish your implementation. I see you use stack size 128. This may not be enough for real world big application which could be up to 4k. I think we should make stack size as part of the input for -P. If not specified, you could use 128 bytes. |
Thank you for your answers and comments. |
c6e4ca1
to
74ad561
Compare
Not yet subject to review. Thank you. |
032adab
to
d689460
Compare
@@ -26,6 +29,10 @@ USE_BLAZESYM ?= 1 | |||
endif | |||
endif | |||
|
|||
ifeq ($(ARCH),x86) | |||
USE_LIBUNWIND = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please tell me if LIBUNWIND should be enabled by default?
case 'P': | ||
env.unwind = true; | ||
break; | ||
case OPT_SAMPLE_STACK_SIZE: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should make stack size as part of the input for -P. If not specified, you could use 128 bytes.
offcputime has a positional argument for the duration, so -P cannot be set to OPTION_ARG_OPTIONAL.
Therefore, a separate option for stack size has been added.
@@ -26,6 +29,10 @@ USE_BLAZESYM ?= 1 | |||
endif | |||
endif | |||
|
|||
ifeq ($(ARCH),x86) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, only build libunwind for x86 is added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a test example using the test application in the description.
# ./offcputime -P --sample-stack-size 1024 -p `pidof test-strlen-abc-nofp-unwtbl`
^C
bpf_prog_99b48c45746a8a74_sched_switch
bpf_prog_99b48c45746a8a74_sched_switch
bpf_trace_run3
__traceiter_sched_switch
__schedule
schedule
exit_to_user_mode_prepare
irqentry_exit_to_user_mode
asm_sysvec_apic_timer_interrupt
strlen
c
b
a
main
__libc_start_main
_start
[unknown]
[unknown]
- test-strlen-abc (26307)
50
test with -v option.
# ./offcputime -P -v --sample-stack-size 1024 -p `pidof test-strlen-abc-nofp-unwtbl`
#0 0xffffffffc001259c bpf_prog_99b48c45746a8a74_sched_switch+0x4bc
#1 0xffffffffc001259c bpf_prog_99b48c45746a8a74_sched_switch+0x4bc
#2 0xffffffff8116952e bpf_trace_run3+0x3e
#3 0xffffffff8109be54 __traceiter_sched_switch+0x34
#4 0xffffffff81c5f7ba __schedule+0x30a
#5 0xffffffff81c5fbff schedule+0x3f
#6 0xffffffff810f3766 exit_to_user_mode_prepare+0x56
#7 0xffffffff81c5d6d5 irqentry_exit_to_user_mode+0x5
#8 0xffffffff81e00c42 asm_sysvec_apic_timer_interrupt+0x12
#9 0x00007f9797d6fbc6 strlen+0x106 (/lib/x86_64-linux-gnu/libc-2.19.so+0x88bc6)
#10 0x00005582b6600716 c+0x2a (/root/es/unwind/test-strlen-abc-nofp-unwtbl+0x716)
#11 0x00005582b66006e4 b+0x9 (/root/es/unwind/test-strlen-abc-nofp-unwtbl+0x6e4)
#12 0x00005582b66006d3 a+0x9 (/root/es/unwind/test-strlen-abc-nofp-unwtbl+0x6d3)
#13 0x00005582b6600756 main+0x11 (/root/es/unwind/test-strlen-abc-nofp-unwtbl+0x756)
#14 0x00007f9797d08ec5 __libc_start_main+0xf5 (/lib/x86_64-linux-gnu/libc-2.19.so+0x21ec5)
#15 0x00005582b66005ea _start+0x2a (/root/es/unwind/test-strlen-abc-nofp-unwtbl+0x5ea)
#16 0xffffffff81c5d6d5 (/root/es/unwind/test-strlen-abc-nofp-unwtbl+0x5ea)
#17 0xffffffff81e00c42 (/root/es/unwind/test-strlen-abc-nofp-unwtbl+0x5ea)
- test-strlen-abc (26307)
54
Thank you for waiting so long.
Could you please review this?
Thank you.
d689460
to
8c28a91
Compare
In the last update, this feature is only built if USE_LIBUNWIND is enabled in the Makefile. |
libbpf-tools/unwind_helpers.h
Outdated
#include <libunwind-ptrace.h> | ||
#include "unwind_types.h" | ||
|
||
enum log_level { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a log level only for this feature(post unwinding
)? Could you please tell me the role of this enum log_level
?
libbpf-tools/unwind_helpers.h
Outdated
struct unw_data data; | ||
}; | ||
|
||
int unw_init(struct unw_info *u, pid_t pid, size_t user_stack_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about mentioning the meaning of each parameters for each APIs?
libbpf-tools/offcputime.c
Outdated
@@ -355,9 +427,25 @@ int main(int argc, char **argv) | |||
*/ | |||
sleep(env.duration); | |||
|
|||
#ifdef USE_LIBUNWIND |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about removing USE_LIBUNWIND
macros?
libbpf-tools/offcputime.c
Outdated
#ifdef USE_LIBUNWIND | ||
if (env.unwind) { | ||
if (post_unwind(u, sample_fd, ustack_fd, next_key.user_stack_id, | ||
ip, env.perf_max_stack_depth) != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if ip
were the last parameter.
@Bojun-Seo |
8c28a91
to
e1485ea
Compare
…ng libunwind unwind.bpf.h: bpf helper API for user stack and register dumps unwind_helpers: helper API for post dwarf unwind using libunwind
Use installed libunwind (Only builds for x86 are supported in this patch.): check Signed-off-by: Eunseon Lee <[email protected]>
…wind_helpers Add -P option to use post dwarf unwind with libunwind. With the option, bpf program dump user stack and user regs. and user program get user stack traces using unwind_helpers to show output.
e1485ea
to
80cf8c0
Compare
This is not the finished version for review. Before I finish, I'd like to know that this feature is required by bcc.
Can you please let me know if post unwind using dwarf unwind via libunwind is needed and it helps with issues like #3515?
FYI, there are a few things left to do for this PR if needed:
test environment
Tested with profile in aarch64 environment.
However, the profile's review PR is not in progress, so I apply it to offcputime to share the code.
This is the test results.
Before:
After:
Test executable has no frame pointer, but has an unwind table (.eh_frame).
3.1 compile option : -fomit-frame-pointer -funwind-tables
3.2 code
Thank you.