Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp4180557rwl; Tue, 27 Dec 2022 23:59:22 -0800 (PST) X-Google-Smtp-Source: AMrXdXvgP9M5i9A9Oad2Aux/B5ZhKQHzt8GB+vw1QwJX61+O8D5XNDQV5KPqllYJGSmVOoIVZee6 X-Received: by 2002:a17:902:edd1:b0:192:50fe:504a with SMTP id q17-20020a170902edd100b0019250fe504amr22546764plk.16.1672214362053; Tue, 27 Dec 2022 23:59:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672214362; cv=none; d=google.com; s=arc-20160816; b=KOCQb5wpdGKd4ulrIDUil1sCG02vTy4iwtckakzHld0o8czm3tdmqu5OMOlzvj/Yu/ nz06Pd4ltwJiOlz8NEIvTQ4Y0+LycK2UhMxpWXEVhhNmcWEcv1UDt7zsgeAlVqHftd/C obyQ7m+n2jMOxRLokZP5fPvqZ74C1y8mRLdqPi7p3OrLrpDgervEQucjNJUufbOXpNZy nKQqHg56c37JocuayVXLH1ghw/zMA61cSya5ylU61w/HTbpxa1TQorc5MbiuFzbZ7voY WyfF+j/ov4FsuM5+sWuARQ0hOiv4P+zbMXnV1wwBXpLBXlejNG/hayFqbXEJQf0MxpbA Q6eQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=7p/vayyP8zWaxjPZEqa7TOM9QZB/OUBM2psrPg6s4TY=; b=P70SSxIO7lkgfmQtEqEzbY+wFufrccbYdQr4+EWBq891grB+JSAdQV7cz2cAGPvkVV /W5zuGgJgdFlDR/zvqiNxxM4Ik0AlgWsvWJ2fZfFUQDt6lY2GYw4uUmnfY00/ojsFW4A OvossZu6/WKKZzp2GTYDaN/9IR40HYAOqn7Wqzm26mDvmK1Qo3XMAoUttd7L9dnrFLZR YU/PyQ80bWSMBPpnlbftys2pRB6J7RhysKswogYOU3S/2qhXZugAEmR2bErP3/cVBcIm Aai0Z3ub+EQRrTjDCMkArBVkKlGmaS51E3TWo1zUut3NWV0BHZ74pUK2FNPKGd0hC86N rk3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XNhzPtEH; 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 l16-20020a170903121000b00187242da09asi17648491plh.265.2022.12.27.23.59.13; Tue, 27 Dec 2022 23:59:22 -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=XNhzPtEH; 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 S229707AbiL1HVN (ORCPT + 65 others); Wed, 28 Dec 2022 02:21:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229705AbiL1HVI (ORCPT ); Wed, 28 Dec 2022 02:21:08 -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 21F4FF5A0 for ; Tue, 27 Dec 2022 23:20:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1672212026; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7p/vayyP8zWaxjPZEqa7TOM9QZB/OUBM2psrPg6s4TY=; b=XNhzPtEHGrGzkqzELeuXmYgTu2JRi+C8g9HqLpyXecp7RtyY7oHUmH/yWYkz/XP6kJs9hk mL3JSeVnehz+ZFYDfGP/1VvSdUIwUidgmtCteZkNH8Wu/Id0UgehphXe2hp3OOw383nqHx P821EI9IWtA+z7Y2HYJVHm5tjLvQJBc= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-75-b8MCS2aTNA2JNmdIZVctwQ-1; Wed, 28 Dec 2022 02:20:24 -0500 X-MC-Unique: b8MCS2aTNA2JNmdIZVctwQ-1 Received: by mail-wm1-f71.google.com with SMTP id j1-20020a05600c1c0100b003d99070f529so1469691wms.9 for ; Tue, 27 Dec 2022 23:20:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7p/vayyP8zWaxjPZEqa7TOM9QZB/OUBM2psrPg6s4TY=; b=n5bDzpuuKJFf8DwgX4t5vU2UCPrRwAMnCKkrw4LTffmE8J2/9nEA0DuA3R3qpDWlYc EZtKu5jgDFlicGarlfwhZwBl+zuIXHWezSMknYtD+nqNItx0VA533DSagn++4UB5/hzt UR8zfM+pLfw/1HgwbsMOgRFPd9jZ87MKfl50p+SWdBv7ZtfgFQqzhPq/CBna+WEIDjWi IFkUpjwBclIT/rQXOgsrca19OOS6G/crva8FzgsZl+fR6Fmk7x1e0grj3hcPL/eDrEeq Ze09PFiPfdmJ6AdXXpCPCT1Nh40Yt1ZE78T/ehPAg6NWyb5jqrDDr8gvKVgZAyq8Mb8R awRQ== X-Gm-Message-State: AFqh2krp/Pn0bt+r701+GqvKodOkdrsNPKVwfAOwMwlgkCQ6qnclS2Jv 3obp3L10wYgb28VSCPwEPX8TVESw4s+yICts9sD6KmiRUb3mOKFurWJAEdHs0J5AJHyEvfJOH7p nQXYEzAG2hdXIJtDs0vDXNIUb X-Received: by 2002:a7b:cbd4:0:b0:3d3:3d51:7d44 with SMTP id n20-20020a7bcbd4000000b003d33d517d44mr17093104wmi.33.1672212023559; Tue, 27 Dec 2022 23:20:23 -0800 (PST) X-Received: by 2002:a7b:cbd4:0:b0:3d3:3d51:7d44 with SMTP id n20-20020a7bcbd4000000b003d33d517d44mr17093090wmi.33.1672212023191; Tue, 27 Dec 2022 23:20:23 -0800 (PST) Received: from redhat.com ([2.52.151.85]) by smtp.gmail.com with ESMTPSA id k31-20020a05600c1c9f00b003d22528decesm26573211wms.43.2022.12.27.23.20.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Dec 2022 23:20:22 -0800 (PST) Date: Wed, 28 Dec 2022 02:20:19 -0500 From: "Michael S. Tsirkin" To: Shunsuke Mie Cc: Jason Wang , Rusty Russell , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 4/9] vringh: unify the APIs for all accessors Message-ID: <20221228021354-mutt-send-email-mst@kernel.org> References: <20221227022528.609839-1-mie@igel.co.jp> <20221227022528.609839-5-mie@igel.co.jp> <20221227020007-mutt-send-email-mst@kernel.org> <20221227075332-mutt-send-email-mst@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 Wed, Dec 28, 2022 at 11:24:10AM +0900, Shunsuke Mie wrote: > 2022年12月27日(火) 23:37 Michael S. Tsirkin : > > > > On Tue, Dec 27, 2022 at 07:22:36PM +0900, Shunsuke Mie wrote: > > > 2022年12月27日(火) 16:49 Shunsuke Mie : > > > > > > > > 2022年12月27日(火) 16:04 Michael S. Tsirkin : > > > > > > > > > > On Tue, Dec 27, 2022 at 11:25:26AM +0900, Shunsuke Mie wrote: > > > > > > Each vringh memory accessors that are for user, kern and iotlb has own > > > > > > interfaces that calls common code. But some codes are duplicated and that > > > > > > becomes loss extendability. > > > > > > > > > > > > Introduce a struct vringh_ops and provide a common APIs for all accessors. > > > > > > It can bee easily extended vringh code for new memory accessor and > > > > > > simplified a caller code. > > > > > > > > > > > > Signed-off-by: Shunsuke Mie > > > > > > --- > > > > > > drivers/vhost/vringh.c | 667 +++++++++++------------------------------ > > > > > > include/linux/vringh.h | 100 +++--- > > > > > > 2 files changed, 225 insertions(+), 542 deletions(-) > > > > > > > > > > > > diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c > > > > > > index aa3cd27d2384..ebfd3644a1a3 100644 > > > > > > --- a/drivers/vhost/vringh.c > > > > > > +++ b/drivers/vhost/vringh.c > > > > > > @@ -35,15 +35,12 @@ static __printf(1,2) __cold void vringh_bad(const char *fmt, ...) > > > > > > } > > > > > > > > > > > > /* Returns vring->num if empty, -ve on error. */ > > > > > > -static inline int __vringh_get_head(const struct vringh *vrh, > > > > > > - int (*getu16)(const struct vringh *vrh, > > > > > > - u16 *val, const __virtio16 *p), > > > > > > - u16 *last_avail_idx) > > > > > > +static inline int __vringh_get_head(const struct vringh *vrh, u16 *last_avail_idx) > > > > > > { > > > > > > u16 avail_idx, i, head; > > > > > > int err; > > > > > > > > > > > > - err = getu16(vrh, &avail_idx, &vrh->vring.avail->idx); > > > > > > + err = vrh->ops.getu16(vrh, &avail_idx, &vrh->vring.avail->idx); > > > > > > if (err) { > > > > > > vringh_bad("Failed to access avail idx at %p", > > > > > > &vrh->vring.avail->idx); > > > > > > > > > > I like that this patch removes more lines of code than it adds. > > > > > > > > > > However one of the design points of vringh abstractions is that they were > > > > > carefully written to be very low overhead. > > > > > This is why we are passing function pointers to inline functions - > > > > > compiler can optimize that out. > > > > > > > > > > I think that introducing ops indirect functions calls here is going to break > > > > > these assumptions and hurt performance. > > > > > Unless compiler can somehow figure it out and optimize? > > > > > I don't see how it's possible with ops pointer in memory > > > > > but maybe I'm wrong. > > > > I think your concern is correct. I have to understand the compiler > > > > optimization and redesign this approach If it is needed. > > > > > Was any effort taken to test effect of these patches on performance? > > > > I just tested vringh_test and already faced little performance reduction. > > > > I have to investigate that, as you said. > > > I attempted to test with perf. I found that the performance of patched code > > > is almost the same as the upstream one. However, I have to investigate way > > > this patch leads to this result, also the profiling should be run on > > > more powerful > > > machines too. > > > > > > environment: > > > $ grep 'model name' /proc/cpuinfo > > > model name : Intel(R) Core(TM) i3-7020U CPU @ 2.30GHz > > > model name : Intel(R) Core(TM) i3-7020U CPU @ 2.30GHz > > > model name : Intel(R) Core(TM) i3-7020U CPU @ 2.30GHz > > > model name : Intel(R) Core(TM) i3-7020U CPU @ 2.30GHz > > > > > > results: > > > * for patched code > > > Performance counter stats for 'nice -n -20 ./vringh_test_patched > > > --parallel --eventidx --fast-vringh --indirect --virtio-1' (20 runs): > > > > > > 3,028.05 msec task-clock # 0.995 CPUs > > > utilized ( +- 0.12% ) > > > 78,150 context-switches # 25.691 K/sec > > > ( +- 0.00% ) > > > 5 cpu-migrations # 1.644 /sec > > > ( +- 3.33% ) > > > 190 page-faults # 62.461 /sec > > > ( +- 0.41% ) > > > 6,919,025,222 cycles # 2.275 GHz > > > ( +- 0.13% ) > > > 8,990,220,160 instructions # 1.29 insn per > > > cycle ( +- 0.04% ) > > > 1,788,326,786 branches # 587.899 M/sec > > > ( +- 0.05% ) > > > 4,557,398 branch-misses # 0.25% of all > > > branches ( +- 0.43% ) > > > > > > 3.04359 +- 0.00378 seconds time elapsed ( +- 0.12% ) > > > > > > * for upstream code > > > Performance counter stats for 'nice -n -20 ./vringh_test_base > > > --parallel --eventidx --fast-vringh --indirect --virtio-1' (10 runs): > > > > > > 3,058.41 msec task-clock # 0.999 CPUs > > > utilized ( +- 0.14% ) > > > 78,149 context-switches # 25.545 K/sec > > > ( +- 0.00% ) > > > 5 cpu-migrations # 1.634 /sec > > > ( +- 2.67% ) > > > 194 page-faults # 63.414 /sec > > > ( +- 0.43% ) > > > 6,988,713,963 cycles # 2.284 GHz > > > ( +- 0.14% ) > > > 8,512,533,269 instructions # 1.22 insn per > > > cycle ( +- 0.04% ) > > > 1,638,375,371 branches # 535.549 M/sec > > > ( +- 0.05% ) > > > 4,428,866 branch-misses # 0.27% of all > > > branches ( +- 22.57% ) > > > > > > 3.06085 +- 0.00420 seconds time elapsed ( +- 0.14% ) > > > > > > How you compiled it also matters. ATM we don't enable retpolines > > and it did not matter since we didn't have indirect calls, > > but we should. Didn't yet investigate how to do that for virtio tools. > I think the retpolines certainly affect performance. Thank you for pointing > it out. I'd like to start the investigation that how to apply the > retpolines to the > virtio tools. > > > > Thank you for your comments. > > > > > Thanks! > > > > > > > > > > > > > > Best, > > > > Shunsuke. This isn't all that trivial if we want this at runtime. But compile time is kind of easy. See Documentation/admin-guide/hw-vuln/spectre.rst -- MST