[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] Use shiny new mutexes instead of semaphores where possible in our Linux code.



# HG changeset patch
# User kaf24@xxxxxxxxxxxxxxxxxxxx
# Node ID b8cc4df90187d98b358e029c542d9c7a54a523e3
# Parent  a07e25890329e6255cbdd9d66b6e32525c74811f
Use shiny new mutexes instead of semaphores where possible in our Linux code.

Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>

diff -r a07e25890329 -r b8cc4df90187 
linux-2.6-xen-sparse/drivers/xen/core/reboot.c
--- a/linux-2.6-xen-sparse/drivers/xen/core/reboot.c    Wed Mar 22 10:30:57 2006
+++ b/linux-2.6-xen-sparse/drivers/xen/core/reboot.c    Wed Mar 22 10:55:43 2006
@@ -122,7 +122,7 @@
        lock_cpu_hotplug();
 #ifdef CONFIG_SMP
        /*
-        * Take all other CPUs offline. We hold the hotplug semaphore to
+        * Take all other CPUs offline. We hold the hotplug mutex to
         * avoid other processes bringing up CPUs under our feet.
         */
        cpus_clear(prev_online_cpus);
diff -r a07e25890329 -r b8cc4df90187 
linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c
--- a/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c      Wed Mar 22 
10:30:57 2006
+++ b/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c      Wed Mar 22 
10:55:43 2006
@@ -43,8 +43,7 @@
 #include <linux/init.h>
 #include <xen/tpmfe.h>
 #include <linux/err.h>
-
-#include <asm/semaphore.h>
+#include <linux/mutex.h>
 #include <asm/io.h>
 #include <xen/evtchn.h>
 #include <xen/interface/grant_table.h>
@@ -153,8 +152,8 @@
 
 **************************************************************/
 
-static DECLARE_MUTEX(upperlayer_lock);
-static DECLARE_MUTEX(suspend_lock);
+static DEFINE_MUTEX(upperlayer_lock);
+static DEFINE_MUTEX(suspend_lock);
 static struct tpmfe_device *upperlayer_tpmfe;
 
 /*
@@ -164,9 +163,9 @@
 {
        int sent;
 
-       down(&suspend_lock);
+       mutex_lock(&suspend_lock);
        sent = tpm_xmit(tp, buf, count, 0, ptr);
-       up(&suspend_lock);
+       mutex_unlock(&suspend_lock);
 
        return sent;
 }
@@ -179,7 +178,7 @@
 {
        int rc = 0;
 
-       down(&upperlayer_lock);
+       mutex_lock(&upperlayer_lock);
        if (NULL == upperlayer_tpmfe) {
                upperlayer_tpmfe = tpmfe_dev;
                tpmfe_dev->max_tx_size = TPMIF_TX_RING_SIZE * PAGE_SIZE;
@@ -190,7 +189,7 @@
        } else {
                rc = -EBUSY;
        }
-       up(&upperlayer_lock);
+       mutex_unlock(&upperlayer_lock);
        return rc;
 }
 EXPORT_SYMBOL(tpm_fe_register_receiver);
@@ -200,9 +199,9 @@
  */
 void tpm_fe_unregister_receiver(void)
 {
-       down(&upperlayer_lock);
+       mutex_lock(&upperlayer_lock);
        upperlayer_tpmfe = NULL;
-       up(&upperlayer_lock);
+       mutex_unlock(&upperlayer_lock);
 }
 EXPORT_SYMBOL(tpm_fe_unregister_receiver);
 
@@ -215,12 +214,12 @@
 {
        int rc = 0;
 
-       down(&upperlayer_lock);
+       mutex_lock(&upperlayer_lock);
 
        if (upperlayer_tpmfe && upperlayer_tpmfe->receive)
                rc = upperlayer_tpmfe->receive(buf, count, ptr);
 
-       up(&upperlayer_lock);
+       mutex_unlock(&upperlayer_lock);
        return rc;
 }
 
@@ -415,7 +414,7 @@
        u32 ctr;
 
        /* lock, so no app can send */
