Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp740652lqt; Tue, 19 Mar 2024 02:18:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVfbDPOly5K3WDDk3DFpOGwCXuTmEEFcwtUEO96bMYTIhc1clCbxi+086er8OcdMWmQYTZltTFIec8aSF6ug9/EE9O4WOb/2jBYA2jTUQ== X-Google-Smtp-Source: AGHT+IGde2q5qHToGC+YZ2Famh+Hpns5I4TXSy7xG5AvcHlAxm6ST7784xVutUe8wOvF9S5ZTg/8 X-Received: by 2002:a17:902:7d92:b0:1dc:3e49:677d with SMTP id a18-20020a1709027d9200b001dc3e49677dmr2047791plm.26.1710839895400; Tue, 19 Mar 2024 02:18:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710839895; cv=pass; d=google.com; s=arc-20160816; b=B0p6Wb1mCqok1QIeuIS7Q6x23ekLIhHL5UcrKi0kV+ndOXwshv9H1SVIgBV0WeAqDU ke//zf6hZT8YSxq9rJD3Hm+B0gufiv3YndZHSoT99QH85Sr3h+/auGFmUJV1vqP5m3BP hs3y4rR0owO+wSztDlbikEo+Cgrr0d6ozVMnt4qDB4N+EUeFCgdIr2hFayiOHhv86gNH GM9vAvNbQfX6WegrWi8ZM3pRPdidE7tePrCi934s1FFB0GVRJj+Aw3oMY8vLrqWTo2qg eOrku/umbj3aFj0qihToQp46yP3FPTKwR0B72+6rzpkVUIT1QaMVNIRbsU2my1fY3a+0 J0Ag== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=wjqlp0xJv9NOBN4udAjUJLPJIpB4vrrXEIpwnbVSvcw=; fh=Vzoq0nVshxERZBL4pLZ68yhgpR1mmqRekZaurNon2Tg=; b=xi2Y5dtZ6f/TeoOkY0f7AXHpSMaX7dKK2jMetXuaLVk23tnE7tH1Jb1Ir1+z7vuVlg aQwM6sQ1TjfQqq9iS0iEyBmJXLP6exY3kr9eQ4FNPDBtPfr2Z1qFU07wUt46YQXmnHPv npN9wZ/NVgSVqhyOMCFvG+Czh5h+1YGt9eHN5evanD+/X26GdHXxtoJeRg3xuWsBSidN czwEY1oykyA91SZm4gLB+SbgJFi9YlmzAbataVMl62jsZbmzJRkTAgt/DT6zSjTD6Pbu f3fDXLmo3V001SlRKWGwg1nkibbyP8py+dQMLNc5BfV9YHRWeKMBHgMosJRahnE/kUy0 3+VQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Tr4nihV4; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-107292-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107292-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. [139.178.88.99]) by mx.google.com with ESMTPS id i18-20020a170902c95200b001e003f31d70si5787747pla.574.2024.03.19.02.18.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 02:18:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-107292-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Tr4nihV4; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-107292-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107292-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 AF8672824E4 for ; Tue, 19 Mar 2024 09:18:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 58ECD7C6CC; Tue, 19 Mar 2024 09:18:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Tr4nihV4" 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 8085A65190 for ; Tue, 19 Mar 2024 09:18:04 +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=1710839884; cv=none; b=gmjh1xd9DNNLFntTq7w0FqlRFFOXme8cZzbA+UAMc4tx4iNjXpAn0tSMRIT/ZY4ZanqVdBFj6Uv8Yr+l2YIRnQ6W/fAcnT+iL2fcR+bmugqfzUN7wR5kFi4PkGVn+VJQYk7x519TLVi248PphtgtUlO2RfIARuiVE1HHf8X4pu4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710839884; c=relaxed/simple; bh=ADlsmypvlr4K5Ss+djFQKD0ML+Ud9B5+9VJcMzQaWZM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sVFJagiSN90fNDJoxG0qSG7LbHT16x7u6Aa8KfBOxiQPIQyUKcMjP/mPORxkSa4++skW8iqAdnpvEdKwPqLmkyDjlnTChZsO2GZqgR2aBUfxzK8QKOqZfgZmanPJOTJebDKo/WWGC/kGNc1rd42a41/ppRA503Ue7B9BO6aitLI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Tr4nihV4; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A40AAC433C7; Tue, 19 Mar 2024 09:18:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710839884; bh=ADlsmypvlr4K5Ss+djFQKD0ML+Ud9B5+9VJcMzQaWZM=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=Tr4nihV4V8tirh0D7kC8aEprkQb2FJloB50BEVD1bCx1/RzA2nnZHq/gZoVzQdvYP +WzqoiA07ObLVHAiag4h45DlRu/KQme4WtYBPXpJO4HLbK1iRyUrbpYFY7yVr+W5Hq zKwWnpueNELxCphTUO/t2j/OcDwroe67zB0hl8hmyM2IUuQPXVbefhZgLx9fXZo/+6 xcLifj+/KrFYNX1gdGLglM9X/1HwWPJAqLh7BqDgPQxKCaFoittyofr8NpEGnu1xh5 V7PjaDJIDexJ43vO2uReI/CJjWI3BYSpSIDA6HB+WwGFS1upp4KSH+6VVJCt38w+Tu thYMPnYq5Bxyw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id E4D09CE0D20; Tue, 19 Mar 2024 02:18:00 -0700 (PDT) Date: Tue, 19 Mar 2024 02:18:00 -0700 From: "Paul E. McKenney" To: Frederic Weisbecker Cc: Thomas Gleixner , LKML , Ingo Molnar , Anna-Maria Behnsen Subject: Re: [PATCH 2/2] timers: Fix removed self-IPI on global timer's enqueue in nohz_full Message-ID: <464f6be2-4a72-440d-be53-6a1035d56a4f@paulmck-laptop> Reply-To: paulmck@kernel.org References: <20240318230729.15497-1-frederic@kernel.org> <20240318230729.15497-3-frederic@kernel.org> 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=us-ascii Content-Disposition: inline In-Reply-To: <20240318230729.15497-3-frederic@kernel.org> On Tue, Mar 19, 2024 at 12:07:29AM +0100, Frederic Weisbecker wrote: > While running in nohz_full mode, a task may enqueue a timer while the > tick is stopped. However the only places where the timer wheel, > alongside the timer migration machinery's decision, may reprogram the > next event accordingly with that new timer's expiry are the idle loop or > any IRQ tail. > > However neither the idle task nor an interrupt may run on the CPU if it > resumes busy work in userspace for a long while in full dynticks mode. > > To solve this, the timer enqueue path raises a self-IPI that will > re-evaluate the timer wheel on its IRQ tail. This asynchronous solution > avoids potential locking inversion. > > This is supposed to happen both for local and global timers but commit: > > b2cf7507e186 ("timers: Always queue timers on the local CPU") > > broke the global timers case with removing the ->is_idle field handling > for the global base. As a result, global timers enqueue may go unnoticed > in nohz_full. > > Fix this with restoring the idle tracking of the global timer's base, > allowing self-IPIs again on enqueue time. Testing with the previous patch (1/2 in this series) reduced the number of problems by about an order of magnitude, down to two sched_tick_remote() instances and one enqueue_hrtimer() instance, very good! I have kicked off a test including this patch. Here is hoping! ;-) Thanx, Paul > Reported-by: Paul E. McKenney > Fixes: b2cf7507e186 ("timers: Always queue timers on the local CPU") > Signed-off-by: Frederic Weisbecker > --- > kernel/time/timer.c | 12 +++++++++++- > 1 file changed, 11 insertions(+), 1 deletion(-) > > diff --git a/kernel/time/timer.c b/kernel/time/timer.c > index e69e75d3858c..dee29f1f5b75 100644 > --- a/kernel/time/timer.c > +++ b/kernel/time/timer.c > @@ -642,7 +642,8 @@ trigger_dyntick_cpu(struct timer_base *base, struct timer_list *timer) > * the base lock: > */ > if (base->is_idle) { > - WARN_ON_ONCE(!(timer->flags & TIMER_PINNED)); > + WARN_ON_ONCE(!(timer->flags & TIMER_PINNED || > + tick_nohz_full_cpu(base->cpu))); > wake_up_nohz_cpu(base->cpu); > } > } > @@ -2292,6 +2293,13 @@ static inline u64 __get_next_timer_interrupt(unsigned long basej, u64 basem, > */ > if (!base_local->is_idle && time_after(nextevt, basej + 1)) { > base_local->is_idle = true; > + /* > + * Global timers queued locally while running in a task > + * in nohz_full mode need a self-IPI to kick reprogramming > + * in IRQ tail. > + */ > + if (tick_nohz_full_cpu(base_local->cpu)) > + base_global->is_idle = true; > trace_timer_base_idle(true, base_local->cpu); > } > *idle = base_local->is_idle; > @@ -2364,6 +2372,8 @@ void timer_clear_idle(void) > * path. Required for BASE_LOCAL only. > */ > __this_cpu_write(timer_bases[BASE_LOCAL].is_idle, false); > + if (tick_nohz_full_cpu(smp_processor_id())) > + __this_cpu_write(timer_bases[BASE_GLOBAL].is_idle, false); > trace_timer_base_idle(false, smp_processor_id()); > > /* Activate without holding the timer_base->lock */ > -- > 2.44.0 >