All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tools/testing/selftests/powerpc: Add Anton's null_syscall benchmark to the selftests
@ 2016-09-23  8:14 Rui Teng
  2016-09-27 10:18 ` Michael Ellerman
  0 siblings, 1 reply; 7+ messages in thread
From: Rui Teng @ 2016-09-23  8:14 UTC (permalink / raw)
  To: linux-kselftest, linux-kernel
  Cc: Shuah Khan, Michael Ellerman, Anton Blanchard, Cyril Bur,
	Michael Neuling, Rui Teng

From: Anton Blanchard <anton@au.ibm.com>

Pull in a version of Anton's null_syscall benchmark:
http://ozlabs.org/~anton/junkcode/null_syscall.c
Into tools/testing/selftests/powerpc/benchmarks.

Suggested-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Anton Blanchard <anton@au.ibm.com>
Signed-off-by: Rui Teng <rui.teng@linux.vnet.ibm.com>
---
 .../testing/selftests/powerpc/benchmarks/Makefile  |   2 +-
 .../selftests/powerpc/benchmarks/null_syscall.c    | 157 +++++++++++++++++++++
 2 files changed, 158 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/benchmarks/null_syscall.c

diff --git a/tools/testing/selftests/powerpc/benchmarks/Makefile b/tools/testing/selftests/powerpc/benchmarks/Makefile
index a9adfb7..545077f 100644
--- a/tools/testing/selftests/powerpc/benchmarks/Makefile
+++ b/tools/testing/selftests/powerpc/benchmarks/Makefile
@@ -1,4 +1,4 @@
-TEST_PROGS := gettimeofday context_switch mmap_bench futex_bench
+TEST_PROGS := gettimeofday context_switch mmap_bench futex_bench null_syscall
 
 CFLAGS += -O2
 
diff --git a/tools/testing/selftests/powerpc/benchmarks/null_syscall.c b/tools/testing/selftests/powerpc/benchmarks/null_syscall.c
new file mode 100644
index 0000000..59c2f45
--- /dev/null
+++ b/tools/testing/selftests/powerpc/benchmarks/null_syscall.c
@@ -0,0 +1,157 @@
+/*
+ * Test null syscall performance
+ *
+ * Copyright (C) 2009-2015 Anton Blanchard <anton@au.ibm.com>, IBM
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#define NR_LOOPS 10000000
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <time.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <signal.h>
+
+static volatile int soak_done;
+unsigned long long clock_frequency;
+unsigned long long timebase_frequency;
+double timebase_multiplier;
+
+static inline unsigned long long mftb(void)
+{
+	unsigned long low;
+
+	asm volatile("mftb %0" : "=r" (low));
+
+	return low;
+}
+
+static void sigalrm_handler(int unused)
+{
+	soak_done = 1;
+}
+
+/*
+ * Use a timer instead of busy looping on clock_gettime() so we don't
+ * pollute profiles with glibc and VDSO hits.
+ */
+static void cpu_soak_usecs(unsigned long usecs)
+{
+	struct itimerval val;
+
+	memset(&val, 0, sizeof(val));
+	val.it_value.tv_usec = usecs;
+
+	signal(SIGALRM, sigalrm_handler);
+	setitimer(ITIMER_REAL, &val, NULL);
+
+	while (1) {
+		if (soak_done)
+			break;
+	}
+
+	signal(SIGALRM, SIG_DFL);
+}
+
+/*
+ * This only works with recent kernels where cpufreq modifies
+ * /proc/cpuinfo dynamically.
+ */
+static void get_proc_frequency(void)
+{
+	FILE *f;
+	char line[128];
+	char *p, *end;
+	unsigned long v;
+	double d;
+	char *override;
+
+	/* Try to get out of low power/low frequency mode */
+	cpu_soak_usecs(0.25 * 1000000);
+
+	f = fopen("/proc/cpuinfo", "r");
+	if (f == NULL)
+		return;
+
+	timebase_frequency = 0;
+
+	while (fgets(line, sizeof(line), f) != NULL) {
+		if (strncmp(line, "timebase", 8) == 0) {
+			p = strchr(line, ':');
+			if (p != NULL) {
+				v = strtoull(p + 1, &end, 0);
+				if (end != p + 1)
+					timebase_frequency = v;
+			}
+		}
+
+		if (((strncmp(line, "clock", 5) == 0) ||
+		     (strncmp(line, "cpu MHz", 7) == 0))) {
+			p = strchr(line, ':');
+			if (p != NULL) {
+				d = strtod(p + 1, &end);
+				if (end != p + 1) {
+					/* Find fastest clock frequency */
+					if ((d * 1000000ULL) > clock_frequency)
+						clock_frequency = d * 1000000ULL;
+				}
+			}
+		}
+	}
+
+	fclose(f);
+
+	override = getenv("FREQUENCY");
+	if (override)
+		clock_frequency = strtoull(override, NULL, 10);
+
+	if (timebase_frequency)
+		timebase_multiplier = (double)clock_frequency
+					/ timebase_frequency;
+	else
+		timebase_multiplier = 1;
+}
+
+static void do_null_syscall(unsigned long nr)
+{
+	unsigned long i;
+
+	for (i = 0; i < nr; i++)
+		getppid();
+}
+
+#define TIME(A, STR) \
+
+int main(void)
+{
+	unsigned long tb_start, tb_now;
+	struct timespec tv_start, tv_now;
+	unsigned long long elapsed_ns, elapsed_tb;
+
+	get_proc_frequency();
+
+	clock_gettime(CLOCK_MONOTONIC, &tv_start);
+	tb_start = mftb();
+
+	do_null_syscall(NR_LOOPS);
+
+	clock_gettime(CLOCK_MONOTONIC, &tv_now);
+	tb_now = mftb();
+
+	elapsed_ns = (tv_now.tv_sec - tv_start.tv_sec) * 1000000000ULL +
+			(tv_now.tv_nsec - tv_start.tv_nsec);
+	elapsed_tb = tb_now - tb_start;
+
+	printf("%10.2f ns %10.2f cycles\n", (float)elapsed_ns / NR_LOOPS,
+			(float)elapsed_tb * timebase_multiplier / NR_LOOPS);
+
+	return 0;
+}
-- 
2.7.4

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

* Re: [PATCH] tools/testing/selftests/powerpc: Add Anton's null_syscall benchmark to the selftests
  2016-09-23  8:14 [PATCH] tools/testing/selftests/powerpc: Add Anton's null_syscall benchmark to the selftests Rui Teng
@ 2016-09-27 10:18 ` Michael Ellerman
  0 siblings, 0 replies; 7+ messages in thread
