[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20180515180256.GO12217@hirez.programming.kicks-ass.net>
Date: Tue, 15 May 2018 20:02:56 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Waiman Long <longman@...hat.com>
Cc: Ingo Molnar <mingo@...hat.com>,
Thomas Gleixner <tglx@...utronix.de>,
linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org,
Davidlohr Bueso <dave@...olabs.net>,
"Theodore Y. Ts'o" <tytso@....edu>,
Oleg Nesterov <oleg@...hat.com>,
Amir Goldstein <amir73il@...il.com>, Jan Kara <jack@...e.cz>,
Matthew Wilcox <willy@...radead.org>
Subject: Re: [PATCH v3 1/2] locking/rwsem: Add a new RWSEM_ANONYMOUSLY_OWNED
flag
On Tue, May 15, 2018 at 01:38:03PM -0400, Waiman Long wrote:
> diff --git a/kernel/locking/rwsem-xadd.c b/kernel/locking/rwsem-xadd.c
> index e795908..a27dbb4 100644
> --- a/kernel/locking/rwsem-xadd.c
> +++ b/kernel/locking/rwsem-xadd.c
> @@ -357,11 +357,8 @@ static inline bool rwsem_can_spin_on_owner(struct rw_semaphore *sem)
>
> rcu_read_lock();
> owner = READ_ONCE(sem->owner);
> - if (!rwsem_owner_is_writer(owner)) {
> - /*
> - * Don't spin if the rwsem is readers owned.
> - */
> - ret = !rwsem_owner_is_reader(owner);
> + if (!owner || !is_rwsem_owner_spinnable(owner)) {
> + ret = !owner; /* !owner is spinnable */
> goto done;
> }
>
> @@ -382,8 +379,10 @@ static noinline bool rwsem_spin_on_owner(struct rw_semaphore *sem)
> {
> struct task_struct *owner = READ_ONCE(sem->owner);
>
> - if (!rwsem_owner_is_writer(owner))
> - goto out;
> + if (!owner)
> + return true;
> + else if (!is_rwsem_owner_spinnable(owner))
> + return false;
s/else //
> rcu_read_lock();
> while (sem->owner == owner) {
> @@ -408,12 +407,12 @@ static noinline bool rwsem_spin_on_owner(struct rw_semaphore *sem)
> cpu_relax();
> }
> rcu_read_unlock();
> -out:
> +
> /*
> * If there is a new owner or the owner is not set, we continue
> * spinning.
> */
> - return !rwsem_owner_is_reader(READ_ONCE(sem->owner));
> + return is_rwsem_owner_spinnable(READ_ONCE(sem->owner));
> }
The above two cases have explicit owner tests, this one doesn't.
Now I know it works, but maybe:
return !owner || is_rwsem_owner_spinnable(owner);
is easier to read... dunno.
Powered by blists - more mailing lists