tools/perf-bench: Add basic syscall benchmark
PATCH 1/1 tools/perf-bench: Add basic syscall benchmark
The usefulness of having a standard way of testing syscall performance has come up from time to time[0]. Furthermore, some of our testing machinery (such as 'mmtests') already makes use of a simplified version of the microbenchmark. This patch mainly takes the same idea to measure syscall throughput compatible with 'perf-bench' via getppid(2), yet without any of the additional template stuff from Ingo's version (based on numa.c). The code is identical to what mmtests uses.
https://www.mail-archive.com/[email protected]/msg1067469.html
--- tools/perf/bench/Build | 1 + tools/perf/bench/bench.h | 1 + tools/perf/bench/syscall.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++ tools/perf/builtin-bench.c | 8 +++++ 4 files changed, 90 insertions(+) create mode 100644 tools/perf/bench/syscall.c
tools/perf/bench/Build +1 -0
@@ -1,5 +1,6 @@ perf-y += sched-messaging.o perf-y += sched-pipe.o +perf-y += syscall.o perf-y += mem-functions.o perf-y += futex-hash.o perf-y += futex-wake.o
tools/perf/bench/bench.h +1 -0
@@ -29,6 +29,7 @@int bench_numa (int argc,const char **argv);int bench_sched_messaging (int argc,const char **argv);int bench_sched_pipe (int argc,const char **argv); +int bench_syscall_basic (int argc,const char **argv);int bench_mem_memcpy (int argc,const char **argv);int bench_mem_memset (int argc,const char **argv);int bench_futex_hash (int argc,const char **argv);
tools/perf/bench/syscall.c new file +80 -0
80 lines not on this page · raw message
tools/perf/builtin-bench.c +8 -0
@@ -11,6 +11,7 @@* Available benchmark collection list: * * sched ... scheduler and IPC performance +* syscall ... System call performance * mem ... memory access performance * numa ... NUMA scheduling and MM performance * futex ... Futex performance
@@ -50,6 +51,12 @@ static struct bench sched_benchmarks[] = { { NULL, NULL, NULL } }; +static struct bench syscall_benchmarks[] = { + {"basic" ,"Benchmark for basic getppid() system calls" , bench_syscall_basic }, + {"all" ,"Run all syscall benchmarks" ,NULL }, + {NULL ,NULL ,NULL }, +}; +static struct bench mem_benchmarks[] = { {"memcpy" ,"Benchmark for memcpy() functions" , bench_mem_memcpy }, {"memset" ,"Benchmark for memset() functions" , bench_mem_memset },
@@ -85,6 +92,7 @@ struct collection {static struct collection collections[] = { {"sched" ,"Scheduler and IPC benchmarks" , sched_benchmarks }, + {"syscall" ,"System call benchmarks" , syscall_benchmarks }, {"mem" ,"Memory access benchmarks" , mem_benchmarks }, #ifdef HAVE_LIBNUMA_SUPPORT { "numa", "NUMA scheduling and MM benchmarks", numa_benchmarks },
Signature · 1 line
2.16.4
Em Thu, Mar 07, 2019 at 10:52:53AM -0800, Davidlohr Bueso escreveu:
Quoted 7 lines
The usefulness of having a standard way of testing syscall performance has come up from time to time[0]. Furthermore, some of our testing machinery (such as 'mmtests') already makes use of a simplified version of the microbenchmark. This patch mainly takes the same idea to measure syscall throughput compatible with 'perf-bench' via getppid(2), yet without any of the additional template stuff from Ingo's version (based on
numa.c). The code is identical to what mmtests uses.
You forgot to update tools/perf/Documentation/perf-bench.txt, and please take a look at tools/perf/util/pmu.c convert_scale() to see how to save the current locale, set the one you want, then restore the previous one, so that at the end of this benchmark the environment is back to where it was.
Thanks.
- Arnaldo
Quoted 155 lines
https://www.mail-archive.com/[email protected]/msg1067469.html
Signed-off-by Davidlohr Bueso <[email protected]>--- tools/perf/bench/Build | 1 + tools/perf/bench/bench.h | 1 + tools/perf/bench/syscall.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++ tools/perf/builtin-bench.c | 8 +++++ 4 files changed, 90 insertions(+) create mode 100644 tools/perf/bench/syscall.ctools/perf/bench/Build +1
-0@@ -1,5 +1,6 @@ perf-y += sched-messaging.o perf-y += sched-pipe.o +perf-y += syscall.o perf-y += mem-functions.o perf-y += futex-hash.o perf-y += futex-wake.otools/perf/bench/bench.h +1
-0@@ -29,6 +29,7 @@int bench_numa (int argc,const char **argv);int bench_sched_messaging (int argc,const char **argv);int bench_sched_pipe (int argc,const char **argv); +int bench_syscall_basic (int argc,const char **argv);int bench_mem_memcpy (int argc,const char **argv);int bench_mem_memset (int argc,const char **argv);int bench_futex_hash (int argc,const char **argv);tools/perf/bench/syscall.c new file +80
-0@@ -0,0 +1,80 @@ +/* +* +* syscall.c +* +* syscall: Benchmark for system call performance +*/ +#include "../perf.h" +#include "../util/util.h" +#include <subcmd/parse-options.h> +#include "../builtin.h" +#include "bench.h" + +#include <stdio.h> +#include <locale.h> +#include <sys/time.h> +#include <sys/syscall.h> + +#define LOOPS_DEFAULT 10000000 +static int loops =LOOPS_DEFAULT ; + +static const struct option options[] = { +OPT_INTEGER ('l' ,"loop" , &loops,"Specify number of loops" ), +OPT_END () +}; + +static const char *const bench_syscall_usage[] = { +"perf bench syscall <options>" , +NULL +}; + +int bench_syscall_basic (int argc,const char **argv) +{ +struct timeval start, stop, diff; +unsigned long long result_usec =0 ; +int i; + + argc =parse_options (argc, argv, options, bench_syscall_usage,0 ); + +gettimeofday (&start,NULL ); + +for (i =0 ; i < loops; i++) +getppid (); + +gettimeofday (&stop,NULL ); +timersub (&stop, &start, &diff); + +switch (bench_format) { +case BENCH_FORMAT_DEFAULT : +setlocale (LC_NUMERIC ,"" ); +printf ("# Executed %'d getppid() calls\n" , loops); + + result_usec = diff.tv_sec *1000000 ; + result_usec += diff.tv_usec; + +printf (" %14s: %lu.%03lu [sec]\n\n" ,"Total time" , + diff.tv_sec, + (unsigned long ) (diff.tv_usec/1000 )); + +printf (" %14lf usecs/op\n" , + (double )result_usec / (double )loops); +printf (" %'14d ops/sec\n" , + (int )((double )loops / + ((double )result_usec / (double )1000000 ))); +break ; + +case BENCH_FORMAT_SIMPLE : +printf ("%lu.%03lu\n" , + diff.tv_sec, + (unsigned long ) (diff.tv_usec /1000 )); +break ; + +default : +/* reaching here is something disaster */ +fprintf (stderr,"Unknown format:%d\n" , bench_format); +exit (1 ); +break ; + } + +return 0 ; +}tools/perf/builtin-bench.c +8
-0@@ -11,6 +11,7 @@* Available benchmark collection list: * * sched ... scheduler and IPC performance +* syscall ... System call performance * mem ... memory access performance * numa ... NUMA scheduling and MM performance * futex ... Futex performance @@ -50,6 +51,12 @@ static struct bench sched_benchmarks[] = { { NULL, NULL, NULL } }; +static struct bench syscall_benchmarks[] = { + {"basic" ,"Benchmark for basic getppid() system calls" , bench_syscall_basic }, + {"all" ,"Run all syscall benchmarks" ,NULL }, + {NULL ,NULL ,NULL }, +}; +static struct bench mem_benchmarks[] = { {"memcpy" ,"Benchmark for memcpy() functions" , bench_mem_memcpy }, {"memset" ,"Benchmark for memset() functions" , bench_mem_memset },@@ -85,6 +92,7 @@ struct collection {static struct collection collections[] = { {"sched" ,"Scheduler and IPC benchmarks" , sched_benchmarks }, + {"syscall" ,"System call benchmarks" , syscall_benchmarks }, {"mem" ,"Memory access benchmarks" , mem_benchmarks }, #ifdef HAVE_LIBNUMA_SUPPORT { "numa", "NUMA scheduling and MM benchmarks", numa_benchmarks },Signature · 1 line
2.16.4
Signature · 1 line
- Arnaldo
Quoted 5 lines · Arnaldo Carvalho de Melo
You forgot to update
tools/perf/Documentation/perf-bench.txt, and please take a look attools/perf/util/pmu.cconvert_scale()to see how to save the current locale, set the one you want, then restore the previous one, so that at the end of this benchmark the environment is back to where it was.
Here's an updated version with the corresponding docs, but I removed the setlocale() - doesn't seem worth it; I hope Mel has no strong objection.
Thanks.
-------8<---------------------------------------------------------- [PATCH v2] tools/perf-bench: Add basic syscall benchmark
The usefulness of having a standard way of testing syscall performance has come up from time to time[0]. Furthermore, some of our testing machinery (such as 'mmtests') already makes use of a simplified version of the microbenchmark. This patch mainly takes the same idea to measure syscall throughput compatible with 'perf-bench' via getppid(2), yet without any of the additional template stuff from Ingo's version (based on numa.c). The code is identical to what mmtests uses.
[0] https://lore.kernel.org/lkml/[email protected]/
---
tools/perf/Documentation/perf-bench.txt | 11 +++++ tools/perf/bench/Build | 1 + tools/perf/bench/bench.h | 1 + tools/perf/bench/syscall.c | 78 +++++++++++++++++++++++++++++++++ tools/perf/builtin-bench.c | 8 ++++ 5 files changed, 99 insertions(+)
create mode 100644 tools/perf/bench/syscall.c
tools/perf/Documentation/perf-bench.txt +0 -0
@@ -49,6 +49,9 @@ SUBSYSTEM
'sched'::
Scheduler and IPC mechanisms.
+'syscall'::
+ System call performance (throughput).
+
'mem'::
Memory access performance.
@@ -134,6 +137,14 @@ Example of *pipe*
59004 ops/sec
---------------------
+SUITES FOR 'syscall'
+~~~~~~~~~~~~~~~~~~
+*basic*::
+Suite for evaluating performance of core system call throughput (both usecs/op and ops/sec metrics). +This uses a single thread simply doing getppid(2), which is a simple syscall where the result is not +cached by glibc.
+
+
SUITES FOR 'mem'
~~~~~~~~~~~~~~~~
*memcpy*::
tools/perf/bench/Build +0 -0
@@ -1,5 +1,6 @@
perf-y += sched-messaging.o
perf-y += sched-pipe.o
+perf-y += syscall.o
perf-y += mem-functions.o
perf-y += futex-hash.o
perf-y += futex-wake.o
tools/perf/bench/bench.h +0 -0
@@ -29,6 +29,7 @@
int bench_numa(int argc, const char **argv); int bench_sched_messaging(int argc, const char **argv); int bench_sched_pipe(int argc, const char **argv); +int bench_syscall_basic(int argc, const char **argv); int bench_mem_memcpy(int argc, const char **argv); int bench_mem_memset(int argc, const char **argv); int bench_futex_hash(int argc, const char **argv);
tools/perf/bench/syscall.c new file +78 -0
78 lines not on this page · raw message
tools/perf/builtin-bench.c +1 -0
@@ -11,6 +11,7 @@* Available benchmark collection list: * * sched ... scheduler and IPC performance +* syscall ... System call performance * mem ... memory access performance * numa ... NUMA scheduling and MM performance * futex ... Futex performance
@@ -50,6 +51,12 @@ static struct bench sched_benchmarks[] = {
{ NULL, NULL, NULL }
};+static struct bench syscall_benchmarks[] = {
+ { "basic", "Benchmark for basic getppid(2) calls", bench_syscall_basic },
+ { "all", "Run all syscall benchmarks", NULL },
+ { NULL, NULL, NULL },
+};
+
static struct bench mem_benchmarks[] = {
{ "memcpy", "Benchmark for memcpy() functions", bench_mem_memcpy },
{ "memset", "Benchmark for memset() functions", bench_mem_memset },
@@ -85,6 +92,7 @@ struct collection {
static struct collection collections[] = {
{ "sched", "Scheduler and IPC benchmarks", sched_benchmarks },
+ { "syscall", "System call benchmarks", syscall_benchmarks },
{ "mem", "Memory access benchmarks", mem_benchmarks },#ifdef HAVE_LIBNUMA_SUPPORT
{ "numa", "NUMA scheduling and MM benchmarks", numa_benchmarks },
Signature · 1 line
2.16.4
Quoted 10 lines · Davidlohr Bueso
Quoted 5 lines · Arnaldo Carvalho de Melo
You forgot to update
tools/perf/Documentation/perf-bench.txt, and please take a look attools/perf/util/pmu.cconvert_scale()to see how to save the current locale, set the one you want, then restore the previous one, so that at the end of this benchmark the environment is back to where it was.Here's an updated version with the corresponding docs, but I removed the
setlocale()- doesn't seem worth it; I hope Mel has no strong objection.
No objection, thanks!
Signature · 2 lines
Mel Gorman SUSE Labs
Quoted 23 lines · Davidlohr Bueso
Quoted 5 lines · Arnaldo Carvalho de Melo
You forgot to update
tools/perf/Documentation/perf-bench.txt, and please take a look attools/perf/util/pmu.cconvert_scale()to see how to save the current locale, set the one you want, then restore the previous one, so that at the end of this benchmark the environment is back to where it was.Here's an updated version with the corresponding docs, but I removed the
setlocale()- doesn't seem worth it; I hope Mel has no strong objection.Thanks.
-------8<---------------------------------------------------------- [PATCH v2]
tools/perf-bench: Add basic syscall benchmarkThe usefulness of having a standard way of testing syscall performance has come up from time to time[0]. Furthermore, some of our testing machinery (such as 'mmtests') already makes use of a simplified version of the microbenchmark. This patch mainly takes the same idea to measure syscall throughput compatible with 'perf-bench' via getppid(2), yet without any of the additional template stuff from Ingo's version (based on
numa.c). The code is identical to what mmtests uses.
Quoted 3 lines
[0] https://lore.kernel.org/lkml/[email protected]/
Signed-off-by Davidlohr Bueso <[email protected]>
It would be nice to see this merged. I posted something very similar back in 2016.
Signature · 1 line
Josh
Arnaldo Carvalho de Melo
maintainerEm Thu, May 14, 2020 at 03:39:42PM -0500, Josh Poimboeuf escreveu:
Quoted 24 lines · Davidlohr Bueso
Quoted 23 lines · Arnaldo Carvalho de Melo
Quoted 5 lines
You forgot to update
tools/perf/Documentation/perf-bench.txt, and please take a look attools/perf/util/pmu.cconvert_scale()to see how to save the current locale, set the one you want, then restore the previous one, so that at the end of this benchmark the environment is back to where it was.Here's an updated version with the corresponding docs, but I removed the
setlocale()- doesn't seem worth it; I hope Mel has no strong objection.Thanks.
-------8<---------------------------------------------------------- [PATCH v2]
tools/perf-bench: Add basic syscall benchmarkThe usefulness of having a standard way of testing syscall performance has come up from time to time[0]. Furthermore, some of our testing machinery (such as 'mmtests') already makes use of a simplified version of the microbenchmark. This patch mainly takes the same idea to measure syscall throughput compatible with 'perf-bench' via getppid(2), yet without any of the additional template stuff from Ingo's version (based on
numa.c). The code is identical to what mmtests uses.
Quoted 6 lines
Quoted 3 lines
[0] https://lore.kernel.org/lkml/[email protected]/
Signed-off-by Davidlohr Bueso <[email protected]>It would be nice to see this merged. I posted something very similar back in 2016.
So, I took this as an Acked-by: Josh, and the previous "no objection" from Mel as well, its now in my tmp.perf/core branch while it, together with other stuff goes thru build tests + 'perf test'.
Sorry for the long delay in processing it, I shoudl've noticed that my review comments were addressed in v2.
- Arnaldo