Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp884585ybz; Fri, 1 May 2020 10:16:25 -0700 (PDT) X-Google-Smtp-Source: APiQypJPrNBRYUzxrD0gQU1GD0BKr9nQDB/PX4GoZft0QqRS8u91TdDMAdv7lO/lw4uNKrfoOsA8 X-Received: by 2002:a05:6402:1d09:: with SMTP id dg9mr4564771edb.118.1588353384851; Fri, 01 May 2020 10:16:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588353384; cv=none; d=google.com; s=arc-20160816; b=dFir/j+8VjsllhCmR6wv45fjB8H3NeKSAolMl+CrP6ekFBr2KyhWQ10WMv3ePgRWgM jgsBZABLG+OHnpiILYcM/xEk7TFm1hP7IFYY7fGLNspGZrtFK4Mk8C67YFagXNrmN3QE 1PWpP0bEeFqx8klfxjSrEWZmPD3+qIaQ5G4Kfk39HtV242nz7RI/Wvn55PEpsdqKey3A U8uUZkXy9g0/YzfkgABP6BE6vCPArZkAKmixgDpntGjZVYYmFmI+LeL9TMCzN0xX7cLc zJkLAg4+8tY7PFjB71Y4EfAOXBldL3mN5LdSTtRmVgfutkrsP/52DjEvhmm8oCDF4Yq0 RnNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=MmerXamu3rCHo11eVKURrsxvAGsE5k5a/dBbhSFaJpA=; b=PWMQVCcCzLoRy/G5JoMWiWUaz3Ab7oTDey8lpioXaLIskKWbP8ZXo/amf2PXrVHNn9 /OqYAINEsDpJIVNUmrXW4sIM//MvMj4w1P5zgESCLMhOmpIACOrAq/L82dSpfS1NbEHc pGPm6HseKXyaQAo4EWR4BwY65zAHSGdkPhj0wNzmXMbqPkPvec1i7I0FVbHmcAdrOqmw axBrvEWKIsgjELyiiA4hKKAYSh2xKoXIp9vkjwxLvN6KvD1AXTvbEZJy2RfQTAvN8eGb SFIWDuO87WjMJnESqGhesQOi4mDuapK2Slf1vH35IU6Oa12URIFzmNRavkjCXdqTLc/h Iffg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ByLudkkN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b18si2120980ejb.281.2020.05.01.10.16.01; Fri, 01 May 2020 10:16:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ByLudkkN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729291AbgEAROA (ORCPT + 99 others); Fri, 1 May 2020 13:14:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:52696 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729007AbgEAROA (ORCPT ); Fri, 1 May 2020 13:14:00 -0400 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9E11320857; Fri, 1 May 2020 17:13:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588353239; bh=R0ki2wvkvI2qui/yAMaKz5ZcbVfyz67MBU2R+c/6MuI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ByLudkkNaIRn0Vwk82fzw+Xu8DhfezjKR4Vhj5u/163f7MwbSAWySSMaOWTZHAbx6 Fto9cQbRjrZ7LL55Y5XUeJCtDZPWAX5Rb6gUwwFd2CLItjr4lxC+XztE+J1GVVx3o0 prq1YS2q5dSif5OxN+aCai4P81kQ9B7wF3Urz1mQ= Date: Fri, 1 May 2020 18:13:53 +0100 From: Will Deacon To: Leo Yan Cc: Peter Zijlstra , Marc Zyngier , Mark Rutland , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Catalin Marinas , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mathieu Poirier , Mike Leach , Al Grant , James Clark , tglx@linutronix.de Subject: Re: [PATCH] arm64: perf_event: Fix time_offset for arch timer Message-ID: <20200501171353.GB19048@willie-the-truck> References: <20200320093545.28227-1-leo.yan@linaro.org> <20200430145823.GA25258@willie-the-truck> <4d924f705245c797a19d3a73eb0c1ba0@kernel.org> <20200430160436.GC13575@hirez.programming.kicks-ass.net> <20200430161815.GE25258@willie-the-truck> <20200501151448.GA9650@leoy-ThinkPad-X240s> <20200501152609.GA17646@willie-the-truck> <20200501161050.GA16001@leoy-ThinkPad-X240s> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200501161050.GA16001@leoy-ThinkPad-X240s> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, May 02, 2020 at 12:10:50AM +0800, Leo Yan wrote: > On Fri, May 01, 2020 at 04:26:09PM +0100, Will Deacon wrote: > > [...] > > > > > > Let me try and understand your particular problem better. > > > > > > > > I think the long and short of it is that userspace needs a way to convert > > > > the raw counter cycles into a ns value that can be compared against values > > > > coming out of sched_clock. To do this accurately, I think it needs the > > > > cycles value at the point when sched_clock was initialised. > > > > > > Will's understanding is exactly what I want to resolve in this patch. > > > > > > The background info is for the ARM SPE [1] decoding with perf tool, if > > > the timestamp is enabled, it uses the generic timer's counter as > > > timestamp source. SPE trace data only contains the raw counter cycles, > > > as Will mentioned, the perf tool needs to convert it to a coordinate > > > value with sched_clock. This is why this patch tries to calculate the > > > offset between the raw counter's ns value and sched_clock, eventually > > > this offset value will be used by SPE's decoding code in Perf tool to > > > calibrate a 'correct' timestamp. > > > > > > Based on your suggestions, I will use __sched_clock_offset to resolve > > > the accuracy issue in patch v2. (I noticed Peter suggested to use a > > > new API for wrapping clock_data structure, IIUC, __sched_clock_offset > > > is more straightforward for this case). > > > > > > Please correct if I miss anything. Thank you for reviewing and > > > suggestions! > > > > I don't think you can use __sched_clock_offset without selecting > > HAVE_UNSTABLE_SCHED_CLOCK, and we really don't want to do that just > > for this. So Peter's idea about exposing what we need is better, although > > you'll probably need to take care with the switch-over from jiffies. > > > > It needs some thought, but one possibility would be to introduce a new > > variant of sthe ched_clock_register() function that returns the cycle > > offset, and then we could fish that out of the timer driver. > > Thanks a lot for you and Marc for correction. > > > If we're > > crossing all the 'i's and dotting all the 't's then we'd want to disable the > > perf userpage if sched_clock changes clocksource too (a bit like we do for > > the vDSO). > > To be honest, one thing is not clear for me is how the perf tool to > update the arch timer's parameters in the middle of tracing after > disable and re-enable per userpage. I will note for this and look > into detailed implementation for this part. I don't fully understand the concern but, generally, the seqlock should take care of any inconsistencies in the data page. Will