From a00b3eb58fbcedf29c7426cc1300549d6b72b52c Mon Sep 17 00:00:00 2001 From: Chunwei Chen Date: Tue, 1 Sep 2015 23:28:02 +0800 Subject: [PATCH] rwsem use kernel provided owner when possible If CONFIG_RWSEM_SPIN_ON_OWNER is defined, rw_semaphore will have an owner field, so we don't need our own. Signed-off-by: Chunwei Chen Signed-off-by: Brian Behlendorf Issue #473 --- include/sys/rwlock.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/include/sys/rwlock.h b/include/sys/rwlock.h index 62544f3a81..a3350b138c 100644 --- a/include/sys/rwlock.h +++ b/include/sys/rwlock.h @@ -40,29 +40,47 @@ typedef enum { RW_READER = 2 } krw_t; +/* + * If CONFIG_RWSEM_SPIN_ON_OWNER is defined, rw_semaphore will have an owner + * field, so we don't need our own. + */ typedef struct { struct rw_semaphore rw_rwlock; +#ifndef CONFIG_RWSEM_SPIN_ON_OWNER kthread_t *rw_owner; +#endif } krwlock_t; -#define SEM(rwp) ((struct rw_semaphore *)(rwp)) +#define SEM(rwp) (&(rwp)->rw_rwlock) static inline void spl_rw_set_owner(krwlock_t *rwp) { +/* + * If CONFIG_RWSEM_SPIN_ON_OWNER is defined, down_write, up_write, + * downgrade_write and __init_rwsem will set/clear owner for us. + */ +#ifndef CONFIG_RWSEM_SPIN_ON_OWNER rwp->rw_owner = current; +#endif } static inline void spl_rw_clear_owner(krwlock_t *rwp) { +#ifndef CONFIG_RWSEM_SPIN_ON_OWNER rwp->rw_owner = NULL; +#endif } static inline kthread_t * rw_owner(krwlock_t *rwp) { +#ifdef CONFIG_RWSEM_SPIN_ON_OWNER + return SEM(rwp)->owner; +#else return rwp->rw_owner; +#endif } static inline int @@ -153,6 +171,9 @@ RW_LOCK_HELD(krwlock_t *rwp) }) #if defined(CONFIG_RWSEM_GENERIC_SPINLOCK) +#ifdef CONFIG_RWSEM_SPIN_ON_OWNER +#error spinlock rwsem should not have spin on owner +#endif /* * For the generic implementations of rw-semaphores the following is * true. If your semaphore implementation internally represents the