]> www.infradead.org Git - users/hch/misc.git/commitdiff
perf bench mem: Refactor mem_options
authorAnkur Arora <ankur.a.arora@oracle.com>
Wed, 17 Sep 2025 15:24:10 +0000 (08:24 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 19 Sep 2025 15:43:49 +0000 (12:43 -0300)
Split mem benchmark options into common and memset/memcpy specific.

Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Ankur Arora <ankur.a.arora@oracle.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Mateusz Guzik <mjguzik@gmail.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Raghavendra K T <raghavendra.kt@amd.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/bench/mem-functions.c

index 69968ba63d81329d5ca61d27a2ff705676492a98..2a23bed8c2d39dd1c89a3ecfc0fe9e3ea00e3a8e 100644 (file)
@@ -41,7 +41,7 @@ static unsigned int   nr_loops        = 1;
 static bool            use_cycles;
 static int             cycles_fd;
 
-static const struct option options[] = {
+static const struct option bench_common_options[] = {
        OPT_STRING('s', "size", &size_str, "1MB",
                    "Specify the size of the memory buffers. "
                    "Available units: B, KB, MB, GB and TB (case insensitive)"),
@@ -50,10 +50,6 @@ static const struct option options[] = {
                    "Specify page-size for mapping memory buffers. "
                    "Available sizes: 4KB, 2MB, 1GB (case insensitive)"),
 
-       OPT_STRING('k', "chunk", &chunk_size_str, "0",
-                   "Specify the chunk-size for each invocation. "
-                   "Available units: B, KB, MB, GB and TB (case insensitive)"),
-
        OPT_STRING('f', "function", &function_str, "all",
                    "Specify the function to run, \"all\" runs all available functions, \"help\" lists them"),
 
@@ -66,6 +62,14 @@ static const struct option options[] = {
        OPT_END()
 };
 
+static const struct option bench_mem_options[] = {
+       OPT_STRING('k', "chunk", &chunk_size_str, "0",
+                   "Specify the chunk-size for each invocation. "
+                   "Available units: B, KB, MB, GB and TB (case insensitive)"),
+       OPT_PARENT(bench_common_options),
+       OPT_END()
+};
+
 union bench_clock {
        u64             cycles;
        struct timeval  tv;
@@ -84,6 +88,7 @@ struct bench_mem_info {
        int (*do_op)(const struct function *r, struct bench_params *p,
                     void *src, void *dst, union bench_clock *rt);
        const char *const *usage;
+       const struct option *options;
        bool alloc_src;
 };
 
@@ -230,7 +235,7 @@ static int bench_mem_common(int argc, const char **argv, struct bench_mem_info *
        struct bench_params p = { 0 };
        unsigned int page_size;
 
-       argc = parse_options(argc, argv, options, info->usage, 0);
+       argc = parse_options(argc, argv, info->options, info->usage, 0);
 
        if (use_cycles) {
                i = init_cycles();
@@ -397,6 +402,7 @@ int bench_mem_memcpy(int argc, const char **argv)
                .functions              = memcpy_functions,
                .do_op                  = do_memcpy,
                .usage                  = bench_mem_memcpy_usage,
+               .options                = bench_mem_options,
                .alloc_src              = true,
        };
 
@@ -454,6 +460,7 @@ int bench_mem_memset(int argc, const char **argv)
                .functions              = memset_functions,
                .do_op                  = do_memset,
                .usage                  = bench_mem_memset_usage,
+               .options                = bench_mem_options,
        };
 
        return bench_mem_common(argc, argv, &info);