Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754647Ab3IXXa1 (ORCPT ); Tue, 24 Sep 2013 19:30:27 -0400 Received: from mga02.intel.com ([134.134.136.20]:60662 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753996Ab3IXXa0 (ORCPT ); Tue, 24 Sep 2013 19:30:26 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.90,974,1371106800"; d="scan'208";a="408623546" Subject: Re: [PATCH v5 1/6] rwsem: check the lock before cpmxchg in down_write_trylock From: Tim Chen To: Jason Low 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 In-Reply-To: References: <1380061346.3467.50.camel@schen9-DESK> Content-Type: text/plain; charset="UTF-8" Date: Tue, 24 Sep 2013 16:30:19 -0700 Message-ID: <1380065419.3467.59.camel@schen9-DESK> Mime-Version: 1.0 X-Mailer: Evolution 2.32.3 (2.32.3-1.fc14) Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1287 Lines: 38 On Tue, 2013-09-24 at 16:22 -0700, Jason Low wrote: > 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; > + Considering that tmp has just been assigned the value of sem->count, the added if check failure is unlikely and probably not needed. We should proceed to cmpxchg below. > if (tmp == cmpxchg(&sem->count, tmp, > tmp + RWSEM_ACTIVE_READ_BIAS)) { > return 1; Tim -- 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/