public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] perf bench: Fix initialization of union
@ 2026-02-19  0:44 Namhyung Kim
  2026-02-19  0:44 ` [PATCH v2 2/2] perf bench: Add -t/--threads option to perf bench mem mmap Namhyung Kim
  2026-02-19 10:36 ` [PATCH v2 1/2] perf bench: Fix initialization of union James Clark
  0 siblings, 2 replies; 11+ messages in thread
From: Namhyung Kim @ 2026-02-19  0:44 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ian Rogers, James Clark
  Cc: Jiri Olsa, Adrian Hunter, Peter Zijlstra, Ingo Molnar, LKML,
	linux-perf-users

Recent compilers don't initialize all members (or the largest member) in
an union.  Instead it seems to set the first member only.  So some perf
bench output shows invalid numbers like below on my system with GCC 15.

Before:
  $ perf bench mem mmap
  # Running 'mem/mmap' benchmark:
  # function 'demand' (Demand loaded mmap())
  # Copying 1MB bytes ...

         0.011127 bytes/sec
  # function 'populate' (Eagerly populated mmap())
  # Copying 1MB bytes ...

         0.011127 bytes/sec

After:
  $ perf bench mem mmap
  # Running 'mem/mmap' benchmark:
  # function 'demand' (Demand loaded mmap())
  # Copying 1MB bytes ...

         2.209417 GB/sec
  # function 'populate' (Eagerly populated mmap())
  # Copying 1MB bytes ...

         7.875504 GB/sec

Because the first member of bench_clock is u64 ('cycles'), the default
struct timeval wasn't fully initialized.  Let's use memset to reset the
whole memory.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/bench/mem-functions.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/bench/mem-functions.c b/tools/perf/bench/mem-functions.c
index 2908a3a796c932d0..676c8d18f4c2e259 100644
--- a/tools/perf/bench/mem-functions.c
+++ b/tools/perf/bench/mem-functions.c
@@ -193,9 +193,10 @@ static void __bench_mem_function(struct bench_mem_info *info, struct bench_param
 {
 	const struct function *r = &info->functions[r_idx];
 	double result_bps = 0.0;
-	union bench_clock rt = { 0 };
+	union bench_clock rt;
 	void *src = NULL, *dst = NULL;
 
+	memset(&rt, 0, sizeof(rt));
 	printf("# function '%s' (%s)\n", r->name, r->desc);
 
 	if (r->fn.init && r->fn.init(info, p, &src, &dst))
-- 
2.53.0.335.g19a08e0c02-goog


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-02-27 21:42 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-19  0:44 [PATCH v2 1/2] perf bench: Fix initialization of union Namhyung Kim
2026-02-19  0:44 ` [PATCH v2 2/2] perf bench: Add -t/--threads option to perf bench mem mmap Namhyung Kim
2026-02-19 10:43   ` James Clark
2026-02-26  7:02   ` Ankur Arora
2026-02-27 21:42   ` Namhyung Kim
2026-02-19 10:36 ` [PATCH v2 1/2] perf bench: Fix initialization of union James Clark
2026-02-19 10:38   ` James Clark
2026-02-19 15:02     ` Leo Yan
2026-02-19 19:00       ` Namhyung Kim
2026-02-23 19:12         ` Namhyung Kim
2026-02-24 12:20           ` Leo Yan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox