[RFC PATCH v3 12/12] powerpc/vdso: provide __arch_is_hw_counter_valid()

Christophe Leroy christophe.leroy at c-s.fr
Tue Jan 14 04:08:50 AEDT 2020


To avoid a double verification of the hw_counter validity,
provide __arch_is_hw_counter_valid()

Before:
clock-gettime-realtime:    vdso: 1078 nsec/call

After:
clock-gettime-realtime:    vdso: 1064 nsec/call

The * shows the test of the clock type.
The > shows the additional test on the counter,
that goes away with this patch

Before:
 5e0:	81 25 00 04 	lwz     r9,4(r5)
*5e4:	2f 89 00 00 	cmpwi   cr7,r9,0
*5e8:	40 9e 01 3c 	bne     cr7,724 <__c_kernel_clock_gettime+0x17c>
 5ec:	94 21 ff e0 	stwu    r1,-32(r1)
 5f0:	93 61 00 0c 	stw     r27,12(r1)
 5f4:	93 81 00 10 	stw     r28,16(r1)
 5f8:	93 a1 00 14 	stw     r29,20(r1)
 5fc:	93 c1 00 18 	stw     r30,24(r1)
 600:	93 e1 00 1c 	stw     r31,28(r1)
 604:	7d 8d 42 e6 	mftbu   r12
 608:	7f ac 42 e6 	mftb    r29
 60c:	7c cd 42 e6 	mftbu   r6
 610:	7f 8c 30 40 	cmplw   cr7,r12,r6
 614:	40 9e ff f0 	bne     cr7,604 <__c_kernel_clock_gettime+0x5c>
>618:	2f 8c 00 00 	cmpwi   cr7,r12,0
 61c:	83 6b 00 28 	lwz     r27,40(r11)
 620:	83 8b 00 2c 	lwz     r28,44(r11)
 624:	81 45 00 08 	lwz     r10,8(r5)
 628:	80 e5 00 0c 	lwz     r7,12(r5)
>62c:	41 9c 00 b4 	blt     cr7,6e0 <__c_kernel_clock_gettime+0x138>
 630:	81 05 00 18 	lwz     r8,24(r5)
 634:	83 c5 00 1c 	lwz     r30,28(r5)
 638:	80 cb 00 24 	lwz     r6,36(r11)
 63c:	83 e5 00 00 	lwz     r31,0(r5)
 640:	7f 9f 00 40 	cmplw   cr7,r31,r0
 644:	40 9e 00 84 	bne     cr7,6c8 <__c_kernel_clock_gettime+0x120>

After:
 5e0:	81 25 00 04 	lwz     r9,4(r5)
*5e4:	2f 89 00 00 	cmpwi   cr7,r9,0
*5e8:	40 9e 01 88 	bne     cr7,770 <__c_kernel_clock_gettime+0x1c8>
 5ec:	94 21 ff e0 	stwu    r1,-32(r1)
 5f0:	93 61 00 0c 	stw     r27,12(r1)
 5f4:	93 81 00 10 	stw     r28,16(r1)
 5f8:	93 a1 00 14 	stw     r29,20(r1)
 5fc:	93 c1 00 18 	stw     r30,24(r1)
 600:	93 e1 00 1c 	stw     r31,28(r1)
 604:	7f cd 42 e6 	mftbu   r30
 608:	7f ac 42 e6 	mftb    r29
 60c:	7c cd 42 e6 	mftbu   r6
 610:	7f 9e 30 40 	cmplw   cr7,r30,r6
 614:	40 9e ff f0 	bne     cr7,604 <__c_kernel_clock_gettime+0x5c>
 618:	83 6b 00 28 	lwz     r27,40(r11)
 61c:	83 8b 00 2c 	lwz     r28,44(r11)
 620:	81 45 00 08 	lwz     r10,8(r5)
 624:	80 e5 00 0c 	lwz     r7,12(r5)
 628:	81 05 00 18 	lwz     r8,24(r5)
 62c:	83 e5 00 1c 	lwz     r31,28(r5)
 630:	80 cb 00 24 	lwz     r6,36(r11)
 634:	81 85 00 00 	lwz     r12,0(r5)
 638:	7f 8c 00 40 	cmplw   cr7,r12,r0
 63c:	40 9e 00 84 	bne     cr7,6c0 <__c_kernel_clock_gettime+0x118>

Signed-off-by: Christophe Leroy <christophe.leroy at c-s.fr>
---
 arch/powerpc/include/asm/vdso/gettimeofday.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/include/asm/vdso/gettimeofday.h b/arch/powerpc/include/asm/vdso/gettimeofday.h
index d1e702e0ea86..c5a24f31382e 100644
--- a/arch/powerpc/include/asm/vdso/gettimeofday.h
+++ b/arch/powerpc/include/asm/vdso/gettimeofday.h
@@ -69,15 +69,18 @@ int clock_getres32_fallback(clockid_t _clkid, struct old_timespec32 *_ts)
 }
 #endif
 
-static __always_inline u64 __arch_get_hw_counter(s32 clock_mode)
+static __always_inline bool __arch_is_hw_counter_valid(s32 clock_mode)
 {
 	/*
 	 * clock_mode == 0 implies that vDSO are enabled otherwise
 	 * fallback on syscall.
 	 */
-	if (clock_mode != 0)
-		return U64_MAX;
+	return clock_mode == 0 ? true : false;
+}
+#define __arch_is_hw_counter_valid __arch_is_hw_counter_valid
 
+static __always_inline u64 __arch_get_hw_counter(s32 clock_mode)
+{
 	return get_tb();
 }
 
-- 
2.13.3



More information about the Linuxppc-dev mailing list