Commit dd4eadfc authored by Thomas Gleixner's avatar Thomas Gleixner

semaphore: Introduce anon_semaphore

Add anon_semaphore to annotate the code for real anonymous semaphores.
Map semaphores to them for !RT
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent 2fce95d0
...@@ -13,6 +13,54 @@ ...@@ -13,6 +13,54 @@
#include <linux/spinlock.h> #include <linux/spinlock.h>
/* Please don't access any members of this structure directly */ /* Please don't access any members of this structure directly */
struct anon_semaphore {
spinlock_t lock;
unsigned int count;
struct list_head wait_list;
};
#define __ANON_SEMAPHORE_INITIALIZER(name, n) \
{ \
.lock = __SPIN_LOCK_UNLOCKED((name).lock), \
.count = n, \
.wait_list = LIST_HEAD_INIT((name).wait_list), \
}
#define DEFINE_ANON_SEMAPHORE(name) \
struct anon_semaphore name = __ANON_SEMAPHORE_INITIALIZER(name, 1)
static inline void anon_sema_init(struct anon_semaphore *sem, int val)
{
static struct lock_class_key __key;
*sem = (struct anon_semaphore) __ANON_SEMAPHORE_INITIALIZER(*sem, val);
lockdep_init_map(&sem->lock.dep_map, "semaphore->lock", &__key, 0);
}
static inline void anon_semaphore_init(struct anon_semaphore *sem)
{
anon_sema_init(sem, 1);
}
/*
* semaphore_init_locked() is mostly a sign for a mutex which is
* abused as completion.
*/
static inline void __deprecated
anon_semaphore_init_locked(struct anon_semaphore *sem)
{
anon_sema_init(sem, 0);
}
extern void anon_down(struct anon_semaphore *sem);
extern int __must_check anon_down_interruptible(struct anon_semaphore *sem);
extern int __must_check anon_down_killable(struct anon_semaphore *sem);
extern int __must_check anon_down_trylock(struct anon_semaphore *sem);
extern int __must_check anon_down_timeout(struct anon_semaphore *sem, long jiffies);
extern void anon_up(struct anon_semaphore *sem);
/*
* Non preempt-rt maps semaphores to anon semaphores
*/
struct semaphore { struct semaphore {
spinlock_t lock; spinlock_t lock;
unsigned int count; unsigned int count;
...@@ -27,18 +75,16 @@ struct semaphore { ...@@ -27,18 +75,16 @@ struct semaphore {
} }
#define DEFINE_SEMAPHORE(name) \ #define DEFINE_SEMAPHORE(name) \
struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1) struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
static inline void sema_init(struct semaphore *sem, int val) static inline void sema_init(struct semaphore *sem, int val)
{ {
static struct lock_class_key __key; anon_sema_init((struct anon_semaphore *)sem, val);
*sem = (struct semaphore) __SEMAPHORE_INITIALIZER(*sem, val);
lockdep_init_map(&sem->lock.dep_map, "semaphore->lock", &__key, 0);
} }
static inline void semaphore_init(struct semaphore *sem) static inline void semaphore_init(struct semaphore *sem)
{ {
sema_init(sem, 1); anon_sema_init((struct anon_semaphore *)sem, 1);
} }
/* /*
...@@ -47,14 +93,37 @@ static inline void semaphore_init(struct semaphore *sem) ...@@ -47,14 +93,37 @@ static inline void semaphore_init(struct semaphore *sem)
*/ */
static inline void __deprecated semaphore_init_locked(struct semaphore *sem) static inline void __deprecated semaphore_init_locked(struct semaphore *sem)
{ {
sema_init(sem, 0); anon_sema_init((struct anon_semaphore *)sem, 0);
}
static inline void down(struct semaphore *sem)
{
anon_down((struct anon_semaphore *)sem);
}
static inline int __must_check down_interruptible(struct semaphore *sem)
{
return anon_down_interruptible((struct anon_semaphore *)sem);
}
static inline int __must_check down_killable(struct semaphore *sem)
{
return anon_down_killable((struct anon_semaphore *)sem);
}
static inline int __must_check down_trylock(struct semaphore *sem)
{
return anon_down_trylock((struct anon_semaphore *)sem);
}
static inline int __must_check
down_timeout(struct semaphore *sem, long jiffies)
{
return anon_down_timeout((struct anon_semaphore *)sem, jiffies);
} }
extern void down(struct semaphore *sem); static inline void up(struct semaphore *sem)
extern int __must_check down_interruptible(struct semaphore *sem); {
extern int __must_check down_killable(struct semaphore *sem); anon_up((struct anon_semaphore *)sem);
extern int __must_check down_trylock(struct semaphore *sem); }
extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
extern void up(struct semaphore *sem);
#endif /* __LINUX_SEMAPHORE_H */ #endif /* __LINUX_SEMAPHORE_H */
...@@ -33,11 +33,11 @@ ...@@ -33,11 +33,11 @@
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/ftrace.h> #include <linux/ftrace.h>
static noinline void __down(struct semaphore *sem); static noinline void __down(struct anon_semaphore *sem);
static noinline int __down_interruptible(struct semaphore *sem); static noinline int __down_interruptible(struct anon_semaphore *sem);
static noinline int __down_killable(struct semaphore *sem); static noinline int __down_killable(struct anon_semaphore *sem);
static noinline int __down_timeout(struct semaphore *sem, long jiffies); static noinline int __down_timeout(struct anon_semaphore *sem, long jiffies);
static noinline void __up(struct semaphore *sem); static noinline void __up(struct anon_semaphore *sem);
/** /**
* down - acquire the semaphore * down - acquire the semaphore
...@@ -50,7 +50,7 @@ static noinline void __up(struct semaphore *sem); ...@@ -50,7 +50,7 @@ static noinline void __up(struct semaphore *sem);
* Use of this function is deprecated, please use down_interruptible() or * Use of this function is deprecated, please use down_interruptible() or
* down_killable() instead. * down_killable() instead.
*/ */
void down(struct semaphore *sem) void anon_down(struct anon_semaphore *sem)
{ {
unsigned long flags; unsigned long flags;
...@@ -61,7 +61,7 @@ void down(struct semaphore *sem) ...@@ -61,7 +61,7 @@ void down(struct semaphore *sem)
__down(sem); __down(sem);
spin_unlock_irqrestore(&sem->lock, flags); spin_unlock_irqrestore(&sem->lock, flags);
} }
EXPORT_SYMBOL(down); EXPORT_SYMBOL(anon_down);
/** /**
* down_interruptible - acquire the semaphore unless interrupted * down_interruptible - acquire the semaphore unless interrupted
...@@ -72,7 +72,7 @@ EXPORT_SYMBOL(down); ...@@ -72,7 +72,7 @@ EXPORT_SYMBOL(down);
* If the sleep is interrupted by a signal, this function will return -EINTR. * If the sleep is interrupted by a signal, this function will return -EINTR.
* If the semaphore is successfully acquired, this function returns 0. * If the semaphore is successfully acquired, this function returns 0.
*/ */
int down_interruptible(struct semaphore *sem) int anon_down_interruptible(struct anon_semaphore *sem)
{ {
unsigned long flags; unsigned long flags;
int result = 0; int result = 0;
...@@ -86,7 +86,7 @@ int down_interruptible(struct semaphore *sem) ...@@ -86,7 +86,7 @@ int down_interruptible(struct semaphore *sem)
return result; return result;
} }
EXPORT_SYMBOL(down_interruptible); EXPORT_SYMBOL(anon_down_interruptible);
/** /**
* down_killable - acquire the semaphore unless killed * down_killable - acquire the semaphore unless killed
...@@ -98,7 +98,7 @@ EXPORT_SYMBOL(down_interruptible); ...@@ -98,7 +98,7 @@ EXPORT_SYMBOL(down_interruptible);
* -EINTR. If the semaphore is successfully acquired, this function returns * -EINTR. If the semaphore is successfully acquired, this function returns
* 0. * 0.
*/ */
int down_killable(struct semaphore *sem) int anon_down_killable(struct anon_semaphore *sem)
{ {
unsigned long flags; unsigned long flags;
int result = 0; int result = 0;
...@@ -112,7 +112,7 @@ int down_killable(struct semaphore *sem) ...@@ -112,7 +112,7 @@ int down_killable(struct semaphore *sem)
return result; return result;
} }
EXPORT_SYMBOL(down_killable); EXPORT_SYMBOL(anon_down_killable);
/** /**
* down_trylock - try to acquire the semaphore, without waiting * down_trylock - try to acquire the semaphore, without waiting
...@@ -127,7 +127,7 @@ EXPORT_SYMBOL(down_killable); ...@@ -127,7 +127,7 @@ EXPORT_SYMBOL(down_killable);
* Unlike mutex_trylock, this function can be used from interrupt context, * Unlike mutex_trylock, this function can be used from interrupt context,
* and the semaphore can be released by any task or interrupt. * and the semaphore can be released by any task or interrupt.
*/ */
int down_trylock(struct semaphore *sem) int anon_down_trylock(struct anon_semaphore *sem)
{ {
unsigned long flags; unsigned long flags;
int count; int count;
...@@ -140,7 +140,7 @@ int down_trylock(struct semaphore *sem) ...@@ -140,7 +140,7 @@ int down_trylock(struct semaphore *sem)
return (count < 0); return (count < 0);
} }
EXPORT_SYMBOL(down_trylock); EXPORT_SYMBOL(anon_down_trylock);
/** /**
* down_timeout - acquire the semaphore within a specified time * down_timeout - acquire the semaphore within a specified time
...@@ -152,7 +152,7 @@ EXPORT_SYMBOL(down_trylock); ...@@ -152,7 +152,7 @@ EXPORT_SYMBOL(down_trylock);
* If the semaphore is not released within the specified number of jiffies, * If the semaphore is not released within the specified number of jiffies,
* this function returns -ETIME. It returns 0 if the semaphore was acquired. * this function returns -ETIME. It returns 0 if the semaphore was acquired.
*/ */
int down_timeout(struct semaphore *sem, long jiffies) int anon_down_timeout(struct anon_semaphore *sem, long jiffies)
{ {
unsigned long flags; unsigned long flags;
int result = 0; int result = 0;
...@@ -166,7 +166,7 @@ int down_timeout(struct semaphore *sem, long jiffies) ...@@ -166,7 +166,7 @@ int down_timeout(struct semaphore *sem, long jiffies)
return result; return result;
} }
EXPORT_SYMBOL(down_timeout); EXPORT_SYMBOL(anon_down_timeout);
/** /**
* up - release the semaphore * up - release the semaphore
...@@ -175,7 +175,7 @@ EXPORT_SYMBOL(down_timeout); ...@@ -175,7 +175,7 @@ EXPORT_SYMBOL(down_timeout);
* Release the semaphore. Unlike mutexes, up() may be called from any * Release the semaphore. Unlike mutexes, up() may be called from any
* context and even by tasks which have never called down(). * context and even by tasks which have never called down().
*/ */
void up(struct semaphore *sem) void anon_up(struct anon_semaphore *sem)
{ {
unsigned long flags; unsigned long flags;
...@@ -186,7 +186,7 @@ void up(struct semaphore *sem) ...@@ -186,7 +186,7 @@ void up(struct semaphore *sem)
__up(sem); __up(sem);
spin_unlock_irqrestore(&sem->lock, flags); spin_unlock_irqrestore(&sem->lock, flags);
} }
EXPORT_SYMBOL(up); EXPORT_SYMBOL(anon_up);
/* Functions for the contended case */ /* Functions for the contended case */
...@@ -201,7 +201,7 @@ struct semaphore_waiter { ...@@ -201,7 +201,7 @@ struct semaphore_waiter {
* constant, and thus optimised away by the compiler. Likewise the * constant, and thus optimised away by the compiler. Likewise the
* 'timeout' parameter for the cases without timeouts. * 'timeout' parameter for the cases without timeouts.
*/ */
static inline int __sched __down_common(struct semaphore *sem, long state, static inline int __sched __down_common(struct anon_semaphore *sem, long state,
long timeout) long timeout)
{ {
struct task_struct *task = current; struct task_struct *task = current;
...@@ -233,27 +233,27 @@ static inline int __sched __down_common(struct semaphore *sem, long state, ...@@ -233,27 +233,27 @@ static inline int __sched __down_common(struct semaphore *sem, long state,
return -EINTR; return -EINTR;
} }
static noinline void __sched __down(struct semaphore *sem) static noinline void __sched __down(struct anon_semaphore *sem)
{ {
__down_common(sem, TASK_UNINTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT); __down_common(sem, TASK_UNINTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT);
} }
static noinline int __sched __down_interruptible(struct semaphore *sem) static noinline int __sched __down_interruptible(struct anon_semaphore *sem)
{ {
return __down_common(sem, TASK_INTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT); return __down_common(sem, TASK_INTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT);
} }
static noinline int __sched __down_killable(struct semaphore *sem) static noinline int __sched __down_killable(struct anon_semaphore *sem)
{ {
return __down_common(sem, TASK_KILLABLE, MAX_SCHEDULE_TIMEOUT); return __down_common(sem, TASK_KILLABLE, MAX_SCHEDULE_TIMEOUT);
} }
static noinline int __sched __down_timeout(struct semaphore *sem, long jiffies) static noinline int __sched __down_timeout(struct anon_semaphore *sem, long jiffies)
{ {
return __down_common(sem, TASK_UNINTERRUPTIBLE, jiffies); return __down_common(sem, TASK_UNINTERRUPTIBLE, jiffies);
} }
static noinline void __sched __up(struct semaphore *sem) static noinline void __sched __up(struct anon_semaphore *sem)
{ {
struct semaphore_waiter *waiter = list_first_entry(&sem->wait_list, struct semaphore_waiter *waiter = list_first_entry(&sem->wait_list,
struct semaphore_waiter, list); struct semaphore_waiter, list);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment