]> git.proxmox.com Git - mirror_spl-debian.git/blob - module/spl/spl-mutex.c
d452681b13193411df9de5b0330183913e0f5e5f
[mirror_spl-debian.git] / module / spl / spl-mutex.c
1 /*****************************************************************************\
2 * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
3 * Copyright (C) 2007 The Regents of the University of California.
4 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
5 * Written by Brian Behlendorf <behlendorf1@llnl.gov>.
6 * UCRL-CODE-235197
7 *
8 * This file is part of the SPL, Solaris Porting Layer.
9 * For details, see <http://github.com/behlendorf/spl/>.
10 *
11 * The SPL is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 *
16 * The SPL is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
23 *****************************************************************************
24 * Solaris Porting Layer (SPL) Mutex Implementation.
25 \*****************************************************************************/
26
27 #include <sys/mutex.h>
28
29 #ifdef DEBUG_SUBSYSTEM
30 #undef DEBUG_SUBSYSTEM
31 #endif
32
33 #define DEBUG_SUBSYSTEM S_MUTEX
34
35 /*
36 * While a standard mutex implementation has been available in the kernel
37 * for quite some time. It was not until 2.6.29 and latter kernels that
38 * adaptive mutexs were embraced and integrated with the scheduler. This
39 * brought a significant performance improvement, but just as importantly
40 * it added a lock owner to the generic mutex outside CONFIG_DEBUG_MUTEXES
41 * builds. This is critical for correctly supporting the mutex_owner()
42 * Solaris primitive. When the owner is available we use a pure Linux
43 * mutex implementation. When the owner is not available we still use
44 * Linux mutexs as a base but also reserve space for an owner field right
45 * after the mutex structure.
46 *
47 * In the case when HAVE_MUTEX_OWNER is not defined your code may
48 * still me able to leverage adaptive mutexs. As long as the task_curr()
49 * symbol is exported this code will provide a poor mans adaptive mutex
50 * implementation. However, this is not required and if the symbol is
51 * unavailable we provide a standard mutex.
52 */
53
54 #if !defined(HAVE_MUTEX_OWNER) || !defined(CONFIG_SMP) || defined(CONFIG_DEBUG_MUTEXES)
55 #ifdef HAVE_TASK_CURR
56 /*
57 * mutex_spin_max = { 0, -1, 1-MAX_INT }
58 * 0: Never spin when trying to acquire lock
59 * -1: Spin until acquired or holder yields without dropping lock
60 * 1-MAX_INT: Spin for N attempts before sleeping for lock
61 */
62 int mutex_spin_max = 0;
63 module_param(mutex_spin_max, int, 0644);
64 MODULE_PARM_DESC(mutex_spin_max, "Spin a maximum of N times to acquire lock");
65
66 int
67 spl_mutex_spin_max(void)
68 {
69 return mutex_spin_max;
70 }
71 EXPORT_SYMBOL(spl_mutex_spin_max);
72
73 #endif /* HAVE_TASK_CURR */
74 #endif /* !HAVE_MUTEX_OWNER */
75
76 int spl_mutex_init(void) { return 0; }
77 void spl_mutex_fini(void) { }