2013-06-26 22:27:54

by Tim Chen

[permalink] [raw]
Subject: [PATCH v4 1/5] rwsem: check the lock before cpmxchg in down_write_trylock

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 <[email protected]>
---
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



2013-06-27 01:32:58

by Alex Shi

[permalink] [raw]
Subject: Re: [PATCH v4 1/5] rwsem: check the lock before cpmxchg in down_write_trylock


The following line should be added head of commit log on patches 1~4. :)

From: Alex Shi <[email protected]>


> 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 <[email protected]>


--
Thanks
Alex

2013-06-27 15:59:19

by Tim Chen

[permalink] [raw]
Subject: Re: [PATCH v4 1/5] rwsem: check the lock before cpmxchg in down_write_trylock

On Thu, 2013-06-27 at 09:32 +0800, Alex Shi wrote:
> The following line should be added head of commit log on patches 1~4. :)
>
> From: Alex Shi <[email protected]>
>
>
> > 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 <[email protected]>
>
>

Okay. Will add the From line in addition to Signed off line on next
update.

Tim