[{"id":1764630,"web_url":"http://patchwork.ozlabs.org/comment/1764630/","msgid":"<20170907100333.y6srewaeoxb2gy24@santosiv.in.ibm.com>","date":"2017-09-07T10:03:33","subject":"Re: [PATCH resend] powerpc/vdso64: Add support for\n\tCLOCK_{REALTIME/MONOTONIC}_COARSE","submitter":{"id":71831,"url":"http://patchwork.ozlabs.org/api/people/71831/","name":"Santosh Sivaraj","email":"santosh@fossix.org"},"content":"Hi all,\n\nAny comments on the below patch?\n\nThanks,\nSantosh\n* Santosh Sivaraj <santosh@fossix.org> wrote (on 2017-08-28 13:14:40 +0530):\n\n> Current vDSO64 implementation does not have support for coarse clocks\n> (CLOCK_MONOTONIC_COARSE, CLOCK_REALTIME_COARSE), for which it falls back\n> to system call, increasing the response time, vDSO implementation reduces\n> the cycle time. Below is a benchmark of the difference in execution time\n> with and without vDSO support.\n> \n> (Non-coarse clocks are also included just for completion)\n> \n> Without vDSO support:\n> --------------------\n> clock-gettime-realtime: syscall: 172 nsec/call\n> clock-gettime-realtime:    libc: 26 nsec/call\n> clock-gettime-realtime:    vdso: 21 nsec/call\n> clock-gettime-monotonic: syscall: 170 nsec/call\n> clock-gettime-monotonic:    libc: 30 nsec/call\n> clock-gettime-monotonic:    vdso: 24 nsec/call\n> clock-gettime-realtime-coarse: syscall: 153 nsec/call\n> clock-gettime-realtime-coarse:    libc: 15 nsec/call\n> clock-gettime-realtime-coarse:    vdso: 9 nsec/call\n> clock-gettime-monotonic-coarse: syscall: 167 nsec/call\n> clock-gettime-monotonic-coarse:    libc: 15 nsec/call\n> clock-gettime-monotonic-coarse:    vdso: 11 nsec/call\n> \n> CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>\n> Signed-off-by: Santosh Sivaraj <santosh@fossix.org>\n> ---\n>  arch/powerpc/kernel/asm-offsets.c         |  2 +\n>  arch/powerpc/kernel/vdso64/gettimeofday.S | 70 ++++++++++++++++++++++++++++---\n>  2 files changed, 66 insertions(+), 6 deletions(-)\n> \n> diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c\n> index 6e95c2c19a7e..c6acaa5edd16 100644\n> --- a/arch/powerpc/kernel/asm-offsets.c\n> +++ b/arch/powerpc/kernel/asm-offsets.c\n> @@ -396,6 +396,8 @@ int main(void)\n>  \t/* Other bits used by the vdso */\n>  \tDEFINE(CLOCK_REALTIME, CLOCK_REALTIME);\n>  \tDEFINE(CLOCK_MONOTONIC, CLOCK_MONOTONIC);\n> +\tDEFINE(CLOCK_REALTIME_COARSE, CLOCK_REALTIME_COARSE);\n> +\tDEFINE(CLOCK_MONOTONIC_COARSE, CLOCK_MONOTONIC_COARSE);\n>  \tDEFINE(NSEC_PER_SEC, NSEC_PER_SEC);\n>  \tDEFINE(CLOCK_REALTIME_RES, MONOTONIC_RES_NSEC);\n>  \n> diff --git a/arch/powerpc/kernel/vdso64/gettimeofday.S b/arch/powerpc/kernel/vdso64/gettimeofday.S\n> index 382021324883..bae197a81add 100644\n> --- a/arch/powerpc/kernel/vdso64/gettimeofday.S\n> +++ b/arch/powerpc/kernel/vdso64/gettimeofday.S\n> @@ -60,18 +60,25 @@ V_FUNCTION_END(__kernel_gettimeofday)\n>   */\n>  V_FUNCTION_BEGIN(__kernel_clock_gettime)\n>    .cfi_startproc\n> +\tmr\tr11,r4\t\t\t/* r11 saves tp */\n> +\tmflr\tr12\t\t\t/* r12 saves lr */\n> +\tlis\tr7,NSEC_PER_SEC@h\t/* want nanoseconds */\n> +\tori\tr7,r7,NSEC_PER_SEC@l\n> +\n>  \t/* Check for supported clock IDs */\n>  \tcmpwi\tcr0,r3,CLOCK_REALTIME\n>  \tcmpwi\tcr1,r3,CLOCK_MONOTONIC\n>  \tcror\tcr0*4+eq,cr0*4+eq,cr1*4+eq\n> -\tbne\tcr0,99f\n> +\tbeq\tcr0,49f\n>  \n> -\tmflr\tr12\t\t\t/* r12 saves lr */\n> +\tcmpwi\tcr0,r3,CLOCK_REALTIME_COARSE\n> +\tcmpwi\tcr1,r3,CLOCK_MONOTONIC_COARSE\n> +\tcror\tcr0*4+eq,cr0*4+eq,cr1*4+eq\n> +\tbeq\tcr0,65f\n> +\n> +\tb\t99f\t\t/* Fallback to syscall */\n>    .cfi_register lr,r12\n> -\tmr\tr11,r4\t\t\t/* r11 saves tp */\n> -\tbl\tV_LOCAL_FUNC(__get_datapage)\t/* get data page */\n> -\tlis\tr7,NSEC_PER_SEC@h\t/* want nanoseconds */\n> -\tori\tr7,r7,NSEC_PER_SEC@l\n> +49:\tbl\tV_LOCAL_FUNC(__get_datapage)\t/* get data page */\n>  50:\tbl\tV_LOCAL_FUNC(__do_get_tspec)\t/* get time from tb & kernel */\n>  \tbne\tcr1,80f\t\t\t/* if not monotonic, all done */\n>  \n> @@ -110,6 +117,57 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime)\n>  1:\tbge\tcr1,80f\n>  \taddi\tr4,r4,-1\n>  \tadd\tr5,r5,r7\n> +\tb\t80f\n> +\n> +\t/*\n> +\t * For coarse clocks we get data directly from the vdso data page, so\n> +\t * we don't need to call __do_get_tspec, but we still need to do the\n> +\t * counter trick.\n> +\t */\n> +65:\tbl\tV_LOCAL_FUNC(__get_datapage)\t/* get data page */\n> +70:\tld\tr8,CFG_TB_UPDATE_COUNT(r3)\n> +\tandi.\tr0,r8,1\t\t\t/* pending update ? loop */\n> +\tbne-\t70b\n> +\txor\tr0,r8,r8\t\t/* create dependency */\n> +\tadd\tr3,r3,r0\n> +\n> +\t/*\n> +\t * CLOCK_REALTIME_COARSE, below values are needed for MONOTONIC_COARSE\n> +\t * too\n> +\t */\n> +\tld\tr4,STAMP_XTIME+TSPC64_TV_SEC(r3)\n> +\tld\tr5,STAMP_XTIME+TSPC64_TV_NSEC(r3)\n> +\tbne\tcr1,78f\n> +\n> +\t/* CLOCK_MONOTONIC_COARSE */\n> +\tlwa\tr6,WTOM_CLOCK_SEC(r3)\n> +\tlwa\tr9,WTOM_CLOCK_NSEC(r3)\n> +\n> +\t/* check if counter has updated */\n> +78:\tor\tr0,r6,r9\n> +\txor\tr0,r0,r0\n> +\tadd\tr3,r3,r0\n> +\tld\tr0,CFG_TB_UPDATE_COUNT(r3)\n> +\tcmpld\tcr0,r0,r8\t\t/* check if updated */\n> +\tbne-\t70b\n> +\n> +\t/* Counter has not updated, so continue calculating proper values for\n> +\t * sec and nsec if monotonic coarse, or just return with the proper\n> +\t * values for realtime.\n> +\t */\n> +\tbne\tcr1,80f\n> +\n> +\t/* Add wall->monotonic offset and check for overflow or underflow */\n> +\tadd\tr4,r4,r6\n> +\tadd\tr5,r5,r9\n> +\tcmpd\tcr0,r5,r7\n> +\tcmpdi\tcr1,r5,0\n> +\tblt\t79f\n> +\tsubf\tr5,r7,r5\n> +\taddi\tr4,r4,1\n> +79:\tbge\tcr1,80f\n> +\taddi\tr4,r4,-1\n> +\tadd\tr5,r5,r7\n>  \n>  80:\tstd\tr4,TSPC64_TV_SEC(r11)\n>  \tstd\tr5,TSPC64_TV_NSEC(r11)\n\n--","headers":{"Return-Path":"<linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org>","X-Original-To":["patchwork-incoming@ozlabs.org","linuxppc-dev@lists.ozlabs.org"],"Delivered-To":["patchwork-incoming@ozlabs.org","linuxppc-dev@lists.ozlabs.org"],"Received":["from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\t(using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xnx084mddz9t2R\n\tfor <patchwork-incoming@ozlabs.org>;\n\tThu,  7 Sep 2017 20:05:12 +1000 (AEST)","from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 3xnx083QmKzDrWb\n\tfor <patchwork-incoming@ozlabs.org>;\n\tThu,  7 Sep 2017 20:05:12 +1000 (AEST)","from mail-pf0-x242.google.com (mail-pf0-x242.google.com\n\t[IPv6:2607:f8b0:400e:c00::242])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128\n\tbits)) (No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 3xnwyM3TvVzDrWK\n\tfor <linuxppc-dev@lists.ozlabs.org>;\n\tThu,  7 Sep 2017 20:03:39 +1000 (AEST)","by mail-pf0-x242.google.com with SMTP id y68so4303695pfd.1\n\tfor <linuxppc-dev@lists.ozlabs.org>;\n\tThu, 07 Sep 2017 03:03:39 -0700 (PDT)","from localhost ([125.16.167.56]) by smtp.gmail.com with ESMTPSA id\n\ts1sm3537965pfk.27.2017.09.07.03.03.35\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tThu, 07 Sep 2017 03:03:36 -0700 (PDT)"],"Authentication-Results":["ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=fossix-org.20150623.gappssmtp.com\n\theader.i=@fossix-org.20150623.gappssmtp.com\n\theader.b=\"vrxpwJvg\"; dkim-atps=neutral","lists.ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=fossix-org.20150623.gappssmtp.com\n\theader.i=@fossix-org.20150623.gappssmtp.com\n\theader.b=\"vrxpwJvg\"; dkim-atps=neutral","ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=fossix.org\n\t(client-ip=2607:f8b0:400e:c00::242; helo=mail-pf0-x242.google.com;\n\tenvelope-from=santosh@fossix.org; receiver=<UNKNOWN>)","lists.ozlabs.org; dkim=pass (2048-bit key;\n\tunprotected) header.d=fossix-org.20150623.gappssmtp.com\n\theader.i=@fossix-org.20150623.gappssmtp.com header.b=\"vrxpwJvg\"; \n\tdkim-atps=neutral"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=fossix-org.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:in-reply-to:user-agent;\n\tbh=zOMK3BVpCBdRFaHv3CgVDm6YBQwaHui5IVID2Y3GE2s=;\n\tb=vrxpwJvg6Va8qbaOknQqe+Tbp1u81oBBY8A+cCrfSojaIZHAeqgUL1ZbE8WFgWFCeK\n\t0CVCpUT8AjRMFf2VmtSihldjvED8iclQDLalg7krZJTiVFPoPunhs18UKYNsXOFHoXcl\n\t8iNQvzzLOugdo02l7EHZkz2lEAywpv+7/kuiRXpTk3hN4rab+Qc9Iwnb2kcIQTMlr+r8\n\tpz4wC2g+3NMZecSmJPAO/SLFP4cxZYs+Md3a1w2a515eTZqU/Zx4nlFQl8ppW26EoY7g\n\tsxBN7AQs9YobEONM0qDQTT++V1GmiALJRW+4uDZJrXFdYP34EKU5TLVSJBbnY7NX8uKf\n\tmObw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:in-reply-to:user-agent;\n\tbh=zOMK3BVpCBdRFaHv3CgVDm6YBQwaHui5IVID2Y3GE2s=;\n\tb=LjfZ4iLMG79OTalPr/GmgyF+7G+e87y48bjIGplAJsp+iK+6NgnVhseUpCRjq9/C1N\n\tf3jdYj9lVvNGXRcjKdrxE7Zwf6aP2G2mu9k3oHIOZNPVSQ/umlIpGwkD4rwXDgOc/85N\n\tS3cGKXURslQR6+pfKg2WAYBnTlumcNLuLxNBYZBfgLm4AgHMvvkovyf+6FQ+lSAgjEEt\n\trfX3sQ1Cq0fx7jlLuE4YJRtNnrGSADG/ZqdIPJwUglE9FX2WYbpdUaGzcTpD85Kfst26\n\t31kksnWi2s1MLicP99q1B2QqI5RJS1zuvEIpI9NEESmlmYc6oP+0OdYzY78kCh0TO7B7\n\tRGBw==","X-Gm-Message-State":"AHPjjUjU3Ksw8j8pXGiaXKRIvFZzHsWtN9ga3zqyb3zFk77I/nucvCk4\n\tigCeG3x7BkxMJgOfs22dbg==","X-Google-Smtp-Source":"ADKCNb6R1Y9otd97w02emUYicBMJ+WEy8n8BVC1Ow76MmLga7qK26bZp+2jhOQ1ahtJjTCNKmvkIkw==","X-Received":"by 10.98.34.149 with SMTP id p21mr2192571pfj.322.1504778616809; \n\tThu, 07 Sep 2017 03:03:36 -0700 (PDT)","Date":"Thu, 7 Sep 2017 15:33:33 +0530","From":"Santosh Sivaraj <santosh@fossix.org>","To":"linuxppc-dev <linuxppc-dev@lists.ozlabs.org>","Subject":"Re: [PATCH resend] powerpc/vdso64: Add support for\n\tCLOCK_{REALTIME/MONOTONIC}_COARSE","Message-ID":"<20170907100333.y6srewaeoxb2gy24@santosiv.in.ibm.com>","References":"<20170828074440.18766-1-santosh@fossix.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20170828074440.18766-1-santosh@fossix.org>","User-Agent":"NeoMutt/20170714 (1.8.3)","X-BeenThere":"linuxppc-dev@lists.ozlabs.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"Linux on PowerPC Developers Mail List\n\t<linuxppc-dev.lists.ozlabs.org>","List-Unsubscribe":"<https://lists.ozlabs.org/options/linuxppc-dev>,\n\t<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=unsubscribe>","List-Archive":"<http://lists.ozlabs.org/pipermail/linuxppc-dev/>","List-Post":"<mailto:linuxppc-dev@lists.ozlabs.org>","List-Help":"<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=help>","List-Subscribe":"<https://lists.ozlabs.org/listinfo/linuxppc-dev>,\n\t<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=subscribe>","Cc":"John Stultz <john.stultz@linaro.org>,\n\tThomas Gleixner <tglx@linutronix.de>, \n\tFrederic Weisbecker <fweisbec@gmail.com>","Errors-To":"linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org","Sender":"\"Linuxppc-dev\"\n\t<linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org>"}}]