[PATCH 3/6] perf bench: Constify tables

Arnaldo Carvalho de Melo
2026-04-07T19:52:09Z

Those tables and variables don't change, better capture this by
explicitely using 'const'.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-bench.c | 42 +++++++++++++++++++-------------------
1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/tools/perf/builtin-bench.c b/tools/perf/builtin-bench.c
index 02dea1b8822864e8..02d47913cc6a3fae 100644
--- a/tools/perf/builtin-bench.c
+++ b/tools/perf/builtin-bench.c
@@ -37,14 +37,14 @@ struct bench {
};

#ifdef HAVE_LIBNUMA_SUPPORT
-static struct bench numa_benchmarks[] = {
+static const struct bench numa_benchmarks[] = {
{ "mem", "Benchmark for NUMA workloads", bench_numa },
{ "all", "Run all NUMA benchmarks", NULL },
{ NULL, NULL, NULL }
};
#endif

-static struct bench sched_benchmarks[] = {
+static const struct bench sched_benchmarks[] = {
{ "messaging", "Benchmark for scheduling and IPC", bench_sched_messaging },
{ "pipe", "Benchmark for pipe() between two processes", bench_sched_pipe },
{ "seccomp-notify", "Benchmark for seccomp user notify", bench_sched_seccomp_notify},
@@ -52,7 +52,7 @@ static struct bench sched_benchmarks[] = {
{ NULL, NULL, NULL }
};

-static struct bench syscall_benchmarks[] = {
+static const struct bench syscall_benchmarks[] = {
{ "basic", "Benchmark for basic getppid(2) calls", bench_syscall_basic },
{ "getpgid", "Benchmark for getpgid(2) calls", bench_syscall_getpgid },
{ "fork", "Benchmark for fork(2) calls", bench_syscall_fork },
@@ -61,7 +61,7 @@ static struct bench syscall_benchmarks[] = {
{ NULL, NULL, NULL },
};

-static struct bench mem_benchmarks[] = {
+static const struct bench mem_benchmarks[] = {
{ "memcpy", "Benchmark for memcpy() functions", bench_mem_memcpy },
{ "memset", "Benchmark for memset() functions", bench_mem_memset },
{ "find_bit", "Benchmark for find_bit() functions", bench_mem_find_bit },
@@ -70,7 +70,7 @@ static struct bench mem_benchmarks[] = {
{ NULL, NULL, NULL }
};

-static struct bench futex_benchmarks[] = {
+static const struct bench futex_benchmarks[] = {
{ "hash", "Benchmark for futex hash table", bench_futex_hash },
{ "wake", "Benchmark for futex wake calls", bench_futex_wake },
{ "wake-parallel", "Benchmark for parallel futex wake calls", bench_futex_wake_parallel },
@@ -82,7 +82,7 @@ static struct bench futex_benchmarks[] = {
};

#ifdef HAVE_EVENTFD_SUPPORT
-static struct bench epoll_benchmarks[] = {
+static const struct bench epoll_benchmarks[] = {
{ "wait", "Benchmark epoll concurrent epoll_waits", bench_epoll_wait },
{ "ctl", "Benchmark epoll concurrent epoll_ctls", bench_epoll_ctl },
{ "all", "Run all futex benchmarks", NULL },
@@ -90,7 +90,7 @@ static struct bench epoll_benchmarks[] = {
};
#endif // HAVE_EVENTFD_SUPPORT

-static struct bench internals_benchmarks[] = {
+static const struct bench internals_benchmarks[] = {
{ "synthesize", "Benchmark perf event synthesis", bench_synthesize },
{ "kallsyms-parse", "Benchmark kallsyms parsing", bench_kallsyms_parse },
{ "inject-build-id", "Benchmark build-id injection", bench_inject_build_id },
@@ -99,14 +99,14 @@ static struct bench internals_benchmarks[] = {
{ NULL, NULL, NULL }
};

-static struct bench breakpoint_benchmarks[] = {
+static const struct bench breakpoint_benchmarks[] = {
{ "thread", "Benchmark thread start/finish with breakpoints", bench_breakpoint_thread},
{ "enable", "Benchmark breakpoint enable/disable", bench_breakpoint_enable},
{ "all", "Run all breakpoint benchmarks", NULL},
{ NULL, NULL, NULL },
};

-static struct bench uprobe_benchmarks[] = {
+static const struct bench uprobe_benchmarks[] = {
{ "baseline", "Baseline libc usleep(1000) call", bench_uprobe_baseline, },
{ "empty", "Attach empty BPF prog to uprobe on usleep, system wide", bench_uprobe_empty, },
{ "trace_printk", "Attach trace_printk BPF prog to uprobe on usleep syswide", bench_uprobe_trace_printk, },
@@ -116,12 +116,12 @@ static struct bench uprobe_benchmarks[] = {
};

struct collection {
- const char *name;
- const char *summary;
- struct bench *benchmarks;
+ const char *name;
+ const char *summary;
+ const struct bench *benchmarks;
};

-static struct collection collections[] = {
+static const struct collection collections[] = {
{ "sched", "Scheduler and IPC benchmarks", sched_benchmarks },
{ "syscall", "System call benchmarks", syscall_benchmarks },
{ "mem", "Memory access benchmarks", mem_benchmarks },
@@ -147,9 +147,9 @@ static struct collection collections[] = {
#define for_each_bench(coll, bench) \
for (bench = coll->benchmarks; bench && bench->name; bench++)

-static void dump_benchmarks(struct collection *coll)
+static void dump_benchmarks(const struct collection *coll)
{
- struct bench *bench;
+ const struct bench *bench;

printf("\n # List of available benchmarks for collection '%s':\n\n", coll->name);

@@ -178,7 +178,7 @@ static const char * const bench_usage[] = {

static void print_usage(void)
{
- struct collection *coll;
+ const struct collection *coll;
int i;

printf("Usage: \n");
@@ -234,9 +234,9 @@ static int run_bench(const char *coll_name, const char *bench_name, bench_fn_t f
return ret;
}

-static void run_collection(struct collection *coll)
+static void run_collection(const struct collection *coll)
{
- struct bench *bench;
+ const struct bench *bench;
const char *argv[2];

argv[1] = NULL;
@@ -260,7 +260,7 @@ static void run_collection(struct collection *coll)

static void run_all_collections(void)
{
- struct collection *coll;
+ const struct collection *coll;

for_each_collection(coll)
run_collection(coll);
@@ -268,7 +268,7 @@ static void run_all_collections(void)

int cmd_bench(int argc, const char **argv)
{
- struct collection *coll;
+ const struct collection *coll;
int ret = 0;

/* Unbuffered output */
@@ -306,7 +306,7 @@ int cmd_bench(int argc, const char **argv)
}

for_each_collection(coll) {
- struct bench *bench;
+ const struct bench *bench;

if (strcmp(coll->name, argv[0]))
continue;
--
2.53.0