Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp3298230rwl; Tue, 27 Dec 2022 07:12:33 -0800 (PST) X-Google-Smtp-Source: AMrXdXuGRCkS7xyTjr0tmTeyA44CswymHaBesEV6GKh79Ihkms7YZW1SLNgg5ousymqCQmPAkAoL X-Received: by 2002:a05:6a20:3d26:b0:a4:69a2:6dd7 with SMTP id y38-20020a056a203d2600b000a469a26dd7mr30830240pzi.0.1672153953545; Tue, 27 Dec 2022 07:12:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672153953; cv=none; d=google.com; s=arc-20160816; b=A0tvxE2pNyZc7dgsGPNJSOku13o9CtFtIwhtHy5aOOs7eQdcyvipu+Nv65kTAL5IOL KU/lQekRXhr8vaLPFz8LTRsJSPp/M6aNhY4cCNlgVcYBomzChPY/X1IdLTnpIk5Q8wFD Mh09EUSnVaaWCA1wwTNsPybbyu7pHND28Y05N1beDD5T/8l32dzFW7WFVgLxGnN+tbyh LIazcZKjFGbq3qs3RQurxCSOAaThfRL5WmI4mZxpUPXOnRHiLwf2NRh5N3OYY05q5kD3 PsXaHVuByjFuBiuRIiOmGySawwxjKV8bmkfS7TPulVCoLj/UM0DzG+cLuprmCCACi8v4 WEIg== 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=xgCz+tLYAfF9d3fkcqmVpnYWdED3weMm6ilwwtC+TyE=; b=IMBCowMu5Q+D5nGVuiD0Fw5s6ux4iVjI14E1U/zbIkKK/WMp0YxxP5y7UAlYmwV7Al MD4cO5QwZ7yxTRePgEWor9dW54Pux3jVMflelO/wmgpxbizClJI0QD7GRM79tPCfjLXZ 6HlC02LdN0bM2GTDhPdAMFbY11R5xHLyThpcnavhgHhLPO5ewcRdksJ2WjsEZpgDLQXe pfoD8eO4lSzsbO9ZHWBgMmFoa6avzokqZtE0/9zyEXf+9K20hXHwwmGtS5jELX6ZhKbh INbUZ+EkwjLjOQBnmEttxf4Cr1/Sty7mGotPns1fvOtceWsEekvECvrIyNY2cJRqRsG1 HD8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fzPa3yTR; 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 g18-20020a056a000b9200b005772295cb2csi15101094pfj.271.2022.12.27.07.12.24; Tue, 27 Dec 2022 07:12:33 -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=fzPa3yTR; 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 S231925AbiL0Oi2 (ORCPT + 66 others); Tue, 27 Dec 2022 09:38:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232050AbiL0OiQ (ORCPT ); Tue, 27 Dec 2022 09:38:16 -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 AFF6E2A3 for ; Tue, 27 Dec 2022 06:37:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1672151846; 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=xgCz+tLYAfF9d3fkcqmVpnYWdED3weMm6ilwwtC+TyE=; b=fzPa3yTR0JMwQ2SRs2eYsCz1kzN+CqeiQ+fPLwe/jhSqbLDmFEFaa7BqFkGttHPamBvl+X uuyhCCXvSaHzRf79ttaQzO3nV+PYSj3eH+V3vuWktrdpwh0MC3+GdUZf+fA9J0dCe8cvRs bEGRzpsuNXBqAgDZ0r55h+CnYJPGWZ4= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-487-_C6ffTvZMaKy7deaj9gXfA-1; Tue, 27 Dec 2022 09:37:25 -0500 X-MC-Unique: _C6ffTvZMaKy7deaj9gXfA-1 Received: by mail-wm1-f69.google.com with SMTP id i7-20020a05600c354700b003d62131fe46so9590690wmq.5 for ; Tue, 27 Dec 2022 06:37: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=xgCz+tLYAfF9d3fkcqmVpnYWdED3weMm6ilwwtC+TyE=; b=JypL8SSj7fRs8p6S27PkprTrNRpCvavekADSF5Q6oxwJLWC8bAe5fQpyZRJQ8otk/s GhlJVxbsuGzTXsMtVXmT7AHhgAZArf7cjcjPFp/s+upEGEkuTuaBBLPphuPzaODdjFBT RKg8ng2foq/wSQWW7Y3F/M7yrarveWJEMDx1h36Tssf2140zu9w2+SwxnnbvXTPDfWMU koEautFZOiGlmn+M07WsIE+zFRyzWef9yasxJ5E8pdue4slB9QVeJrkGdtn5AWpNSVIk /8PaCL4tuewjeE7b/x1RG9/PoQGowjaBjr5H0nT25nqsHQbGfRYmG6O4eAM5wJsWRa1C oUiw== X-Gm-Message-State: AFqh2kqYUx67yuoGPkCfFwVXUC+NBklIxO8T1a8ikijG4Ss8WMM7KATw Z8fSDQcMPJyftG7OKWpwUGmcyysRd+Jw8bfcqzuBqhsk2nFL5YcKeuYIcUb9LODizqDy+yy7zeI BAjpvUMVNnmqAKKnYLbApbG9U X-Received: by 2002:adf:e810:0:b0:276:4089:81c2 with SMTP id o16-20020adfe810000000b00276408981c2mr7127722wrm.41.1672151843991; Tue, 27 Dec 2022 06:37:23 -0800 (PST) X-Received: by 2002:adf:e810:0:b0:276:4089:81c2 with SMTP id o16-20020adfe810000000b00276408981c2mr7127707wrm.41.1672151843730; Tue, 27 Dec 2022 06:37:23 -0800 (PST) Received: from redhat.com ([2.52.151.85]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b0027e5501f7f5sm5002656wru.53.2022.12.27.06.37.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Dec 2022 06:37:23 -0800 (PST) Date: Tue, 27 Dec 2022 09:37:20 -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: <20221227075332-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> 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 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. > > Thank you for your comments. > > > Thanks! > > > > > > > > Best, > > Shunsuke.