[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87zfmt6hk2.ffs@tglx>
Date: Thu, 24 Oct 2024 10:17:33 +0200
From: Thomas Gleixner <tglx@...utronix.de>
To: Boqun Feng <boqun.feng@...il.com>
Cc: Dirk Behme <dirk.behme@...il.com>, Lyude Paul <lyude@...hat.com>,
rust-for-linux@...r.kernel.org, Danilo Krummrich <dakr@...hat.com>,
airlied@...hat.com, Ingo Molnar <mingo@...hat.com>, will@...nel.org,
Waiman Long <longman@...hat.com>, Peter Zijlstra <peterz@...radead.org>,
linux-kernel@...r.kernel.org, Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor
<alex.gaynor@...il.com>, wedsonaf@...il.com, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>, Benno Lossin
<benno.lossin@...ton.me>, Andreas Hindborg <a.hindborg@...sung.com>,
aliceryhl@...gle.com, Trevor Gross <tmgross@...ch.edu>
Subject: Re: [POC 1/6] irq & spin_lock: Add counted interrupt
disabling/enabling
On Wed, Oct 23 2024 at 22:05, Boqun Feng wrote:
> On Wed, Oct 23, 2024 at 09:34:27PM +0200, Thomas Gleixner wrote:
>> local_interrupt_enable()
>> {
>> if ((preempt_count() & LOCALIRQ_MASK) == LOCALIRQ_OFFSET) {
>> local_irq_restore(this_cpu_read(...flags);
>> preempt_count_sub_test_resched(LOCALIRQ_OFFSET);
>> } else {
>> // Does not need a resched test because it's not going
>> // to 0
>> preempt_count_sub(LOCALIRQ_OFFSET);
>> }
>> }
>>
>
> Yes, this looks nice, one tiny problem is that it requires
> PREEMPT_COUNT=y ;-) Maybe we can do: if PREEMPT_COUNT=y, we use preempt
> count, otherwise use a percpu?
>
> Hmm... but this will essentially be: we have a irq_disable_count() which
> is always built-in, and we also uses it as preempt count if
> PREEMPT_COUNT=y. This doesn't look too bad to me.
The preempt counter is always there even when PREEMPT_COUNT=n. It's
required for tracking hard/soft interrupt and NMI context.
The only difference is that preempt_disable()/enable() are NOOPs. So in
that case preempt_count_sub_test_resched() becomes a plain preempt_count_sub().
>> and then the lock thing becomes
>>
>> spin_lock_irq_disable()
>> {
>> local_interrupt_disable();
>> lock();
>> }
>>
>> spin_unlock_irq_enable()
>> {
>> unlock();
>> local_interrupt_enable();
>> }
>>
>> instead having to do:
>>
>> spin_unlock_irq_enable()
>> {
>> unlock();
>> local_interrupt_enable();
>> preempt_enable();
>> }
>>
>> Which needs two distinct checks, one for the interrupt and one for the
>
> No? Because now since we fold the interrupt disable count into preempt
> count, so we don't need to care about preempt count any more if we we
> local_interrupt_{disable,enable}(). For example, in the above
> local_interrupt_enable(), interrupts are checked at local_irq_restore()
> and preemption is checked at preempt_count_sub_test_resched(). Right?
Correct. That's what I pointed out. By folding it into preempt count
this becomes one operation, while in your POC it's two distinct checks
and operations.
Thanks,
tglx
Powered by blists - more mailing lists