Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1800717rdb; Tue, 20 Feb 2024 07:25:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU2KDMxXDlDFfUT0HKyWbtJ4pFgvYdRfcvwxv8h5U7ZE/+FeL7vBSs7WpmmEN2YkeManDtiC2B/JntdpX7oTEtI9+2MXFlv/waly4q9cA== X-Google-Smtp-Source: AGHT+IEI9TmFGOnZgI53K75ghXiCxSX6dR/MdITKXsQJFi+ObpbHOkM6ayjjB1PC1pn8oP1+sufv X-Received: by 2002:a05:6a21:3a4b:b0:1a0:912c:ef08 with SMTP id zu11-20020a056a213a4b00b001a0912cef08mr8368682pzb.38.1708442739179; Tue, 20 Feb 2024 07:25:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708442739; cv=pass; d=google.com; s=arc-20160816; b=HdjVDTZ5rbFFgUQ4OR/hAMil3L2tE+apLAjdjIeBo1aqIOg2x5K3P/dQWzABzp77pd 9kkmlsfpU3DwTRzlOfGYbeFkzhUi9bVEiC/e4hhCOXf2Tblw5v9X5/wisPpFdfki2Uli 8d4GNOUDS9XhD7mC+elcXwwNuSL/gb8+ejx/jr0OURfNM00FHVnzrHCdjceZZwsq/1o7 i4EhaVNED1P5WGKgfbXF8lyF6jcnfQDd+ezbkKFkfSOPr6Y7kcRBwyoM4ac2BpkFYkz7 rX1n5z6JF8p4l0+1mauy9n/EL3WwzXG7MkHn19jNn+YNWhWHUNrgn/uinJaCs/YmgSs1 +LVA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=DXzbe4h8bhxfVha+wY6bRZmO1mjmsMXRa52STpDlbjI=; fh=rlwn4pxNjzZxzAe0OFpEm5XldgGOhioyoE/W5GSrSmE=; b=0K7zN5eY14LsEsypbOZ/IbCbwO471PUzR2htul4XOdcg3wwOhygSuZBT/tNhqgMn6h Ou7KcThYjkPa5uHpYZZv2UGME4nVFOE2f1CzGleDAN2Rn2kQFrgpUOmcmxpPH1OnaNrT NpjS71qB1zLCqtRf6Amh842QMP18gwVmvRVKfcwgktjJNUfxr6C0gAKA4xG2A9TanNEa RWvi/fSvOIZmJ8G5bxBS494gTsdAIXK+pn67E23vj3mwzZw98+XADRV8WAqEHfcrQ1qt t35FbbKm8xLhZyG/lWP48cQS1xiUSOS5CUxPjExJ7bF0ct0QUZ7bfPMBam2ydUV39AWa YUgg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fPGQGUkn; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-73236-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73236-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id q21-20020a638c55000000b005dc97d88897si6412693pgn.698.2024.02.20.07.25.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 07:25:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73236-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fPGQGUkn; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-73236-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73236-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 7978BB21110 for ; Tue, 20 Feb 2024 15:25:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C8B2576031; Tue, 20 Feb 2024 15:25:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fPGQGUkn" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E609F664CF for ; Tue, 20 Feb 2024 15:25:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708442721; cv=none; b=o8HWq4DT53V6wNBsvdwzka5Qp8EWZ1Bpa/J96nrUFs+yvEgiOZKkA8xOrhfcMseksKurKWDZysWk7nIs4YVZ8NwbG0YbVPTk8BLAugYOzKxYngcWbUdWEppWHMqtlbsBH3ZJBRQ6DRF+jUYozc77IUjdTCV+rwftbPYFhloh3sc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708442721; c=relaxed/simple; bh=H11T1WxBwEldo6EiYSV/RGXHW7Z56nxdIvscgYONvgU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JAodVeZ0RBtbSxvdq/XbZ8wXMFrsbE9MMqoyFWL+AOgwCzUnvpE2RCkXZYrb6EfWzQcXlxblm0uBbaE4dA+bM4YqFZjwnWW/5A5YPa8mVsA0DJU6DnBe8xC2fqAkCnjrcGuY5Zvb4M2IJwZoesgNN54r6uyH3qlc6r2Drg9u7wo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fPGQGUkn; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27541C43394; Tue, 20 Feb 2024 15:25:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708442720; bh=H11T1WxBwEldo6EiYSV/RGXHW7Z56nxdIvscgYONvgU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=fPGQGUknuDIYNssTnCNs+rhm/mn5dHhQ1ZHV7cwngEnwb9pGQj46Ph7fH2oSjquId KHDC+xyG2G7SkwSourvcux1FolPq9ztGfmfouDK0dukzkJesi/cugS4f2qSkYOTEW6 2crkOPCHexSrLV9V4kPE0nAKc4Vjykn0Ug+um7J6JXO3Il4A/IS00BXkcM6/5eWTAV c9OQ18CCXpsi77xGCV+q9elJOC3qywOXQViNXqSdFG5MPlrD1gWv1UadIzmsT3FOy8 5bI/oaeqyG2v7Glp5hOgYwa6CYZpoqflF3HmDZXTGhAwcJ2eteDJwchemOyxTZO+xt 3Qv1E34FOfUYA== Date: Tue, 20 Feb 2024 16:25:17 +0100 From: Frederic Weisbecker To: Anna-Maria Behnsen Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , John Stultz , Thomas Gleixner , Eric Dumazet , "Rafael J . Wysocki" , Arjan van de Ven , "Paul E . McKenney" , Rik van Riel , Steven Rostedt , Sebastian Siewior , Giovanni Gherdovich , Lukasz Luba , "Gautham R . Shenoy" , Srinivas Pandruvada , K Prateek Nayak Subject: Re: [PATCH v10a] timers: Move marking timer bases idle into tick_nohz_stop_tick() Message-ID: References: <20240115143743.27827-4-anna-maria@linutronix.de> <20240219085236.10624-1-anna-maria@linutronix.de> <878r3f5s3w.fsf@somnus> <87zfvv4a45.fsf@somnus> <87ttm344me.fsf@somnus> <87o7cb40sx.fsf@somnus> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <87o7cb40sx.fsf@somnus> On Tue, Feb 20, 2024 at 04:23:26PM +0100, Anna-Maria Behnsen wrote: > Frederic Weisbecker writes: > > > On Tue, Feb 20, 2024 at 03:00:57PM +0100, Anna-Maria Behnsen wrote: > >> Frederic Weisbecker writes: > >> > >> > Le Tue, Feb 20, 2024 at 01:02:18PM +0100, Anna-Maria Behnsen a ?crit : > >> >> Frederic Weisbecker writes: > >> >> > >> >> > Le Tue, Feb 20, 2024 at 11:48:19AM +0100, Anna-Maria Behnsen a ?crit : > >> >> >> Frederic Weisbecker writes: > >> >> >> diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c > >> >> >> index 01fb50c1b17e..b93f0e6f273f 100644 > >> >> >> --- a/kernel/time/tick-sched.c > >> >> >> +++ b/kernel/time/tick-sched.c > >> >> >> @@ -895,21 +895,6 @@ static void tick_nohz_stop_tick(struct tick_sched *ts, int cpu) > >> >> >> /* Make sure we won't be trying to stop it twice in a row. */ > >> >> >> ts->timer_expires_base = 0; > >> >> >> > >> >> >> - /* > >> >> >> - * If this CPU is the one which updates jiffies, then give up > >> >> >> - * the assignment and let it be taken by the CPU which runs > >> >> >> - * the tick timer next, which might be this CPU as well. If we > >> >> >> - * don't drop this here, the jiffies might be stale and > >> >> >> - * do_timer() never gets invoked. Keep track of the fact that it > >> >> >> - * was the one which had the do_timer() duty last. > >> >> >> - */ > >> >> >> - if (cpu == tick_do_timer_cpu) { > >> >> >> - tick_do_timer_cpu = TICK_DO_TIMER_NONE; > >> >> >> - ts->do_timer_last = 1; > >> >> >> - } else if (tick_do_timer_cpu != TICK_DO_TIMER_NONE) { > >> >> >> - ts->do_timer_last = 0; > >> >> >> - } > >> >> >> - > >> >> >> /* Skip reprogram of event if it's not changed */ > >> >> >> if (ts->tick_stopped && (expires == ts->next_tick)) { > >> >> >> /* Sanity check: make sure clockevent is actually programmed */ > >> >> > > >> >> > That should work but then you lose the optimization that resets > >> >> > ts->do_timer_last even if the next timer hasn't changed. > >> >> > > >> >> > >> >> Beside of this optimization thing, I see onther problem. But I'm not > >> >> sure, if I understood it correctly: When the CPU drops the > >> >> tick_do_timer_cpu assignment and stops the tick, it is possible, that > >> >> this CPU nevertheless executes tick_sched_do_timer() and then reassigns > >> >> to tick_do_timer_cpu? > >> > > >> > Yes but in this case a timer interrupt has executed and ts->next_tick > >> > is cleared, so the above skip reprogramm branch is not taken. > >> > > >> > >> Yes... So I need to change it without dropping the > >> optimization. Otherwise someone might complain about it. > >> > >> Two possible solutions: > >> > >> a) split out this if/else thing for dropping the tick_do_timer_cpu > >> assignment into a separate function and call it: > >> - before the return in the skip reprogramm branch > >> - and after the if clause which contains stopping the tick (where it > >> is executed in the current proposal) > >> > >> b) Take my current proposal and add before the return in the skip > >> reprogramm branch the following lines: > >> > >> if (tick_do_timer_cpu != TICK_DO_TIMER_NONE) > >> ts->do_timer_last = 0; > >> > >> as the first part of the tick_do_timer_cpu/last logic shouldn't be > >> required (because then also ts->next_tick is already cleared). > >> > >> What do you prefere? Or do you prefere something else? > > > > Wouldn't the following work? If timer_idle is false, then the tick isn't > > even stopped and there is nothing to do? So you can early return. > > > > diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c > > index fdd57f1af1d7..1b2984acafbd 100644 > > --- a/kernel/time/tick-sched.c > > +++ b/kernel/time/tick-sched.c > > @@ -924,6 +924,9 @@ static void tick_nohz_stop_tick(struct tick_sched *ts, int cpu) > > expires = ts->timer_expires; > > } > > > > + if (!timer_idle) > > + return; > > + > > /* > > * If this CPU is the one which updates jiffies, then give up > > * the assignment and let it be taken by the CPU which runs > > Yes... And then I can drop the if (!timer_idle) thing inside > !ts->tick_stopped branch. > Right!