2008-05-26 08:38:26 +04:00
|
|
|
/*
|
|
|
|
* This file is part of the SPL: Solaris Porting Layer.
|
|
|
|
*
|
2009-09-26 01:47:01 +04:00
|
|
|
* Copyright (c) 2009 Lawrence Livermore National Security, LLC.
|
2008-05-26 08:38:26 +04:00
|
|
|
* Produced at Lawrence Livermore National Laboratory
|
|
|
|
* Written by:
|
|
|
|
* Brian Behlendorf <behlendorf1@llnl.gov>,
|
|
|
|
* Herb Wartens <wartens2@llnl.gov>,
|
|
|
|
* Jim Garlick <garlick@llnl.gov>
|
|
|
|
* UCRL-CODE-235197
|
|
|
|
*
|
|
|
|
* This is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 00:18:49 +04:00
|
|
|
#include <sys/mutex.h>
|
|
|
|
|
|
|
|
#ifdef DEBUG_SUBSYSTEM
|
|
|
|
#undef DEBUG_SUBSYSTEM
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define DEBUG_SUBSYSTEM S_MUTEX
|
|
|
|
|
2009-09-26 01:47:01 +04:00
|
|
|
/*
|
|
|
|
* While a standard mutex implementation has been available in the kernel
|
|
|
|
* for quite some time. It was not until 2.6.29 and latter kernels that
|
|
|
|
* adaptive mutexs were embraced and integrated with the scheduler. This
|
|
|
|
* brought a significant performance improvement, but just as importantly
|
|
|
|
* it added a lock owner to the generic mutex outside CONFIG_DEBUG_MUTEXES
|
|
|
|
* builds. This is critical for correctly supporting the mutex_owner()
|
|
|
|
* Solaris primitive. When the owner is available we use a pure Linux
|
|
|
|
* mutex implementation. When the owner is not available we still use
|
|
|
|
* Linux mutexs as a base but also reserve space for an owner field right
|
|
|
|
* after the mutex structure.
|
2008-05-06 00:18:49 +04:00
|
|
|
*
|
2009-09-26 01:47:01 +04:00
|
|
|
* In the case when HAVE_MUTEX_OWNER is not defined your code may
|
|
|
|
* still me able to leverage adaptive mutexs. As long as the task_curr()
|
|
|
|
* symbol is exported this code will provide a poor mans adaptive mutex
|
|
|
|
* implementation. However, this is not required and if the symbol is
|
|
|
|
* unavailable we provide a standard mutex.
|
2008-05-06 00:18:49 +04:00
|
|
|
*/
|
|
|
|
|
2009-09-26 01:47:01 +04:00
|
|
|
#ifndef HAVE_MUTEX_OWNER
|
|
|
|
#ifdef HAVE_TASK_CURR
|
|
|
|
/*
|
|
|
|
* mutex_spin_max = { 0, -1, 1-MAX_INT }
|
|
|
|
* 0: Never spin when trying to acquire lock
|
|
|
|
* -1: Spin until acquired or holder yields without dropping lock
|
2008-05-06 00:18:49 +04:00
|
|
|
* 1-MAX_INT: Spin for N attempts before sleeping for lock
|
|
|
|
*/
|
2008-05-15 21:32:41 +04:00
|
|
|
int mutex_spin_max = 0;
|
2009-09-26 01:47:01 +04:00
|
|
|
module_param(mutex_spin_max, int, 0644);
|
|
|
|
MODULE_PARM_DESC(mutex_spin_max, "Spin a maximum of N times to acquire lock");
|
2008-05-06 00:18:49 +04:00
|
|
|
|
|
|
|
int
|
2009-09-26 01:47:01 +04:00
|
|
|
spl_mutex_spin_max(void)
|
2008-05-06 00:18:49 +04:00
|
|
|
{
|
2009-09-26 01:47:01 +04:00
|
|
|
return mutex_spin_max;
|
2008-05-06 00:18:49 +04:00
|
|
|
}
|
2009-09-26 01:47:01 +04:00
|
|
|
EXPORT_SYMBOL(spl_mutex_spin_max);
|
2008-05-06 00:18:49 +04:00
|
|
|
|
2009-09-26 01:47:01 +04:00
|
|
|
#endif /* HAVE_TASK_CURR */
|
|
|
|
#endif /* !HAVE_MUTEX_OWNER */
|
2008-05-06 00:18:49 +04:00
|
|
|
|
2009-09-26 01:47:01 +04:00
|
|
|
int spl_mutex_init(void) { return 0; }
|
|
|
|
void spl_mutex_fini(void) { }
|