Mikulas Patocka | 62ac665 | 2012-09-26 07:46:43 +0200 | [diff] [blame] | 1 | #ifndef _LINUX_PERCPU_RWSEM_H |
| 2 | #define _LINUX_PERCPU_RWSEM_H |
| 3 | |
Oleg Nesterov | 9390ef0 | 2012-12-17 16:01:36 -0800 | [diff] [blame] | 4 | #include <linux/atomic.h> |
Oleg Nesterov | a1fd3e2 | 2012-12-17 16:01:32 -0800 | [diff] [blame] | 5 | #include <linux/rwsem.h> |
Mikulas Patocka | 62ac665 | 2012-09-26 07:46:43 +0200 | [diff] [blame] | 6 | #include <linux/percpu.h> |
Oleg Nesterov | a1fd3e2 | 2012-12-17 16:01:32 -0800 | [diff] [blame] | 7 | #include <linux/wait.h> |
Oleg Nesterov | 001dac6 | 2015-08-21 19:42:57 +0200 | [diff] [blame] | 8 | #include <linux/rcu_sync.h> |
Oleg Nesterov | 8ebe347 | 2012-12-17 16:01:38 -0800 | [diff] [blame] | 9 | #include <linux/lockdep.h> |
Mikulas Patocka | 62ac665 | 2012-09-26 07:46:43 +0200 | [diff] [blame] | 10 | |
| 11 | struct percpu_rw_semaphore { |
Oleg Nesterov | 001dac6 | 2015-08-21 19:42:57 +0200 | [diff] [blame] | 12 | struct rcu_sync rss; |
Oleg Nesterov | a1fd3e2 | 2012-12-17 16:01:32 -0800 | [diff] [blame] | 13 | unsigned int __percpu *fast_read_ctr; |
Oleg Nesterov | a1fd3e2 | 2012-12-17 16:01:32 -0800 | [diff] [blame] | 14 | struct rw_semaphore rw_sem; |
| 15 | atomic_t slow_read_ctr; |
| 16 | wait_queue_head_t write_waitq; |
Mikulas Patocka | 62ac665 | 2012-09-26 07:46:43 +0200 | [diff] [blame] | 17 | }; |
| 18 | |
Oleg Nesterov | a1fd3e2 | 2012-12-17 16:01:32 -0800 | [diff] [blame] | 19 | extern void percpu_down_read(struct percpu_rw_semaphore *); |
Oleg Nesterov | 9287f69 | 2015-07-21 17:45:57 +0200 | [diff] [blame] | 20 | extern int percpu_down_read_trylock(struct percpu_rw_semaphore *); |
Oleg Nesterov | a1fd3e2 | 2012-12-17 16:01:32 -0800 | [diff] [blame] | 21 | extern void percpu_up_read(struct percpu_rw_semaphore *); |
Mikulas Patocka | 5c1eabe | 2012-10-22 19:37:47 -0400 | [diff] [blame] | 22 | |
Oleg Nesterov | a1fd3e2 | 2012-12-17 16:01:32 -0800 | [diff] [blame] | 23 | extern void percpu_down_write(struct percpu_rw_semaphore *); |
| 24 | extern void percpu_up_write(struct percpu_rw_semaphore *); |
Mikulas Patocka | 62ac665 | 2012-09-26 07:46:43 +0200 | [diff] [blame] | 25 | |
Oleg Nesterov | 8ebe347 | 2012-12-17 16:01:38 -0800 | [diff] [blame] | 26 | extern int __percpu_init_rwsem(struct percpu_rw_semaphore *, |
| 27 | const char *, struct lock_class_key *); |
Oleg Nesterov | a1fd3e2 | 2012-12-17 16:01:32 -0800 | [diff] [blame] | 28 | extern void percpu_free_rwsem(struct percpu_rw_semaphore *); |
Mikulas Patocka | 62ac665 | 2012-09-26 07:46:43 +0200 | [diff] [blame] | 29 | |
Oleg Nesterov | 8ebe347 | 2012-12-17 16:01:38 -0800 | [diff] [blame] | 30 | #define percpu_init_rwsem(brw) \ |
| 31 | ({ \ |
| 32 | static struct lock_class_key rwsem_key; \ |
| 33 | __percpu_init_rwsem(brw, #brw, &rwsem_key); \ |
| 34 | }) |
| 35 | |
Oleg Nesterov | 55cc15650 | 2015-07-21 20:26:44 +0200 | [diff] [blame] | 36 | |
| 37 | #define percpu_rwsem_is_held(sem) lockdep_is_held(&(sem)->rw_sem) |
| 38 | |
| 39 | static inline void percpu_rwsem_release(struct percpu_rw_semaphore *sem, |
| 40 | bool read, unsigned long ip) |
| 41 | { |
| 42 | lock_release(&sem->rw_sem.dep_map, 1, ip); |
| 43 | #ifdef CONFIG_RWSEM_SPIN_ON_OWNER |
| 44 | if (!read) |
| 45 | sem->rw_sem.owner = NULL; |
| 46 | #endif |
| 47 | } |
| 48 | |
| 49 | static inline void percpu_rwsem_acquire(struct percpu_rw_semaphore *sem, |
| 50 | bool read, unsigned long ip) |
| 51 | { |
| 52 | lock_acquire(&sem->rw_sem.dep_map, 0, 1, read, 1, NULL, ip); |
| 53 | } |
| 54 | |
Mikulas Patocka | 62ac665 | 2012-09-26 07:46:43 +0200 | [diff] [blame] | 55 | #endif |