blob: d48cc77ba70db09707444d42ffa12affa691a99f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __LINUX_SMPLOCK_H
2#define __LINUX_SMPLOCK_H
3
Al Virof0373602005-11-13 16:06:57 -08004#ifdef CONFIG_LOCK_KERNEL
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#include <linux/sched.h>
Frederic Weisbecker96a2c462009-08-01 01:34:24 +02006#include <trace/events/bkl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#define kernel_locked() (current->lock_depth >= 0)
9
10extern int __lockfunc __reacquire_kernel_lock(void);
11extern void __lockfunc __release_kernel_lock(void);
12
13/*
14 * Release/re-acquire global kernel lock for the scheduler
15 */
16#define release_kernel_lock(tsk) do { \
17 if (unlikely((tsk)->lock_depth >= 0)) \
18 __release_kernel_lock(); \
19} while (0)
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021static inline int reacquire_kernel_lock(struct task_struct *task)
22{
23 if (unlikely(task->lock_depth >= 0))
Ingo Molnar6478d882008-01-25 21:08:33 +010024 return __reacquire_kernel_lock();
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 return 0;
26}
27
Frederic Weisbecker96a2c462009-08-01 01:34:24 +020028extern void __lockfunc _lock_kernel(void) __acquires(kernel_lock);
29extern void __lockfunc _unlock_kernel(void) __releases(kernel_lock);
30
31#define lock_kernel() { \
32 trace_lock_kernel(__func__, __FILE__, __LINE__); \
33 _lock_kernel(); \
34}
35
36#define unlock_kernel() { \
37 trace_unlock_kernel(__func__, __FILE__, __LINE__); \
38 _unlock_kernel(); \
39}
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Jonathan Corbet0b280672008-05-18 14:27:41 -060041/*
42 * Various legacy drivers don't really need the BKL in a specific
43 * function, but they *do* need to know that the BKL became available.
44 * This function just avoids wrapping a bunch of lock/unlock pairs
45 * around code which doesn't really need it.
46 */
47static inline void cycle_kernel_lock(void)
48{
49 lock_kernel();
50 unlock_kernel();
51}
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#else
54
Frederic Weisbecker96a2c462009-08-01 01:34:24 +020055#define lock_kernel() trace_lock_kernel(__func__, __FILE__, __LINE__);
56#define unlock_kernel() trace_unlock_kernel(__func__, __FILE__, __LINE__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#define release_kernel_lock(task) do { } while(0)
Jonathan Corbet0b280672008-05-18 14:27:41 -060058#define cycle_kernel_lock() do { } while(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#define reacquire_kernel_lock(task) 0
60#define kernel_locked() 1
61
62#endif /* CONFIG_LOCK_KERNEL */
63#endif /* __LINUX_SMPLOCK_H */