Thread (4 messages) 4 messages, 4 authors, 2019-08-01

Re: [PATCH bpf v2] libbpf : make libbpf_num_possible_cpus function thread safe

From: Alexei Starovoitov <hidden>
Date: 2019-08-01 03:40:44

On Wed, Jul 31, 2019 at 3:11 PM Takshak Chahande [off-list ref] wrote:
Having static variable `cpus` in libbpf_num_possible_cpus function
without guarding it with mutex makes this function thread-unsafe.

If multiple threads accessing this function, in the current form; it
leads to incrementing the static variable value `cpus` in the multiple
of total available CPUs.

Used local stack variable to calculate the number of possible CPUs and
then updated the static variable using WRITE_ONCE().

Changes since v1:
 * added stack variable to calculate cpus
 * serialized static variable update using WRITE_ONCE()
 * fixed Fixes tag

Fixes: 6446b3155521 ("bpf: add a new API libbpf_num_possible_cpus()")
Signed-off-by: Takshak Chahande <redacted>
Applied. Thanks.
Thanks for keeping 'changes since v1 part' as part of git history.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help