Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp2975878rwl; Tue, 27 Dec 2022 02:29:02 -0800 (PST) X-Google-Smtp-Source: AMrXdXsbOLv36y+RBqZwdYAThpyXFdAaa4kdD37tYjSeq0vtdrkJy7T5p32OBgSuVzeIFmC9cV5s X-Received: by 2002:a17:907:cb85:b0:7c0:f216:cc14 with SMTP id un5-20020a170907cb8500b007c0f216cc14mr18157141ejc.11.1672136942202; Tue, 27 Dec 2022 02:29:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672136942; cv=none; d=google.com; s=arc-20160816; b=tTE62UZTJYpsFm96QhgupP0tqX4L2SCwYsT22eAG7noyPiL17DvOqmMcXWK2lALgNG Qg4UNpuloaA+3XlsPAFfxZvPbsdBs6lMrEfO/wHGrPB6DE3tJR9t+CssO8IPtV6lnWhq GQmk6M7MpNKJ4DBmAtwgma/0AEnhpvhK2RMN1LMfn+GH8DgD149CU7whoCLYHpUgSrNf wW0z31Cvt93cCHP0507letlMXiffj/GC5Wx4ljy+ZYBGtRQSChtfMDRBOZKj1PVeXF7W 03ZSX7uqASO847nBh3V2dGy8YyGNO+oRnFU44Pf0uN2byLcW0YIM1Ebko4WULhBfQ3y2 EruA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=C5/0JksOM2lGuEYSzF1Qu3MnIOgzw58Ul9AktACBNVI=; b=Zi3BagxeTmFToHkk/I6TDOkO7zzM5GPD9BPbnddFISa8wezGn6YVEIrRT1BXc7jULF OpHrvd1OAdPT4Y2a+UaXE5+hVfnmilfcDtKzJrdxqD5PzgfrYkISxx7UXOHSAHB5oXFB EsupfIsFObmvgP6j2ey6NdvX0vDTKb4FUZKYTCwMh/IjalkGbSK9/0ZlI07z+4n60FB3 nUzUwbMprmxyhyk04mZtns7lVvy/0SVEuu47o/U2lrSWxsnO84Bb1Omj7WweGMwuisd1 1p+5zVrSgyvQdWEgwImnETTmrYtIiQ0IL0+FxdNlHtm/WMRWCwCL828EDkBp0RshFp+4 jbPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@igel-co-jp.20210112.gappssmtp.com header.s=20210112 header.b=NoTyXYNT; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hp1-20020a1709073e0100b007c0dcc79ec1si9547881ejc.164.2022.12.27.02.28.45; Tue, 27 Dec 2022 02:29:02 -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=@igel-co-jp.20210112.gappssmtp.com header.s=20210112 header.b=NoTyXYNT; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230325AbiL0KWv (ORCPT + 66 others); Tue, 27 Dec 2022 05:22:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229621AbiL0KWt (ORCPT ); Tue, 27 Dec 2022 05:22:49 -0500 Received: from mail-vk1-xa2a.google.com (mail-vk1-xa2a.google.com [IPv6:2607:f8b0:4864:20::a2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DD5425E2 for ; Tue, 27 Dec 2022 02:22:48 -0800 (PST) Received: by mail-vk1-xa2a.google.com with SMTP id h4so1032520vkn.3 for ; Tue, 27 Dec 2022 02:22:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=igel-co-jp.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=C5/0JksOM2lGuEYSzF1Qu3MnIOgzw58Ul9AktACBNVI=; b=NoTyXYNTcm9i+GC7/+I09XJcPjGPm2toisrvYx3dF44c57grwNAzYz5vVRbhRnJA9S B34KZz4oVKrZN6wpBQ+QnVG35XqSCtcpouGuyB3/fUIXDDIpvt2o1dete8IQ4jhB2VK4 pTiaILZwM41NBdToO6kueGNZ1CXaHt5GRY3XI59BNUIdJR6mN615Mf+88Gmm6QxHb95p U2SNRsXu3eqo5n5Smjbcca054NvBvgIuwPw6R1Xds9lzkojAc2OLtCvD9hN5aBTgkIPV WpOHVwYJ4HgifzdLK3a+ewkHHdUb5DUt4wNyHa5aVn0xUqXEJ4EnpoZHjRQsUqZ3yip/ TFJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding: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=C5/0JksOM2lGuEYSzF1Qu3MnIOgzw58Ul9AktACBNVI=; b=Il6eqtAlMxzqg8sy5yhYV41ohLJYYCHQ18bR0eAALSviJGF6VtTPRGiOEeuOG6I3Wk YAWuRWgw2gDuB4EvbetZFCZ9MJFqvNgmLTNKH/ljEe9gabd29qdkQp09KGwZzqO9d4Vk WxXIZ0cwxPSkrvbQQjM+YJrt3qFsSrl5SIPy8WOA1qBqa0ocvod6+zX9Jsj9ZGZ5pMaX 0lEnS3ARaKpsnnktLWudIjfn495SwXZaghkd8ijvKlYuVr+Xb9afTEh9sOO8fC7Pzqqw pytkHCRRqivzUeVgfyhKhsObEn1AHCnT8Ja6SXvULnj1EjiyrN4Ds4ZIcR1f/Qr0bD0K kwyw== X-Gm-Message-State: AFqh2krBNi0oFrfv3rfEs0HK7+MwHpQqSet3IAnKOPaAscTFmOjmhexQ Xbj02lOD3sN0sS8anWTAgGXtVtwON9YZ4HgHEsFeyg== X-Received: by 2002:a1f:2016:0:b0:3d5:53d8:aa10 with SMTP id g22-20020a1f2016000000b003d553d8aa10mr872944vkg.21.1672136567160; Tue, 27 Dec 2022 02:22:47 -0800 (PST) MIME-Version: 1.0 References: <20221227022528.609839-1-mie@igel.co.jp> <20221227022528.609839-5-mie@igel.co.jp> <20221227020007-mutt-send-email-mst@kernel.org> In-Reply-To: From: Shunsuke Mie Date: Tue, 27 Dec 2022 19:22:36 +0900 Message-ID: Subject: Re: [RFC PATCH 4/9] vringh: unify the APIs for all accessors To: "Michael S. Tsirkin" Cc: Jason Wang , Rusty Russell , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 2022=E5=B9=B412=E6=9C=8827=E6=97=A5(=E7=81=AB) 16:49 Shunsuke Mie : > > 2022=E5=B9=B412=E6=9C=8827=E6=97=A5(=E7=81=AB) 16:04 Michael S. Tsirkin <= mst@redhat.com>: > > > > 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 ow= n > > > 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 acces= sors. > > > 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 __vir= tio16 *p), > > > - u16 *last_avail_idx) > > > +static inline int __vringh_get_head(const struct vringh *vrh, u16 *l= ast_avail_idx) > > > { > > > u16 avail_idx, i, head; > > > int err; > > > > > > - err =3D getu16(vrh, &avail_idx, &vrh->vring.avail->idx); > > > + err =3D 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 we= re > > 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% ) > Thank you for your comments. > > Thanks! > > > > > Best, > Shunsuke.