-       down(&suspend_lock);
+       mutex_lock(&suspend_lock);
        tp->is_suspended = 1;
 
        for (ctr = 0; atomic_read(&tp->tx_busy) && ctr <= 25; ctr++) {
@@ -647,7 +646,7 @@
         * Notify upper layer about the state of the connection
         * to the BE.
         */
-       down(&upperlayer_lock);
+       mutex_lock(&upperlayer_lock);
 
        if (upperlayer_tpmfe != NULL) {
                if (tp->is_connected) {
@@ -656,7 +655,7 @@
                        upperlayer_tpmfe->status(0);
                }
        }
-       up(&upperlayer_lock);
+       mutex_unlock(&upperlayer_lock);
 }
 
 
@@ -665,21 +664,21 @@
        /*
         * Don't notify upper layer if we are in suspend mode and
         * should disconnect - assumption is that we will resume
-        * The semaphore keeps apps from sending.
+        * The mutex keeps apps from sending.
         */
        if (is_connected == 0 && tp->is_suspended == 1) {
                return;
        }
 
        /*
-        * Unlock the semaphore if we are connected again
+        * Unlock the mutex if we are connected again
         * after being suspended - now resuming.
         * This also removes the suspend state.
         */
        if (is_connected == 1 && tp->is_suspended == 1) {
                tp->is_suspended = 0;
                /* unlock, so apps can resume sending */
-               up(&suspend_lock);
+               mutex_unlock(&suspend_lock);
        }
 
        if (is_connected != tp->is_connected) {
diff -r a07e25890329 -r b8cc4df90187 
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c
--- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c    Wed Mar 22 
10:30:57 2006
+++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c    Wed Mar 22 
10:55:43 2006
@@ -52,7 +52,7 @@
 
 #include "xenbus_comms.h"
 
-extern struct semaphore xenwatch_mutex;
+extern struct mutex xenwatch_mutex;
 
 #define streq(a, b) (strcmp((a), (b)) == 0)
 
@@ -399,9 +399,9 @@
        drv->driver.probe = xenbus_dev_probe;
        drv->driver.remove = xenbus_dev_remove;
 
-       down(&xenwatch_mutex);
+       mutex_lock(&xenwatch_mutex);
        ret = driver_register(&drv->driver);
-       up(&xenwatch_mutex);
+       mutex_unlock(&xenwatch_mutex);
        return ret;
 }
 
diff -r a07e25890329 -r b8cc4df90187 
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c
--- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c       Wed Mar 22 
10:30:57 2006
+++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c       Wed Mar 22 
10:55:43 2006
@@ -41,6 +41,7 @@
 #include <linux/slab.h>
 #include <linux/fcntl.h>
 #include <linux/kthread.h>
+#include <linux/rwsem.h>
 #include <xen/xenbus.h>
 #include "xenbus_comms.h"
 
@@ -76,7 +77,7 @@
        wait_queue_head_t reply_waitq;
 
        /* One request at a time. */
-       struct semaphore request_mutex;
+       struct mutex request_mutex;
 
        /* Protect transactions against save/restore. */
        struct rw_semaphore suspend_mutex;
@@ -99,7 +100,7 @@
  * carrying out work.
  */
 static pid_t xenwatch_pid;
-/* static */ DECLARE_MUTEX(xenwatch_mutex);
+/* static */ DEFINE_MUTEX(xenwatch_mutex);
 static DECLARE_WAIT_QUEUE_HEAD(watch_events_waitq);
 
 static int get_error(const char *errorstring)
@@ -156,12 +157,12 @@
        msg.type = XS_DEBUG;
        msg.len = sizeof("print") + count + 1;
 
-       down(&xs_state.request_mutex);
+       mutex_lock(&xs_state.request_mutex);
        xb_write(&msg, sizeof(msg));
        xb_write("print", sizeof("print"));
        xb_write(str, count);
        xb_write("", 1);
-       up(&xs_state.request_mutex);
+       mutex_unlock(&xs_state.request_mutex);
 }
 
 void *xenbus_dev_request_and_reply(struct xsd_sockmsg *msg)
@@ -173,7 +174,7 @@
        if (req_msg.type == XS_TRANSACTION_START)
                down_read(&xs_state.suspend_mutex);
 
