[PATCH V2] lglock: add read-preference local-global rwlock
Srivatsa S. Bhat
srivatsa.bhat at linux.vnet.ibm.com
Tue Mar 5 12:55:05 EST 2013
On 03/05/2013 09:11 PM, Lai Jiangshan wrote:
> 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 at cn.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);
>
Ah, ok.. I had missed that.
Regards,
Srivatsa S. Bhat
More information about the linux-arm-kernel
mailing list