From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 193B2C54E8B for ; Tue, 12 May 2020 10:01:36 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DCF3E20733 for ; Tue, 12 May 2020 10:01:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="acKBZzTt" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DCF3E20733 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tP64gFWWNSqtTgqzL4DabL0yWvo2fERfzniY6qy6yoc=; b=acKBZzTt39R3Vx 3z4EFv55ltTlP9aMjB28/kWzLr6ML9llHxIRgkUyAnubbVCY2h5QmZGclR55DGoudkqII92/4JH2l xLjIpezmBtb1dslDyYJY8oP4ivKgU6YYq/Gh1oeRkO5kW1n5HH6IhrH8xxmR8Azwoerr9wHmdBMSU V2gZNNyPHQ+hCTdfDJFY/Xy2tne5b+ruDwfCDNFJtrSuSfdrwWMOkUuk7r3kPzyK65eP7H5cEHW/q M1Ntq7+ngMOhfTNSwgxMPsWd2tGv2Tigd+kA3a5xkjHGGDo57WiUOBUqIuB1++wiKcEmoBv0xOaQC fzDLgoqdJIP5Z/UsMesw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jYRjD-0008Ap-Ef; Tue, 12 May 2020 10:01:35 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jYRj9-00089e-S9 for linux-arm-kernel@lists.infradead.org; Tue, 12 May 2020 10:01:33 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5BF391FB; Tue, 12 May 2020 03:01:28 -0700 (PDT) Received: from C02TD0UTHF1T.local (unknown [10.57.28.99]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E94313F71E; Tue, 12 May 2020 03:01:23 -0700 (PDT) Date: Tue, 12 May 2020 11:01:14 +0100 From: Mark Rutland To: Peter Zijlstra Subject: Re: [PATCH v2 0/3] arm64: perf_event: Fix time offset prior to epoch Message-ID: <20200512100114.GA60359@C02TD0UTHF1T.local> References: <20200505135544.6003-1-leo.yan@linaro.org> <20200511092200.GF2957@hirez.programming.kicks-ass.net> <20200511092519.GA3001@hirez.programming.kicks-ass.net> <20200512063812.GA20352@leoy-ThinkPad-X240s> <20200512091918.GH2978@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200512091918.GH2978@hirez.programming.kicks-ass.net> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200512_030131_957329_D11D0C08 X-CRM114-Status: GOOD ( 16.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kate Stewart , Enrico Weigelt , Catalin Marinas , Greg Kroah-Hartman , Alexander Shishkin , Marc Zyngier , Jiri Olsa , Daniel Lezcano , linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , Paul Cercueil , Alexios Zavras , "Ahmed S. Darwish" , Ingo Molnar , linux-arm-kernel@lists.infradead.org, Leo Yan , Namhyung Kim , Thomas Gleixner , Will Deacon , "Ben Dooks \(Codethink\)" , Allison Randal Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, May 12, 2020 at 11:19:18AM +0200, Peter Zijlstra wrote: > On Tue, May 12, 2020 at 02:38:12PM +0800, Leo Yan wrote: > > @@ -1165,28 +1166,26 @@ device_initcall(armv8_pmu_driver_init) > > void arch_perf_update_userpage(struct perf_event *event, > > struct perf_event_mmap_page *userpg, u64 now) > > { > > + struct clock_read_data *rd; > > + unsigned int seq; > > > > /* > > * Internal timekeeping for enabled/running/stopped times > > * is always computed with the sched_clock. > > */ > > userpg->cap_user_time = 1; > > + userpg->cap_user_time_zero = 1; > > > > + do { > > + rd = sched_clock_read_begin(&seq); > > + > > + userpg->time_mult = rd->mult; > > + userpg->time_shift = rd->shift; > > + userpg->time_zero = rd->epoch_ns; > > + > > + userpg->time_zero -= (rd->epoch_cyc * rd->mult) >> rd->shift; > > Damn, I think this is broken vs the counter wrapping. > > So what the sched_clock code does is: > > cyc_to_ns((cyc - rd->epoch_cyc) & rd->sched_clock_mask, rd->mult, rd->shift) > > But because the perf interface assumes a simple linear relation, we > can't express that properly. > > Now, your arm64 counter is 56 bits, so wrapping is rare, but still, we > should probably fix that. And that probably needs an ABI extention > *sigh*. FWIW, its's /at least/ 56 bits wide, and the ARM ARM says that it shouldn't wrap in fewer than 40 years, so no correct implementation should wrap before the 2050s. If it's wider than 56 bits, the 56-bit portion could wrap more quickly than that, so we should probably always treat it as 64-bits. >From ARMv8.6 it's always 64 bits wide @ a nominal 1GHz, and a 64-bit wrap will take ~584.9 years (with a 56-bit wrap taking ~834 days). See D11.1.2 "The system counter" in the latest ARM ARM (0487F.b): https://static.docs.arm.com/ddi0487/fb/DDI0487F_b_armv8_arm.pdf?_ga=2.83012310.1749782910.1589218924-1447552059.1588172444 https://developer.arm.com/docs/ddi0487/latest Thanks, Mark. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel