From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752156Ab3CBMNW (ORCPT ); Sat, 2 Mar 2013 07:13:22 -0500 Received: from mail-ie0-f172.google.com ([209.85.223.172]:45869 "EHLO mail-ie0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752022Ab3CBMNS (ORCPT ); Sat, 2 Mar 2013 07:13:18 -0500 MIME-Version: 1.0 In-Reply-To: <20130301182854.GA3631@redhat.com> References: <512BBAD8.8010006@linux.vnet.ibm.com> <512C7A38.8060906@linux.vnet.ibm.com> <512CC509.1050000@linux.vnet.ibm.com> <512D0D67.9010609@linux.vnet.ibm.com> <512E7879.20109@linux.vnet.ibm.com> <5130E8E2.50206@cn.fujitsu.com> <20130301182854.GA3631@redhat.com> Date: Sat, 2 Mar 2013 20:13:17 +0800 Message-ID: Subject: Re: [PATCH] lglock: add read-preference local-global rwlock From: Michel Lespinasse To: Oleg Nesterov Cc: Lai Jiangshan , "Srivatsa S. Bhat" , Lai Jiangshan , linux-doc@vger.kernel.org, peterz@infradead.org, fweisbec@gmail.com, linux-kernel@vger.kernel.org, namhyung@kernel.org, mingo@kernel.org, linux-arch@vger.kernel.org, linux@arm.linux.org.uk, xiaoguangrong@linux.vnet.ibm.com, wangyun@linux.vnet.ibm.com, paulmck@linux.vnet.ibm.com, nikunj@linux.vnet.ibm.com, linux-pm@vger.kernel.org, rusty@rustcorp.com.au, rostedt@goodmis.org, rjw@sisk.pl, vincent.guittot@linaro.org, tglx@linutronix.de, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, sbw@mit.edu, tj@kernel.org, akpm@linux-foundation.org, linuxppc-dev@lists.ozlabs.org Content-Type: text/plain; charset=ISO-8859-1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Mar 2, 2013 at 2:28 AM, Oleg Nesterov wrote: > Lai, I didn't read this discussion except the code posted by Michel. > I'll try to read this patch carefully later, but I'd like to ask > a couple of questions. > > This version looks more complex than Michel's, why? Just curious, I > am trying to understand what I missed. See > http://marc.info/?l=linux-kernel&m=136196350213593 >>From what I can see, my version used local_refcnt to count how many reentrant locks are represented by the fastpath lglock spinlock; Lai's version uses it to count how many reentrant locks are represented by either the fastpath lglock spinlock or the global rwlock, with FALLBACK_BASE being a bit thrown in so we can remember which of these locks was acquired. My version would be slower if it needs to take the slow path in a reentrant way, but I'm not sure it matters either :) > Interrupt handler on CPU_1 does _read_lock() notices ->reader_refcnt != 0 > and simply does this_cpu_inc(), so reader_refcnt == FALLBACK_BASE + 1. > > Then irq does _read_unlock(), and > >> +void lg_rwlock_local_read_unlock(struct lgrwlock *lgrw) >> +{ >> + switch (__this_cpu_dec_return(*lgrw->reader_refcnt)) { >> + case 0: >> + lg_local_unlock(&lgrw->lglock); >> + return; >> + case FALLBACK_BASE: >> + __this_cpu_sub(*lgrw->reader_refcnt, FALLBACK_BASE); >> + read_unlock(&lgrw->fallback_rwlock); > > hits this case? > > Doesn't look right, but most probably I missed something. Good catch. I think this is easily fixed by setting reader_refcn directly to FALLBACK_BASE+1, instead of setting it to FALLBACK_BASE and then incrementing it to FALLBACK_BASE+1. -- Michel "Walken" Lespinasse A program is never fully debugged until the last user dies. From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michel Lespinasse Subject: Re: [PATCH] lglock: add read-preference local-global rwlock Date: Sat, 2 Mar 2013 20:13:17 +0800 Message-ID: References: <512BBAD8.8010006@linux.vnet.ibm.com> <512C7A38.8060906@linux.vnet.ibm.com> <512CC509.1050000@linux.vnet.ibm.com> <512D0D67.9010609@linux.vnet.ibm.com> <512E7879.20109@linux.vnet.ibm.com> <5130E8E2.50206@cn.fujitsu.com> <20130301182854.GA3631@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Return-path: Received: from mail-ie0-f179.google.com ([209.85.223.179]:35940 "EHLO mail-ie0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751988Ab3CBMNS (ORCPT ); Sat, 2 Mar 2013 07:13:18 -0500 Received: by mail-ie0-f179.google.com with SMTP id k11so4601811iea.10 for ; Sat, 02 Mar 2013 04:13:18 -0800 (PST) In-Reply-To: <20130301182854.GA3631@redhat.com> Sender: linux-arch-owner@vger.kernel.org List-ID: To: Oleg Nesterov Cc: Lai Jiangshan , "Srivatsa S. Bhat" , Lai Jiangshan , linux-doc@vger.kernel.org, peterz@infradead.org, fweisbec@gmail.com, linux-kernel@vger.kernel.org, namhyung@kernel.org, mingo@kernel.org, linux-arch@vger.kernel.org, linux@arm.linux.org.uk, xiaoguangrong@linux.vnet.ibm.com, wangyun@linux.vnet.ibm.com, paulmck@linux.vnet.ibm.com, nikunj@linux.vnet.ibm.com, linux-pm@vger.kernel.org, rusty@rustcorp.com.au, rostedt@goodmis.org, rjw@sisk.pl, vincent.guittot@linaro.org, tglx@linutronix.de, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, sbw@mit.edu, tj@kernel.org, akpm@linux-foundation.org, linuxppc-dev@lists.ozlabs.org On Sat, Mar 2, 2013 at 2:28 AM, Oleg Nesterov wrote: > Lai, I didn't read this discussion except the code posted by Michel. > I'll try to read this patch carefully later, but I'd like to ask > a couple of questions. > > This version looks more complex than Michel's, why? Just curious, I > am trying to understand what I missed. See > http://marc.info/?l=linux-kernel&m=136196350213593 >From what I can see, my version used local_refcnt to count how many reentrant locks are represented by the fastpath lglock spinlock; Lai's version uses it to count how many reentrant locks are represented by either the fastpath lglock spinlock or the global rwlock, with FALLBACK_BASE being a bit thrown in so we can remember which of these locks was acquired. My version would be slower if it needs to take the slow path in a reentrant way, but I'm not sure it matters either :) > Interrupt handler on CPU_1 does _read_lock() notices ->reader_refcnt != 0 > and simply does this_cpu_inc(), so reader_refcnt == FALLBACK_BASE + 1. > > Then irq does _read_unlock(), and > >> +void lg_rwlock_local_read_unlock(struct lgrwlock *lgrw) >> +{ >> + switch (__this_cpu_dec_return(*lgrw->reader_refcnt)) { >> + case 0: >> + lg_local_unlock(&lgrw->lglock); >> + return; >> + case FALLBACK_BASE: >> + __this_cpu_sub(*lgrw->reader_refcnt, FALLBACK_BASE); >> + read_unlock(&lgrw->fallback_rwlock); > > hits this case? > > Doesn't look right, but most probably I missed something. Good catch. I think this is easily fixed by setting reader_refcn directly to FALLBACK_BASE+1, instead of setting it to FALLBACK_BASE and then incrementing it to FALLBACK_BASE+1. -- Michel "Walken" Lespinasse A program is never fully debugged until the last user dies. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ia0-x22c.google.com (mail-ia0-x22c.google.com [IPv6:2607:f8b0:4001:c02::22c]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id DBE742C02F6 for ; Sat, 2 Mar 2013 23:13:21 +1100 (EST) Received: by mail-ia0-f172.google.com with SMTP id l29so3497931iag.31 for ; Sat, 02 Mar 2013 04:13:18 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <20130301182854.GA3631@redhat.com> References: <512BBAD8.8010006@linux.vnet.ibm.com> <512C7A38.8060906@linux.vnet.ibm.com> <512CC509.1050000@linux.vnet.ibm.com> <512D0D67.9010609@linux.vnet.ibm.com> <512E7879.20109@linux.vnet.ibm.com> <5130E8E2.50206@cn.fujitsu.com> <20130301182854.GA3631@redhat.com> Date: Sat, 2 Mar 2013 20:13:17 +0800 Message-ID: Subject: Re: [PATCH] lglock: add read-preference local-global rwlock From: Michel Lespinasse To: Oleg Nesterov Content-Type: text/plain; charset=ISO-8859-1 Cc: Lai Jiangshan , linux-doc@vger.kernel.org, peterz@infradead.org, fweisbec@gmail.com, mingo@kernel.org, linux-arch@vger.kernel.org, linux@arm.linux.org.uk, xiaoguangrong@linux.vnet.ibm.com, wangyun@linux.vnet.ibm.com, paulmck@linux.vnet.ibm.com, nikunj@linux.vnet.ibm.com, linux-pm@vger.kernel.org, rusty@rustcorp.com.au, rostedt@goodmis.org, rjw@sisk.pl, namhyung@kernel.org, tglx@linutronix.de, linux-arm-kernel@lists.infradead.org, Lai Jiangshan , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, vincent.guittot@linaro.org, sbw@mit.edu, "Srivatsa S. Bhat" , tj@kernel.org, akpm@linux-foundation.org, linuxppc-dev@lists.ozlabs.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , On Sat, Mar 2, 2013 at 2:28 AM, Oleg Nesterov wrote: > Lai, I didn't read this discussion except the code posted by Michel. > I'll try to read this patch carefully later, but I'd like to ask > a couple of questions. > > This version looks more complex than Michel's, why? Just curious, I > am trying to understand what I missed. See > http://marc.info/?l=linux-kernel&m=136196350213593 >>From what I can see, my version used local_refcnt to count how many reentrant locks are represented by the fastpath lglock spinlock; Lai's version uses it to count how many reentrant locks are represented by either the fastpath lglock spinlock or the global rwlock, with FALLBACK_BASE being a bit thrown in so we can remember which of these locks was acquired. My version would be slower if it needs to take the slow path in a reentrant way, but I'm not sure it matters either :) > Interrupt handler on CPU_1 does _read_lock() notices ->reader_refcnt != 0 > and simply does this_cpu_inc(), so reader_refcnt == FALLBACK_BASE + 1. > > Then irq does _read_unlock(), and > >> +void lg_rwlock_local_read_unlock(struct lgrwlock *lgrw) >> +{ >> + switch (__this_cpu_dec_return(*lgrw->reader_refcnt)) { >> + case 0: >> + lg_local_unlock(&lgrw->lglock); >> + return; >> + case FALLBACK_BASE: >> + __this_cpu_sub(*lgrw->reader_refcnt, FALLBACK_BASE); >> + read_unlock(&lgrw->fallback_rwlock); > > hits this case? > > Doesn't look right, but most probably I missed something. Good catch. I think this is easily fixed by setting reader_refcn directly to FALLBACK_BASE+1, instead of setting it to FALLBACK_BASE and then incrementing it to FALLBACK_BASE+1. -- Michel "Walken" Lespinasse A program is never fully debugged until the last user dies. From mboxrd@z Thu Jan 1 00:00:00 1970 From: walken@google.com (Michel Lespinasse) Date: Sat, 2 Mar 2013 20:13:17 +0800 Subject: [PATCH] lglock: add read-preference local-global rwlock In-Reply-To: <20130301182854.GA3631@redhat.com> References: <512BBAD8.8010006@linux.vnet.ibm.com> <512C7A38.8060906@linux.vnet.ibm.com> <512CC509.1050000@linux.vnet.ibm.com> <512D0D67.9010609@linux.vnet.ibm.com> <512E7879.20109@linux.vnet.ibm.com> <5130E8E2.50206@cn.fujitsu.com> <20130301182854.GA3631@redhat.com> Message-ID: To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org On Sat, Mar 2, 2013 at 2:28 AM, Oleg Nesterov wrote: > Lai, I didn't read this discussion except the code posted by Michel. > I'll try to read this patch carefully later, but I'd like to ask > a couple of questions. > > This version looks more complex than Michel's, why? Just curious, I > am trying to understand what I missed. See > http://marc.info/?l=linux-kernel&m=136196350213593 >>From what I can see, my version used local_refcnt to count how many reentrant locks are represented by the fastpath lglock spinlock; Lai's version uses it to count how many reentrant locks are represented by either the fastpath lglock spinlock or the global rwlock, with FALLBACK_BASE being a bit thrown in so we can remember which of these locks was acquired. My version would be slower if it needs to take the slow path in a reentrant way, but I'm not sure it matters either :) > Interrupt handler on CPU_1 does _read_lock() notices ->reader_refcnt != 0 > and simply does this_cpu_inc(), so reader_refcnt == FALLBACK_BASE + 1. > > Then irq does _read_unlock(), and > >> +void lg_rwlock_local_read_unlock(struct lgrwlock *lgrw) >> +{ >> + switch (__this_cpu_dec_return(*lgrw->reader_refcnt)) { >> + case 0: >> + lg_local_unlock(&lgrw->lglock); >> + return; >> + case FALLBACK_BASE: >> + __this_cpu_sub(*lgrw->reader_refcnt, FALLBACK_BASE); >> + read_unlock(&lgrw->fallback_rwlock); > > hits this case? > > Doesn't look right, but most probably I missed something. Good catch. I think this is easily fixed by setting reader_refcn directly to FALLBACK_BASE+1, instead of setting it to FALLBACK_BASE and then incrementing it to FALLBACK_BASE+1. -- Michel "Walken" Lespinasse A program is never fully debugged until the last user dies.