diff mbox series

[RFC,2/2] MIPS: VDSO: support extcc-based timekeeping

Message ID 20190224093635.1242-3-kernel@xen0n.name (mailing list archive)
State Changes Requested
Headers show
Series MIPS: Loongson: ExtCC clocksource support | expand

Commit Message

WANG Xuerui Feb. 24, 2019, 9:36 a.m. UTC
From: Wang Xuerui <wangxuerui@qiniu.com>

The clocksource bits are ready, just wire things up in VDSO for a
significant user-space timekeeping performance gain.  There are several
ABI problems uncovered by vdsotest though, but daily usage of the test
system didn't expose any of them.  These inconsistencies will be fixed
in a later commit (presently TODO).

According to vdsotest (formatting is manually added, only the affected
figures are shown):

    category                          before  after
    --------                          ------  -----
    clock-gettime-monotonic: syscall: 409     401 nsec/call
    clock-gettime-monotonic:    libc: 476     141 nsec/call
    clock-gettime-monotonic:    vdso: 462     123 nsec/call

    clock-gettime-realtime:  syscall: 405     407 nsec/call
    clock-gettime-realtime:     libc: 474     142 nsec/call
    clock-gettime-realtime:     vdso: 457     125 nsec/call

    gettimeofday:            syscall: 406     407 nsec/call
    gettimeofday:               libc: 455     121 nsec/call
    gettimeofday:               vdso: 440     102 nsec/call

The benchmark was run on a single-socket 3A3000 @ 1.4GHz.  There is
still plenty of headroom for improvements of course, but let's take
care of the micro-optimizations later.

Signed-off-by: Wang Xuerui <wangxuerui@qiniu.com>
Tested-by: Wang Xuerui <wangxuerui@qiniu.com>
Cc: Huacai Chen <chenhc@lemote.com>
Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
Cc: James Hogan <jhogan@kernel.org>
Cc: Paul Burton <paul.burton@mips.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: linux-mips@linux-mips.org
---
 arch/mips/include/asm/clocksource.h | 1 +
 arch/mips/loongson64/common/extcc.c | 3 +--
 arch/mips/vdso/gettimeofday.c       | 8 ++++++++
 3 files changed, 10 insertions(+), 2 deletions(-)

Comments

Paul Burton Feb. 28, 2019, 3:17 a.m. UTC | #1
Hi Wang,

On Sun, Feb 24, 2019 at 05:36:35PM +0800, kernel@xen0n.name wrote:
> From: Wang Xuerui <wangxuerui@qiniu.com>
> 
> The clocksource bits are ready, just wire things up in VDSO for a
> significant user-space timekeeping performance gain.  There are several
> ABI problems uncovered by vdsotest though, but daily usage of the test
> system didn't expose any of them.  These inconsistencies will be fixed
> in a later commit (presently TODO).

I'm afraid that's not how this works... :)

We should make sure this works properly before merging it - could you
provide details of the problems vdsotest found?

> According to vdsotest (formatting is manually added, only the affected
> figures are shown):
> 
>     category                          before  after
>     --------                          ------  -----
>     clock-gettime-monotonic: syscall: 409     401 nsec/call
>     clock-gettime-monotonic:    libc: 476     141 nsec/call
>     clock-gettime-monotonic:    vdso: 462     123 nsec/call
> 
>     clock-gettime-realtime:  syscall: 405     407 nsec/call
>     clock-gettime-realtime:     libc: 474     142 nsec/call
>     clock-gettime-realtime:     vdso: 457     125 nsec/call
> 
>     gettimeofday:            syscall: 406     407 nsec/call
>     gettimeofday:               libc: 455     121 nsec/call
>     gettimeofday:               vdso: 440     102 nsec/call

I'd rather be sure the kernel gives the right answer than have it give
the wrong answer 4x faster, so this looks promising but let's fix the
test failures before moving forwards.

Thanks,
    Paul
diff mbox series

Patch

diff --git a/arch/mips/include/asm/clocksource.h b/arch/mips/include/asm/clocksource.h
index 3deb1d0c1a94..6a126a475892 100644
--- a/arch/mips/include/asm/clocksource.h
+++ b/arch/mips/include/asm/clocksource.h
@@ -17,6 +17,7 @@ 
 #define VDSO_CLOCK_NONE		0	/* No suitable clocksource. */
 #define VDSO_CLOCK_R4K		1	/* Use the coprocessor 0 count. */
 #define VDSO_CLOCK_GIC		2	/* Use the GIC. */
+#define VDSO_CLOCK_EXTCC	3	/* Use the Loongson ExtCC. */
 
 /**
  * struct arch_clocksource_data - Architecture-specific clocksource information.
diff --git a/arch/mips/loongson64/common/extcc.c b/arch/mips/loongson64/common/extcc.c
index 702cb389856a..0f6775099411 100644
--- a/arch/mips/loongson64/common/extcc.c
+++ b/arch/mips/loongson64/common/extcc.c
@@ -23,8 +23,7 @@  static struct clocksource extcc_clocksource = {
 	.read		= extcc_read,
 	.mask		= CLOCKSOURCE_MASK(64),
 	.flags		= CLOCK_SOURCE_IS_CONTINUOUS | CLOCK_SOURCE_VALID_FOR_HRES,
-	/* TODO later */
-	.archdata	= { .vdso_clock_mode = VDSO_CLOCK_NONE },
+	.archdata	= { .vdso_clock_mode = VDSO_CLOCK_EXTCC },
 };
 
 void __init extcc_clocksource_init(void)
diff --git a/arch/mips/vdso/gettimeofday.c b/arch/mips/vdso/gettimeofday.c
index e22b422f282c..92eef8de36a4 100644
--- a/arch/mips/vdso/gettimeofday.c
+++ b/arch/mips/vdso/gettimeofday.c
@@ -17,6 +17,9 @@ 
 #include <asm/io.h>
 #include <asm/unistd.h>
 #include <asm/vdso.h>
+#ifdef CONFIG_LOONGSON_EXTCC_CLKSRC
+#include <asm/mach-loongson64/extcc.h>
+#endif
 
 #ifdef CONFIG_MIPS_CLOCK_VSYSCALL
 
@@ -148,6 +151,11 @@  static __always_inline u64 get_ns(const union mips_vdso_data *data)
 	case VDSO_CLOCK_GIC:
 		cycle_now = read_gic_count(data);
 		break;
+#endif
+#ifdef CONFIG_LOONGSON_EXTCC_CLKSRC
+	case VDSO_CLOCK_EXTCC:
+		cycle_now = __extcc_read_ordered();
+		break;
 #endif
 	default:
 		return 0;