From patchwork Mon Aug 28 07:44:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Santosh Sivaraj X-Patchwork-Id: 806419 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xgkNf0JNFz9sNq for ; Mon, 28 Aug 2017 17:46:26 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=fossix-org.20150623.gappssmtp.com header.i=@fossix-org.20150623.gappssmtp.com header.b="esveyHfk"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xgkNd6HcczDqG3 for ; Mon, 28 Aug 2017 17:46:25 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=fossix-org.20150623.gappssmtp.com header.i=@fossix-org.20150623.gappssmtp.com header.b="esveyHfk"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mail-pg0-x244.google.com (mail-pg0-x244.google.com [IPv6:2607:f8b0:400e:c05::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3xgkLq5shpzDq5m for ; Mon, 28 Aug 2017 17:44:51 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=fossix-org.20150623.gappssmtp.com header.i=@fossix-org.20150623.gappssmtp.com header.b="esveyHfk"; dkim-atps=neutral Received: by mail-pg0-x244.google.com with SMTP id r133so5778748pgr.2 for ; Mon, 28 Aug 2017 00:44:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fossix-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=ucWlJvtN2ZggpLPZuS13Zm43sTx4Rex3mFDP0vS4lPs=; b=esveyHfkf9+HhoJxmhMTUpS0JtHQFWCub6mEGG+sChUzXvDkMhgtKDoTwc1X5plJRD 2QkLg9uZACJq5VsyymxWTsJLe90w+61oTvXEwgxR4t+XNsPC0oueq25hqHhI0JRs5hOz VSsmb+yKLju++owrLVTbmSuw/6ijnCIHyLvUX2UlNdEkJd1BeULm4X0H1okiPJsufI5w sV2GeJlRih2slqFb+joPK3pfsDYoRU1+dh2esAEqlH2yr38KKKRpM7F8UVXgguSktZzc 5MHNDJFCKIoPIA/dakfs/CxD93t5RH4hOi+NKY+a6yoLthKzsQl5oPfuQcpPXOHtAZWI BEVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ucWlJvtN2ZggpLPZuS13Zm43sTx4Rex3mFDP0vS4lPs=; b=LC7aGGeqvhgoEECuVbV/YMjvsnVVP+P1mAL0QzvXTGKP0P5w5A/NS4PQurH+o7T06I rFJn7OC7Aw7vfG7T1LwppivWW/HvzrGxgKXMLm6PObUnV4abZbTm33n1R0b6KSolMwdp Acgwr1baNXACfOqLxvyCPbtqVQrLBiz3y+w4DxBgd89fpb9NcVHyiOdB8WbvaELt+BEk SPXqAjYm2yRaZBTnQslz/J1bO2b2u6fXbih5VoU5NO5+oFwwfRd+EWPNjIfqC0xzVCrW 8iIAbzGwHF3Pbq7pJrP+ox54WoRBtr1wKRMVYMCQ2SJ8ISoeReV8AEYaei1Kfda+YlHO ZvQA== X-Gm-Message-State: AHYfb5gLOJqmb5+KUxQrvSmvTalU2+E/2Mhde5lHOJyQ5vLfzvvU8T+v qD4vHzIN32pR10dep/Y= X-Received: by 10.84.215.130 with SMTP id l2mr7238457pli.116.1503906289262; Mon, 28 Aug 2017 00:44:49 -0700 (PDT) Received: from santosiv.in.ibm.com ([125.16.167.56]) by smtp.gmail.com with ESMTPSA id c4sm20693166pfm.114.2017.08.28.00.44.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Aug 2017 00:44:48 -0700 (PDT) From: Santosh Sivaraj To: linuxppc-dev Subject: [PATCH resend] powerpc/vdso64: Add support for CLOCK_{REALTIME/MONOTONIC}_COARSE Date: Mon, 28 Aug 2017 13:14:40 +0530 Message-Id: <20170828074440.18766-1-santosh@fossix.org> X-Mailer: git-send-email 2.13.5 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Gleixner , John Stultz , Frederic Weisbecker Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Current vDSO64 implementation does not have support for coarse clocks (CLOCK_MONOTONIC_COARSE, CLOCK_REALTIME_COARSE), for which it falls back to system call, increasing the response time, vDSO implementation reduces the cycle time. Below is a benchmark of the difference in execution time with and without vDSO support. (Non-coarse clocks are also included just for completion) Without vDSO support: -------------------- clock-gettime-realtime: syscall: 172 nsec/call clock-gettime-realtime: libc: 26 nsec/call clock-gettime-realtime: vdso: 21 nsec/call clock-gettime-monotonic: syscall: 170 nsec/call clock-gettime-monotonic: libc: 30 nsec/call clock-gettime-monotonic: vdso: 24 nsec/call clock-gettime-realtime-coarse: syscall: 153 nsec/call clock-gettime-realtime-coarse: libc: 15 nsec/call clock-gettime-realtime-coarse: vdso: 9 nsec/call clock-gettime-monotonic-coarse: syscall: 167 nsec/call clock-gettime-monotonic-coarse: libc: 15 nsec/call clock-gettime-monotonic-coarse: vdso: 11 nsec/call CC: Benjamin Herrenschmidt Signed-off-by: Santosh Sivaraj --- arch/powerpc/kernel/asm-offsets.c | 2 + arch/powerpc/kernel/vdso64/gettimeofday.S | 70 ++++++++++++++++++++++++++++--- 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c index 6e95c2c19a7e..c6acaa5edd16 100644 --- a/arch/powerpc/kernel/asm-offsets.c +++ b/arch/powerpc/kernel/asm-offsets.c @@ -396,6 +396,8 @@ int main(void) /* Other bits used by the vdso */ DEFINE(CLOCK_REALTIME, CLOCK_REALTIME); DEFINE(CLOCK_MONOTONIC, CLOCK_MONOTONIC); + DEFINE(CLOCK_REALTIME_COARSE, CLOCK_REALTIME_COARSE); + DEFINE(CLOCK_MONOTONIC_COARSE, CLOCK_MONOTONIC_COARSE); DEFINE(NSEC_PER_SEC, NSEC_PER_SEC); DEFINE(CLOCK_REALTIME_RES, MONOTONIC_RES_NSEC); diff --git a/arch/powerpc/kernel/vdso64/gettimeofday.S b/arch/powerpc/kernel/vdso64/gettimeofday.S index 382021324883..bae197a81add 100644 --- a/arch/powerpc/kernel/vdso64/gettimeofday.S +++ b/arch/powerpc/kernel/vdso64/gettimeofday.S @@ -60,18 +60,25 @@ V_FUNCTION_END(__kernel_gettimeofday) */ V_FUNCTION_BEGIN(__kernel_clock_gettime) .cfi_startproc + mr r11,r4 /* r11 saves tp */ + mflr r12 /* r12 saves lr */ + lis r7,NSEC_PER_SEC@h /* want nanoseconds */ + ori r7,r7,NSEC_PER_SEC@l + /* Check for supported clock IDs */ cmpwi cr0,r3,CLOCK_REALTIME cmpwi cr1,r3,CLOCK_MONOTONIC cror cr0*4+eq,cr0*4+eq,cr1*4+eq - bne cr0,99f + beq cr0,49f - mflr r12 /* r12 saves lr */ + cmpwi cr0,r3,CLOCK_REALTIME_COARSE + cmpwi cr1,r3,CLOCK_MONOTONIC_COARSE + cror cr0*4+eq,cr0*4+eq,cr1*4+eq + beq cr0,65f + + b 99f /* Fallback to syscall */ .cfi_register lr,r12 - mr r11,r4 /* r11 saves tp */ - bl V_LOCAL_FUNC(__get_datapage) /* get data page */ - lis r7,NSEC_PER_SEC@h /* want nanoseconds */ - ori r7,r7,NSEC_PER_SEC@l +49: bl V_LOCAL_FUNC(__get_datapage) /* get data page */ 50: bl V_LOCAL_FUNC(__do_get_tspec) /* get time from tb & kernel */ bne cr1,80f /* if not monotonic, all done */ @@ -110,6 +117,57 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime) 1: bge cr1,80f addi r4,r4,-1 add r5,r5,r7 + b 80f + + /* + * 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. + */ +65: bl V_LOCAL_FUNC(__get_datapage) /* get data page */ +70: ld r8,CFG_TB_UPDATE_COUNT(r3) + andi. r0,r8,1 /* pending update ? loop */ + bne- 70b + xor r0,r8,r8 /* create dependency */ + add r3,r3,r0 + + /* + * CLOCK_REALTIME_COARSE, below values are needed for MONOTONIC_COARSE + * too + */ + ld r4,STAMP_XTIME+TSPC64_TV_SEC(r3) + ld r5,STAMP_XTIME+TSPC64_TV_NSEC(r3) + bne cr1,78f + + /* CLOCK_MONOTONIC_COARSE */ + lwa r6,WTOM_CLOCK_SEC(r3) + lwa r9,WTOM_CLOCK_NSEC(r3) + + /* check if counter has updated */ +78: or r0,r6,r9 + xor r0,r0,r0 + add r3,r3,r0 + ld r0,CFG_TB_UPDATE_COUNT(r3) + cmpld 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 cr1,80f + + /* Add wall->monotonic offset and check for overflow or underflow */ + add r4,r4,r6 + add r5,r5,r9 + cmpd cr0,r5,r7 + cmpdi cr1,r5,0 + blt 79f + subf r5,r7,r5 + addi r4,r4,1 +79: bge cr1,80f + addi r4,r4,-1 + add r5,r5,r7 80: std r4,TSPC64_TV_SEC(r11) std r5,TSPC64_TV_NSEC(r11)