Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2257930rwb; Thu, 15 Dec 2022 22:47:20 -0800 (PST) X-Google-Smtp-Source: AA0mqf4K+h50kS90OJz04Nck4fs6hPn3ZubpW79Sh415jC76P3+YmjMEK2V0EUvJUcSjfpgV1ljk X-Received: by 2002:a17:906:36d8:b0:7be:665a:c915 with SMTP id b24-20020a17090636d800b007be665ac915mr24838673ejc.32.1671173240276; Thu, 15 Dec 2022 22:47:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671173240; cv=none; d=google.com; s=arc-20160816; b=RrcBs4OHzRmb1gCC5nk70GBNDzKCY7A5F18ngwyy9MpD5n+DVKi0siM7COqy8CZRFz PSONDT8iWMqXX4jrqmilJ1X37IKwZBVIaQLoFtDkK0Ian1T22V6K+0hYSxc8xp9DxD6v 5knADykrkhp/GiWjfRDLBw9ktUpAvndQt6iidi7h4qIoa29xpHGA9HFzQFXjkGItNuMC X8z9tI5FIRIFJ3lPmv4racrHkM+P4x3/1lz+MlolkAcLAsZOWwiUlZVX+AL1JI81xzC+ jeuUSijx7Nv06muWdWzrFFNXkLuH6aut8pPdI4FyDXH5GGgOc2AuC+ZeIF1NEiWg8mOx K8DQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=lR7WnqvDc+rTDFoKYRWuh6MMYqCYo5ZyrUKVWQtJrjg=; b=P3kPZ+YO8MpF4L/udi/yVg+VTw3tCHIg1WUp7osgeo5nxI+fWeOS8clcnoZGECmB4B S3JEBa1opzN+J6ov9fS+wpj//8UjarJpCNoZ3p5pNyISbbVWz+1SBqJpiYquNZDqJJ5R RV8Sgwr/3y2wPdzjDHCHJKXEMvHDLsYBpFt/d+f38AnyS+lKQzdL5Xi1NfNctjK5dVGj El3SgCt2WKfK8SIDB9cRyz0cRSshdUdWdp8MIHEjSemf5cnp2fXRqpVDuV3Zpuj0lULw qClBI2QyuGFpXWqe9fRGxLC4umpZS8zP2f8WqtZk3UREPRG3eJvRNwQZxI+ZIVxIX+Xc LdSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XGIbqKrS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sz15-20020a1709078b0f00b007c4f2a63a40si1325278ejc.574.2022.12.15.22.47.04; Thu, 15 Dec 2022 22:47:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XGIbqKrS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229661AbiLPFoC (ORCPT + 68 others); Fri, 16 Dec 2022 00:44:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbiLPFoA (ORCPT ); Fri, 16 Dec 2022 00:44:00 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08C365D6BB for ; Thu, 15 Dec 2022 21:43:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671169393; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=lR7WnqvDc+rTDFoKYRWuh6MMYqCYo5ZyrUKVWQtJrjg=; b=XGIbqKrS7Z/VZG7W+k/Swl9AVnVx4QkyAFIH2y0cfOqOwXQOCq7a/Bg/42klLOmjfyZ5PZ isFFhxMmoRldT4WMT20ZjvJvjNmq2qHH1oLxDNtxiDLgBdWElgNhvIgUPZbQN18gRcOJWy /PQSTkC5/V41aydmeXQP88MkU8Olbi8= Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-557-4vOkpTXoNv2npgsWFK-6ig-1; Fri, 16 Dec 2022 00:43:12 -0500 X-MC-Unique: 4vOkpTXoNv2npgsWFK-6ig-1 Received: by mail-ot1-f70.google.com with SMTP id bx9-20020a056830600900b0066debed5e7dso792748otb.10 for ; Thu, 15 Dec 2022 21:43:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lR7WnqvDc+rTDFoKYRWuh6MMYqCYo5ZyrUKVWQtJrjg=; b=r02KDmGGHhOcd1XUsh8ENb8P6eNNK5iavK3bNVq/EsVqVpfOOApod2kwPjYdGGIjws 83sk4EyD2m+Hes1DNtX1FrmHVUWnhtYRryzKRZHiG5bWSho5Zf9xBGwh9A8YR/6AtQF3 NxVmnlwC2ZSVM0Q1sIaDeFJoTcZxP99JyC3xWW3ybW2jq12y1dh4aHckrtvvYppVBbYC QLSautV/MsnF8CgWgUosGVXC3qHMZ2uZ86yBeE+Kjs5uo9aXmo2gYaPWKAfjwomROFtq Lv6L1Szu37GCygBFAxxzjyivyn3BPExpUI4wJ0voB2UR/h7OFln38qjZI476U7nQgt8X CaEw== X-Gm-Message-State: ANoB5plISnWM4NAxwsvWM/w6X3rI2KIlSFgHA0cD++7LIKV2GQ1nfNG1 +mpLZXTMnIcmxCvqugMdSBD73uGbr0ikSXqSt+SciZ3+Si14t20NI0bUH3F3Vy8SRtORuJPvkT9 NZWajc4sBGuPgW2YZwWr2jH05qptilCrxV8IZWCq2 X-Received: by 2002:a4a:94a9:0:b0:480:8f4a:7062 with SMTP id k38-20020a4a94a9000000b004808f4a7062mr31914715ooi.57.1671169391286; Thu, 15 Dec 2022 21:43:11 -0800 (PST) X-Received: by 2002:a4a:94a9:0:b0:480:8f4a:7062 with SMTP id k38-20020a4a94a9000000b004808f4a7062mr31914710ooi.57.1671169391057; Thu, 15 Dec 2022 21:43:11 -0800 (PST) MIME-Version: 1.0 References: <20221205084127.535-1-xieyongji@bytedance.com> <20221205090243.791-1-xieyongji@bytedance.com> <20221205090243.791-3-xieyongji@bytedance.com> In-Reply-To: <20221205090243.791-3-xieyongji@bytedance.com> From: Jason Wang Date: Fri, 16 Dec 2022 13:43:00 +0800 Message-ID: Subject: Re: [PATCH v2 09/11] vduse: Add enable_irq_wq sysfs interface for virtqueues To: Xie Yongji Cc: mst@redhat.com, tglx@linutronix.de, hch@lst.de, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 5, 2022 at 5:03 PM Xie Yongji wrote: > > Add enable_irq_wq sysfs interface to control whether > use workqueue to inject irq or not. The vhost-vdpa case > can benefit from it. Do we have a benchmark result for this? Or I wonder if we can extend set_vq_cb() by associating an eventfd then VDUSE can signal that eventfd directly? Thanks > > Signed-off-by: Xie Yongji > --- > drivers/vdpa/vdpa_user/vduse_dev.c | 50 +++++++++++++++++++++++++++++- > 1 file changed, 49 insertions(+), 1 deletion(-) > > diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c > index c65f84100e30..ed06c7afd484 100644 > --- a/drivers/vdpa/vdpa_user/vduse_dev.c > +++ b/drivers/vdpa/vdpa_user/vduse_dev.c > @@ -62,6 +62,7 @@ struct vduse_virtqueue { > struct cpumask irq_affinity; > spinlock_t irq_affinity_lock; > struct kobject kobj; > + bool enable_irq_wq; > }; > > struct vduse_dev; > @@ -1013,6 +1014,26 @@ static int vduse_dev_queue_irq_work(struct vduse_dev *dev, > return ret; > } > > +static int vduse_dev_inject_vq_irq(struct vduse_dev *dev, > + struct vduse_virtqueue *vq) > +{ > + int ret = -EINVAL; > + > + down_read(&dev->rwsem); > + if (!(dev->status & VIRTIO_CONFIG_S_DRIVER_OK)) > + goto unlock; > + > + ret = 0; > + spin_lock_irq(&vq->irq_lock); > + if (vq->ready && vq->cb.callback) > + vq->cb.callback(vq->cb.private); > + spin_unlock_irq(&vq->irq_lock); > +unlock: > + up_read(&dev->rwsem); > + > + return ret; > +} > + > static int vduse_dev_dereg_umem(struct vduse_dev *dev, > u64 iova, u64 size) > { > @@ -1278,8 +1299,12 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, > break; > > index = array_index_nospec(index, dev->vq_num); > - ret = vduse_dev_queue_irq_work(dev, &dev->vqs[index]->inject, > + if (dev->vqs[index]->enable_irq_wq) > + ret = vduse_dev_queue_irq_work(dev, > + &dev->vqs[index]->inject, > dev->vqs[index]->irq_effective_cpu); > + else > + ret = vduse_dev_inject_vq_irq(dev, dev->vqs[index]); > break; > } > case VDUSE_IOTLB_REG_UMEM: { > @@ -1420,6 +1445,26 @@ static const struct file_operations vduse_dev_fops = { > .llseek = noop_llseek, > }; > > +static ssize_t enable_irq_wq_show(struct vduse_virtqueue *vq, char *buf) > +{ > + return sprintf(buf, "%d\n", vq->enable_irq_wq); > +} > + > +static ssize_t enable_irq_wq_store(struct vduse_virtqueue *vq, > + const char *buf, size_t count) > +{ > + bool enabled; > + int ret; > + > + ret = kstrtobool(buf, &enabled); > + if (ret) > + return ret; > + > + vq->enable_irq_wq = enabled; > + > + return count; > +} > + > static ssize_t irq_cb_affinity_show(struct vduse_virtqueue *vq, char *buf) > { > return sprintf(buf, "%*pb\n", cpumask_pr_args(&vq->irq_affinity)); > @@ -1480,10 +1525,12 @@ struct vq_sysfs_entry { > static struct vq_sysfs_entry irq_cb_affinity_attr = __ATTR_RO(irq_cb_affinity); > static struct vq_sysfs_entry irq_cb_effective_affinity_attr = > __ATTR_RW(irq_cb_effective_affinity); > +static struct vq_sysfs_entry enable_irq_wq_attr = __ATTR_RW(enable_irq_wq); > > static struct attribute *vq_attrs[] = { > &irq_cb_affinity_attr.attr, > &irq_cb_effective_affinity_attr.attr, > + &enable_irq_wq_attr.attr, > NULL, > }; > ATTRIBUTE_GROUPS(vq); > @@ -1565,6 +1612,7 @@ static int vduse_dev_init_vqs(struct vduse_dev *dev, u32 vq_align, u32 vq_num) > > dev->vqs[i]->index = i; > dev->vqs[i]->irq_effective_cpu = -1; > + dev->vqs[i]->enable_irq_wq = true; > INIT_WORK(&dev->vqs[i]->inject, vduse_vq_irq_inject); > INIT_WORK(&dev->vqs[i]->kick, vduse_vq_kick_work); > spin_lock_init(&dev->vqs[i]->kick_lock); > -- > 2.20.1 >