Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1870199lqe; Tue, 9 Apr 2024 02:57:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWEzGGTI9zq3l6M1RvZsnOGt0qt7VIkvvFmKJwRdbTlnKbK0OKP+1LsvWYsmdVH6+VEh8/+arcBggYrkkLBTBHtuACXDKigavWLJvtA4w== X-Google-Smtp-Source: AGHT+IFZS4MABIAsoKmQfkN6qJ+GG8HZM9t2hGIhgK75joYQeHSgn4ibCdncX79VwzbDcMf52b9+ X-Received: by 2002:a17:906:7f1a:b0:a51:91ac:ad9d with SMTP id d26-20020a1709067f1a00b00a5191acad9dmr6963014ejr.63.1712656659189; Tue, 09 Apr 2024 02:57:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712656659; cv=pass; d=google.com; s=arc-20160816; b=MSdH6Z16Az50XeGnlzA69q4Scxi9Va5u9KPdnZmJH+Acvyzgw0M2Ei/X19AoHW+kHE 6lZqYDchQAmMo+2mAadTm4G6U/4FbmGgyNcnAIoiMgjV0TlMyYa4lKucdNo87nk6LyMt 7d4cIkPZhr0UqRw16dUtGB7pXpBafnKHOflo2ViJlLe1zisEhj3NY9+GrKScy1dFn49I HikrKpw+QP2EyCwhYQaJgZP+E9BvI0nkHgloEgfx9ctu66P6d0Bb5NTs58rQ1N5WxR5W CYGmPoJHxvMqLFsIyJszbKrNaisVm7qBzCb/oAwx/d3j02V4FSwC9hBfrW9wZrgAVdZN 67YA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id:dkim-signature; bh=OQGIdks+efdOpe57pVeyT82POjXjytrYc+w+BN9nedU=; fh=Ep7EAIeE3Dthwlk6Pko+jkMkq8wEwgyskQZlHOY0LX0=; b=OWw43oE3SDenGhqWo1d7B5fdpe0FH5peqMOqhYbWQGhkIZk9ZV9D03kKyqdsb6NXWx jHDNg+Zg6umrCdksg09aktGH7QU854roh82dEQnh7lswbENR/fSSbF5tIX535xRwk2t4 Z0BaAeO1OGY0F8wHnUvNgR4V3lds0e7jxxMKEsSoVGaMeAgdq3jd2IWWMdyYHaatUjm8 xitk0ylooZTvXqW1nCfON8ehTOba1v/JuVoHCQ/W/cijyONYgV13Gba8fzawRcVRIIjg 36a+jo8H81WIXKV4mbzHf9HHq9dnJxfqfVY/Qn+bCoZgiy3OaWyRj+jf3sJdU2XVXzR0 rJag==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=fVvPcU0Z; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-136606-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136606-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id x24-20020a1709064a9800b00a4e3bf46fabsi4505005eju.68.2024.04.09.02.57.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 02:57:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-136606-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=fVvPcU0Z; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-136606-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136606-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id BDDA61F2430F for ; Tue, 9 Apr 2024 09:57:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DDB2984A2B; Tue, 9 Apr 2024 09:56:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="fVvPcU0Z" Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAE6882D9C for ; Tue, 9 Apr 2024 09:56:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.113 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712656616; cv=none; b=JSWSMV8AnGb0VKc0Ya8sGJQZPmV0iD6ysBAA3PPkU0FMS7ajUoXVdRD68P1PPQm5HncDG044krYCNUUxWZW3w8C66YG8LQuRfxKORBYXAQU8bdXGFbBEYpEkkKzglEbhC56p2Cbw8SxsYXxwQu9Hz/qzWu5VcTfo+yRNn+YVQvI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712656616; c=relaxed/simple; bh=23riWL0Gd60rPfm/N+Bksf6fpUnyFPCyw8iYZCSbqm4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=AXrjRVu8FFDLX8kBK//yqsVoRk4MCMyKtKxPubHkvDegkl4rPeEDFYyPNRywvpJv5xM5t+yBZcpKCm+CXEL42cPunRiEm3dk5WBuuxuJ7wni0a2cumVWUflvyOv4aCwPRzuuGvfuDjC9lLOxQHv5iuZoLI8TulcsigME/XUYSkk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=fVvPcU0Z; arc=none smtp.client-ip=115.124.30.113 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1712656605; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=OQGIdks+efdOpe57pVeyT82POjXjytrYc+w+BN9nedU=; b=fVvPcU0ZviY6wU5aXzWT4UeS8viYIYGU0mWzvHF1X2n/f+bF8S+ISZm9gb4wyjzelg4JNjFUVE9oL1sqfa4Hfz6OA2ljl8pKzEwjjjX3T0XR34feP9awzBgwYvyS3az+nb+XCI3nXLxvRRRTqrnQSlUrCcCJVOxDa2b5SS9VuHc= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=hengqi@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0W4E4QQU_1712656603; Received: from 30.221.146.5(mailfrom:hengqi@linux.alibaba.com fp:SMTPD_---0W4E4QQU_1712656603) by smtp.aliyun-inc.com; Tue, 09 Apr 2024 17:56:44 +0800 Message-ID: Date: Tue, 9 Apr 2024 17:56:43 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4] vp_vdpa: don't allocate unused msix vectors To: lyx634449800 Cc: angus.chen@jaguarmicro.com, virtualization@lists.linux.dev, xuanzhuo@linux.alibaba.com, linux-kernel@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang References: <20240409013020-mutt-send-email-mst@kernel.org> <20240409085818.1242-1-yuxue.liu@jaguarmicro.com> From: Heng Qi In-Reply-To: <20240409085818.1242-1-yuxue.liu@jaguarmicro.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 在 2024/4/9 下午4:58, lyx634449800 写道: > From: Yuxue Liu > > When there is a ctlq and it doesn't require interrupt > callbacks,the original method of calculating vectors > wastes hardware msi or msix resources as well as system > IRQ resources. > > When conducting performance testing using testpmd in the > guest os, it was found that the performance was lower compared > to directly using vfio-pci to passthrough the device > > In scenarios where the virtio device in the guest os does > not utilize interrupts, the vdpa driver still configures > the hardware's msix vector. Therefore, the hardware still > sends interrupts to the host os. Because of this unnecessary > action by the hardware, hardware performance decreases, and > it also affects the performance of the host os. > > Before modification:(interrupt mode) > 32: 0 0 0 0 PCI-MSI 32768-edge vp-vdpa[0000:00:02.0]-0 > 33: 0 0 0 0 PCI-MSI 32769-edge vp-vdpa[0000:00:02.0]-1 > 34: 0 0 0 0 PCI-MSI 32770-edge vp-vdpa[0000:00:02.0]-2 > 35: 0 0 0 0 PCI-MSI 32771-edge vp-vdpa[0000:00:02.0]-config > > After modification:(interrupt mode) > 32: 0 0 1 7 PCI-MSI 32768-edge vp-vdpa[0000:00:02.0]-0 > 33: 36 0 3 0 PCI-MSI 32769-edge vp-vdpa[0000:00:02.0]-1 > 34: 0 0 0 0 PCI-MSI 32770-edge vp-vdpa[0000:00:02.0]-config > > Before modification:(virtio pmd mode for guest os) > 32: 0 0 0 0 PCI-MSI 32768-edge vp-vdpa[0000:00:02.0]-0 > 33: 0 0 0 0 PCI-MSI 32769-edge vp-vdpa[0000:00:02.0]-1 > 34: 0 0 0 0 PCI-MSI 32770-edge vp-vdpa[0000:00:02.0]-2 > 35: 0 0 0 0 PCI-MSI 32771-edge vp-vdpa[0000:00:02.0]-config > > After modification:(virtio pmd mode for guest os) > 32: 0 0 0 0 PCI-MSI 32768-edge vp-vdpa[0000:00:02.0]-config > > To verify the use of the virtio PMD mode in the guest operating > system, the following patch needs to be applied to QEMU: > https://lore.kernel.org/all/20240408073311.2049-1-yuxue.liu@jaguarmicro.com > > Signed-off-by: Yuxue Liu > Acked-by: Jason Wang > --- > V4: Update the title and assign values to uninitialized variables > V3: delete unused variables and add validation records > V2: fix when allocating IRQs, scan all queues > > drivers/vdpa/virtio_pci/vp_vdpa.c | 23 +++++++++++++++++------ > 1 file changed, 17 insertions(+), 6 deletions(-) > > diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c b/drivers/vdpa/virtio_pci/vp_vdpa.c > index df5f4a3bccb5..74bc8adfc7e8 100644 > --- a/drivers/vdpa/virtio_pci/vp_vdpa.c > +++ b/drivers/vdpa/virtio_pci/vp_vdpa.c > @@ -160,7 +160,14 @@ static int vp_vdpa_request_irq(struct vp_vdpa *vp_vdpa) > struct pci_dev *pdev = mdev->pci_dev; > int i, ret, irq; > int queues = vp_vdpa->queues; > - int vectors = queues + 1; > + int vectors = 0; > + int msix_vec = 0; > + > + for (i = 0; i < queues; i++) { > + if (vp_vdpa->vring[i].cb.callback) > + vectors++; > + } > + vectors++; > > ret = pci_alloc_irq_vectors(pdev, vectors, vectors, PCI_IRQ_MSIX); > if (ret != vectors) { > @@ -173,9 +180,12 @@ static int vp_vdpa_request_irq(struct vp_vdpa *vp_vdpa) > vp_vdpa->vectors = vectors; > > for (i = 0; i < queues; i++) { > + if (!vp_vdpa->vring[i].cb.callback) > + continue; > + > snprintf(vp_vdpa->vring[i].msix_name, VP_VDPA_NAME_SIZE, > "vp-vdpa[%s]-%d\n", pci_name(pdev), i); > - irq = pci_irq_vector(pdev, i); > + irq = pci_irq_vector(pdev, msix_vec); > ret = devm_request_irq(&pdev->dev, irq, > vp_vdpa_vq_handler, > 0, vp_vdpa->vring[i].msix_name, > @@ -185,21 +195,22 @@ static int vp_vdpa_request_irq(struct vp_vdpa *vp_vdpa) > "vp_vdpa: fail to request irq for vq %d\n", i); > goto err; > } > - vp_modern_queue_vector(mdev, i, i); > + vp_modern_queue_vector(mdev, i, msix_vec); > vp_vdpa->vring[i].irq = irq; > + msix_vec++; > } > > snprintf(vp_vdpa->msix_name, VP_VDPA_NAME_SIZE, "vp-vdpa[%s]-config\n", > pci_name(pdev)); > - irq = pci_irq_vector(pdev, queues); > + irq = pci_irq_vector(pdev, msix_vec); > ret = devm_request_irq(&pdev->dev, irq, vp_vdpa_config_handler, 0, > vp_vdpa->msix_name, vp_vdpa); > if (ret) { > dev_err(&pdev->dev, > - "vp_vdpa: fail to request irq for vq %d\n", i); > + "vp_vdpa: fail to request irq for config, ret %d\n", ret); > goto err; > } > - vp_modern_config_vector(mdev, queues); > + vp_modern_config_vector(mdev, msix_vec); > vp_vdpa->config_irq = irq; > > return 0; Reviewed-by: Heng Qi