All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] powerpc/vdso32: Add support for CLOCK_{REALTIME/MONOTONIC}_COARSE
@ 2019-08-16 13:01 Christophe Leroy
  2019-08-16 16:44   ` Segher Boessenkool
  2019-08-19 16:37   ` Nathan Lynch
  0 siblings, 2 replies; 8+ messages in thread
From: Christophe Leroy @ 2019-08-16 13:01 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman
  Cc: Naveen N. Rao, Santosh Sivaraj, linuxppc-dev, linux-kernel

This is copied and adapted from commit 5c929885f1bb ("powerpc/vdso64:
Add support for CLOCK_{REALTIME/MONOTONIC}_COARSE")
from Santosh Sivaraj <santosh@fossix.org>

Benchmark from vdsotest:
clock-gettime-realtime: syscall: 3601 nsec/call
clock-gettime-realtime:    libc: 1072 nsec/call
clock-gettime-realtime:    vdso: 931 nsec/call
clock-gettime-monotonic: syscall: 4034 nsec/call
clock-gettime-monotonic:    libc: 1213 nsec/call
clock-gettime-monotonic:    vdso: 1076 nsec/call
clock-gettime-realtime-coarse: syscall: 2722 nsec/call
clock-gettime-realtime-coarse:    libc: 805 nsec/call
clock-gettime-realtime-coarse:    vdso: 668 nsec/call
clock-gettime-monotonic-coarse: syscall: 2949 nsec/call
clock-gettime-monotonic-coarse:    libc: 882 nsec/call
clock-gettime-monotonic-coarse:    vdso: 745 nsec/call

Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Santosh Sivaraj <santosh@fossix.org>
Link: https://github.com/linuxppc/issues/issues/41
---
 arch/powerpc/kernel/vdso32/gettimeofday.S | 48 ++++++++++++++++++++++++++++++-
 1 file changed, 47 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/vdso32/gettimeofday.S b/arch/powerpc/kernel/vdso32/gettimeofday.S
index becd9f8767ed..e10098cde89c 100644
--- a/arch/powerpc/kernel/vdso32/gettimeofday.S
+++ b/arch/powerpc/kernel/vdso32/gettimeofday.S
@@ -71,6 +71,12 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime)
 	cmpli	cr0,r3,CLOCK_REALTIME
 	cmpli	cr1,r3,CLOCK_MONOTONIC
 	cror	cr0*4+eq,cr0*4+eq,cr1*4+eq
+
+	cmpli	cr5,r3,CLOCK_REALTIME_COARSE
+	cmpli	cr6,r3,CLOCK_MONOTONIC_COARSE
+	cror	cr5*4+eq,cr5*4+eq,cr6*4+eq
+
+	cror	cr0*4+eq,cr0*4+eq,cr5*4+eq
 	bne	cr0,99f
 
 	mflr	r12			/* r12 saves lr */
@@ -80,6 +86,7 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime)
 	mr	r9,r3			/* datapage ptr in r9 */
 	lis	r7,NSEC_PER_SEC@h	/* want nanoseconds */
 	ori	r7,r7,NSEC_PER_SEC@l
+	beq	cr5,70f
 50:	bl	__do_get_tspec@local	/* get sec/nsec from tb & kernel */
 	bne	cr1,80f			/* not monotonic -> all done */
 
@@ -106,12 +113,51 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime)
 	lwz	r0,(CFG_TB_UPDATE_COUNT+LOPART)(r9)
         cmpl    cr0,r8,r0		/* check if updated */
 	bne-	50b
