Re: [PATCH] powerpc/vdso64: Add support for CLOCK_{REALTIME/MONOTONIC}_COARSE
From: Santosh Sivaraj <hidden>
Date: 2017-07-21 04:40:55
* Michael Ellerman [off-list ref] wrote (on 2017-07-20 23:18:26 +1000= ):
Santosh Sivaraj [off-list ref] writes: =20quoted
Current vDSO64 implementation does not have support for coarse clocks (CLOCK_MONOTONIC_COARSE, CLOCK_REALTIME_COARSE), for which it fa=
lls
quoted
back to system call. Below is a benchmark of the difference in execution time with and without vDSO support.=20 Hi Santosh, =20 Great patch! Always good to see asm replaced with C. =20quoted
diff --git a/arch/powerpc/kernel/vdso64/gettime.c b/arch/powerpc/kernel=
/vdso64/gettime.c
quoted
new file mode 100644 index 0000000..01f411f--- /dev/null +++ b/arch/powerpc/kernel/vdso64/gettime.c@@ -0,0 +1,162 @@...quoted
+static notrace int gettime_syscall_fallback(clockid_t clk_id, + struct timespec *tp) +{ + register clockid_t id asm("r3") =3D clk_id; + register struct timespec *t asm("r4") =3D tp; + register int nr asm("r0") =3D __NR_clock_gettime; + register int ret asm("r3");=20 I guess this works. I've always been a bit nervous about register variables TBH.
Yes, this works. It falls back to syscall in the case of CLOCK_BOOTTIME.
=20quoted
+ asm volatile("sc" + : "=3Dr" (ret) + : "r"(nr), "r"(id), "r"(t) + : "memory");=20 Not sure we need the memory clobber? =20 It can clobber more registers than that though. =20 See: Documentation/powerpc/syscall64-abi.txt =20quoted
diff --git a/arch/powerpc/kernel/vdso64/gettimeofday.S b/arch/powerpc/k=
ernel/vdso64/gettimeofday.S
quoted
index 3820213..1258009 100644--- a/arch/powerpc/kernel/vdso64/gettimeofday.S +++ b/arch/powerpc/kernel/vdso64/gettimeofday.S@@ -51,85 +53,21 @@ V_FUNCTION_BEGIN(__kernel_gettimeofday)...quoted
+ stwu r1,-112(r1) + .cfi_register lr,r6 + std r6,24(r1) + bl V_LOCAL_FUNC(kernel_clock_gettime) crclr cr0*4+so=20 Clearing CR0[SO] says that the syscall always succeeded. =20 What happens if you call this with a completely bogus clock id?
In case of a bogus clock id, the default case sets 'ret' to -1, which force= s it to fallback to the syscall.
I think the solution is probably to do the syscall fallback in asm, and everything else in C.
Ok. That's what Sergey also sugested. I will send a v2. Thanks, Santosh
=20 cheers
--=20