Re: [PATCH 2/2] mutex: use spin_[un]lock instead ofarch_spin_[un]lock

From: Ingo Molnar
Date: Thu Jan 24 2013 - 05:14:46 EST



* Yuanhan Liu <yuanhan.liu@xxxxxxxxxxxxxxx> wrote:

> On Thu, Jan 24, 2013 at 10:58:07AM +0100, Ingo Molnar wrote:
> >
> > * Yuanhan Liu <yuanhan.liu@xxxxxxxxxxxxxxx> wrote:
> >
> > > Use spin_[un]lock instead of arch_spin_[un]lock in mutex-debug.h so
> > > that we can collect the lock statistics of spin_lock_mutex from
> > > /proc/lock_stat.
> > >
> > > Cc: Ingo Molnar <mingo@xxxxxxxxxx>
> > > Signed-off-by: Yuanhan Liu <yuanhan.liu@xxxxxxxxxxxxxxx>
> > > ---
> > > kernel/mutex-debug.h | 4 ++--
> > > 1 files changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
> > > index 0799fd3..556c0bc 100644
> > > --- a/kernel/mutex-debug.h
> > > +++ b/kernel/mutex-debug.h
> > > @@ -43,13 +43,13 @@ static inline void mutex_clear_owner(struct mutex *lock)
> > > \
> > > DEBUG_LOCKS_WARN_ON(in_interrupt()); \
> > > local_irq_save(flags); \
> > > - arch_spin_lock(&(lock)->rlock.raw_lock);\
> > > + spin_lock(lock); \
> >
> > But in that case it could probably use the spin_lock_irqsave()
> > primitive, right?
>
> Right, in that case I should use spin_lock_irqsave.
>
> But one question, why we use spin_lock at kernel/mutex.h,
> while use 'local_irq_save(); arch_spin_lock' at
> kernel/mutex-debug.h?
>
> Shouldn't we keep it consistent? Say use spin_lock_irqsave?

I think we did it to increase performance with lockdep enabled -
this particular lockdep annotation, given the short codepaths,
is not that hard to verify - and if it breaks it will break a
thousand mutex locking places in the kernel.

So maybe it's better to leave it alone - maybe add a comment
that explains the reason.

Thanks,

Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/