+	b	78f
+
+	/*
+	 * For coarse clocks we get data directly from the vdso data page, so
+	 * we don't need to call __do_get_tspec, but we still need to do the
+	 * counter trick.
+	 */
+70:	lwz	r8,(CFG_TB_UPDATE_COUNT+LOPART)(r9)
+	andi.	r0,r8,1                 /* pending update ? loop */
+	bne-	70b
+	add	r9,r9,r0		/* r0 is already 0 */
+
+	/*
+	 * CLOCK_REALTIME_COARSE, below values are needed for MONOTONIC_COARSE
+	 * too
+	 */
+	lwz	r3,STAMP_XTIME+TSPC32_TV_SEC(r9)
+	lwz	r4,STAMP_XTIME+TSPC32_TV_NSEC(r9)
+	bne	cr6,75f
+
+	/* CLOCK_MONOTONIC_COARSE */
+	lwz	r5,(WTOM_CLOCK_SEC+LOPART)(r9)
+	lwz	r6,WTOM_CLOCK_NSEC(r9)
+
+	/* check if counter has updated */
+	or	r0,r6,r5
+75:	or	r0,r0,r3
+	or	r0,r0,r4
+	xor	r0,r0,r0
+	add	r3,r3,r0
+	lwz	r0,CFG_TB_UPDATE_COUNT+LOPART(r9)
+	cmpl	cr0,r0,r8               /* check if updated */
+	bne-	70b
+
+	/* Counter has not updated, so continue calculating proper values for
+	 * sec and nsec if monotonic coarse, or just return with the proper
+	 * values for realtime.
+	 */
+	bne	cr6,80f
 
 	/* Calculate and store result. Note that this mimics the C code,
 	 * which may cause funny results if nsec goes negative... is that
 	 * possible at all ?
 	 */
-	add	r3,r3,r5
+78:	add	r3,r3,r5
 	add	r4,r4,r6
 	cmpw	cr0,r4,r7
 	cmpwi	cr1,r4,0
-- 
2.13.3


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

* Re: [PATCH] powerpc/vdso32: Add support for CLOCK_{REALTIME/MONOTONIC}_COARSE
  2019-08-16 13:01 [PATCH] powerpc/vdso32: Add support for CLOCK_{REALTIME/MONOTONIC}_COARSE Christophe Leroy
@ 2019-08-16 16:44   ` Segher Boessenkool
  2019-08-19 16:37   ` Nathan Lynch
  1 sibling, 0 replies; 8+ messages in thread
From: Segher Boessenkool @ 2019-08-16 16:44 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
	Naveen N. Rao, Santosh Sivaraj, linuxppc-dev, linux-kernel

On Fri, Aug 16, 2019 at 01:01:50PM +0000, Christophe Leroy wrote:
> -	add	r3,r3,r5
> +78:	add	r3,r3,r5

You can use actual names for the labels as well...  .Lsomething if you
want it to stay a local symbol only.


Segher

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

* Re: [PATCH] powerpc/vdso32: Add support for CLOCK_{REALTIME/MONOTONIC}_COARSE
@ 2019-08-16 16:44   ` Segher Boessenkool
  0 siblings, 0 replies; 8+ messages in thread
From: Segher Boessenkool @ 2019-08-16 16:44 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: Santosh Sivaraj, linux-kernel, Paul Mackerras, Naveen N. Rao,
	linuxppc-dev

On Fri, Aug 16, 2019 at 01:01:50PM +0000, Christophe Leroy wrote:
> -	add	r3,r3,r5
> +78:	add	r3,r3,r5

You can use actual names for the labels as well...  .Lsomething if you
want it to stay a local symbol only.


Segher

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

* Re: [PATCH] powerpc/vdso32: Add support for CLOCK_{REALTIME/MONOTONIC}_COARSE
  2019-08-16 13:01 [PATCH] powerpc/vdso32: Add support for CLOCK_{REALTIME/MONOTONIC}_COARSE Christophe Leroy
@ 2019-08-19 16:37   ` Nathan Lynch
  2019-08-19 16:37   ` Nathan Lynch
  1 sibling, 0 replies; 8+ messages in thread
From: Nathan Lynch @ 2019-08-19 16:37 UTC (permalink / raw)
  To: Christophe Leroy, Benjamin Herrenschmidt, Paul Mackerras,
	Michael Ellerman
  Cc: Naveen N. Rao, Santosh Sivaraj, linuxppc-dev, linux-kernel

Hi,

Christophe Leroy <christophe.leroy@c-s.fr> writes:
> Benchmark from vdsotest:

I assume you also ran the verification/correctness parts of vdsotest...? :-)



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

* Re: [PATCH] powerpc/vdso32: Add support for CLOCK_{REALTIME/MONOTONIC}_COARSE
@ 2019-08-19 16:37   ` Nathan Lynch
  0 siblings, 0 replies; 8+ messages in thread
