Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf bench: Fix perf bench syscall loop count

Command 'perf bench syscall fork -l 100000' offers option -l to run for
a specified number of iterations. However this option is not always
observed. The number is silently limited to 10000 iterations as can be
seen:

Output before:
# perf bench syscall fork -l 100000
# Running 'syscall/fork' benchmark:
# Executed 10,000 fork() calls
Total time: 23.388 [sec]

2338.809800 usecs/op
427 ops/sec
#

When explicitly specified with option -l or --loops, also observe
higher number of iterations:

Output after:
# perf bench syscall fork -l 100000
# Running 'syscall/fork' benchmark:
# Executed 100,000 fork() calls
Total time: 716.982 [sec]

7169.829510 usecs/op
139 ops/sec
#

This patch fixes the issue for basic execve fork and getpgid.

Fixes: ece7f7c0507c ("perf bench syscall: Add fork syscall benchmark")
Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Acked-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
Tested-by: Athira Rajeev <atrajeev@linux.ibm.com>
Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
Link: https://lore.kernel.org/r/20250304092349.2618082-1-tmricht@linux.ibm.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Thomas Richter and committed by
Namhyung Kim
957d1941 b627b443

+13 -9
+13 -9
tools/perf/bench/syscall.c
··· 22 22 #define __NR_fork -1 23 23 #endif 24 24 25 - #define LOOPS_DEFAULT 10000000 26 - static int loops = LOOPS_DEFAULT; 25 + static int loops; 27 26 28 27 static const struct option options[] = { 29 28 OPT_INTEGER('l', "loop", &loops, "Specify number of loops"), ··· 79 80 const char *name = NULL; 80 81 int i; 81 82 83 + switch (syscall) { 84 + case __NR_fork: 85 + case __NR_execve: 86 + /* Limit default loop to 10000 times to save time */ 87 + loops = 10000; 88 + break; 89 + default: 90 + loops = 10000000; 91 + break; 92 + } 93 + 94 + /* Options -l and --loops override default above */ 82 95 argc = parse_options(argc, argv, options, bench_syscall_usage, 0); 83 96 84 97 gettimeofday(&start, NULL); ··· 105 94 break; 106 95 case __NR_fork: 107 96 test_fork(); 108 - /* Only loop 10000 times to save time */ 109 - if (i == 10000) 110 - loops = 10000; 111 97 break; 112 98 case __NR_execve: 113 99 test_execve(); 114 - /* Only loop 10000 times to save time */ 115 - if (i == 10000) 116 - loops = 10000; 117 - break; 118 100 default: 119 101 break; 120 102 }