Skip to content
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

bpf_get_prandom_u32 has the wrong type and can't be called #398

Open
goldshtn opened this issue Feb 18, 2016 · 9 comments
Open

bpf_get_prandom_u32 has the wrong type and can't be called #398

goldshtn opened this issue Feb 18, 2016 · 9 comments
Assignees

Comments

@goldshtn
Copy link
Collaborator

It seems that bpf_get_prandom_u32 is declared as a u32 * in the headers. That's due to missing parens.

- static u32 (*bpf_get_prandom_u32) =
+ static u32 (*bpf_get_prandom_u32)(void) =

Also, after fixing the signature, a BPF program that uses this function doesn't pass verification. I get the following error:

bpf: Invalid argument                                                                
0: (bf) r6 = r1                                                                      
1: (85) call 14                                                                      
2: (67) r0 <<= 32                                                                    
3: (77) r0 >>= 32                                                                    
4: (15) if r0 == 0x437c goto pc+27                                                   
R0=inv R6=ctx R10=fp                                                                
5: (85) call 7                                                                       
unknown func 7 
@drzaeus77
Copy link
Collaborator

Oops, obvious syntax issue. However, the second issue is there because this func is only exported to networking programs.

@goldshtn
Copy link
Collaborator Author

Oh. Is there any particular reason for that?

@4ast
Copy link
Member

4ast commented Feb 18, 2016

it's not exposed to tracing, because there was no use case for it yet.
could you describe how you want to use it?

drzaeus77 pushed a commit that referenced this issue Feb 18, 2016
Fixes: #398
Signed-off-by: Brenden Blanco <[email protected]>
@goldshtn
Copy link
Collaborator Author

Well, for the trace tool, it could be useful if the user could do something like ($random & 7 == 0) to sample traces. It could be done by looking at the time stamp too, I guess.

goldshtn pushed a commit to goldshtn/bcc that referenced this issue Feb 21, 2016
@goldshtn
Copy link
Collaborator Author

@4ast So, do you think it will be exposed to tracing programs in the future, or do you not see this use case as compelling?

@4ast
Copy link
Member

4ast commented Feb 22, 2016

I would like to see a real use case when random sampling is actually needed. Do you want to prepare and test a kernel patch?

@goldshtn
Copy link
Collaborator Author

I've never done it, but I'm willing to learn. Is there some kind of Kernel Patches for Dummies that you recommend?

Regarding a test case, @brendangregg - what do you think?

@4ast 4ast reopened this Aug 11, 2016
@4ast
Copy link
Member

4ast commented Aug 11, 2016

the real use case came up. When we're doing sampling in kprobes and tracepoints it's often useful not to process every event and instead randomly drop most of them. arraymap counter can be used as token but random is easier to use. timestamp doesn't have entropy when there are lots of events. So pretty much what @goldshtn said. We just faced the issue on our own :)

@4ast 4ast self-assigned this Aug 11, 2016
@pchaigno
Copy link
Contributor

pchaigno commented Aug 7, 2017

Fixed with 8937bd80fce6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants