Skip to content

Commit 9a5f25a

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
selftests/bpf: Fix sample_cnt shared between two threads
Make sample_cnt volatile to fix possible selftests failure due to compiler optimization preventing latest sample_cnt value to be visible to main thread. sample_cnt is incremented in background thread, which is then joined into main thread. So in terms of visibility sample_cnt update is ok. But because it's not volatile, compiler might make optimizations that would prevent main thread to see latest updated value. Fix this by marking global variable volatile. Fixes: cb1c9dd ("selftests/bpf: Add BPF ringbuf selftests") Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Song Liu <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent f371c92 commit 9a5f25a

File tree

1 file changed

+1
-1
lines changed
  • tools/testing/selftests/bpf/prog_tests

1 file changed

+1
-1
lines changed

tools/testing/selftests/bpf/prog_tests/ringbuf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct sample {
2525
char comm[16];
2626
};
2727

28-
static int sample_cnt;
28+
static volatile int sample_cnt;
2929

3030
static int process_sample(void *ctx, void *data, size_t len)
3131
{

0 commit comments

Comments
 (0)