[PATCH v3 05/20] arm64: entry: move preempt logic to C

Mark Rutland mark.rutland at arm.com
Fri Jun 4 09:54:00 PDT 2021


On Fri, Jun 04, 2021 at 04:43:10PM +0100, Will Deacon wrote:
> On Tue, May 25, 2021 at 07:32:47PM +0100, Mark Rutland wrote:
> > Currently portions of our preempt logic are written in C while other
> > parts are written in assembly. There's no reason any of this needs to
> > live in assembly, so let's move the rest of the lgoic to C. At the same
> > time, let's make the comment a bit clearer.
> > 
> > Other than the increased lockdep coverage there should be no functional
> > change as a result of this patch.
> > 
> > Signed-off-by: Mark Rutland <mark.rutland at arm.com>
> > Reviewed-by: Joey Gouly <joey.gouly at arm.com>
> > Cc: Catalin Marinas <catalin.marinas at arm.com>
> > Cc: James Morse <james.morse at arm.com>
> > Cc: Marc Zyngier <maz at kernel.org>
> > Cc: Will Deacon <will at kernel.org>
> > ---
> >  arch/arm64/kernel/entry-common.c | 12 ++++++++++++
> >  arch/arm64/kernel/entry.S        | 13 -------------
> >  2 files changed, 12 insertions(+), 13 deletions(-)
> > 
> > diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c
> > index 1fe60578e556..dbe0bb09fe86 100644
> > --- a/arch/arm64/kernel/entry-common.c
> > +++ b/arch/arm64/kernel/entry-common.c
> > @@ -121,6 +121,18 @@ asmlinkage void __sched arm64_preempt_schedule_irq(void)
> >  {
> >  	lockdep_assert_irqs_disabled();
> >  
> > +	if (preempt_count() != 0)
> > +		return;
> 
> Careful, I don't think this is quite the same: preempt_count() just looks at
> the 32-bit count portion of the preempt-structure,

I thought I had carefully checked that, since it actually reads the u64
field in the union, but I missed that it got truncated to int.

Placement aside, when I do add this, I'll make that:

| READ_ONCE(current_thread_info()->preempt_count)

> whereas the old code only
> bothers calling into the scheduler if we actually need to reschedule:
> 
> > diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
> > index 656f3129bfef..8c7ddd651756 100644
> > --- a/arch/arm64/kernel/entry.S
> > +++ b/arch/arm64/kernel/entry.S
> > @@ -561,20 +561,7 @@ tsk	.req	x28		// current thread_info
> >  	irq_handler	\handler
> >  
> >  #ifdef CONFIG_PREEMPTION
> > -	ldr	x24, [tsk, #TSK_TI_PREEMPT]	// get preempt count
> 
> It would be nice if we could keep this check on the fast path.

Sure; I can leave this here for now.

I'll fold it into el1_interrupt() when this path is converted to C later
in the series.

Thanks,
Mark.



More information about the linux-arm-kernel mailing list