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 @@
#include <linux/spinlock.h>
/* 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 {
spinlock_t lock;
unsigned int count;
......@@ -31,14 +79,12 @@ struct semaphore {
static inline void sema_init(struct semaphore *sem, int val)
{
static struct lock_class_key __key;
*sem = (struct semaphore) __SEMAPHORE_INITIALIZER(*sem, val);
lockdep_init_map(&sem->lock.dep_map, "semaphore->lock", &__key, 0);
anon_sema_init((struct anon_semaphore *)sem, val);
}
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)
*/
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);
extern int __must_check down_interruptible(struct semaphore *sem);
extern int __must_check down_killable(struct 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);
static inline void up(struct semaphore *sem)
{
anon_up((struct anon_semaphore *)sem);
}
#endif /* __LINUX_SEMAPHORE_H */
......@@ -33,11 +33,11 @@
#include <linux/spinlock.h>
#include <linux/ftrace.h>
static noinline void __down(struct semaphore *sem);
static noinline int __down_interruptible(struct semaphore *sem);
static noinline int __down_killable(struct semaphore *sem);
static noinline int __down_timeout(struct semaphore *sem, long jiffies);
static noinline void __up(struct semaphore *sem);
static noinline void __down(struct anon_semaphore *sem);
static noinline int __down_interruptible(struct anon_semaphore *sem);
static noinline int __down_killable(struct anon_semaphore *sem);
static noinline int __down_timeout(struct anon_semaphore *sem, long jiffies);
static noinline void __up(struct anon_semaphore *sem);
/**
* down - acquire the semaphore
......@@ -50,7 +50,7 @@ static noinline void __up(struct semaphore *sem);
* Use of this function is deprecated, please use down_interruptible() or
* down_killable() instead.
*/
void down(struct semaphore *sem)
void anon_down(struct anon_semaphore *sem)
{
unsigned long flags;
......@@ -61,7 +61,7 @@ void down(struct semaphore *sem)
__down(sem);
spin_unlock_irqrestore(&sem->lock, flags);
}
EXPORT_SYMBOL(down);
EXPORT_SYMBOL(anon_down);
/**
* down_interruptible - acquire the semaphore unless interrupted
......@@ -72,7 +72,7 @@ EXPORT_SYMBOL(down);
* If the sleep is interrupted by a signal, this function will return -EINTR.
* 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;
int result = 0;
......@@ -86,7 +86,7 @@ int down_interruptible(struct semaphore *sem)
return result;
}
EXPORT_SYMBOL(down_interruptible);
EXPORT_SYMBOL(anon_down_interruptible);
/**
* down_killable - acquire the semaphore unless killed
......@@ -98,7 +98,7 @@ EXPORT_SYMBOL(down_interruptible);
* -EINTR. If the semaphore is successfully acquired, this function returns
* 0.
*/
int down_killable(struct semaphore *sem)
int anon_down_killable(struct anon_semaphore *sem)
{
unsigned long flags;
int result = 0;
......@@ -112,7 +112,7 @@ int down_killable(struct semaphore *sem)
return result;
}
EXPORT_SYMBOL(down_killable);
EXPORT_SYMBOL(anon_down_killable);
/**
* down_trylock - try to acquire the semaphore, without waiting
......@@ -127,7 +127,7 @@ EXPORT_SYMBOL(down_killable);
* Unlike mutex_trylock, this function can be used from interrupt context,
* 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;
int count;
......@@ -140,7 +140,7 @@ int down_trylock(struct semaphore *sem)
return (count < 0);
}
EXPORT_SYMBOL(down_trylock);
EXPORT_SYMBOL(anon_down_trylock);
/**
* down_timeout - acquire the semaphore within a specified time
......@@ -152,7 +152,7 @@ EXPORT_SYMBOL(down_trylock);
* If the semaphore is not released within the specified number of jiffies,
* 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;
int result = 0;
......@@ -166,7 +166,7 @@ int down_timeout(struct semaphore *sem, long jiffies)
return result;
}
EXPORT_SYMBOL(down_timeout);
EXPORT_SYMBOL(anon_down_timeout);
/**
* up - release the semaphore
......@@ -175,7 +175,7 @@ EXPORT_SYMBOL(down_timeout);
* Release the semaphore. Unlike mutexes, up() may be called from any
* 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;
......@@ -186,7 +186,7 @@ void up(struct semaphore *sem)
__up(sem);
spin_unlock_irqrestore(&sem->lock, flags);
}
EXPORT_SYMBOL(up);
EXPORT_SYMBOL(anon_up);
/* Functions for the contended case */
......@@ -201,7 +201,7 @@ struct semaphore_waiter {
* constant, and thus optimised away by the compiler. Likewise the
* '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)
{
struct task_struct *task = current;
......@@ -233,27 +233,27 @@ static inline int __sched __down_common(struct semaphore *sem, long state,
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);
}
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);
}
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);
}
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);
}
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, 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