bpf: Share __NR_CPUS__ value with Golang side#12310
Conversation
|
@gandro You're not missing something. I shouldn't send patches after 10pm on Fridays 🤦 |
1492405 to
21f778d
Compare
21f778d to
8be1ed3
Compare
There was a problem hiding this comment.
Since it was a bit unclear to me, when nproc --all would be wrong in the first place, it did some testing and it seems like the main problem is that nproc --all does not deal with SMT, at least on my laptop it does not agree with possible. This is indeed something my original PR did not consider.
In any case, we probably should really make sure we use exactly the same parsing mechanism in Golang and in the Makefiles to avoid further mistakes. Maybe have a shell script that parses possible the same way we do it in Golang?
On Golang side we get the number of CPUs from /sys/devices/system/cpu/possible. On BPF side, we use $(nproc -all). nproc calls num_processors() from the gnulib. That function, however, may not always return the value from the /sys file above. Instead, we should use the exact same source as Golang side to ensure both sides have the same value and avoid issues later on. See #12070 for details. The __NR_CPUS__ values in test/bpf/Makefile and bpf/Makefile.bpf do not need to be in sync. with Golang values because these files are only used for unit tests, sparse, and compile testing. Fixes: 8191b16 ("bpf: Use `nproc --all` for __NR_CPUS__") Signed-off-by: Paul Chaignon <paul@cilium.io>
8be1ed3 to
69f06e0
Compare
|
test-me-please |
|
I was able to reproduce the problem with |
gandro
left a comment
There was a problem hiding this comment.
I'm not too familiar with the BPF build process. We are still using nproc --all in the BPF Makefiles. Are these not used by the datapath and only used for testing?
@gandro As far as I'm aware, yes, we only use them for testing. All BPF programs loaded by cilium/pkg/datapath/loader/compile.go Lines 92 to 93 in 8191b16 |
On Golang side we get the number of CPUs from
/sys/devices/system/cpu/possible. On BPF side, we use$(nproc -all).nproccallsnum_processors()from the gnulib. That function, however, may not always return the value from the/sysfile above.Instead, we should use the exact same source as Golang side to ensure both sides have the same value and avoid issues later on. See #12070 for details.
The
__NR_CPUS__values intest/bpf/Makefileandbpf/Makefile.bpfdo not need to be in sync. with Golang values because these files are only used for unit tests, sparse, and compile testing.Fixes: #12121
/cc @gandro