eea62f831b
lglocks and brlocks are currently generated with some complicated macros in lglock.h. But there's no reason to not just use common utility functions and put all the data into a common data structure. Since there are at least two users it makes sense to share this code in a library. This is also easier maintainable than a macro forest. This will also make it later possible to dynamically allocate lglocks and also use them in modules (this would both still need some additional, but now straightforward, code) [akpm@linux-foundation.org: checkpatch fixes] Signed-off-by: Andi Kleen <ak@linux.intel.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
73 lines
2.3 KiB
C
73 lines
2.3 KiB
C
/*
|
|
* Specialised local-global spinlock. Can only be declared as global variables
|
|
* to avoid overhead and keep things simple (and we don't want to start using
|
|
* these inside dynamically allocated structures).
|
|
*
|
|
* "local/global locks" (lglocks) can be used to:
|
|
*
|
|
* - Provide fast exclusive access to per-CPU data, with exclusive access to
|
|
* another CPU's data allowed but possibly subject to contention, and to
|
|
* provide very slow exclusive access to all per-CPU data.
|
|
* - Or to provide very fast and scalable read serialisation, and to provide
|
|
* very slow exclusive serialisation of data (not necessarily per-CPU data).
|
|
*
|
|
* Brlocks are also implemented as a short-hand notation for the latter use
|
|
* case.
|
|
*
|
|
* Copyright 2009, 2010, Nick Piggin, Novell Inc.
|
|
*/
|
|
#ifndef __LINUX_LGLOCK_H
|
|
#define __LINUX_LGLOCK_H
|
|
|
|
#include <linux/spinlock.h>
|
|
#include <linux/lockdep.h>
|
|
#include <linux/percpu.h>
|
|
#include <linux/cpu.h>
|
|
#include <linux/notifier.h>
|
|
|
|
/* can make br locks by using local lock for read side, global lock for write */
|
|
#define br_lock_init(name) lg_lock_init(name, #name)
|
|
#define br_read_lock(name) lg_local_lock(name)
|
|
#define br_read_unlock(name) lg_local_unlock(name)
|
|
#define br_write_lock(name) lg_global_lock(name)
|
|
#define br_write_unlock(name) lg_global_unlock(name)
|
|
|
|
#define DEFINE_BRLOCK(name) DEFINE_LGLOCK(name)
|
|
|
|
#ifdef CONFIG_DEBUG_LOCK_ALLOC
|
|
#define LOCKDEP_INIT_MAP lockdep_init_map
|
|
|
|
#define DEFINE_LGLOCK_LOCKDEP(name) \
|
|
struct lock_class_key name##_lock_key; \
|
|
struct lockdep_map name##_lock_dep_map; \
|
|
EXPORT_SYMBOL(name##_lock_dep_map)
|
|
|
|
#else
|
|
#define LOCKDEP_INIT_MAP(a, b, c, d)
|
|
|
|
#define DEFINE_LGLOCK_LOCKDEP(name)
|
|
#endif
|
|
|
|
struct lglock {
|
|
arch_spinlock_t __percpu *lock;
|
|
#ifdef CONFIG_DEBUG_LOCK_ALLOC
|
|
struct lock_class_key lock_key;
|
|
struct lockdep_map lock_dep_map;
|
|
#endif
|
|
};
|
|
|
|
#define DEFINE_LGLOCK(name) \
|
|
DEFINE_LGLOCK_LOCKDEP(name); \
|
|
DEFINE_PER_CPU(arch_spinlock_t, name ## _lock) \
|
|
= __ARCH_SPIN_LOCK_UNLOCKED; \
|
|
struct lglock name = { .lock = &name ## _lock }
|
|
|
|
void lg_lock_init(struct lglock *lg, char *name);
|
|
void lg_local_lock(struct lglock *lg);
|
|
void lg_local_unlock(struct lglock *lg);
|
|
void lg_local_lock_cpu(struct lglock *lg, int cpu);
|
|
void lg_local_unlock_cpu(struct lglock *lg, int cpu);
|
|
void lg_global_lock(struct lglock *lg);
|
|
void lg_global_unlock(struct lglock *lg);
|
|
|
|
#endif
|