Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754589Ab3IXXW4 (ORCPT ); Tue, 24 Sep 2013 19:22:56 -0400 Received: from mail-bk0-f46.google.com ([209.85.214.46]:39061 "EHLO mail-bk0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753920Ab3IXXWz (ORCPT ); Tue, 24 Sep 2013 19:22:55 -0400 MIME-Version: 1.0 In-Reply-To: <1380061346.3467.50.camel@schen9-DESK> References: <1380061346.3467.50.camel@schen9-DESK> Date: Tue, 24 Sep 2013 16:22:53 -0700 X-Google-Sender-Auth: 6FNuC_0HJ5F7EBx-THjHHy8NSO8 Message-ID: Subject: Re: [PATCH v5 1/6] rwsem: check the lock before cpmxchg in down_write_trylock From: Jason Low To: Tim Chen Cc: Ingo Molnar , Andrew Morton , Andrea Arcangeli , Alex Shi , Andi Kleen , Michel Lespinasse , Davidlohr Bueso , Matthew R Wilcox , Dave Hansen , Peter Zijlstra , Rik van Riel , Peter Hurley , linux-kernel@vger.kernel.org, linux-mm Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2468 Lines: 73 Should we do something similar with __down_read_trylock, such as the following? Signed-off-by: Jason Low --- include/asm-generic/rwsem.h | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/include/asm-generic/rwsem.h b/include/asm-generic/rwsem.h index bb1e2cd..47990dc 100644 --- a/include/asm-generic/rwsem.h +++ b/include/asm-generic/rwsem.h @@ -42,6 +42,9 @@ static inline int __down_read_trylock(struct rw_semaphore *sem) long tmp; while ((tmp = sem->count) >= 0) { + if (sem->count != tmp) + continue; + if (tmp == cmpxchg(&sem->count, tmp, tmp + RWSEM_ACTIVE_READ_BIAS)) { return 1; -- 1.7.1 On Tue, Sep 24, 2013 at 3:22 PM, Tim Chen wrote: > Cmpxchg will cause the cacheline bouning when do the value checking, > that cause scalability issue in a large machine (like a 80 core box). > > So a lock pre-read can relief this contention. > > Signed-off-by: Alex Shi > --- > include/asm-generic/rwsem.h | 8 ++++---- > 1 files changed, 4 insertions(+), 4 deletions(-) > > diff --git a/include/asm-generic/rwsem.h b/include/asm-generic/rwsem.h > index bb1e2cd..5ba80e7 100644 > --- a/include/asm-generic/rwsem.h > +++ b/include/asm-generic/rwsem.h > @@ -70,11 +70,11 @@ static inline void __down_write(struct rw_semaphore *sem) > > static inline int __down_write_trylock(struct rw_semaphore *sem) > { > - long tmp; > + if (unlikely(sem->count != RWSEM_UNLOCKED_VALUE)) > + return 0; > > - tmp = cmpxchg(&sem->count, RWSEM_UNLOCKED_VALUE, > - RWSEM_ACTIVE_WRITE_BIAS); > - return tmp == RWSEM_UNLOCKED_VALUE; > + return cmpxchg(&sem->count, RWSEM_UNLOCKED_VALUE, > + RWSEM_ACTIVE_WRITE_BIAS) == RWSEM_UNLOCKED_VALUE; > } > > /* > -- > 1.7.4.4 > > > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/