From: Michael Ellerman @ 2016-09-27 10:18 UTC (permalink / raw)
  To: Rui Teng, linux-kselftest, linux-kernel
  Cc: Shuah Khan, Anton Blanchard, Cyril Bur, Michael Neuling, Rui Teng

Rui Teng <rui.teng@linux.vnet.ibm.com> writes:

> From: Anton Blanchard <anton@au.ibm.com>
>
> Pull in a version of Anton's null_syscall benchmark:
> http://ozlabs.org/~anton/junkcode/null_syscall.c
> Into tools/testing/selftests/powerpc/benchmarks.
>
> Suggested-by: Michael Ellerman <mpe@ellerman.id.au>
> Signed-off-by: Anton Blanchard <anton@au.ibm.com>
> Signed-off-by: Rui Teng <rui.teng@linux.vnet.ibm.com>

Can you please resend this CC'ed to linuxppc-dev, that way patchwork
will see it, which is where I look for patches.

I see that MAINTAINERS doesn't list tools/testing/selftests/powerpc
under the PPC section, which it should, so I'll fix that.

cheers

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

* Re: [PATCH] tools/testing/selftests/powerpc: Add Anton's null_syscall benchmark to the selftests
  2016-09-27 14:10 Rui Teng
  2019-01-23 14:56   ` christophe.leroy
  (?)
@ 2019-01-23 14:56   ` christophe.leroy
  0 siblings, 0 replies; 7+ messages in thread
From: Christophe Leroy @ 2019-01-23 14:56 UTC (permalink / raw)
  To: Rui Teng, Anton Blanchard
  Cc: linuxppc-dev, linux-kselftest, linux-kernel, Michael Neuling,
	Shuah Khan, Cyril Bur



Le 27/09/2016 à 16:10, Rui Teng a écrit :
> From: Anton Blanchard <anton@au.ibm.com>
> 
> Pull in a version of Anton's null_syscall benchmark:
> http://ozlabs.org/~anton/junkcode/null_syscall.c
> Into tools/testing/selftests/powerpc/benchmarks.
> 
> Suggested-by: Michael Ellerman <mpe@ellerman.id.au>
> Signed-off-by: Anton Blanchard <anton@au.ibm.com>
> Signed-off-by: Rui Teng <rui.teng@linux.vnet.ibm.com>
> ---
>   .../testing/selftests/powerpc/benchmarks/Makefile  |   2 +-
>   .../selftests/powerpc/benchmarks/null_syscall.c    | 157 +++++++++++++++++++++
>   2 files changed, 158 insertions(+), 1 deletion(-)
>   create mode 100644 tools/testing/selftests/powerpc/benchmarks/null_syscall.c
> 

[...]

> +
> +static void do_null_syscall(unsigned long nr)
> +{
> +	unsigned long i;
> +
> +	for (i = 0; i < nr; i++)
> +		getppid();
> +}
> +

Looks like getppid() performs a rcu_read_lock(). Is that what we want ?

Shouldn't we use getpid() instead for a lighter syscall ?

Christophe

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

* [PATCH] tools/testing/selftests/powerpc: Add Anton's null_syscall benchmark to the selftests
@ 2019-01-23 14:56   ` christophe.leroy
  0 siblings, 0 replies; 7+ messages in thread
From: christophe.leroy @ 2019-01-23 14:56 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1007 bytes --]



Le 27/09/2016 à 16:10, Rui Teng a écrit :
> From: Anton Blanchard <anton at au.ibm.com>
> 
> Pull in a version of Anton's null_syscall benchmark:
> http://ozlabs.org/~anton/junkcode/null_syscall.c
> Into tools/testing/selftests/powerpc/benchmarks.
> 
> Suggested-by: Michael Ellerman <mpe at ellerman.id.au>
> Signed-off-by: Anton Blanchard <anton at au.ibm.com>
> Signed-off-by: Rui Teng <rui.teng at linux.vnet.ibm.com>
> ---
>   .../testing/selftests/powerpc/benchmarks/Makefile  |   2 +-
>   .../selftests/powerpc/benchmarks/null_syscall.c    | 157 +++++++++++++++++++++
>   2 files changed, 158 insertions(+), 1 deletion(-)
>   create mode 100644 tools/testing/selftests/powerpc/benchmarks/null_syscall.c
> 

[...]

> +
> +static void do_null_syscall(unsigned long nr)
> +{
> +	unsigned long i;
> +
> +	for (i = 0; i < nr; i++)
> +		getppid();
> +}
> +

Looks like getppid() performs a rcu_read_lock(). Is that what we want ?

Shouldn't we use getpid() instead for a lighter syscall ?

Christophe

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

* [PATCH] tools/testing/selftests/powerpc: Add Anton's null_syscall benchmark to the selftests
@ 2019-01-23 14:56   ` christophe.leroy
  0 siblings, 0 replies; 7+ messages in thread
From: Christophe Leroy @ 2019-01-23 14:56 UTC (permalink / raw)




Le 27/09/2016 à 16:10, Rui Teng a écrit :
> From: Anton Blanchard <anton at au.ibm.com>
> 
> Pull in a version of Anton's null_syscall benchmark:
> http://ozlabs.org/~anton/junkcode/null_syscall.c
> Into tools/testing/selftests/powerpc/benchmarks.
> 
> Suggested-by: Michael Ellerman <mpe at ellerman.id.au>
> Signed-off-by: Anton Blanchard <anton at au.ibm.com>
> Signed-off-by: Rui Teng <rui.teng at linux.vnet.ibm.com>
> ---
>   .../testing/selftests/powerpc/benchmarks/Makefile  |   2 +-
>   .../selftests/powerpc/benchmarks/null_syscall.c    | 157 +++++++++++++++++++++
>   2 files changed, 158 insertions(+), 1 deletion(-)
>   create mode 100644 tools/testing/selftests/powerpc/benchmarks/null_syscall.c
> 

[...]

> +
> +static void do_null_syscall(unsigned long nr)
> +{
> +	unsigned long i;
> +
> +	for (i = 0; i < nr; i++)
> +		getppid();
> +}
> +

Looks like getppid() performs a rcu_read_lock(). Is that what we want ?

Shouldn't we use getpid() instead for a lighter syscall ?

Christophe

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

