[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5136123C.3040508@cn.fujitsu.com>
Date: Tue, 05 Mar 2013 23:41:48 +0800
From: Lai Jiangshan <laijs@...fujitsu.com>
To: "Srivatsa S. Bhat" <srivatsa.bhat@...ux.vnet.ibm.com>
CC: Michel Lespinasse <walken@...gle.com>,
Oleg Nesterov <oleg@...hat.com>,
Lai Jiangshan <eag0628@...il.com>, linux-doc@...r.kernel.org,
peterz@...radead.org, fweisbec@...il.com,
linux-kernel@...r.kernel.org, namhyung@...nel.org,
mingo@...nel.org, linux-arch@...r.kernel.org,
linux@....linux.org.uk, xiaoguangrong@...ux.vnet.ibm.com,
wangyun@...ux.vnet.ibm.com, paulmck@...ux.vnet.ibm.com,
nikunj@...ux.vnet.ibm.com, linux-pm@...r.kernel.org,
rusty@...tcorp.com.au, rostedt@...dmis.org, rjw@...k.pl,
vincent.guittot@...aro.org, tglx@...utronix.de,
linux-arm-kernel@...ts.infradead.org, netdev@...r.kernel.org,
sbw@....edu, tj@...nel.org, akpm@...ux-foundation.org,
linuxppc-dev@...ts.ozlabs.org
Subject: Re: [PATCH V2] lglock: add read-preference local-global rwlock
On 03/03/13 01:11, Srivatsa S. Bhat wrote:
> On 03/02/2013 06:44 PM, Lai Jiangshan wrote:
>> From 345a7a75c314ff567be48983e0892bc69c4452e7 Mon Sep 17 00:00:00 2001
>> From: Lai Jiangshan <laijs@...fujitsu.com>
>> Date: Sat, 2 Mar 2013 20:33:14 +0800
>> Subject: [PATCH] lglock: add read-preference local-global rwlock
>>
>> Current lglock is not read-preference, so it can't be used on some cases
>> which read-preference rwlock can do. Example, get_cpu_online_atomic().
>>
> [...]
>> diff --git a/kernel/lglock.c b/kernel/lglock.c
>> index 6535a66..52e9b2c 100644
>> --- a/kernel/lglock.c
>> +++ b/kernel/lglock.c
>> @@ -87,3 +87,71 @@ void lg_global_unlock(struct lglock *lg)
>> preempt_enable();
>> }
>> EXPORT_SYMBOL(lg_global_unlock);
>> +
>> +#define FALLBACK_BASE (1UL << 30)
>> +
>> +void lg_rwlock_local_read_lock(struct lgrwlock *lgrw)
>> +{
>> + struct lglock *lg = &lgrw->lglock;
>> +
>> + preempt_disable();
>> + if (likely(!__this_cpu_read(*lgrw->reader_refcnt))) {
>> + rwlock_acquire_read(&lg->lock_dep_map, 0, 0, _RET_IP_);
>> + if (unlikely(!arch_spin_trylock(this_cpu_ptr(lg->lock)))) {
>> + read_lock(&lgrw->fallback_rwlock);
>> + __this_cpu_write(*lgrw->reader_refcnt, FALLBACK_BASE);
>> + return;
>> + }
>> + }
>> +
>> + __this_cpu_inc(*lgrw->reader_refcnt);
>> +}
>> +EXPORT_SYMBOL(lg_rwlock_local_read_lock);
>> +
>> +void lg_rwlock_local_read_unlock(struct lgrwlock *lgrw)
>> +{
>> + switch (__this_cpu_read(*lgrw->reader_refcnt)) {
>> + case 1:
>> + __this_cpu_write(*lgrw->reader_refcnt, 0);
>> + lg_local_unlock(&lgrw->lglock);
>> + return;
>
> This should be a break, instead of a return, right?
> Otherwise, there will be a preempt imbalance...
"lockdep" and "preempt" are handled in lg_local_unlock(&lgrw->lglock);
Thanks,
Lai
>
>> + case FALLBACK_BASE:
>> + __this_cpu_write(*lgrw->reader_refcnt, 0);
>> + read_unlock(&lgrw->fallback_rwlock);
>> + rwlock_release(&lg->lock_dep_map, 1, _RET_IP_);
>> + break;
>> + default:
>> + __this_cpu_dec(*lgrw->reader_refcnt);
>> + break;
>> + }
>> +
>> + preempt_enable();
>> +}
>
>
> Regards,
> Srivatsa S. Bhat
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@...r.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 netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists