[PATCH] lglock: Use spinlock_t instead of arch_spinlock_t

From: Daniel Wagner
Date: Thu Mar 26 2015 - 11:02:25 EST


arch_spinlock_t is the most low level spinlock type. lglock is not
depending on arch_spinlock_t type and works also fine with normal
spinlock_t. So there is no need to use it outside of the archicture
code.

There are two users of lglock which is fs/locks.c and
kernel/stop_machine.c. The later doesn't depend on performance. So
here some numbers for fs/locks.c only.

Running all tests from lockperf 100 times on a 4 socket machine,
Intel(R) Xeon(R) CPU E5-4610 v2 @ 2.30GHz.

flock01 -n 128 -l 128
mean variance sigma max min
4.0.0-rc5 448.0287 15417.8359 124.1686 527.8083 0.0081
4.0.0-rc5-spinlocks_t 395.1646 28713.4347 169.4504 520.7507 0.0075

flock02 -n 256 -l 20480
mean variance sigma max min
4.0.0-rc5 6.9185 0.8830 0.9397 10.6138 4.9707
4.0.0-rc5-spinlocks_t 6.2474 0.9234 0.9610 9.5478 4.3703

lease01 -n 128 -l 128
mean variance sigma max min
4.0.0-rc5 7.7040 0.3930 0.6269 9.1874 5.4179
4.0.0-rc5-spinlocks_t 7.6862 0.7794 0.8828 9.0623 1.3639

lease02 -n 128 -l 512
mean variance sigma max min
4.0.0-rc5 16.3074 0.1418 0.3766 17.1600 15.0240
4.0.0-rc5-spinlocks_t 16.2698 0.2772 0.5265 17.2221 13.4127

posix01 -n 128 -l 128
mean variance sigma max min
4.0.0-rc5 531.5151 181.3078 13.4651 596.5883 501.2940
4.0.0-rc5-spinlocks_t 531.3600 209.0023 14.4569 600.7317 507.1767

posix02 -n 256 -l 20480
mean variance sigma max min
4.0.0-rc5 13.8395 2.9768 1.7253 22.0783 9.9136
4.0.0-rc5-spinlocks_t 12.6822 3.1645 1.7789 18.1258 9.0030

posix03 -n 512 -i 128
mean variance sigma max min
4.0.0-rc5 0.8939 0.0006 0.0242 0.9392 0.8360
4.0.0-rc5-spinlocks_t 0.9050 0.0006 0.0254 0.9617 0.8454

posix04 -n 64 -i 32
mean variance sigma max min
4.0.0-rc5 0.0122 0.0000 0.0023 0.0227 0.0083
4.0.0-rc5-spinlocks_t 0.0115 0.0000 0.0016 0.0165 0.0091

This also makes -rt a bit more happy place since normal spinlocks_t can sleep with
PREEMPT_RT=y.

Link: https://git.samba.org/jlayton/linux.git/?p=jlayton/lockperf.git;a=summary
Link: https://lwn.net/Articles/365863/
Link: http://marc.info/?l=linux-kernel&m=142737586415051&w=2

Signed-off-by: Daniel Wagner <daniel.wagner@xxxxxxxxxxxx>
Cc: Alexander Viro <viro@xxxxxxxxxxxxxxxxxx>
Cc: Jeff Layton <jlayton@xxxxxxxxxxxxxxx>
Cc: "J. Bruce Fields" <bfields@xxxxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: Andi Kleen <andi@xxxxxxxxxxxxxx>
Cc: linux-fsdevel@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
---
include/linux/lglock.h | 10 +++++-----
kernel/locking/lglock.c | 24 ++++++++++++------------
2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/include/linux/lglock.h b/include/linux/lglock.h
index 0081f00..ea97f74 100644
--- a/include/linux/lglock.h
+++ b/include/linux/lglock.h
@@ -34,7 +34,7 @@
#endif

