Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp1406991pxy; Thu, 6 May 2021 07:24:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxL1JNZqD8l+GAYda6/6/e6wXcOB6o2a6qM/h/49chZuTPW0kv9pl2EgiEeNwCUy3C6GFf0 X-Received: by 2002:a63:e712:: with SMTP id b18mr4587277pgi.2.1620311093384; Thu, 06 May 2021 07:24:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620311093; cv=none; d=google.com; s=arc-20160816; b=p/3gw7uVGp7FgBBMj5ZxOix+A8OHezxN/7t5d93IJigG/wTXfFYXZBMWVmoamYcpV0 uRgR01+uuGB0mU53pBEjerCAU7uwT94Z4r5J8d0DJdtIJh1L8XnRJw5FyyWGUSci41L9 X+fcbBCm7DdAu+JoZhOif84ybWHaIiPoV4ccjL628pDHIPGoD/YhAlq+UqhlYzzSGt2B LJH4fAUpZOh2mgc0wPBmmKKI9WyycrJXZwfIt3TJR7EHyHhqIDBui8igrWvafSsRt5Pq 84dnc9GiIqWdCkXPWkI+htte7UlcQU+Yb901ebH8Ucg/GBdVriZhPlOs+gL2q0QWM/kf tHRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=L7Wckp9ebZm0QWNsvc214TUX7ukxMswtFUJfcKeZEFg=; b=Gf1AXzm7qp+UeUZUVu6bXdxLuMi99e3zXaMXQbrd4Vjex5TuJwGVU9oQoQrrknFNiW rGrWMlkDNLHF/dyi207ruYG1O1ndrwIEYx6fAACWHvjBDz4M54xs/sdDgJpOCQjaIVmT yc66HegHThO0E/42yLS4Wr7eUG2VrrHb04kC3jSQDXj/GTxLBuHH5UPM+J7wG6x+SYVx Ex7KwM3NRk0Y6mDOao1IhI2CQij16o0X1PeOxtldrbVCa2a2VNNOtWxLGf5kb1bf/z6A BlsGsSH8kABEEQn2Itenb8u+Gat5d2r+6XRQ7w7TJq9CfPbAgb7+3f5urOXau3VmmTHv LY0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=SfWSlpnc; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j17si3384207pgg.304.2021.05.06.07.24.39; Thu, 06 May 2021 07:24:53 -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=@infradead.org header.s=casper.20170209 header.b=SfWSlpnc; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234754AbhEFOXr (ORCPT + 99 others); Thu, 6 May 2021 10:23:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234721AbhEFOXq (ORCPT ); Thu, 6 May 2021 10:23:46 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9804EC061574; Thu, 6 May 2021 07:22:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=L7Wckp9ebZm0QWNsvc214TUX7ukxMswtFUJfcKeZEFg=; b=SfWSlpncig8YbvX0yr1ScJII4O 69V9ZMrQ2D1FemHQkoVhAgvjBRcLzyxCB39gPXRH0N5C4VFCT2XtDYtQFXIA+sD4pasT8kEMS00R6 pHOQ/GopqFXDuECTVqOJ2aK7z12AXZPXaXhxDuPNOM3Bt6WuUT4SMG2idr6C6rLTmvmyhsbDShmGK /Jd1eh4Ewi/Os1OaNQmBktoYVYfTjV3LvUbKvNBTpNNlhy702AwPmyqrLWnwBFqnbNiAYMIJ8kkoC xBwo7Geh3RTA2/KN7rpVAAVp63fliiot6hZPE+R1TUnYyIyGsEaep7+CBC7P6wmNOyV36SxwiMh3z iFDq8mtA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1leeop-001njw-Hk; Thu, 06 May 2021 14:18:32 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id D7BC93001DB; Thu, 6 May 2021 16:17:33 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id B50D720224220; Thu, 6 May 2021 16:17:33 +0200 (CEST) Date: Thu, 6 May 2021 16:17:33 +0200 From: Peter Zijlstra To: Johannes Weiner Cc: tglx@linutronix.de, mingo@kernel.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, bsingharora@gmail.com, pbonzini@redhat.com, maz@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, riel@surriel.com Subject: Re: [PATCH 1/6] delayacct: Use sched_clock() Message-ID: References: <20210505105940.190490250@infradead.org> <20210505111525.001031466@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 06, 2021 at 09:59:11AM -0400, Johannes Weiner wrote: > On Wed, May 05, 2021 at 12:59:41PM +0200, Peter Zijlstra wrote: > > @@ -42,10 +42,9 @@ void __delayacct_tsk_init(struct task_st > > * Finish delay accounting for a statistic using its timestamps (@start), > > * accumalator (@total) and @count > > */ > > -static void delayacct_end(raw_spinlock_t *lock, u64 *start, u64 *total, > > - u32 *count) > > +static void delayacct_end(raw_spinlock_t *lock, u64 *start, u64 *total, u32 *count) > > { > > - s64 ns = ktime_get_ns() - *start; > > + s64 ns = local_clock() - *start; > > I don't think this is safe. These time sections that have preemption > and migration enabled and so might span multiple CPUs. local_clock() > could end up behind *start, AFAICS. Only if you have really crummy hardware, and in that case the drift is bounded by around 1 tick. Also, this function actually checks: ns > 0. And if you do have crummy hardware like that, ktime_get_ns() is the very last thing you want to call at any frequency because it'll be the HPET.