From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 D72932EC09F; Thu, 28 May 2026 14:31:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779978677; cv=none; b=TdHmqHqCsp0soj77mvLZXKGCVz48vfS104dm+34loOQH//RMNKbdhY06oTtrpm64ETv1dklaYeiqunRklao+3XJ11h5Axz500JHX0j81t7gpGgx7VNaIbFZL3xi2ZMWfitEE/nX4XpKouZnTGTSyMIAZPDromPo0Gg2+lcm2pe0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779978677; c=relaxed/simple; bh=HyG3NhA74udUzGo9m8hVndsOjCW8hLVkkXqs8g+WHWw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ssZqTL679Q45quJDtIlbHTk1Wa8LRtk2ce2ACYIyVa+I5cJx6ilAMlbQgxE3g2k4Yd5GRITxfHzE12BTC6TKJhe0hTQdH0cAG6TvkX57guqIkK4fyzsVca0nf9ooeZoO6ptCkR/GLWmNgJfpQ9QtIr0U6C/nsWUXSQJ+CLe/KRU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oin1mPok; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oin1mPok" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A85491F00A3C; Thu, 28 May 2026 14:31:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779978675; bh=1DVdNYWfBcGfeuR0GBfeFu8IJ/Pnixr7g+Fqa3nO+H0=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=oin1mPok6UGYJl/Etw15mrDHA3DQp8pKz3i7jzWvx3AfkQT8Zw5/N8ZyaSjRfPP25 Sw4zgD3K+/tFZQI1gDr4+JQwOFufGd7mTmoM4vbiLF0y+vry8FuM8j1mMJdfdOM/1M Si6a6WlKSfSp7Tqq0T7Dow5ku1Bs6PYHQFpXCAzowhJ29xp0G6FgoG1fn8RK/p/VYa 2qCfXQUN710eTVbmcveoo3/dLt9lQyF5tqNPmjX9+N8fCW5IL9k+O2Axe4aPBar1SR q5b16m8D4iaUFA5V4ORaTp8n1yGAJi/BbpWK8DCwN7ocj90RECiZOCrJ/HZJPTS2gf Qpt32kDD8pr/g== Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfauth.phl.internal (Postfix) with ESMTP id DF885F40070; Thu, 28 May 2026 10:31:12 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Thu, 28 May 2026 10:31:12 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTGmOu92/emQ6/8NtZxrb8FuF/kXoQFx4FVQajYdCwtwrfJNzuKxPiWQpBvD6lzT7m u5kMCl+R3sw5frRhPe4eyROj7Ohh/pSoh5xUNqsY8aaPmxoqiDL1FvoZKkvizys5jRD7P1 YVFb7crsifvSyqsMmsbNzMiL3QulZpbP+zTU9yBNghgl4U89nlXECmGRd2skBS10v3HBI6 zoZTZ6Cj8CZJ8dP6EH8kjdUFN++7KJlzHgvyw3XD8g/LivVXd66XX27qMANKiUMOWBKqlz k/6WBw5B7NC5SMyAxv3fmFVerHhVO8RbL7VasgSoEzxAOYOkLaY1zXQt5E41VyuVGgPGS/ U9k4HG09llWC3TKqt0uX+iNNHZqi6eYXlwY08ew1wkHPB26PjjtUaiGNZxhvXYUIO+ISfL nXWnb+o7TmHyKz4QTOdNYxfye7/gMXfBtXwa54u5chLEBCuk7QtnZOblv0XXuTuEB438i8 93IFRdj0buZ1EQYXRj68KCw90y9Q3VwtcOuiUEwt2gU/aEghKVnFpzaYWTHscOwOq9X987 b0+KPVCpmCD6bstECL3QZrhomIXetmSaSy8sBWCllnh7c8lU/26XcziHKDSBgbFkndVOHH qk0DrWzdsrEc7qU9hVqkUE+Jb53cnhpqm+P5V0TpVJnit+UUigQLQiz9hnzA X-ME-Proxy: Feedback-ID: i8dbe485b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 28 May 2026 10:31:11 -0400 (EDT) Date: Thu, 28 May 2026 07:31:10 -0700 From: Boqun Feng To: Peter Zijlstra Cc: Catalin Marinas , Will Deacon , Jonas Bonn , Stefan Kristiansson , Stafford Horne , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Arnd Bergmann , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , Waiman Long , Andrew Morton , Andrii Nakryiko , Eduard Zingerman , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Kumar Kartikeya Dwivedi , Song Liu , Yonghong Song , Jiri Olsa , Shuah Khan , Miguel Ojeda , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Jinjie Ruan , Lyude Paul , Thomas Huth , Sohil Mehta , "Xin Li (Intel)" , Pawan Gupta , Nikunj A Dadhania , Joel Fernandes , Andy Shevchenko , Randy Dunlap , Yury Norov , Sebastian Andrzej Siewior , linux-kernel@vger.kernel.org, linux-openrisc@vger.kernel.org, linux-s390@vger.kernel.org, linux-arch@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, rust-for-linux@vger.kernel.org, Onur =?iso-8859-1?Q?=D6zkan?= , Daniel Almeida , Boqun Feng Subject: Re: [PATCH v2 05/12] irq & spin_lock: Add counted interrupt disabling/enabling Message-ID: References: <20260526152148.30514-1-boqun@kernel.org> <20260526152148.30514-6-boqun@kernel.org> <20260528104322.GF343181@noisy.programming.kicks-ass.net> 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: <20260528104322.GF343181@noisy.programming.kicks-ass.net> On Thu, May 28, 2026 at 12:43:22PM +0200, Peter Zijlstra wrote: > On Tue, May 26, 2026 at 08:21:41AM -0700, Boqun Feng wrote: > > > diff --git a/include/linux/preempt.h b/include/linux/preempt.h > > index e2d3079d3f5f..33fc4c814a9f 100644 > > --- a/include/linux/preempt.h > > +++ b/include/linux/preempt.h > > @@ -151,6 +151,10 @@ static __always_inline unsigned char interrupt_context_level(void) > > #define in_softirq() (softirq_count()) > > #define in_interrupt() (irq_count()) > > > > +#define hardirq_disable_count() ((preempt_count() & HARDIRQ_DISABLE_MASK) >> HARDIRQ_DISABLE_SHIFT) > > +#define hardirq_disable_enter() __preempt_count_add_return(HARDIRQ_DISABLE_OFFSET) > > +#define hardirq_disable_exit() __preempt_count_sub_return(HARDIRQ_DISABLE_OFFSET) > > + > > /* > > * The preempt_count offset after preempt_disable(); > > */ > > > diff --git a/include/linux/interrupt_rc.h b/include/linux/interrupt_rc.h > > new file mode 100644 > > index 000000000000..868f32524a87 > > --- /dev/null > > +++ b/include/linux/interrupt_rc.h > > @@ -0,0 +1,65 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +/* > > + * include/linux/interrupt_rc.h - refcounted local processor interrupt > > + * management. > > + * > > + * Since the implementation of this API currently depends on > > + * local_irq_save()/local_irq_restore(), we split this into it's own header to > > + * make it easier to include without hitting circular header dependencies. > > + */ > > + > > +#ifndef __LINUX_INTERRUPT_RC_H > > +#define __LINUX_INTERRUPT_RC_H > > + > > +#include > > +#include > > +#ifdef CONFIG_SMP > > +#include > > +#endif > > + > > +/* Per-cpu interrupt disabling state for local_interrupt_{disable,enable}() */ > > +struct interrupt_disable_state { > > + unsigned long flags; > > +}; > > + > > +DECLARE_PER_CPU(struct interrupt_disable_state, local_interrupt_disable_state); > > + > > +static inline void local_interrupt_disable(void) > > +{ > > + unsigned long flags; > > + int new_count; > > + > > + new_count = hardirq_disable_enter(); > > + > > + /* Interrupts can happen here, but it's OK, see __irq_exit_rcu(). */ > > + > > + if ((new_count & HARDIRQ_DISABLE_MASK) == HARDIRQ_DISABLE_OFFSET) { > > + local_irq_save(flags); > > + raw_cpu_write(local_interrupt_disable_state.flags, flags); > > + } > > +} > > + > > +static inline void local_interrupt_enable(void) > > +{ > > + int new_count; > > + > > + new_count = hardirq_disable_exit(); > > + > > + if ((new_count & HARDIRQ_DISABLE_MASK) == 0) { > > + unsigned long flags; > > + > > + flags = raw_cpu_read(local_interrupt_disable_state.flags); > > + local_irq_restore(flags); > > + /* > > + * TODO: re-read preempt count can be avoided, but it needs > > + * should_resched() taking another parameter as the current > > + * preempt count > > + */ > > +#ifdef CONFIG_PREEMPTION > > + if (should_resched(0)) > > + __preempt_schedule(); > > I'm not sure why you bother with should_resched() at this point, can't > you simply write: > > if (!new_count) > __preempt_schedule(); > I was trying to not re-invent the wheel for "checking whether we can preempt" (because the definition of preempt condition might be changed in the future?), but yes I think directly using new_count should be fine here. Although I think I need to check tif_need_resched() for other architectures? Regards, Boqun > > +#endif > > + } > > +} > > + > > +#endif /* !__LINUX_INTERRUPT_RC_H */