Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp379042pxj; Wed, 16 Jun 2021 04:43:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqhkZqkovzd+ALDj5QZYXydXCg9WGaqsqk0UPjFmpuhsFyRDdDnzJWK3LmB8XWhV3Jt3iV X-Received: by 2002:a05:6602:2283:: with SMTP id d3mr3370328iod.121.1623843816978; Wed, 16 Jun 2021 04:43:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623843816; cv=none; d=google.com; s=arc-20160816; b=vK4OANQduaL/HZLIXM5yMsFzT5IE/U7fm6mDlmAApukx4N25b8zsrhtfelb4RWFdCb fFZGBJwZPcMjtml9zgVSgdxhFkFzFqYfGePmJNWFWJ6kUIN5TlD+9yHbSCc9apXKqP6B S2rJX7T7Zat3wMc2ca2YFbzX8iaB7yxnomGwQtN9ifRuq97G4QQo8t3XOHEAP/3Ct5up ZX81ykPtZX75d0bhjXKgI7pV0KdKGbNGlRsGwu7lHgwkGL9e7+iAeNO/TII6QEl9ufHm mPFWpSBuTK971p2PNYEHqZgwMaGnb89Q1wf/+36xDTgh4KPQ5vmTJBJiyhu0OW/F+mcZ nJ0A== 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=bYtfClwMmhpkY2mnoZSeVVW3hwWO6HCXgLD2xMPwtY4=; b=gkbtwjaUCBceZ39qUv0sVtTZA5uN8F6D0olj6FNLp/tB4fEcy0Ei/h4hfgUX2W+rDi kWfklfTUbJXTQBPYHu5sLZiFHcw2Xz0ax4imVawifK/wsVrTIIHcMS5iB5r0hRv2O9EE hA6jhRVjyxk1hIyOnjUriU3d5TorvDAaEnoLrnLrvM9ByFNvsgOXB25Jsn15LolMBc5M RAOETgG5aQrtiW9iGIteLDoIdt3NQZJ0wyQmXZjKE/BesCXcKx7g/gufzSyyfDaeYlkN 1JpPSgMNUlaFfG4HhrdGTvT6xFzFOubZ3R55uMq/1ZTFVM5H2scdckSEr0G0GlosokKs zyXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=oGk6Z+FS; 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 m3si2074087ild.74.2021.06.16.04.43.21; Wed, 16 Jun 2021 04:43:36 -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=desiato.20200630 header.b=oGk6Z+FS; 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 S229943AbhFPL2o (ORCPT + 99 others); Wed, 16 Jun 2021 07:28:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229502AbhFPL2n (ORCPT ); Wed, 16 Jun 2021 07:28:43 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3825BC061574 for ; Wed, 16 Jun 2021 04:26:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=bYtfClwMmhpkY2mnoZSeVVW3hwWO6HCXgLD2xMPwtY4=; b=oGk6Z+FS98Mo1I2M2EfODEv8nJ +VMkAtQv18uqmq7nvnLOoFJLyy7/3uEqVXfkgZRAyQJFJNXoGnTsgLHpNDjRe+Wcu5wpa0iANV+LP Z8NpKm4zIsYOL0LQZVHWASIiFiHExOJBysm8B43kugoqG3UJZNHwJQxsfVhtHNCgePqSjlW8hypLI jE5gF5Xwcy/2HpVZyxgYpGvxgaQ1px7430z209y9bH0mQw1MYM7G++znZSqko3a117gJ5qJep+Lgx CWh2MzzBYTolMkjavw/nH+NEgL765/CCFavIk1RLrCcbfNo3WUyihRcZAPYujarcbIFF9+R3/VUrD q7NPJxng==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1ltTgf-008J57-Ds; Wed, 16 Jun 2021 11:26: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 CCD3A300252; Wed, 16 Jun 2021 13:26:30 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id B28FC20C169EA; Wed, 16 Jun 2021 13:26:30 +0200 (CEST) Date: Wed, 16 Jun 2021 13:26:30 +0200 From: Peter Zijlstra To: Frederic Weisbecker Cc: Thomas Gleixner , LKML , "Eric W . Biederman" , Oleg Nesterov , Ingo Molnar Subject: Re: [PATCH 2/6] posix-cpu-timers: Don't start process wide cputime counter if timer is disabled Message-ID: References: <20210604113159.26177-1-frederic@kernel.org> <20210604113159.26177-3-frederic@kernel.org> <20210616105116.GA801071@lothringen> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210616105116.GA801071@lothringen> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 16, 2021 at 12:51:16PM +0200, Frederic Weisbecker wrote: > On Wed, Jun 16, 2021 at 10:51:21AM +0200, Peter Zijlstra wrote: > > The cpu_timer_enqueue() is in arm_timer() and the condition for calling > > that is: > > > > 'new_expires != 0 && val < new_expires' > > > > Which is not the same as the one you add. > > There are two different things here: > > 1) the threadgroup cputime counter, activated by cpu_clock_sample_group(clkid, > p, true) > > 2) the expiration set (+ the callback enqueued) in arm_timer() > > The issue here is that we go through 1) but not through 2) Correct, but then I would think the cleanup would need the same conditions as 2, and not something slightly different, which is what confused me. > > I'm thinking the fundamental problem here is the disconnect between > > cpu_timer_enqueue() and pct->timers_active ? > > You're right it's the core issue. But what prevents the whole to be > fundamentally connected is a circular dependency: we need to know the > threadgroup cputime before arming the timer, but we would need to know > if we arm the timer before starting the threadgroup cputime counter > > To sum up, the current sequence is: > > * fetch the threadgroup cputime AND start the whole threadgroup counter > > * arm the timer if it isn't zero and it hasn't yet expired > > While the ideal sequence should be: > > * fetch the threadgroup cputime (without starting the whole threadgroup counter > yet) > > * arm the timer if it isn't zero and it hasn't yet expired > > * iff we armed the timer, start the whole theadgroup counter > > But that means re-iterating the whole threadgroup and update atomically > the group counter with each task's time. Right, so by the time patch #5 comes around, you seem to be at the point where you can do: * fetch cputime and start threadgroup counter * possibly arm timer * if expired: - fire now - if armed, disarm (which leads to stop) Which is the other 'obvious' solution to not starting it.