Skip to content

Commit

Permalink
IB: convert from semaphores to mutexes
Browse files Browse the repository at this point in the history
semaphore to mutex conversion by Ingo and Arjan's script.

Signed-off-by: Ingo Molnar <mingo@elte.hu>
[ Sanity-checked on real IB hardware ]
Signed-off-by: Roland Dreier <rolandd@cisco.com>
  • Loading branch information
Ingo Molnar authored and Roland Dreier committed Jan 13, 2006
1 parent 9eacee2 commit 95ed644
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 144 deletions.
23 changes: 11 additions & 12 deletions drivers/infiniband/core/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
#include <linux/errno.h>
#include <linux/slab.h>
#include <linux/init.h>

#include <asm/semaphore.h>
#include <linux/mutex.h>

#include "core_priv.h"

Expand All @@ -57,13 +56,13 @@ static LIST_HEAD(device_list);
static LIST_HEAD(client_list);

/*
* device_sem protects access to both device_list and client_list.
* device_mutex protects access to both device_list and client_list.
* There's no real point to using multiple locks or something fancier
* like an rwsem: we always access both lists, and we're always
* modifying one list or the other list. In any case this is not a
* hot path so there's no point in trying to optimize.
*/
static DECLARE_MUTEX(device_sem);
static DEFINE_MUTEX(device_mutex);

static int ib_device_check_mandatory(struct ib_device *device)
{
Expand Down Expand Up @@ -221,7 +220,7 @@ int ib_register_device(struct ib_device *device)
{
int ret;

down(&device_sem);
mutex_lock(&device_mutex);

if (strchr(device->name, '%')) {
ret = alloc_name(device->name);
Expand Down Expand Up @@ -259,7 +258,7 @@ int ib_register_device(struct ib_device *device)
}

out:
up(&device_sem);
mutex_unlock(&device_mutex);
return ret;
}
EXPORT_SYMBOL(ib_register_device);
Expand All @@ -276,15 +275,15 @@ void ib_unregister_device(struct ib_device *device)
struct ib_client_data *context, *tmp;
unsigned long flags;

down(&device_sem);
mutex_lock(&device_mutex);

list_for_each_entry_reverse(client, &client_list, list)
if (client->remove)
client->remove(device);

list_del(&device->core_list);

up(&device_sem);
mutex_unlock(&device_mutex);

spin_lock_irqsave(&device->client_data_lock, flags);
list_for_each_entry_safe(context, tmp, &device->client_data_list, list)
Expand Down Expand Up @@ -312,14 +311,14 @@ int ib_register_client(struct ib_client *client)
{
struct ib_device *device;

down(&device_sem);
mutex_lock(&device_mutex);

list_add_tail(&client->list, &client_list);
list_for_each_entry(device, &device_list, core_list)
if (client->add && !add_client_context(device, client))
client->add(device);

up(&device_sem);
mutex_unlock(&device_mutex);

return 0;
}
Expand All @@ -339,7 +338,7 @@ void ib_unregister_client(struct ib_client *client)
struct ib_device *device;
unsigned long flags;

down(&device_sem);
mutex_lock(&device_mutex);

list_for_each_entry(device, &device_list, core_list) {
if (client->remove)
Expand All @@ -355,7 +354,7 @@ void ib_unregister_client(struct ib_client *client)
}
list_del(&client->list);

up(&device_sem);
mutex_unlock(&device_mutex);
}
EXPORT_SYMBOL(ib_unregister_client);

Expand Down
23 changes: 12 additions & 11 deletions drivers/infiniband/core/ucm.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <linux/mount.h>
#include <linux/cdev.h>
#include <linux/idr.h>
#include <linux/mutex.h>

#include <asm/uaccess.h>

Expand Down Expand Up @@ -113,23 +114,23 @@ static struct ib_client ucm_client = {
.remove = ib_ucm_remove_one
};

static DECLARE_MUTEX(ctx_id_mutex);
static DEFINE_MUTEX(ctx_id_mutex);
static DEFINE_IDR(ctx_id_table);
static DECLARE_BITMAP(dev_map, IB_UCM_MAX_DEVICES);

