All of lore.kernel.org
 help / color / mirror / Atom feed
* using skip>0 with bpf_get_stack()
@ 2021-05-28 22:16 Eugene Loh
  2021-06-01 21:48 ` Yonghong Song
  0 siblings, 1 reply; 7+ messages in thread
From: Eugene Loh @ 2021-05-28 22:16 UTC (permalink / raw)
  To: bpf

I have a question about bpf_get_stack().  I'm interested in the case
         skip > 0
         user_build_id == 0
         num_elem < sysctl_perf_event_max_stack

The function sets
         init_nr = sysctl_perf_event_max_stack - num_elem;
which means that get_perf_callchain() will return "num_elem" stack 
frames.  Then, since we skip "skip" frames, we'll fill the user buffer 
with only "num_elem - skip" frames, the remaining frames being filled zero.

For example, let's say the call stack is
         leaf <- caller <- foo1 <- foo2 <- foo3 <- foo4 <- foo5 <- foo6

Let's say I pass bpf_get_stack() a buffer with num_elem==4 and ask 
skip==2.  I would expect to skip 2 frames then get 4 frames, getting back:
         foo1  foo2  foo3  foo4

Instead, I get
         foo1  foo2  0  0
skipping 2 frames but also leaving frames zeroed out.

I think the init_nr computation should be:

-       if (sysctl_perf_event_max_stack < num_elem)
+       if (sysctl_perf_event_max_stack <= num_elem + skip)
                 init_nr = 0;
         else
-               init_nr = sysctl_perf_event_max_stack - num_elem;
+               init_nr = sysctl_perf_event_max_stack - num_elem - skip;

Incidentally, the return value of the function is presumably the size of 
the returned data.  Would it make sense to say so in 
include/uapi/linux/bpf.h?


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-03-04 21:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-28 22:16 using skip>0 with bpf_get_stack() Eugene Loh
2021-06-01 21:48 ` Yonghong Song
2021-06-26  1:22   ` Eugene Loh
2021-06-29  3:33     ` Yonghong Song
2022-03-04 20:37       ` Namhyung Kim
2022-03-04 20:50         ` Eugene Loh
2022-03-04 21:16           ` Namhyung Kim

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.