From: Wang Xuerui <wangxuerui@xxxxxxxxx> 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@xxxxxxxxx> Tested-by: Wang Xuerui <wangxuerui@xxxxxxxxx> Cc: Huacai Chen <chenhc@xxxxxxxxxx> Cc: Jiaxun Yang <jiaxun.yang@xxxxxxxxxxx> Cc: James Hogan <jhogan@xxxxxxxxxx> Cc: Paul Burton <paul.burton@xxxxxxxx> Cc: Ralf Baechle <ralf@xxxxxxxxxxxxxx> Cc: linux-mips@xxxxxxxxxxxxxx --- 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