Commit 75ff6457 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar

locking/percpu-rwsem: Extract __percpu_down_read_trylock()

In preparation for removing the embedded rwsem and building a custom
lock, extract the read-trylock primitive.
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
Reviewed-by: default avatarDavidlohr Bueso <dbueso@suse.de>
Acked-by: default avatarWill Deacon <will@kernel.org>
Acked-by: default avatarWaiman Long <longman@redhat.com>
Tested-by: default avatarJuri Lelli <juri.lelli@redhat.com>
Link: https://lkml.kernel.org/r/20200131151540.098485539@infradead.org
parent 71365d40
...@@ -45,7 +45,7 @@ void percpu_free_rwsem(struct percpu_rw_semaphore *sem) ...@@ -45,7 +45,7 @@ void percpu_free_rwsem(struct percpu_rw_semaphore *sem)
} }
EXPORT_SYMBOL_GPL(percpu_free_rwsem); EXPORT_SYMBOL_GPL(percpu_free_rwsem);
bool __percpu_down_read(struct percpu_rw_semaphore *sem, bool try) static bool __percpu_down_read_trylock(struct percpu_rw_semaphore *sem)
{ {
__this_cpu_inc(*sem->read_count); __this_cpu_inc(*sem->read_count);
...@@ -73,11 +73,18 @@ bool __percpu_down_read(struct percpu_rw_semaphore *sem, bool try) ...@@ -73,11 +73,18 @@ bool __percpu_down_read(struct percpu_rw_semaphore *sem, bool try)
if (likely(!smp_load_acquire(&sem->readers_block))) if (likely(!smp_load_acquire(&sem->readers_block)))
return true; return true;
/* __this_cpu_dec(*sem->read_count);
* Per the above comment; we still have preemption disabled and
* will thus decrement on the same CPU as we incremented. /* Prod writer to re-evaluate readers_active_check() */
*/ rcuwait_wake_up(&sem->writer);
__percpu_up_read(sem);
return false;
}
bool __percpu_down_read(struct percpu_rw_semaphore *sem, bool try)
{
if (__percpu_down_read_trylock(sem))
return true;
if (try) if (try)
return false; return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment