linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: kernel@xen0n.name
To: linux-mips@vger.kernel.org
Cc: Wang Xuerui <wangxuerui@qiniu.com>,
	Huacai Chen <chenhc@lemote.com>,
	Jiaxun Yang <jiaxun.yang@flygoat.com>,
	James Hogan <jhogan@kernel.org>,
	Paul Burton <paul.burton@mips.com>,
	Ralf Baechle <ralf@linux-mips.org>,
	linux-mips@linux-mips.org
Subject: [RFC PATCH 2/2] MIPS: VDSO: support extcc-based timekeeping
Date: Sun, 24 Feb 2019 17:36:35 +0800	[thread overview]
Message-ID: <20190224093635.1242-3-kernel@xen0n.name> (raw)
In-Reply-To: <20190224093635.1242-1-kernel@xen0n.name>

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(-)

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;
-- 
2.20.1


  parent reply	other threads:[~2019-02-24 10:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-24  9:36 [RFC PATCH 0/2] MIPS: Loongson: ExtCC clocksource support kernel
2019-02-24  9:36 ` [RFC PATCH 1/2] MIPS: Loongson: add extcc clocksource kernel
2019-02-28  3:12   ` Paul Burton
2019-02-24  9:36 ` kernel [this message]
2019-02-28  3:17   ` [RFC PATCH 2/2] MIPS: VDSO: support extcc-based timekeeping Paul Burton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190224093635.1242-3-kernel@xen0n.name \
    --to=kernel@xen0n.name \
    --cc=chenhc@lemote.com \
    --cc=jhogan@kernel.org \
    --cc=jiaxun.yang@flygoat.com \
    --cc=linux-mips@linux-mips.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=paul.burton@mips.com \
    --cc=ralf@linux-mips.org \
    --cc=wangxuerui@qiniu.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).