ia64/xen-unstable

changeset 9387:b8cc4df90187

Use shiny new mutexes instead of semaphores where possible in our Linux code.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Wed Mar 22 11:55:43 2006 +0100 (2006-03-22)
parents a07e25890329
children ecb99d1ce57d
files linux-2.6-xen-sparse/drivers/xen/core/reboot.c linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c linux-2.6-xen-sparse/include/xen/xenbus.h
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/core/reboot.c	Wed Mar 22 11:30:57 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/core/reboot.c	Wed Mar 22 11:55:43 2006 +0100
     1.3 @@ -122,7 +122,7 @@ static int __do_suspend(void *ignore)
     1.4  	lock_cpu_hotplug();
     1.5  #ifdef CONFIG_SMP
     1.6  	/*
     1.7 -	 * Take all other CPUs offline. We hold the hotplug semaphore to
     1.8 +	 * Take all other CPUs offline. We hold the hotplug mutex to
     1.9  	 * avoid other processes bringing up CPUs under our feet.
    1.10  	 */
    1.11  	cpus_clear(prev_online_cpus);
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c	Wed Mar 22 11:30:57 2006 +0100
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c	Wed Mar 22 11:55:43 2006 +0100
     2.3 @@ -43,8 +43,7 @@
     2.4  #include <linux/init.h>
     2.5  #include <xen/tpmfe.h>
     2.6  #include <linux/err.h>
     2.7 -
     2.8 -#include <asm/semaphore.h>
     2.9 +#include <linux/mutex.h>
    2.10  #include <asm/io.h>
    2.11  #include <xen/evtchn.h>
    2.12  #include <xen/interface/grant_table.h>
    2.13 @@ -153,8 +152,8 @@ static inline void tpm_private_free(void
    2.14  
    2.15  **************************************************************/
    2.16  
    2.17 -static DECLARE_MUTEX(upperlayer_lock);
    2.18 -static DECLARE_MUTEX(suspend_lock);
    2.19 +static DEFINE_MUTEX(upperlayer_lock);
    2.20 +static DEFINE_MUTEX(suspend_lock);
    2.21  static struct tpmfe_device *upperlayer_tpmfe;
    2.22  
    2.23  /*
    2.24 @@ -164,9 +163,9 @@ int tpm_fe_send(struct tpm_private *tp, 
    2.25  {
    2.26  	int sent;
    2.27  
    2.28 -	down(&suspend_lock);
    2.29 +	mutex_lock(&suspend_lock);
    2.30  	sent = tpm_xmit(tp, buf, count, 0, ptr);
    2.31 -	up(&suspend_lock);
    2.32 +	mutex_unlock(&suspend_lock);
    2.33  
    2.34  	return sent;
    2.35  }
    2.36 @@ -179,7 +178,7 @@ int tpm_fe_register_receiver(struct tpmf
    2.37  {
    2.38  	int rc = 0;
    2.39  
    2.40 -	down(&upperlayer_lock);
    2.41 +	mutex_lock(&upperlayer_lock);
    2.42  	if (NULL == upperlayer_tpmfe) {
    2.43  		upperlayer_tpmfe = tpmfe_dev;
    2.44  		tpmfe_dev->max_tx_size = TPMIF_TX_RING_SIZE * PAGE_SIZE;
    2.45 @@ -190,7 +189,7 @@ int tpm_fe_register_receiver(struct tpmf
    2.46  	} else {
    2.47  		rc = -EBUSY;
    2.48  	}
    2.49 -	up(&upperlayer_lock);
    2.50 +	mutex_unlock(&upperlayer_lock);
    2.51  	return rc;
    2.52  }
    2.53  EXPORT_SYMBOL(tpm_fe_register_receiver);
    2.54 @@ -200,9 +199,9 @@ EXPORT_SYMBOL(tpm_fe_register_receiver);
    2.55   */
    2.56  void tpm_fe_unregister_receiver(void)
    2.57  {
    2.58 -	down(&upperlayer_lock);
    2.59 +	mutex_lock(&upperlayer_lock);
    2.60  	upperlayer_tpmfe = NULL;
    2.61 -	up(&upperlayer_lock);
    2.62 +	mutex_unlock(&upperlayer_lock);
    2.63  }
    2.64  EXPORT_SYMBOL(tpm_fe_unregister_receiver);
    2.65  
    2.66 @@ -215,12 +214,12 @@ static int tpm_fe_send_upperlayer(const 
    2.67  {
    2.68  	int rc = 0;
    2.69  
    2.70 -	down(&upperlayer_lock);
    2.71 +	mutex_lock(&upperlayer_lock);
    2.72  
    2.73  	if (upperlayer_tpmfe && upperlayer_tpmfe->receive)
    2.74  		rc = upperlayer_tpmfe->receive(buf, count, ptr);
    2.75  
    2.76 -	up(&upperlayer_lock);
    2.77 +	mutex_unlock(&upperlayer_lock);
    2.78  	return rc;
    2.79  }
    2.80  
    2.81 @@ -415,7 +414,7 @@ tpmfront_suspend(struct xenbus_device *d
    2.82  	u32 ctr;
    2.83  
    2.84  	/* lock, so no app can send */
    2.85 -	down(&suspend_lock);
    2.86 +	mutex_lock(&suspend_lock);
    2.87  	tp->is_suspended = 1;
    2.88  
    2.89  	for (ctr = 0; atomic_read(&tp->tx_busy) && ctr <= 25; ctr++) {
    2.90 @@ -647,7 +646,7 @@ static void tpmif_notify_upperlayer(stru
    2.91  	 * Notify upper layer about the state of the connection
    2.92  	 * to the BE.
    2.93  	 */
    2.94 -	down(&upperlayer_lock);
    2.95 +	mutex_lock(&upperlayer_lock);
    2.96  
    2.97  	if (upperlayer_tpmfe != NULL) {
    2.98  		if (tp->is_connected) {
    2.99 @@ -656,7 +655,7 @@ static void tpmif_notify_upperlayer(stru
   2.100  			upperlayer_tpmfe->status(0);
   2.101  		}
   2.102  	}
   2.103 -	up(&upperlayer_lock);
   2.104 +	mutex_unlock(&upperlayer_lock);
   2.105  }
   2.106  
   2.107  
   2.108 @@ -665,21 +664,21 @@ static void tpmif_set_connected_state(st
   2.109  	/*
   2.110  	 * Don't notify upper layer if we are in suspend mode and
   2.111  	 * should disconnect - assumption is that we will resume
   2.112 -	 * The semaphore keeps apps from sending.
   2.113 +	 * The mutex keeps apps from sending.
   2.114  	 */
   2.115  	if (is_connected == 0 && tp->is_suspended == 1) {
   2.116  		return;
   2.117  	}
   2.118  
   2.119  	/*
   2.120 -	 * Unlock the semaphore if we are connected again
   2.121 +	 * Unlock the mutex if we are connected again
   2.122  	 * after being suspended - now resuming.
   2.123  	 * This also removes the suspend state.
   2.124  	 */
   2.125  	if (is_connected == 1 && tp->is_suspended == 1) {
   2.126  		tp->is_suspended = 0;
   2.127  		/* unlock, so apps can resume sending */
   2.128 -		up(&suspend_lock);
   2.129 +		mutex_unlock(&suspend_lock);
   2.130  	}
   2.131  
   2.132  	if (is_connected != tp->is_connected) {
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Wed Mar 22 11:30:57 2006 +0100
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Wed Mar 22 11:55:43 2006 +0100
     3.3 @@ -52,7 +52,7 @@
     3.4  
     3.5  #include "xenbus_comms.h"
     3.6  
     3.7 -extern struct semaphore xenwatch_mutex;
     3.8 +extern struct mutex xenwatch_mutex;
     3.9  
    3.10  #define streq(a, b) (strcmp((a), (b)) == 0)
    3.11  
    3.12 @@ -399,9 +399,9 @@ static int xenbus_register_driver_common
    3.13  	drv->driver.probe = xenbus_dev_probe;
    3.14  	drv->driver.remove = xenbus_dev_remove;
    3.15  
    3.16 -	down(&xenwatch_mutex);
    3.17 +	mutex_lock(&xenwatch_mutex);
    3.18  	ret = driver_register(&drv->driver);
    3.19 -	up(&xenwatch_mutex);
    3.20 +	mutex_unlock(&xenwatch_mutex);
    3.21  	return ret;
    3.22  }
    3.23  
     4.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Wed Mar 22 11:30:57 2006 +0100
     4.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Wed Mar 22 11:55:43 2006 +0100
     4.3 @@ -41,6 +41,7 @@
     4.4  #include <linux/slab.h>
     4.5  #include <linux/fcntl.h>
     4.6  #include <linux/kthread.h>
     4.7 +#include <linux/rwsem.h>
     4.8  #include <xen/xenbus.h>
     4.9  #include "xenbus_comms.h"
    4.10  
    4.11 @@ -76,7 +77,7 @@ struct xs_handle {
    4.12  	wait_queue_head_t reply_waitq;
    4.13  
    4.14  	/* One request at a time. */
    4.15 -	struct semaphore request_mutex;
    4.16 +	struct mutex request_mutex;
    4.17  
    4.18  	/* Protect transactions against save/restore. */
    4.19  	struct rw_semaphore suspend_mutex;
    4.20 @@ -99,7 +100,7 @@ static DEFINE_SPINLOCK(watch_events_lock
    4.21   * carrying out work.
    4.22   */
    4.23  static pid_t xenwatch_pid;
    4.24 -/* static */ DECLARE_MUTEX(xenwatch_mutex);
    4.25 +/* static */ DEFINE_MUTEX(xenwatch_mutex);
    4.26  static DECLARE_WAIT_QUEUE_HEAD(watch_events_waitq);
    4.27  
    4.28  static int get_error(const char *errorstring)
    4.29 @@ -156,12 +157,12 @@ void xenbus_debug_write(const char *str,
    4.30  	msg.type = XS_DEBUG;
    4.31  	msg.len = sizeof("print") + count + 1;
    4.32  
    4.33 -	down(&xs_state.request_mutex);
    4.34 +	mutex_lock(&xs_state.request_mutex);
    4.35  	xb_write(&msg, sizeof(msg));
    4.36  	xb_write("print", sizeof("print"));
    4.37  	xb_write(str, count);
    4.38  	xb_write("", 1);
    4.39 -	up(&xs_state.request_mutex);
    4.40 +	mutex_unlock(&xs_state.request_mutex);
    4.41  }
    4.42  
    4.43  void *xenbus_dev_request_and_reply(struct xsd_sockmsg *msg)
    4.44 @@ -173,7 +174,7 @@ void *xenbus_dev_request_and_reply(struc
    4.45  	if (req_msg.type == XS_TRANSACTION_START)
    4.46  		down_read(&xs_state.suspend_mutex);
    4.47  
    4.48 -	down(&xs_state.request_mutex);
    4.49 +	mutex_lock(&xs_state.request_mutex);
    4.50  
    4.51  	err = xb_write(msg, sizeof(*msg) + msg->len);
    4.52  	if (err) {
    4.53 @@ -182,7 +183,7 @@ void *xenbus_dev_request_and_reply(struc
    4.54  	} else
    4.55  		ret = read_reply(&msg->type, &msg->len);
    4.56  
    4.57 -	up(&xs_state.request_mutex);
    4.58 +	mutex_unlock(&xs_state.request_mutex);
    4.59  
    4.60  	if ((msg->type == XS_TRANSACTION_END) ||
    4.61  	    ((req_msg.type == XS_TRANSACTION_START) &&
    4.62 @@ -211,25 +212,25 @@ static void *xs_talkv(xenbus_transaction
    4.63  	for (i = 0; i < num_vecs; i++)
    4.64  		msg.len += iovec[i].iov_len;
    4.65  
    4.66 -	down(&xs_state.request_mutex);
    4.67 +	mutex_lock(&xs_state.request_mutex);
    4.68  
    4.69  	err = xb_write(&msg, sizeof(msg));
    4.70  	if (err) {
    4.71 -		up(&xs_state.request_mutex);
    4.72 +		mutex_unlock(&xs_state.request_mutex);
    4.73  		return ERR_PTR(err);
    4.74  	}
    4.75  
    4.76  	for (i = 0; i < num_vecs; i++) {
    4.77  		err = xb_write(iovec[i].iov_base, iovec[i].iov_len);;
    4.78  		if (err) {
    4.79 -			up(&xs_state.request_mutex);
    4.80 +			mutex_unlock(&xs_state.request_mutex);
    4.81  			return ERR_PTR(err);
    4.82  		}
    4.83  	}
    4.84  
    4.85  	ret = read_reply(&msg.type, len);
    4.86  
    4.87 -	up(&xs_state.request_mutex);
    4.88 +	mutex_unlock(&xs_state.request_mutex);
    4.89  
    4.90  	if (IS_ERR(ret))
    4.91  		return ret;
    4.92 @@ -658,8 +659,8 @@ void unregister_xenbus_watch(struct xenb
    4.93  
    4.94  	/* Flush any currently-executing callback, unless we are it. :-) */
    4.95  	if (current->pid != xenwatch_pid) {
    4.96 -		down(&xenwatch_mutex);
    4.97 -		up(&xenwatch_mutex);
    4.98 +		mutex_lock(&xenwatch_mutex);
    4.99 +		mutex_unlock(&xenwatch_mutex);
   4.100  	}
   4.101  }
   4.102  EXPORT_SYMBOL_GPL(unregister_xenbus_watch);
   4.103 @@ -667,7 +668,7 @@ EXPORT_SYMBOL_GPL(unregister_xenbus_watc
   4.104  void xs_suspend(void)
   4.105  {
   4.106  	down_write(&xs_state.suspend_mutex);
   4.107 -	down(&xs_state.request_mutex);
   4.108 +	mutex_lock(&xs_state.request_mutex);
   4.109  }
   4.110  
   4.111  void xs_resume(void)
   4.112 @@ -675,7 +676,7 @@ void xs_resume(void)
   4.113  	struct xenbus_watch *watch;
   4.114  	char token[sizeof(watch) * 2 + 1];
   4.115  
   4.116 -	up(&xs_state.request_mutex);
   4.117 +	mutex_unlock(&xs_state.request_mutex);
   4.118  
   4.119  	/* No need for watches_lock: the suspend_mutex is sufficient. */
   4.120  	list_for_each_entry(watch, &watches, list) {
   4.121 @@ -698,7 +699,7 @@ static int xenwatch_thread(void *unused)
   4.122  		if (kthread_should_stop())
   4.123  			break;
   4.124  
   4.125 -		down(&xenwatch_mutex);
   4.126 +		mutex_lock(&xenwatch_mutex);
   4.127  
   4.128  		spin_lock(&watch_events_lock);
   4.129  		ent = watch_events.next;
   4.130 @@ -716,7 +717,7 @@ static int xenwatch_thread(void *unused)
   4.131  			kfree(msg);
   4.132  		}
   4.133  
   4.134 -		up(&xenwatch_mutex);
   4.135 +		mutex_unlock(&xenwatch_mutex);
   4.136  	}
   4.137  
   4.138  	return 0;
   4.139 @@ -809,7 +810,7 @@ int xs_init(void)
   4.140  	spin_lock_init(&xs_state.reply_lock);
   4.141  	init_waitqueue_head(&xs_state.reply_waitq);
   4.142  
   4.143 -	init_MUTEX(&xs_state.request_mutex);
   4.144 +	mutex_init(&xs_state.request_mutex);
   4.145  	init_rwsem(&xs_state.suspend_mutex);
   4.146  
   4.147  	/* Initialize the shared memory rings to talk to xenstored */
     5.1 --- a/linux-2.6-xen-sparse/include/xen/xenbus.h	Wed Mar 22 11:30:57 2006 +0100
     5.2 +++ b/linux-2.6-xen-sparse/include/xen/xenbus.h	Wed Mar 22 11:55:43 2006 +0100
     5.3 @@ -36,7 +36,7 @@
     5.4  
     5.5  #include <linux/device.h>
     5.6  #include <linux/notifier.h>
     5.7 -#include <asm/semaphore.h>
     5.8 +#include <linux/mutex.h>
     5.9  #include <xen/interface/xen.h>
    5.10  #include <xen/interface/grant_table.h>
    5.11  #include <xen/interface/io/xenbus.h>