Skip to contentSkip to conversation

perf test workload thloop: Make count increments atomic

PATCH In review Ian Rogers 1 participant 2 messages Jan 14, 2023 – Jan 19, 2023 perf events

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 perf test workload thloop: Make count increments atomic

The count variable is incremented by multiple threads, doing so without an atomic operation causes thread sanitizer warnings. Switch to using relaxed atomics.

---
 tools/perf/tests/workloads/thloop.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/workloads/thloop.c +1 -1
index 29193b75717e..af05269c2eb8 100644
@@ -20,7 +20,7 @@ static void sighandler(int sig __maybe_unused)
 noinline void test_loop(void)
 {
 	while (!done)
-		count++;
+		__atomic_fetch_add(&count, 1, __ATOMIC_RELAXED);
 }
 
 static void *thfunc(void *arg)
Signature · 1 line
2.39.0.314.g84b9a713c41-goog
author reviewer
#1 lore raw
Quoted 15 lines · Ian Rogers

The count variable is incremented by multiple threads, doing so without an atomic operation causes thread sanitizer warnings. Switch to using relaxed atomics.

---
 tools/perf/tests/workloads/thloop.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/workloads/thloop.c +0 -0
index 29193b75717e..af05269c2eb8 100644

tools/perf/tests/workloads/thloop.c static void sighandler(int sig __maybe_unused) · line 23

Quoted 5 lines
tools/perf/tests/workloads/thloop.c +1 -1
@@ -20,7 +20,7 @@ static void sighandler(int sig __maybe_unused)
 noinline void test_loop(void)
 {
        while (!done)
-               count++;
+               __atomic_fetch_add(&count, 1, __ATOMIC_RELAXED);

Ping. No functional change, cleans up a lot of thread sanitizer issues, the use of __atomic_fetch_add is consistent with other files.

Thanks,
Ian

Quoted 6 lines
tools/perf/tests/workloads/thloop.c +0 -1
 }
 
 static void *thfunc(void *arg)
--

2.39.0.314.g84b9a713c41-goog