* Re: [PATCH] tools/testing/selftests/powerpc: Add Anton's null_syscall benchmark to the selftests
@ 2019-01-23 14:56   ` christophe.leroy
  0 siblings, 0 replies; 7+ messages in thread
From: Christophe Leroy @ 2019-01-23 14:56 UTC (permalink / raw)
  To: Rui Teng, Anton Blanchard
  Cc: Michael Neuling, linuxppc-dev, linux-kernel, linux-kselftest,
	Shuah Khan, Cyril Bur



Le 27/09/2016 à 16:10, Rui Teng a écrit :
> From: Anton Blanchard <anton@au.ibm.com>
> 
> Pull in a version of Anton's null_syscall benchmark:
> http://ozlabs.org/~anton/junkcode/null_syscall.c
> Into tools/testing/selftests/powerpc/benchmarks.
> 
> Suggested-by: Michael Ellerman <mpe@ellerman.id.au>
> Signed-off-by: Anton Blanchard <anton@au.ibm.com>
> Signed-off-by: Rui Teng <rui.teng@linux.vnet.ibm.com>
> ---
>   .../testing/selftests/powerpc/benchmarks/Makefile  |   2 +-
>   .../selftests/powerpc/benchmarks/null_syscall.c    | 157 +++++++++++++++++++++
>   2 files changed, 158 insertions(+), 1 deletion(-)
>   create mode 100644 tools/testing/selftests/powerpc/benchmarks/null_syscall.c
> 

[...]

> +
> +static void do_null_syscall(unsigned long nr)
> +{
> +	unsigned long i;
> +
> +	for (i = 0; i < nr; i++)
> +		getppid();
> +}
> +

Looks like getppid() performs a rcu_read_lock(). Is that what we want ?

Shouldn't we use getpid() instead for a lighter syscall ?

Christophe

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

* [PATCH] tools/testing/selftests/powerpc: Add Anton's null_syscall benchmark to the selftests
@ 2016-09-27 14:10 Rui Teng
  2019-01-23 14:56   ` christophe.leroy
  0 siblings, 1 reply; 7+ messages in thread
From: Rui Teng @ 2016-09-27 14:10 UTC (permalink / raw)
  To: linuxppc-dev, linux-kselftest, linux-kernel
  Cc: Michael Ellerman, Shuah Khan, Anton Blanchard, Cyril Bur,
	Michael Neuling, Anton Blanchard, Rui Teng

From: Anton Blanchard <anton@au.ibm.com>

Pull in a version of Anton's null_syscall benchmark:
http://ozlabs.org/~anton/junkcode/null_syscall.c
Into tools/testing/selftests/powerpc/benchmarks.

Suggested-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Anton Blanchard <anton@au.ibm.com>
Signed-off-by: Rui Teng <rui.teng@linux.vnet.ibm.com>
---
 .../testing/selftests/powerpc/benchmarks/Makefile  |   2 +-
 .../selftests/powerpc/benchmarks/null_syscall.c    | 157 +++++++++++++++++++++
 2 files changed, 158 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/benchmarks/null_syscall.c

diff --git a/tools/testing/selftests/powerpc/benchmarks/Makefile b/tools/testing/selftests/powerpc/benchmarks/Makefile
index a9adfb7..545077f 100644
--- a/tools/testing/selftests/powerpc/benchmarks/Makefile
+++ b/tools/testing/selftests/powerpc/benchmarks/Makefile
@@ -1,4 +1,4 @@
-TEST_PROGS := gettimeofday context_switch mmap_bench futex_bench
+TEST_PROGS := gettimeofday context_switch mmap_bench futex_bench null_syscall
 
 CFLAGS += -O2
 
