Commit 48380368 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Luis Chamberlain

Change DEFINE_SEMAPHORE() to take a number argument

Fundamentally semaphores are a counted primitive, but
DEFINE_SEMAPHORE() does not expose this and explicitly creates a
binary semaphore.

Change DEFINE_SEMAPHORE() to take a number argument and use that in the
few places that open-coded it using __SEMAPHORE_INITIALIZER().
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
[mcgrof: add some tribal knowledge about why some folks prefer
 binary sempahores over mutexes]
Reviewed-by: default avatarSergey Senozhatsky <senozhatsky@chromium.org>
Reviewed-by: default avatarDavidlohr Bueso <dave@stgolabs.net>
Signed-off-by: default avatarLuis Chamberlain <mcgrof@kernel.org>
parent 430bb0d1
...@@ -72,7 +72,7 @@ extern void pci_console_init(const char *arg); ...@@ -72,7 +72,7 @@ extern void pci_console_init(const char *arg);
static unsigned long long max_memory = ULLONG_MAX; static unsigned long long max_memory = ULLONG_MAX;
static unsigned long long reserve_low_mem; static unsigned long long reserve_low_mem;
DEFINE_SEMAPHORE(octeon_bootbus_sem); DEFINE_SEMAPHORE(octeon_bootbus_sem, 1);
EXPORT_SYMBOL(octeon_bootbus_sem); EXPORT_SYMBOL(octeon_bootbus_sem);
static struct octeon_boot_descriptor *octeon_boot_desc_ptr; static struct octeon_boot_descriptor *octeon_boot_desc_ptr;
......
...@@ -1177,7 +1177,7 @@ static const struct { ...@@ -1177,7 +1177,7 @@ static const struct {
static struct ratelimit_state bld_ratelimit; static struct ratelimit_state bld_ratelimit;
static unsigned int sysctl_sld_mitigate = 1; static unsigned int sysctl_sld_mitigate = 1;
static DEFINE_SEMAPHORE(buslock_sem); static DEFINE_SEMAPHORE(buslock_sem, 1);
#ifdef CONFIG_PROC_SYSCTL #ifdef CONFIG_PROC_SYSCTL
static struct ctl_table sld_sysctls[] = { static struct ctl_table sld_sysctls[] = {
......
...@@ -158,7 +158,7 @@ void efi_call_virt_check_flags(unsigned long flags, const char *call) ...@@ -158,7 +158,7 @@ void efi_call_virt_check_flags(unsigned long flags, const char *call)
* none of the remaining functions are actually ever called at runtime. * none of the remaining functions are actually ever called at runtime.
* So let's just use a single lock to serialize all Runtime Services calls. * So let's just use a single lock to serialize all Runtime Services calls.
*/ */
static DEFINE_SEMAPHORE(efi_runtime_lock); static DEFINE_SEMAPHORE(efi_runtime_lock, 1);
/* /*
* Expose the EFI runtime lock to the UV platform * Expose the EFI runtime lock to the UV platform
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
/* Private pointer to registered efivars */ /* Private pointer to registered efivars */
static struct efivars *__efivars; static struct efivars *__efivars;
static DEFINE_SEMAPHORE(efivars_lock); static DEFINE_SEMAPHORE(efivars_lock, 1);
static efi_status_t check_var_size(bool nonblocking, u32 attributes, static efi_status_t check_var_size(bool nonblocking, u32 attributes,
unsigned long size) unsigned long size)
......
...@@ -80,7 +80,7 @@ static struct adb_driver *adb_controller; ...@@ -80,7 +80,7 @@ static struct adb_driver *adb_controller;
BLOCKING_NOTIFIER_HEAD(adb_client_list); BLOCKING_NOTIFIER_HEAD(adb_client_list);
static int adb_got_sleep; static int adb_got_sleep;
static int adb_inited; static int adb_inited;
static DEFINE_SEMAPHORE(adb_probe_mutex); static DEFINE_SEMAPHORE(adb_probe_mutex, 1);
static int sleepy_trackpad; static int sleepy_trackpad;
static int autopoll_devs; static int autopoll_devs;
int __adb_probe_sync; int __adb_probe_sync;
......
...@@ -298,7 +298,7 @@ const u32 dmae_reg_go_c[] = { ...@@ -298,7 +298,7 @@ const u32 dmae_reg_go_c[] = {
/* Global resources for unloading a previously loaded device */ /* Global resources for unloading a previously loaded device */
#define BNX2X_PREV_WAIT_NEEDED 1 #define BNX2X_PREV_WAIT_NEEDED 1
static DEFINE_SEMAPHORE(bnx2x_prev_sem); static DEFINE_SEMAPHORE(bnx2x_prev_sem, 1);
static LIST_HEAD(bnx2x_prev_list); static LIST_HEAD(bnx2x_prev_list);
/* Forward declaration */ /* Forward declaration */
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* Protects against simultaneous tests on multiple cores, or * Protects against simultaneous tests on multiple cores, or
* reloading can file while a test is in progress * reloading can file while a test is in progress
*/ */
static DEFINE_SEMAPHORE(ifs_sem); static DEFINE_SEMAPHORE(ifs_sem, 1);
/* /*
* The sysfs interface to check additional details of last test * The sysfs interface to check additional details of last test
......
...@@ -56,7 +56,7 @@ dma_addr_t esas2r_buffered_ioctl_addr; ...@@ -56,7 +56,7 @@ dma_addr_t esas2r_buffered_ioctl_addr;
u32 esas2r_buffered_ioctl_size; u32 esas2r_buffered_ioctl_size;
struct pci_dev *esas2r_buffered_ioctl_pcid; struct pci_dev *esas2r_buffered_ioctl_pcid;
static DEFINE_SEMAPHORE(buffered_ioctl_semaphore); static DEFINE_SEMAPHORE(buffered_ioctl_semaphore, 1);
typedef int (*BUFFERED_IOCTL_CALLBACK)(struct esas2r_adapter *, typedef int (*BUFFERED_IOCTL_CALLBACK)(struct esas2r_adapter *,
struct esas2r_request *, struct esas2r_request *,
struct esas2r_sg_context *, struct esas2r_sg_context *,
......
...@@ -149,7 +149,7 @@ static char *g_fragments_base; ...@@ -149,7 +149,7 @@ static char *g_fragments_base;
static char *g_free_fragments; static char *g_free_fragments;
static struct semaphore g_free_fragments_sema; static struct semaphore g_free_fragments_sema;
static DEFINE_SEMAPHORE(g_free_fragments_mutex); static DEFINE_SEMAPHORE(g_free_fragments_mutex, 1);
static int static int
vchiq_blocking_bulk_transfer(struct vchiq_instance *instance, unsigned int handle, void *data, vchiq_blocking_bulk_transfer(struct vchiq_instance *instance, unsigned int handle, void *data,
......
...@@ -25,8 +25,14 @@ struct semaphore { ...@@ -25,8 +25,14 @@ struct semaphore {
.wait_list = LIST_HEAD_INIT((name).wait_list), \ .wait_list = LIST_HEAD_INIT((name).wait_list), \
} }
#define DEFINE_SEMAPHORE(name) \ /*
struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1) * Unlike mutexes, binary semaphores do not have an owner, so up() can
* be called in a different thread from the one which called down().
* It is also safe to call down_trylock() and up() from interrupt
* context.
*/
#define DEFINE_SEMAPHORE(_name, _n) \
struct semaphore _name = __SEMAPHORE_INITIALIZER(_name, _n)
static inline void sema_init(struct semaphore *sem, int val) static inline void sema_init(struct semaphore *sem, int val)
{ {
......
...@@ -89,7 +89,7 @@ static DEFINE_MUTEX(console_mutex); ...@@ -89,7 +89,7 @@ static DEFINE_MUTEX(console_mutex);
* console_sem protects updates to console->seq and console_suspended, * console_sem protects updates to console->seq and console_suspended,
* and also provides serialization for console printing. * and also provides serialization for console printing.
*/ */
static DEFINE_SEMAPHORE(console_sem); static DEFINE_SEMAPHORE(console_sem, 1);
HLIST_HEAD(console_list); HLIST_HEAD(console_list);
EXPORT_SYMBOL_GPL(console_list); EXPORT_SYMBOL_GPL(console_list);
DEFINE_STATIC_SRCU(console_srcu); DEFINE_STATIC_SRCU(console_srcu);
......
...@@ -40,10 +40,8 @@ const char *const rxrpc_call_completions[NR__RXRPC_CALL_COMPLETIONS] = { ...@@ -40,10 +40,8 @@ const char *const rxrpc_call_completions[NR__RXRPC_CALL_COMPLETIONS] = {
struct kmem_cache *rxrpc_call_jar; struct kmem_cache *rxrpc_call_jar;
static struct semaphore rxrpc_call_limiter = static DEFINE_SEMAPHORE(rxrpc_call_limiter, 1000);
__SEMAPHORE_INITIALIZER(rxrpc_call_limiter, 1000); static DEFINE_SEMAPHORE(rxrpc_kernel_call_limiter, 1000);
static struct semaphore rxrpc_kernel_call_limiter =
__SEMAPHORE_INITIALIZER(rxrpc_kernel_call_limiter, 1000);
void rxrpc_poke_call(struct rxrpc_call *call, enum rxrpc_call_poke_trace what) void rxrpc_poke_call(struct rxrpc_call *call, enum rxrpc_call_poke_trace what)
{ {
......
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