struct lglock {
- arch_spinlock_t __percpu *lock;
+ spinlock_t __percpu *lock;
#ifdef CONFIG_DEBUG_LOCK_ALLOC
struct lock_class_key lock_key;
struct lockdep_map lock_dep_map;
@@ -42,13 +42,13 @@ struct lglock {
};

#define DEFINE_LGLOCK(name) \
- static DEFINE_PER_CPU(arch_spinlock_t, name ## _lock) \
- = __ARCH_SPIN_LOCK_UNLOCKED; \
+ static DEFINE_PER_CPU(spinlock_t, name ## _lock) \
+ = __SPIN_LOCK_UNLOCKED(name ## _lock); \
struct lglock name = { .lock = &name ## _lock }

#define DEFINE_STATIC_LGLOCK(name) \
- static DEFINE_PER_CPU(arch_spinlock_t, name ## _lock) \
- = __ARCH_SPIN_LOCK_UNLOCKED; \
+ static DEFINE_PER_CPU(spinlock_t, name ## _lock) \
+ = __SPIN_LOCK_UNLOCKED(name ## _lock); \
static struct lglock name = { .lock = &name ## _lock }

void lg_lock_init(struct lglock *lg, char *name);
diff --git a/kernel/locking/lglock.c b/kernel/locking/lglock.c
index 86ae2ae..34077a7 100644
--- a/kernel/locking/lglock.c
+++ b/kernel/locking/lglock.c
@@ -18,44 +18,44 @@ EXPORT_SYMBOL(lg_lock_init);

void lg_local_lock(struct lglock *lg)
{
- arch_spinlock_t *lock;
+ spinlock_t *lock;

preempt_disable();
lock_acquire_shared(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
lock = this_cpu_ptr(lg->lock);
- arch_spin_lock(lock);
+ spin_lock(lock);
}
EXPORT_SYMBOL(lg_local_lock);

void lg_local_unlock(struct lglock *lg)
{
- arch_spinlock_t *lock;
+ spinlock_t *lock;

lock_release(&lg->lock_dep_map, 1, _RET_IP_);
lock = this_cpu_ptr(lg->lock);
- arch_spin_unlock(lock);
+ spin_unlock(lock);
preempt_enable();
}
EXPORT_SYMBOL(lg_local_unlock);

void lg_local_lock_cpu(struct lglock *lg, int cpu)
{
- arch_spinlock_t *lock;
+ spinlock_t *lock;

preempt_disable();
lock_acquire_shared(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
lock = per_cpu_ptr(lg->lock, cpu);
- arch_spin_lock(lock);
+ spin_lock(lock);
}
EXPORT_SYMBOL(lg_local_lock_cpu);

void lg_local_unlock_cpu(struct lglock *lg, int cpu)
{
- arch_spinlock_t *lock;
+ spinlock_t *lock;

lock_release(&lg->lock_dep_map, 1, _RET_IP_);
lock = per_cpu_ptr(lg->lock, cpu);
- arch_spin_unlock(lock);
+ spin_unlock(lock);
preempt_enable();
}
EXPORT_SYMBOL(lg_local_unlock_cpu);
@@ -67,9 +67,9 @@ void lg_global_lock(struct lglock *lg)
preempt_disable();
lock_acquire_exclusive(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
for_each_possible_cpu(i) {
- arch_spinlock_t *lock;
+ spinlock_t *lock;
lock = per_cpu_ptr(lg->lock, i);
- arch_spin_lock(lock);
+ spin_lock(lock);
}
}
EXPORT_SYMBOL(lg_global_lock);
@@ -80,9 +80,9 @@ void lg_global_unlock(struct lglock *lg)

lock_release(&lg->lock_dep_map, 1, _RET_IP_);
for_each_possible_cpu(i) {
- arch_spinlock_t *lock;
+ spinlock_t *lock;
lock = per_cpu_ptr(lg->lock, i);
- arch_spin_unlock(lock);
+ spin_unlock(lock);
}
preempt_enable();
}
--
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/