Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp243818imm; Wed, 18 Jul 2018 01:08:11 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdqPE8Auf11NRn3z1nFGyXy8u0v1U/9LTtIUmE2SNhbasJTNBBKuLvMe/XsqqbIvi4eIo2d X-Received: by 2002:a17:902:5381:: with SMTP id c1-v6mr4889838pli.137.1531901291512; Wed, 18 Jul 2018 01:08:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531901291; cv=none; d=google.com; s=arc-20160816; b=BfGu85ED0D+Kv0Y8HNtequs452a7YOTmxauwrWj119JMiI44lJghW4ZQIyzEhebpdu ghtZZiwpHjMUZTOhQ61jqDXjjXdLQyOBtig9df+ng+IzHm4DLZENUVLlJcBp74eCXRB0 nXuvYFNIHFhi4wTV9T/XPMkDUmlcKjM8ljebUnm79Fx8EyE7o95SpXXOZwhsp4E/inG5 y7spH3YMNGgvwulXZd7heo7kh6j54AaCRRMsdCfSc5pIozDGTlvs8WvZE8ezyCJHECdf l2TmlIrRY53u5te36aJ0OG2sPhw4lLIcdcnrnLyrXt2rgPfxFKfYjS5bSfUzU6l3SXRH OGtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:date:message-id:subject:from:cc:to :arc-authentication-results; bh=QlB/r4i78eMneV7VxKEOyZYmuO9si1MWwaWkF+osScA=; b=nZef4LbrZWHmJVoSkb78TKz7lqN5t+2CpyeoSl/Y55FMMU8qU3ojnovTfidMUkW5fu aJ4fYlOyLZ+xdzJaZHMj9MvAKftjDvwQL6a+rKr7s2xaOzP7kZyXjXkuuckG/GK1P67Q X1m0qhs5OHV9ng73qFGfFjkN4hYlKOrigBeUfHD/C1O8iDNZiYA9Bfws1Q7bLXAEy1sa O3ifKgZpiglBm7aWkgX0EDI73KwZmUGfMkaiY2wAm1KHKPlCT8P4Gt1X69LQ6PWPgcr3 Z0Y/LaM6bhsSIeRiGgzGqr+IYQ0qv4ZgXTEjwrW7TB7shBFO/wjqRCt+USfd4dPBxTUR ldvg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b74-v6si2964946pfd.273.2018.07.18.01.07.56; Wed, 18 Jul 2018 01:08:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726969AbeGRIoD (ORCPT + 99 others); Wed, 18 Jul 2018 04:44:03 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:57515 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726067AbeGRIoD (ORCPT ); Wed, 18 Jul 2018 04:44:03 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 9B707D89625E3; Wed, 18 Jul 2018 16:07:18 +0800 (CST) Received: from [10.177.253.249] (10.177.253.249) by smtp.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.382.0; Wed, 18 Jul 2018 16:07:16 +0800 To: Dominique Martinet CC: "akpm@linux-foundation.org" , "Eric Van Hensbergen" , Ron Minnich , "Latchesar Ionkov" , Linux Kernel Mailing List , From: piaojun Subject: [PATCH] net/9p/trans_virtio.c: replace mutex_lock with spin_lock to protect 'virtio_chan_list' Message-ID: <5B4EF511.7090104@huawei.com> Date: Wed, 18 Jul 2018 16:06:41 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.253.249] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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); --