]> git.proxmox.com Git - mirror_spl.git/blob - module/spl/spl-mutex.c
Reimplement mutexs for Linux lock profiling/analysis
[mirror_spl.git] / module / spl / spl-mutex.c
1 /*
2 * This file is part of the SPL: Solaris Porting Layer.
3 *
4 * Copyright (c) 2009 Lawrence Livermore National Security, LLC.
5 * Produced at Lawrence Livermore National Laboratory
6 * Written by:
7 * Brian Behlendorf <behlendorf1@llnl.gov>,
8 * Herb Wartens <wartens2@llnl.gov>,
9 * Jim Garlick <garlick@llnl.gov>
10 * UCRL-CODE-235197
11 *
12 * This is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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 #ifndef HAVE_MUTEX_OWNER
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) { }