[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20160824095659.GC16944@arm.com>
Date: Wed, 24 Aug 2016 10:56:59 +0100
From: Will Deacon <will.deacon@....com>
To: Peter Zijlstra <peterz@...radead.org>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>,
Waiman Long <waiman.long@....com>,
Jason Low <jason.low2@....com>,
Ding Tianhong <dingtianhong@...wei.com>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>,
Imre Deak <imre.deak@...el.com>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Davidlohr Bueso <dave@...olabs.net>,
Tim Chen <tim.c.chen@...ux.intel.com>,
Terry Rudd <terry.rudd@....com>,
"Paul E. McKenney" <paulmck@...ibm.com>,
Jason Low <jason.low2@...com>
Subject: Re: [RFC][PATCH 1/3] locking/mutex: Rework mutex::owner
On Tue, Aug 23, 2016 at 02:46:18PM +0200, Peter Zijlstra wrote:
> There's a number of iffy in mutex because mutex::count and
> mutex::owner are two different fields; this too is the reason
> MUTEX_SPIN_ON_OWNER and DEBUG_MUTEX are mutually exclusive.
>
> Cure this by folding them into a single atomic_long_t field.
>
> This nessecairly kills all the architecture specific mutex code.
>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org>
[...]
> void __sched mutex_unlock(struct mutex *lock)
> {
> - /*
> - * The unlocking fastpath is the 0->1 transition from 'locked'
> - * into 'unlocked' state:
> - */
> -#ifndef CONFIG_DEBUG_MUTEXES
> - /*
> - * When debugging is enabled we must not clear the owner before time,
> - * the slow path will always be taken, and that clears the owner field
> - * after verifying that it was indeed current.
> - */
> - mutex_clear_owner(lock);
> + unsigned long owner;
> +
> +#ifdef CONFIG_DEBUG_MUTEXES
> + DEBUG_LOCKS_WARN_ON(__mutex_owner(lock) != current);
> #endif
> - __mutex_fastpath_unlock(&lock->count, __mutex_unlock_slowpath);
> -}
>
> + owner = atomic_long_read(&lock->owner);
> + for (;;) {
> + unsigned long old;
> +
> + old = atomic_long_cmpxchg_release(&lock->owner, owner, owner & 0x03);
> + if (old == owner)
> + break;
> +
> + owner = old;
> + }
Can you rewrite this using atomic_long_fetch_and_release?
Will
Powered by blists - more mailing lists