From: Rik van Riel Here is an incremental fix to the add-sem_is_read-write_locked patch in -mm. The reason for this change is that a lock that's held for reading can be negative when there is a writer waiting, as David pointed out to me a while ago. The corresponding change to swaptoken-tuning.patch is in the next mail. Signed-off-by: Rik van Riel Signed-off-by: Andrew Morton --- include/asm-alpha/rwsem.h | 9 ++------- include/asm-i386/rwsem.h | 9 ++------- include/asm-ia64/rwsem.h | 9 ++------- include/asm-ppc/rwsem.h | 9 ++------- include/asm-ppc64/rwsem.h | 7 +------ include/asm-s390/rwsem.h | 9 ++------- include/asm-sh/rwsem.h | 9 ++------- include/asm-sparc64/rwsem.h | 9 ++------- include/asm-x86_64/rwsem.h | 9 ++------- 9 files changed, 17 insertions(+), 62 deletions(-) diff -puN include/asm-alpha/rwsem.h~add-sem_is_read-write_locked-fix include/asm-alpha/rwsem.h --- devel/include/asm-alpha/rwsem.h~add-sem_is_read-write_locked-fix 2005-09-04 12:55:36.000000000 -0700 +++ devel-akpm/include/asm-alpha/rwsem.h 2005-09-04 12:55:36.000000000 -0700 @@ -262,14 +262,9 @@ static inline long rwsem_atomic_update(l #endif } -static inline int sem_is_read_locked(struct rw_semaphore *sem) +static inline int rwsem_is_locked(struct rw_semaphore *sem) { - return (sem->count > 0); -} - -static inline int sem_is_write_locked(struct rw_semaphore *sem) -{ - return (sem->count < 0); + return (sem->count != 0); } #endif /* __KERNEL__ */ diff -puN include/asm-i386/rwsem.h~add-sem_is_read-write_locked-fix include/asm-i386/rwsem.h --- devel/include/asm-i386/rwsem.h~add-sem_is_read-write_locked-fix 2005-09-04 12:55:36.000000000 -0700 +++ devel-akpm/include/asm-i386/rwsem.h 2005-09-04 12:55:36.000000000 -0700 @@ -284,14 +284,9 @@ LOCK_PREFIX "xadd %0,(%2)" return tmp+delta; } -static inline int sem_is_read_locked(struct rw_semaphore *sem) +static inline int rwsem_is_locked(struct rw_semaphore *sem) { - return (sem->count > 0); -} - -static inline int sem_is_write_locked(struct rw_semaphore *sem) -{ - return (sem->count < 0); + return (sem->count != 0); } #endif /* __KERNEL__ */ diff -puN include/asm-ia64/rwsem.h~add-sem_is_read-write_locked-fix include/asm-ia64/rwsem.h --- devel/include/asm-ia64/rwsem.h~add-sem_is_read-write_locked-fix 2005-09-04 12:55:36.000000000 -0700 +++ devel-akpm/include/asm-ia64/rwsem.h 2005-09-04 12:55:36.000000000 -0700 @@ -186,14 +186,9 @@ __downgrade_write (struct rw_semaphore * #define rwsem_atomic_add(delta, sem) atomic64_add(delta, (atomic64_t *)(&(sem)->count)) #define rwsem_atomic_update(delta, sem) atomic64_add_return(delta, (atomic64_t *)(&(sem)->count)) -static inline int sem_is_read_locked(struct rw_semaphore *sem) +static inline int rwsem_is_locked(struct rw_semaphore *sem) { - return (sem->count > 0); -} - -static inline int sem_is_write_locked(struct rw_semaphore *sem) -{ - return (sem->count < 0); + return (sem->count != 0); } #endif /* _ASM_IA64_RWSEM_H */ diff -puN include/asm-ppc64/rwsem.h~add-sem_is_read-write_locked-fix include/asm-ppc64/rwsem.h --- devel/include/asm-ppc64/rwsem.h~add-sem_is_read-write_locked-fix 2005-09-04 12:55:36.000000000 -0700 +++ devel-akpm/include/asm-ppc64/rwsem.h 2005-09-04 12:55:36.000000000 -0700 @@ -165,12 +165,7 @@ static inline int rwsem_atomic_update(in static inline int sem_is_read_locked(struct rw_semaphore *sem) { - return (sem->count > 0); -} - -static inline int sem_is_write_locked(struct rw_semaphore *sem) -{ - return (sem->count < 0); + return (sem->count != 0); } #endif /* __KERNEL__ */ diff -puN include/asm-ppc/rwsem.h~add-sem_is_read-write_locked-fix include/asm-ppc/rwsem.h --- devel/include/asm-ppc/rwsem.h~add-sem_is_read-write_locked-fix 2005-09-04 12:55:36.000000000 -0700 +++ devel-akpm/include/asm-ppc/rwsem.h 2005-09-04 12:55:36.000000000 -0700 @@ -168,14 +168,9 @@ static inline int rwsem_atomic_update(in return atomic_add_return(delta, (atomic_t *)(&sem->count)); } -static inline int sem_is_read_locked(struct rw_semaphore *sem) +static inline int rwsem_is_locked(struct rw_semaphore *sem) { - return (sem->count > 0); -} - -static inline int sem_is_write_locked(struct rw_semaphore *sem) -{ - return (sem->count < 0); + return (sem->count != 0); } #endif /* __KERNEL__ */ diff -puN include/asm-s390/rwsem.h~add-sem_is_read-write_locked-fix include/asm-s390/rwsem.h --- devel/include/asm-s390/rwsem.h~add-sem_is_read-write_locked-fix 2005-09-04 12:55:36.000000000 -0700 +++ devel-akpm/include/asm-s390/rwsem.h 2005-09-04 12:55:36.000000000 -0700 @@ -351,14 +351,9 @@ static inline long rwsem_atomic_update(l return new; } -static inline int sem_is_read_locked(struct rw_semaphore *sem) +static inline int rwsem_is_locked(struct rw_semaphore *sem) { - return (sem->count > 0); -} - -static inline int sem_is_write_locked(struct rw_semaphore *sem) -{ - return (sem->count < 0); + return (sem->count != 0); } #endif /* __KERNEL__ */ diff -puN include/asm-sh/rwsem.h~add-sem_is_read-write_locked-fix include/asm-sh/rwsem.h --- devel/include/asm-sh/rwsem.h~add-sem_is_read-write_locked-fix 2005-09-04 12:55:36.000000000 -0700 +++ devel-akpm/include/asm-sh/rwsem.h 2005-09-04 12:55:36.000000000 -0700 @@ -166,14 +166,9 @@ static inline int rwsem_atomic_update(in return atomic_add_return(delta, (atomic_t *)(&sem->count)); } -static inline int sem_is_read_locked(struct rw_semaphore *sem) +static inline int rwsem_is_locked(struct rw_semaphore *sem) { - return (sem->count > 0); -} - -static inline int sem_is_write_locked(struct rw_semaphore *sem) -{ - return (sem->count < 0); + return (sem->count != 0); } #endif /* __KERNEL__ */ diff -puN include/asm-sparc64/rwsem.h~add-sem_is_read-write_locked-fix include/asm-sparc64/rwsem.h --- devel/include/asm-sparc64/rwsem.h~add-sem_is_read-write_locked-fix 2005-09-04 12:55:36.000000000 -0700 +++ devel-akpm/include/asm-sparc64/rwsem.h 2005-09-04 12:55:36.000000000 -0700 @@ -56,14 +56,9 @@ static inline void rwsem_atomic_add(int atomic_add(delta, (atomic_t *)(&sem->count)); } -static inline int sem_is_read_locked(struct rw_semaphore *sem) +static inline int rwsem_is_locked(struct rw_semaphore *sem) { - return (sem->count > 0); -} - -static inline int sem_is_write_locked(struct rw_semaphore *sem) -{ - return (sem->count < 0); + return (sem->count != 0); } #endif /* __KERNEL__ */ diff -puN include/asm-x86_64/rwsem.h~add-sem_is_read-write_locked-fix include/asm-x86_64/rwsem.h --- devel/include/asm-x86_64/rwsem.h~add-sem_is_read-write_locked-fix 2005-09-04 12:55:36.000000000 -0700 +++ devel-akpm/include/asm-x86_64/rwsem.h 2005-09-04 12:55:36.000000000 -0700 @@ -274,14 +274,9 @@ LOCK_PREFIX "xaddl %0,(%2)" return tmp+delta; } -static inline int sem_is_read_locked(struct rw_semaphore *sem) +static inline int rwsem_is_locked(struct rw_semaphore *sem) { - return (sem->count > 0); -} - -static inline int sem_is_write_locked(struct rw_semaphore *sem) -{ - return (sem->count < 0); + return (sem->count != 0); } #endif /* __KERNEL__ */ _