static struct ib_ucm_context *ib_ucm_ctx_get(struct ib_ucm_file *file, int id)
{
struct ib_ucm_context *ctx;

down(&ctx_id_mutex);
mutex_lock(&ctx_id_mutex);
ctx = idr_find(&ctx_id_table, id);
if (!ctx)
ctx = ERR_PTR(-ENOENT);
else if (ctx->file != file)
ctx = ERR_PTR(-EINVAL);
else
atomic_inc(&ctx->ref);
up(&ctx_id_mutex);
mutex_unlock(&ctx_id_mutex);

return ctx;
}
Expand Down Expand Up @@ -186,9 +187,9 @@ static struct ib_ucm_context *ib_ucm_ctx_alloc(struct ib_ucm_file *file)
if (!result)
goto error;

down(&ctx_id_mutex);
mutex_lock(&ctx_id_mutex);
result = idr_get_new(&ctx_id_table, ctx, &ctx->id);
up(&ctx_id_mutex);
mutex_unlock(&ctx_id_mutex);
} while (result == -EAGAIN);

if (result)
Expand Down Expand Up @@ -550,9 +551,9 @@ static ssize_t ib_ucm_create_id(struct ib_ucm_file *file,
err2:
ib_destroy_cm_id(ctx->cm_id);
err1:
down(&ctx_id_mutex);
mutex_lock(&ctx_id_mutex);
idr_remove(&ctx_id_table, ctx->id);
up(&ctx_id_mutex);
mutex_unlock(&ctx_id_mutex);
kfree(ctx);
return result;
}
Expand All @@ -572,15 +573,15 @@ static ssize_t ib_ucm_destroy_id(struct ib_ucm_file *file,
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
return -EFAULT;

down(&ctx_id_mutex);
mutex_lock(&ctx_id_mutex);
ctx = idr_find(&ctx_id_table, cmd.id);
if (!ctx)
ctx = ERR_PTR(-ENOENT);
else if (ctx->file != file)
ctx = ERR_PTR(-EINVAL);
else
idr_remove(&ctx_id_table, ctx->id);
up(&ctx_id_mutex);
mutex_unlock(&ctx_id_mutex);

if (IS_ERR(ctx))
return PTR_ERR(ctx);
Expand Down Expand Up @@ -1280,9 +1281,9 @@ static int ib_ucm_close(struct inode *inode, struct file *filp)
struct ib_ucm_context, file_list);
up(&file->mutex);

down(&ctx_id_mutex);
mutex_lock(&ctx_id_mutex);
idr_remove(&ctx_id_table, ctx->id);
up(&ctx_id_mutex);
mutex_unlock(&ctx_id_mutex);

ib_destroy_cm_id(ctx->cm_id);
ib_ucm_cleanup_events(ctx);
Expand Down
5 changes: 3 additions & 2 deletions drivers/infiniband/core/uverbs.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

#include <linux/kref.h>
#include <linux/idr.h>
#include <linux/mutex.h>

#include <rdma/ib_verbs.h>
#include <rdma/ib_user_verbs.h>
Expand Down Expand Up @@ -88,7 +89,7 @@ struct ib_uverbs_event_file {

struct ib_uverbs_file {
struct kref ref;
struct semaphore mutex;
struct mutex mutex;
struct ib_uverbs_device *device;
struct ib_ucontext *ucontext;
struct ib_event_handler event_handler;
Expand Down Expand Up @@ -131,7 +132,7 @@ struct ib_ucq_object {
u32 async_events_reported;
};

extern struct semaphore ib_uverbs_idr_mutex;
extern struct mutex ib_uverbs_idr_mutex;
extern struct idr ib_uverbs_pd_idr;
extern struct idr ib_uverbs_mr_idr;
extern struct idr ib_uverbs_mw_idr;
Expand Down
Loading

0 comments on commit 95ed644

Please sign in to comment.