From: Nathan Lynch @ 2019-08-19 16:37 UTC (permalink / raw)
  To: Christophe Leroy, Benjamin Herrenschmidt, Paul Mackerras,
	Michael Ellerman
  Cc: Naveen N. Rao, linuxppc-dev, Santosh Sivaraj, linux-kernel

Hi,

Christophe Leroy <christophe.leroy@c-s.fr> writes:
> Benchmark from vdsotest:

I assume you also ran the verification/correctness parts of vdsotest...? :-)



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

* Re: [PATCH] powerpc/vdso32: Add support for CLOCK_{REALTIME/MONOTONIC}_COARSE
  2019-08-19 16:37   ` Nathan Lynch
@ 2019-08-19 20:33     ` Christophe Leroy
  -1 siblings, 0 replies; 8+ messages in thread
From: Christophe Leroy @ 2019-08-19 20:33 UTC (permalink / raw)
  To: Nathan Lynch, Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman
  Cc: Naveen N. Rao, Santosh Sivaraj, linuxppc-dev, linux-kernel

Hi,

Le 19/08/2019 à 18:37, Nathan Lynch a écrit :
> Hi,
> 
> Christophe Leroy <christophe.leroy@c-s.fr> writes:
>> Benchmark from vdsotest:
> 
> I assume you also ran the verification/correctness parts of vdsotest...? :-)
> 

I did run vdsotest-all. I guess it runs the verifications too ?

Christophe

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

* Re: [PATCH] powerpc/vdso32: Add support for CLOCK_{REALTIME/MONOTONIC}_COARSE
@ 2019-08-19 20:33     ` Christophe Leroy
  0 siblings, 0 replies; 8+ messages in thread
From: Christophe Leroy @ 2019-08-19 20:33 UTC (permalink / raw)
  To: Nathan Lynch, Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman
  Cc: Naveen N. Rao, linuxppc-dev, Santosh Sivaraj, linux-kernel

Hi,

Le 19/08/2019 à 18:37, Nathan Lynch a écrit :
> Hi,
> 
> Christophe Leroy <christophe.leroy@c-s.fr> writes:
>> Benchmark from vdsotest:
> 
> I assume you also ran the verification/correctness parts of vdsotest...? :-)
> 

I did run vdsotest-all. I guess it runs the verifications too ?

Christophe

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

* Re: [PATCH] powerpc/vdso32: Add support for CLOCK_{REALTIME/MONOTONIC}_COARSE
  2019-08-19 20:33     ` Christophe Leroy
  (?)
@ 2019-08-19 22:34     ` Nathan Lynch
  -1 siblings, 0 replies; 8+ messages in thread
From: Nathan Lynch @ 2019-08-19 22:34 UTC (permalink / raw)
  To: Christophe Leroy, Benjamin Herrenschmidt, Paul Mackerras,
	Michael Ellerman
  Cc: Naveen N. Rao, linuxppc-dev, Santosh Sivaraj, linux-kernel

Christophe Leroy <christophe.leroy@c-s.fr> writes:

> Hi,
>
> Le 19/08/2019 à 18:37, Nathan Lynch a écrit :
>> Hi,
>> 
>> Christophe Leroy <christophe.leroy@c-s.fr> writes:
>>> Benchmark from vdsotest:
>> 
>> I assume you also ran the verification/correctness parts of vdsotest...? :-)
>> 
>
> I did run vdsotest-all. I guess it runs the verifications too ?

It does, but at a quick glance it runs the validation for "only" 1
second per API. It may provide more confidence to allow the validation
to run across several second (tv_sec) transitions, e.g.

vdsotest -d 30 clock-gettime-monotonic-coarse verify

Regardless, I did not see any problem with your patch.

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

end of thread, other threads:[~2019-08-19 22:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-16 13:01 [PATCH] powerpc/vdso32: Add support for CLOCK_{REALTIME/MONOTONIC}_COARSE Christophe Leroy
2019-08-16 16:44 ` Segher Boessenkool
2019-08-16 16:44   ` Segher Boessenkool
2019-08-19 16:37 ` Nathan Lynch
2019-08-19 16:37   ` Nathan Lynch
2019-08-19 20:33   ` Christophe Leroy
2019-08-19 20:33     ` Christophe Leroy
2019-08-19 22:34     ` Nathan Lynch

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.