2012-05-08 06:02:24 +02:00
|
|
|
/* See include/linux/lglock.h for description */
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/lglock.h>
|
|
|
|
#include <linux/cpu.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note there is no uninit, so lglocks cannot be defined in
|
|
|
|
* modules (but it's fine to use them from there)
|
|
|
|
* Could be added though, just undo lg_lock_init
|
|
|
|
*/
|
|
|
|
|
|
|
|
void lg_lock_init(struct lglock *lg, char *name)
|
|
|
|
{
|
|
|
|
LOCKDEP_INIT_MAP(&lg->lock_dep_map, name, &lg->lock_key, 0);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(lg_lock_init);
|
|
|
|
|
|
|
|
void lg_local_lock(struct lglock *lg)
|
|
|
|
{
|
|
|
|
arch_spinlock_t *lock;
|
|
|
|
|
|
|
|
preempt_disable();
|
2013-07-08 23:23:51 +02:00
|
|
|
lock_acquire_shared(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
|
2012-05-08 06:02:24 +02:00
|
|
|
lock = this_cpu_ptr(lg->lock);
|
|
|
|
arch_spin_lock(lock);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(lg_local_lock);
|
|
|
|
|
|
|
|
void lg_local_unlock(struct lglock *lg)
|
|
|
|
{
|
|
|
|
arch_spinlock_t *lock;
|
|
|
|
|
2013-07-08 23:23:51 +02:00
|
|
|
lock_release(&lg->lock_dep_map, 1, _RET_IP_);
|
2012-05-08 06:02:24 +02:00
|
|
|
lock = this_cpu_ptr(lg->lock);
|
|
|
|
arch_spin_unlock(lock);
|
|
|
|
preempt_enable();
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(lg_local_unlock);
|
|
|
|
|
|
|
|
void lg_local_lock_cpu(struct lglock *lg, int cpu)
|
|
|
|
{
|
|
|
|
arch_spinlock_t *lock;
|
|
|
|
|
|
|
|
preempt_disable();
|
2013-07-08 23:23:51 +02:00
|
|
|
lock_acquire_shared(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
|
2012-05-08 06:02:24 +02:00
|
|
|
lock = per_cpu_ptr(lg->lock, cpu);
|
|
|
|
arch_spin_lock(lock);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(lg_local_lock_cpu);
|
|
|
|
|
|
|
|
void lg_local_unlock_cpu(struct lglock *lg, int cpu)
|
|
|
|
{
|
|
|
|
arch_spinlock_t *lock;
|
|
|
|
|
2013-07-08 23:23:51 +02:00
|
|
|
lock_release(&lg->lock_dep_map, 1, _RET_IP_);
|
2012-05-08 06:02:24 +02:00
|
|
|
lock = per_cpu_ptr(lg->lock, cpu);
|
|
|
|
arch_spin_unlock(lock);
|
|
|
|
preempt_enable();
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(lg_local_unlock_cpu);
|
|
|
|
|
|
|
|
void lg_global_lock(struct lglock *lg)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
preempt_disable();
|
2013-07-08 23:23:51 +02:00
|
|
|
lock_acquire_exclusive(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
|
2012-05-08 06:02:24 +02:00
|
|
|
for_each_possible_cpu(i) {
|
|
|
|
arch_spinlock_t *lock;
|
|
|
|
lock = per_cpu_ptr(lg->lock, i);
|
|
|
|
arch_spin_lock(lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(lg_global_lock);
|
|
|
|
|
|
|
|
void lg_global_unlock(struct lglock *lg)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2013-07-08 23:23:51 +02:00
|
|
|
lock_release(&lg->lock_dep_map, 1, _RET_IP_);
|
2012-05-08 06:02:24 +02:00
|
|
|
for_each_possible_cpu(i) {
|
|
|
|
arch_spinlock_t *lock;
|
|
|
|
lock = per_cpu_ptr(lg->lock, i);
|
|
|
|
arch_spin_unlock(lock);
|
|
|
|
}
|
|
|
|
preempt_enable();
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(lg_global_unlock);
|