From 7e44c783ad731856956929f6614bbe045c26ea3a Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Thu, 11 Feb 2016 23:45:37 +0530 Subject: lock: use spinlock only on multicore systems Using spinlocks on a single-core system makes usually no meaning, since as long as the spinlock polling is blocking the only available CPU core, no other thread can run and since no other thread can run, the lock won't be unlocked until its time quantum expires and it gets de-scheduled. In other words, a spinlock wastes CPU time on those systems for no real benefit. If the thread was put to sleep instead, another thread could have ran at once, possibly unlocking the lock and then allowing the first thread to continue processing, once it woke up again. Change-Id: I0ffc14e26c2e150b564bcb682a576859ab1d1872 BUG: 1306807 Signed-off-by: Prasanna Kumar Kalever Reviewed-on: http://review.gluster.org/13432 Smoke: Gluster Build System NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System Reviewed-by: Jeff Darcy --- libglusterfs/src/locking.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 libglusterfs/src/locking.c (limited to 'libglusterfs/src/locking.c') diff --git a/libglusterfs/src/locking.c b/libglusterfs/src/locking.c new file mode 100644 index 00000000000..d3b9754ef76 --- /dev/null +++ b/libglusterfs/src/locking.c @@ -0,0 +1,28 @@ +/* + Copyright (c) 2015 Red Hat, Inc. + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ + +#if defined(HAVE_SPINLOCK) +/* None of this matters otherwise. */ + +#include +#include + +#define LOCKING_IMPL +#include "locking.h" + +int use_spinlocks = 0; + +static void __attribute__((constructor)) +gf_lock_setup (void) +{ + use_spinlocks = (sysconf(_SC_NPROCESSORS_ONLN) > 1); +} + +#endif -- cgit