Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1698383rdb; Tue, 20 Feb 2024 04:34:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXHa1/I3hifz2DdQSIhiLy0UQc9Yha+s3CWjP3P7dExRPjg0EPwGsZI0sGaQFlLQxf6Bes/MkMb/xFyro38fiY1heNkTZoDL6IQw+36xQ== X-Google-Smtp-Source: AGHT+IHSxIZrf9V0X7BXvRPVDaTXNGHLkWSna0cg6NMmpnokLyFdhlxR7P2Ju67EaBw8Ib5Lviuy X-Received: by 2002:a05:6358:c85:b0:17b:c6f:fde6 with SMTP id o5-20020a0563580c8500b0017b0c6ffde6mr20532916rwj.22.1708432488290; Tue, 20 Feb 2024 04:34:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708432488; cv=pass; d=google.com; s=arc-20160816; b=WJQTAoUxy08e9enc+B6xiE+3VAcmAy07qtgbNgIdeG5hS4ByRlFj9RPp6CvuUM++1A /JJC8F+LV2jn7gKxuZMvwlJMJr5gnseZcYeAGVupOqOxlkyjlyFEmdHrLDNKrcLEyTPD Bzy+Qw4BKzVhLqSqmpeDBDaOu6N2SBG0VmHMGVNySN5QYNhwtUx1ebGLgLSV/gu6/7ep 7CJLONNdy/RpIfO9eBRRYkT/NJx1eejOcZ8HPJEM+H5kHDS6xupzf4K+E+ui9grWZDdu y+jbOjR0qG3nGZM0jz/6DFgVM9iWrceCAt5w6NFY0tq+lkAIXHQWlVoNcAKM9x92dmKy 0viQ== 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=QuPnLtsliOmgYs7OTOM1v+DF/W/71SFe08dx7JbqLtU=; fh=rlwn4pxNjzZxzAe0OFpEm5XldgGOhioyoE/W5GSrSmE=; b=Zl0R5qaZ3CICXV1msUoGCzsnh+RAmboMzaGl3dSY+0cjOhl1NrqL3XeRsjHMNVtfV5 xe9MPYunESHT8dn1zQ7h6CD2R2TdmvpdiiccrB/fGnxYlN6GNDQdx0IzAthX24AOQlxI ltudb0DNdJ8xzz6VESw0Tl4pLIN69pv3YWd2cn0VG0eXzZChdumkuofAhjvQ8Hg9zL+/ hN1JAV51pPtabwj5BJ7Uwh3VoOEnxFHEO+g3mIwvu3+rezAZWaWRKJ2cooyS7ziKHuch s7T2d4Cj1Bgde9jNg5l9Vxvt3mPur8o4ewUPWR9K7fGoQpo/HCttCr2na50hu6GX6V1z bRxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IKZ9TzAN; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-73027-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73027-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u26-20020a63b55a000000b005cecd95b6besi6132660pgo.685.2024.02.20.04.34.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 04:34:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73027-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IKZ9TzAN; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-73027-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73027-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id F0C1B2843F4 for ; Tue, 20 Feb 2024 12:34:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A372A67A18; Tue, 20 Feb 2024 12:34:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IKZ9TzAN" 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 D1D265674E for ; Tue, 20 Feb 2024 12:34:41 +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=1708432481; cv=none; b=b2jUOeXj88jWQyedScwv8vwO5nrcO/vIkvDuLyP8TaUn4S2nr+B/BZkr04kE0TlTU3vk/UPQKQXaw0XyJsFBq4HMiN+5fBZAv6emSa2OhVVDKgOr3d5J9RxfuqWDRBg7dqvoL/kBLsMjX0/iQeZTVcZaUz4p05+i17k0vlWiJsI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708432481; c=relaxed/simple; bh=V3/ia4j/mhNRtymZZcoOw8DBsoVzTWm+h8zRwMjxjJI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hFv79Sjb4rhxk1sugiBIn1C4LMzsrddfdxLJ+HjUr9d4yp0DBYLzjVNuu2W9J5E3ldJ7/hMKTxCNQX6tj/f3SylFUpcF9Oe+VfY/fc8oYEIYh4iVSatquwm3ewvD9UxnSWdO+80J4o+AwvJWvXv76NtGftKEIgcFppdOaJ3fd2I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IKZ9TzAN; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC2CCC433F1; Tue, 20 Feb 2024 12:34:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708432481; bh=V3/ia4j/mhNRtymZZcoOw8DBsoVzTWm+h8zRwMjxjJI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=IKZ9TzANIUGmXo7dVfk5ZEhg6fAvJSblMOjOL+ym3D9hrlUvcIiUuyw0Wpe08GpPJ 7PlZyACIFntFwpZYcZwkO+bJ/CQy65mq6YU30OT/H0SCRmUZALdyaIdXWXlGiggTOU 1zyQAndHgOA8A7GJjqH4/TxIWbTet+wuIx2CKqsWE22aKr5PzCrI7EqhvwbEvxoksV mthiJcF7CDHRwEh5R1OV8si2T+P09LdPrgGV/jB9fM94HBNKGnyzcSiVrSNNORwoWP 5CaPLSrY1EVAkXUFVVdWMNNCA87SNheB5EJ4ef3BJ2qrWC6wJKrMHoq3OHNsNzWVVr KI4R1H65BmKHg== Date: Tue, 20 Feb 2024 13:34:38 +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> 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: <87zfvv4a45.fsf@somnus> 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. Thanks. > > Then it is mandatory that we have this drop the assignment also in the > path when the tick is already stopped. Otherwise the problem described > in the comment could happen with stale jiffies, no? > > Thanks > > > Thanks. > > > > > > > >> @@ -938,6 +923,21 @@ static void tick_nohz_stop_tick(struct tick_sched *ts, int cpu) > >> trace_tick_stop(1, TICK_DEP_MASK_NONE); > >> } > >> > >> + /* > >> + * 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; > >> + } > >> + > >> ts->next_tick = expires; > >> > >> /*