diff --git a/tools/testing/selftests/powerpc/benchmarks/null_syscall.c b/tools/testing/selftests/powerpc/benchmarks/null_syscall.c
new file mode 100644
index 0000000..59c2f45
--- /dev/null
+++ b/tools/testing/selftests/powerpc/benchmarks/null_syscall.c
@@ -0,0 +1,157 @@
+/*
+ * Test null syscall performance
+ *
+ * Copyright (C) 2009-2015 Anton Blanchard <anton@au.ibm.com>, IBM
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#define NR_LOOPS 10000000
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <time.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <signal.h>
+
+static volatile int soak_done;
+unsigned long long clock_frequency;
+unsigned long long timebase_frequency;
+double timebase_multiplier;
+
+static inline unsigned long long mftb(void)
+{
+	unsigned long low;
+
+	asm volatile("mftb %0" : "=r" (low));
+
+	return low;
+}
+
+static void sigalrm_handler(int unused)
+{
+	soak_done = 1;
+}
+
+/*
+ * Use a timer instead of busy looping on clock_gettime() so we don't
+ * pollute profiles with glibc and VDSO hits.
+ */
+static void cpu_soak_usecs(unsigned long usecs)
+{
+	struct itimerval val;
+
+	memset(&val, 0, sizeof(val));
+	val.it_value.tv_usec = usecs;
+
+	signal(SIGALRM, sigalrm_handler);
+	setitimer(ITIMER_REAL, &val, NULL);
+
+	while (1) {
+		if (soak_done)
+			break;
+	}
+
+	signal(SIGALRM, SIG_DFL);
+}
+
+/*
+ * This only works with recent kernels where cpufreq modifies
+ * /proc/cpuinfo dynamically.
+ */
+static void get_proc_frequency(void)
+{
+	FILE *f;
+	char line[128];
+	char *p, *end;
+	unsigned long v;
+	double d;
+	char *override;
+
+	/* Try to get out of low power/low frequency mode */
+	cpu_soak_usecs(0.25 * 1000000);
+
+	f = fopen("/proc/cpuinfo", "r");
+	if (f == NULL)
+		return;
+
+	timebase_frequency = 0;
+
+	while (fgets(line, sizeof(line), f) != NULL) {
+		if (strncmp(line, "timebase", 8) == 0) {
+			p = strchr(line, ':');
+			if (p != NULL) {
+				v = strtoull(p + 1, &end, 0);
+				if (end != p + 1)
+					timebase_frequency = v;
+			}
+		}
+
+		if (((strncmp(line, "clock", 5) == 0) ||
+		     (strncmp(line, "cpu MHz", 7) == 0))) {
+			p = strchr(line, ':');
+			if (p != NULL) {
+				d = strtod(p + 1, &end);
+				if (end != p + 1) {
+					/* Find fastest clock frequency */
+					if ((d * 1000000ULL) > clock_frequency)
+						clock_frequency = d * 1000000ULL;
+				}
+			}
+		}
+	}
+
+	fclose(f);
+
+	override = getenv("FREQUENCY");
+	if (override)
+		clock_frequency = strtoull(override, NULL, 10);
+
+	if (timebase_frequency)
+		timebase_multiplier = (double)clock_frequency
+					/ timebase_frequency;
+	else
+		timebase_multiplier = 1;
+}
+
+static void do_null_syscall(unsigned long nr)
+{
+	unsigned long i;
+
+	for (i = 0; i < nr; i++)
+		getppid();
+}
+
+#define TIME(A, STR) \
+
+int main(void)
+{
+	unsigned long tb_start, tb_now;
+	struct timespec tv_start, tv_now;
+	unsigned long long elapsed_ns, elapsed_tb;
+
+	get_proc_frequency();
+
+	clock_gettime(CLOCK_MONOTONIC, &tv_start);
+	tb_start = mftb();
+
+	do_null_syscall(NR_LOOPS);
+
+	clock_gettime(CLOCK_MONOTONIC, &tv_now);
+	tb_now = mftb();
+
+	elapsed_ns = (tv_now.tv_sec - tv_start.tv_sec) * 1000000000ULL +
+			(tv_now.tv_nsec - tv_start.tv_nsec);
+	elapsed_tb = tb_now - tb_start;
+
+	printf("%10.2f ns %10.2f cycles\n", (float)elapsed_ns / NR_LOOPS,
+			(float)elapsed_tb * timebase_multiplier / NR_LOOPS);
+
+	return 0;
+}
-- 
2.7.4

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

end of thread, other threads:[~2019-01-23 14:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-23  8:14 [PATCH] tools/testing/selftests/powerpc: Add Anton's null_syscall benchmark to the selftests Rui Teng
2016-09-27 10:18 ` Michael Ellerman
2016-09-27 14:10 Rui Teng
2019-01-23 14:56 ` Christophe Leroy
2019-01-23 14:56   ` Christophe Leroy
2019-01-23 14:56   ` Christophe Leroy
2019-01-23 14:56   ` christophe.leroy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.