[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87a5eu7gvw.ffs@tglx>
Date: Wed, 23 Oct 2024 21:34:27 +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>, Boqun Feng
<boqun.feng@...il.com>
Subject: Re: [POC 1/6] irq & spin_lock: Add counted interrupt
disabling/enabling
On Thu, Oct 17 2024 at 22:51, Boqun Feng wrote:
> Currently the nested interrupt disabling and enabling is present by
> Also add the corresponding spin_lock primitives: spin_lock_irq_disable()
> and spin_unlock_irq_enable(), as a result, code as follow:
>
> spin_lock_irq_disable(l1);
> spin_lock_irq_disable(l2);
> spin_unlock_irq_enable(l1);
> // Interrupts are still disabled.
> spin_unlock_irq_enable(l2);
>
> doesn't have the issue that interrupts are accidentally enabled.
>
> This also makes the wrapper of interrupt-disabling locks on Rust easier
> to design.
Clever!
> +DECLARE_PER_CPU(struct interrupt_disable_state, local_interrupt_disable_state);
> +
> +static inline void local_interrupt_disable(void)
> +{
> + unsigned long flags;
> + long new_count;
> +
> + local_irq_save(flags);
> +
> + new_count = raw_cpu_inc_return(local_interrupt_disable_state.count);
Ideally you make that part of the preemption count. Bit 24-30 are free
(or we can move them around as needed). That's deep enough and you get
the debug sanity checking of the preemption counter for free (might need
some extra debug for this...)
So then this becomes:
local_interrupt_disable()
{
cnt = preempt_count_add_return(LOCALIRQ_OFFSET);
if ((cnt & LOCALIRQ_MASK) == LOCALIRQ_OFFSET) {
local_irq_save(flags);
this_cpu_write(..., flags);
}
}
and
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);
}
}
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
preemption counter. Hmm?
Thanks,
tglx
Powered by blists - more mailing lists