-       down(&xs_state.request_mutex);
+       mutex_lock(&xs_state.request_mutex);
 
        err = xb_write(msg, sizeof(*msg) + msg->len);
        if (err) {
@@ -182,7 +183,7 @@
        } else
                ret = read_reply(&msg->type, &msg->len);
 
-       up(&xs_state.request_mutex);
+       mutex_unlock(&xs_state.request_mutex);
 
        if ((msg->type == XS_TRANSACTION_END) ||
            ((req_msg.type == XS_TRANSACTION_START) &&
@@ -211,25 +212,25 @@
        for (i = 0; i < num_vecs; i++)
                msg.len += iovec[i].iov_len;
 
-       down(&xs_state.request_mutex);
+       mutex_lock(&xs_state.request_mutex);
 
        err = xb_write(&msg, sizeof(msg));
        if (err) {
-               up(&xs_state.request_mutex);
+               mutex_unlock(&xs_state.request_mutex);
                return ERR_PTR(err);
        }
 
        for (i = 0; i < num_vecs; i++) {
                err = xb_write(iovec[i].iov_base, iovec[i].iov_len);;
                if (err) {
-                       up(&xs_state.request_mutex);
+                       mutex_unlock(&xs_state.request_mutex);
                        return ERR_PTR(err);
                }
        }
 
        ret = read_reply(&msg.type, len);
 
-       up(&xs_state.request_mutex);
+       mutex_unlock(&xs_state.request_mutex);
 
        if (IS_ERR(ret))
                return ret;
@@ -658,8 +659,8 @@
 
        /* Flush any currently-executing callback, unless we are it. :-) */
        if (current->pid != xenwatch_pid) {
-               down(&xenwatch_mutex);
-               up(&xenwatch_mutex);
+               mutex_lock(&xenwatch_mutex);
+               mutex_unlock(&xenwatch_mutex);
        }
 }
 EXPORT_SYMBOL_GPL(unregister_xenbus_watch);
@@ -667,7 +668,7 @@
 void xs_suspend(void)
 {
        down_write(&xs_state.suspend_mutex);
-       down(&xs_state.request_mutex);
+       mutex_lock(&xs_state.request_mutex);
 }
 
 void xs_resume(void)
@@ -675,7 +676,7 @@
        struct xenbus_watch *watch;
        char token[sizeof(watch) * 2 + 1];
 
-       up(&xs_state.request_mutex);
+       mutex_unlock(&xs_state.request_mutex);
 
        /* No need for watches_lock: the suspend_mutex is sufficient. */
        list_for_each_entry(watch, &watches, list) {
@@ -698,7 +699,7 @@
                if (kthread_should_stop())
                        break;
 
-               down(&xenwatch_mutex);
+               mutex_lock(&xenwatch_mutex);
 
                spin_lock(&watch_events_lock);
                ent = watch_events.next;
@@ -716,7 +717,7 @@
                        kfree(msg);
                }
 
-               up(&xenwatch_mutex);
+               mutex_unlock(&xenwatch_mutex);
        }
 
        return 0;
@@ -809,7 +810,7 @@
        spin_lock_init(&xs_state.reply_lock);
        init_waitqueue_head(&xs_state.reply_waitq);
 
-       init_MUTEX(&xs_state.request_mutex);
+       mutex_init(&xs_state.request_mutex);
        init_rwsem(&xs_state.suspend_mutex);
 
        /* Initialize the shared memory rings to talk to xenstored */
diff -r a07e25890329 -r b8cc4df90187 linux-2.6-xen-sparse/include/xen/xenbus.h
--- a/linux-2.6-xen-sparse/include/xen/xenbus.h Wed Mar 22 10:30:57 2006
+++ b/linux-2.6-xen-sparse/include/xen/xenbus.h Wed Mar 22 10:55:43 2006
@@ -36,7 +36,7 @@
 
 #include <linux/device.h>
 #include <linux/notifier.h>
-#include <asm/semaphore.h>
+#include <linux/mutex.h>
 #include <xen/interface/xen.h>
 #include <xen/interface/grant_table.h>
 #include <xen/interface/io/xenbus.h>

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.