-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Use direct inc/dec for ++/-- op #3179
Conversation
This will save a call to bpf_map_update_elem Issue: bpftrace#3175
Compiled bpftrace from this branch. Running this bpftrace oneliner: The resulting byte-code now looks like this: int64 kprobe_cgroup_rstat_flush_locked_1(int8 * ctx):
0: (b7) r1 = 0
1: (7b) *(u64 *)(r10 -16) = r1
2: (bf) r2 = r10
3: (07) r2 += -16
4: (18) r1 = map[id:1391]
6: (85) call __htab_map_lookup_elem#267824
7: (15) if r0 == 0x0 goto pc+1
8: (07) r0 += 56
9: (15) if r0 == 0x0 goto pc+4
10: (79) r1 = *(u64 *)(r0 +0)
11: (07) r1 += 1
12: (7b) *(u64 *)(r0 +0) = r1
13: (05) goto pc+10
14: (b7) r1 = 1
15: (7b) *(u64 *)(r10 -8) = r1
16: (bf) r2 = r10
17: (07) r2 += -16
18: (bf) r3 = r10
19: (07) r3 += -8
20: (18) r1 = map[id:1391]
22: (b7) r4 = 1
23: (85) call htab_map_update_elem#281184
24: (b7) r0 = 0
25: (95) exit This looks like it fixes the bug in #3175. |
(Maybe for another PR) Looking at above BPF byte-code.
This could easily be a simple array-map. |
…omic Fix comment about increment operator being atomic. It is both slow and contains data races as described here: - bpftrace/bpftrace#3175 Maybe this will soon get fixed via: - bpftrace/bpftrace#3179 - bpftrace#3179 Signed-off-by: Jesper Dangaard Brouer <[email protected]>
Yeah true. Additionally, I think we might be causing data races in this implementation by updating the pointer directly instead of utilizing |
Missed this in the initial implementation but this add instruction needs to be atomic because the map value itself is not protected by a spin lock and therefore requires synchronization.
True, I think it would be preferred that we use atomic inc/dec operations, as it is correct that data races still exists without them (still after removing the unnecessary As an end-user of bpftrace, I (falsely) assumed/expected these were atomic inc/dec operators (++/--). |
Hashmap is indeed suboptimal. We can definitely do some additional specialization here: bpftrace/src/ast/passes/codegen_llvm.cpp Line 3534 in 0d06553
As for ++ vs count(), we have in the docs some details about that -- we can make the difference more clear though. https://github.com/bpftrace/bpftrace/blob/master/man/adoc/bpftrace.adoc#count I'm not sure using atomic ops for In your comment in xdp-project/xdp-project@010d6b1, I see your motivation is to be able to printf() a value, right? As a workaround, you could consider doing:
The reason you can't print a map with printf() yet is b/c printf() is synchronous whereas for print() the values we pull out are asynchronous. I believe it should be possible to synchronously print out count() cuz the kernel supports loops over maps elements now. We should support this. |
@danobi We already have this issue filed for our per-cpu functions: #3126
Yes, you're right. I didn't realize all the places we were calling |
This will save a call to bpf_map_update_elem
Issue: #3175
Also make the add operation in CreateMapElemAdd atomic.
Checklist
man/adoc/bpftrace.adoc
CHANGELOG.md