OSDN Git Service

perf test workload thloop: Make count increments atomic
authorIan Rogers <irogers@google.com>
Sat, 14 Jan 2023 21:52:51 +0000 (13:52 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 19 Jan 2023 16:42:06 +0000 (13:42 -0300)
The count variable is incremented by multiple threads, doing so
without an atomic operation causes thread sanitizer warnings. Switch
to using relaxed atomics.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230114215251.271678-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/tests/workloads/thloop.c

index 29193b7..af05269 100644 (file)
@@ -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)