Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp2843547rwl; Mon, 26 Dec 2022 23:59:49 -0800 (PST) X-Google-Smtp-Source: AMrXdXuzgBiyqGQYXNc+BlPGKvCgAuyfZ8rgZASo4M/mmc2Kkv2cuVy3B18toB8Kd7AX3KMV+rbV X-Received: by 2002:a05:6402:b91:b0:487:1a83:a6a0 with SMTP id cf17-20020a0564020b9100b004871a83a6a0mr842147edb.13.1672127989048; Mon, 26 Dec 2022 23:59:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672127989; cv=none; d=google.com; s=arc-20160816; b=ZufRFHcgNwu+3LvxoGFgc4awmNJdeN5R/Z/X92Whf0vvvRyBjcKLZVa0eW5UZA32hM SkrUKSy/UOk/xvnUSAPJr39r81UkW8PPIeSvo1Gkow9/WPcyGMjhKOSQsw1sm3w3sUSX Nw4eUOOblfqHBzmU21qM8qZlaPAbU49P5FJd5pibqL8A4DM0/+HiPitIWi5mGNTutmt/ sbNbq0JHpAonzPsCTaBMKnmV+UbLh10o7UMeyPF+i7VPwoej1Ze+Z5p1LWMc0xk9osEM RBtjWa05n5Im0lR0iDRgXzQoqxErosEC8HVrzc/l1p9HQCzEQOqQ2ZiyT8fZuR6NW9o2 K6jA== 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=W5to3Z4Sn21mWEIZEJGvSoWUEuZOvMtlIkM4pTNXTa4=; b=rOWyCs1pyZmIKkuNiOTV1T93jcLjJ/A0h18ykEUZQjCOM2Y1BNmUWORYt5Fx9u9mZd ViXjXFGwgrS8RJnWi22kji37y8lV6ht1B8fKkUilwJ/05ohNAbcEceYpnnMRn36zkAaK x7UwIaJB5I/+IM1vRpUktiP3rHLA3wtTiGYMit9CzlbHORhkyxX3w5CAputxmpuYQBGl AxCQVJ+Y3WtGIn2JmVNx2a80hp9dbNktGlkklvuP/bj97uFFz+2dd6PMenjVGc4vTEXt AKpGBbBOfoFs+GOTQYwg0CFg3VDNSaHAwL61SoaUKVsEaDJ34HoLpyV2Slm9zJoPaa/t p25Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@igel-co-jp.20210112.gappssmtp.com header.s=20210112 header.b=athKvejD; 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 y19-20020a50e613000000b004591f959c3bsi10394830edm.427.2022.12.26.23.59.33; Mon, 26 Dec 2022 23:59:49 -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=athKvejD; 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 S230088AbiL0Hth (ORCPT + 66 others); Tue, 27 Dec 2022 02:49:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229561AbiL0Hte (ORCPT ); Tue, 27 Dec 2022 02:49:34 -0500 Received: from mail-ua1-x92f.google.com (mail-ua1-x92f.google.com [IPv6:2607:f8b0:4864:20::92f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC48BE1A for ; Mon, 26 Dec 2022 23:49:33 -0800 (PST) Received: by mail-ua1-x92f.google.com with SMTP id f25so2778805uaa.3 for ; Mon, 26 Dec 2022 23:49:33 -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=W5to3Z4Sn21mWEIZEJGvSoWUEuZOvMtlIkM4pTNXTa4=; b=athKvejDkz6WSCUOqN63r4RkPc7PljBcdn1pqKggjZSE8/UMue7d69Hl0+z0dS1T14 TMhEMq/PWya4AXj39g9+GOrmLL/6PF0RM4WrxXttFOwovqpHxNQYtyH4IboGtbgLeNqV SXdXhdL07fADUCEVkrw4TPoqd61my8VqkLH8JoelYHKVxjoTN/wxYvv/ArhTnhs9dRHG k5aaZcuYrmlAQmcwMjLycR0ZuNHCCCf3taivtDVAZ5oAdkOHU0A1//IUelvkKEKIWYYa jNK5gRLbWE3DV++L1ZnaRG6YpOx9jMjvsaOPkoQD+v6pnSzOtW7vFH5SC2hG7hXGo4AN ec2Q== 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=W5to3Z4Sn21mWEIZEJGvSoWUEuZOvMtlIkM4pTNXTa4=; b=7icCIjNs8qKjNjIdHHDMo0M8gZEfbChZrswgcftUf3PWDsC0LHeHmWtNySIBZX3yQt OyAAQLTyxJstcsvaEngaBHQXsvSwkIzwNZB9Epcnmzg1A4Ebqq3aSixdrQf51uGn2OJK QqeY5hoT6VxS9rKAKdQKWSrP1sDM4u15b58z6rQjNlHaMUjHU3VGs2/xSM6JngMVz4Rw fVSqMbU0VLlctveBFG6FO3Nj4OnGzraAtK+oyA7soQZIEYW9PyQzYzM8gjDvWGu7e+te 2CYBreSbhyovlpTjrbuTIow4dhu8QBj9D25w7VlyYdww/EnxYvGFEY+KdW3rtvvWatg2 nyHQ== X-Gm-Message-State: AFqh2kp0+Z9jwhs3i2r33Z1/sbLxHxPrIqTxsd9jRYEwNz8wkiDS3bc+ dzSUMB4cHWLKtAGQeZS66eiBnIObXeAZ79CxjTlsug== X-Received: by 2002:ab0:2eb7:0:b0:43a:243f:35b7 with SMTP id y23-20020ab02eb7000000b0043a243f35b7mr2032126uay.101.1672127372773; Mon, 26 Dec 2022 23:49:32 -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: <20221227020007-mutt-send-email-mst@kernel.org> From: Shunsuke Mie Date: Tue, 27 Dec 2022 16:49:21 +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: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 th= at > > becomes loss extendability. > > > > Introduce a struct vringh_ops and provide a common APIs for all accesso= rs. > > 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 c= har *fmt, ...) > > } > > > > /* Returns vring->num if empty, -ve on error. */ > > -static inline int __vringh_get_head(const struct vringh *vrh, > > - int (*getu16)(const struct vringh *vr= h, > > - u16 *val, const __virti= o16 *p), > > - u16 *last_avail_idx) > > +static inline int __vringh_get_head(const struct vringh *vrh, u16 *las= t_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 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 br= eak > 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. Thank you for your comments. > Thanks! > > Best, Shunsuke.