linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net/9p/trans_virtio.c: replace mutex_lock with spin_lock to protect 'virtio_chan_list'
@ 2018-07-18  8:06 piaojun
  2018-07-18  9:54 ` Dominique Martinet
  0 siblings, 1 reply; 5+ messages in thread
From: piaojun @ 2018-07-18  8:06 UTC (permalink / raw)
  To: Dominique Martinet
  Cc: akpm@linux-foundation.org, Eric Van Hensbergen, Ron Minnich,
	Latchesar Ionkov, Linux Kernel Mailing List, v9fs-developer

spin_lock is more effective for short time protection than mutex_lock, as
mutex lock may cause process sleep and wake up which consume much cpu
time.

Signed-off-by: Jun Piao <piaojun@huawei.com>
---
 net/9p/trans_virtio.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c
index 86077f7..7ec0dbf 100644
--- a/net/9p/trans_virtio.c
+++ b/net/9p/trans_virtio.c
@@ -53,8 +53,8 @@

 #define VIRTQUEUE_NUM	128

-/* a single mutex to manage channel initialization and attachment */
-static DEFINE_MUTEX(virtio_9p_lock);
+/* a single spinlock to manage channel initialization and attachment */
+static DEFINE_SPINLOCK(virtio_9p_lock);
 static DECLARE_WAIT_QUEUE_HEAD(vp_wq);
 static atomic_t vp_pinned = ATOMIC_INIT(0);

@@ -120,10 +120,10 @@ static void p9_virtio_close(struct p9_client *client)
 {
 	struct virtio_chan *chan = client->trans;

-	mutex_lock(&virtio_9p_lock);
+	spin_lock(&virtio_9p_lock);
 	if (chan)
 		chan->inuse = false;
-	mutex_unlock(&virtio_9p_lock);
+	spin_unlock(&virtio_9p_lock);
 }

 /**
@@ -605,9 +605,9 @@ static int p9_virtio_probe(struct virtio_device *vdev)

 	virtio_device_ready(vdev);

-	mutex_lock(&virtio_9p_lock);
+	spin_lock(&virtio_9p_lock);
 	list_add_tail(&chan->chan_list, &virtio_chan_list);
-	mutex_unlock(&virtio_9p_lock);
+	spin_unlock(&virtio_9p_lock);

 	/* Let udev rules use the new mount_tag attribute. */
 	kobject_uevent(&(vdev->dev.kobj), KOBJ_CHANGE);
@@ -645,7 +645,7 @@ static int p9_virtio_probe(struct virtio_device *vdev)
 	int ret = -ENOENT;
 	int found = 0;

-	mutex_lock(&virtio_9p_lock);
+	spin_lock(&virtio_9p_lock);
 	list_for_each_entry(chan, &virtio_chan_list, chan_list) {
 		if (!strncmp(devname, chan->tag, chan->tag_len) &&
 		    strlen(devname) == chan->tag_len) {
@@ -657,7 +657,7 @@ static int p9_virtio_probe(struct virtio_device *vdev)
 			ret = -EBUSY;
 		}
 	}
-	mutex_unlock(&virtio_9p_lock);
+	spin_unlock(&virtio_9p_lock);

 	if (!found) {
 		pr_err("no channels available for device %s\n", devname);
@@ -682,7 +682,7 @@ static void p9_virtio_remove(struct virtio_device *vdev)
 	struct virtio_chan *chan = vdev->priv;
 	unsigned long warning_time;

-	mutex_lock(&virtio_9p_lock);
+	spin_lock(&virtio_9p_lock);

 	/* Remove self from list so we don't get new users. */
 	list_del(&chan->chan_list);
@@ -690,17 +690,17 @@ static void p9_virtio_remove(struct virtio_device *vdev)

 	/* Wait for existing users to close. */
 	while (chan->inuse) {
-		mutex_unlock(&virtio_9p_lock);
+		spin_unlock(&virtio_9p_lock);
 		msleep(250);
 		if (time_after(jiffies, warning_time + 10 * HZ)) {
 			dev_emerg(&vdev->dev,
 				  "p9_virtio_remove: waiting for device in use.\n");
 			warning_time = jiffies;
 		}
-		mutex_lock(&virtio_9p_lock);
+		spin_lock(&virtio_9p_lock);
 	}

-	mutex_unlock(&virtio_9p_lock);
+	spin_unlock(&virtio_9p_lock);

 	vdev->config->reset(vdev);
 	vdev->config->del_vqs(vdev);
-- 

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-07-19  7:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-18  8:06 [PATCH] net/9p/trans_virtio.c: replace mutex_lock with spin_lock to protect 'virtio_chan_list' piaojun
2018-07-18  9:54 ` Dominique Martinet
2018-07-19  2:26   ` piaojun
2018-07-19  3:36     ` Dominique Martinet
2018-07-19  7:44       ` piaojun

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).