From patchwork Thu Mar 26 15:02:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 6099921 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BEA0D9F350 for ; Thu, 26 Mar 2015 15:02:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C17CD2035B for ; Thu, 26 Mar 2015 15:02:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 656DE2041E for ; Thu, 26 Mar 2015 15:02:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752689AbbCZPCT (ORCPT ); Thu, 26 Mar 2015 11:02:19 -0400 Received: from mail.bmw-carit.de ([62.245.222.98]:49235 "EHLO linuxmail.bmw-carit.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752251AbbCZPCS (ORCPT ); Thu, 26 Mar 2015 11:02:18 -0400 Received: from localhost (handman.bmw-carit.intra [192.168.101.32]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: daniel.wagner) by linuxmail.bmw-carit.de (Postfix) with ESMTPSA id 2CF38438E6; Thu, 26 Mar 2015 16:00:45 +0100 (CET) From: Daniel Wagner To: Jeff Layton , Peter Zijlstra , Ingo Molnar Cc: Daniel Wagner , Alexander Viro , "J. Bruce Fields" , Thomas Gleixner , Andi Kleen , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] lglock: Use spinlock_t instead of arch_spinlock_t Date: Thu, 26 Mar 2015 16:02:08 +0100 Message-Id: <1427382128-12541-1-git-send-email-daniel.wagner@bmw-carit.de> X-Mailer: git-send-email 2.1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Cc: Alexander Viro Cc: Jeff Layton Cc: "J. Bruce Fields" Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Thomas Gleixner Cc: Andi Kleen Cc: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- 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(); }