[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <5B4EF511.7090104@huawei.com>
Date: Wed, 18 Jul 2018 16:06:41 +0800
From: piaojun <piaojun@...wei.com>
To: Dominique Martinet <asmadeus@...ewreck.org>
CC: "akpm@...ux-foundation.org" <akpm@...ux-foundation.org>,
"Eric Van Hensbergen" <ericvh@...il.com>,
Ron Minnich <rminnich@...dia.gov>,
"Latchesar Ionkov" <lucho@...kov.net>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
<v9fs-developer@...ts.sourceforge.net>
Subject: [PATCH] net/9p/trans_virtio.c: replace mutex_lock with spin_lock to
protect 'virtio_chan_list'
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@...wei.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);
--
Powered by blists - more mailing lists