Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp524151imm; Mon, 21 May 2018 09:47:18 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqUQIsCiOqGJ0uSWbqfCkVAhDUw6zTXYk53Nq1/0UJLJgc/GzNX4cVcO0ktWMrmtVtYS0nJ X-Received: by 2002:a63:78c3:: with SMTP id t186-v6mr1866564pgc.93.1526921238567; Mon, 21 May 2018 09:47:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526921238; cv=none; d=google.com; s=arc-20160816; b=HKCL1e/nyNnH0fVJVfxpcNSl7SW3Et39rS610wyrJrWhSGaNRk4Diz0D7HP/jEf7Mw D0B7FOMQl13qo+NLIperGFZR6HubOnJxBUfblt7j61xRQOfZ3cB6aH/sptaS/i7HK1qa 08khr7MV7Gb2XzxwKn9mAgxjzR48yDk3ec26mhuQbMDzrxw0I+9k4B1yXA0mrMKr8q1g KXQW+y4JYRaBxC1E1IwuWXxhMW9oS4hWP9Yw+T1iE+OGPetxzKsyD83gTPn9r94gPYM3 ECW+asxXn7zTdR7kYjNo5t8sCcBuziwhIvhoI+gs32AZ3MgthROTnyZRwYzdDTiPydd4 zmhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=qklONUE2YyaKfbH2EzsqwKyVUBLANVowR1k8vIGUNio=; b=KS4eBfGTUoQxBFPODfyxtZsBXet8PmlZ0P5dEiHWKqsxC+pxEfdIb7SZel8Y+3lYBS GCq89TUGUhgA1yimaYpJ/Rt8GG7jvnAezl4HYE0IC7K7RmTP8PPXOccHSk7zH8IR2r6Y XEVAMTCAsqALmdnBFbIOXUwCg8BVEKBePx1JN1luh4Gcl8p/KlXFve1u615wejIIHMYr oAl1GVSQySL+2FBEg62SDHSk4eC8umreEHdE9WJvNs8FZvgEJglZ9d7NiOYUCqe+6Pdr pYma88awvgnUpPPdo7A7Cptzj+B5XrJ2W2PPbHH8grbiTSZdook5brCkpOST+trj6Z// p/Dw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z124-v6si14184487pfb.67.2018.05.21.09.47.03; Mon, 21 May 2018 09:47:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753137AbeEUQqw (ORCPT + 99 others); Mon, 21 May 2018 12:46:52 -0400 Received: from mga14.intel.com ([192.55.52.115]:49136 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752247AbeEUQqr (ORCPT ); Mon, 21 May 2018 12:46:47 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 May 2018 09:46:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,426,1520924400"; d="scan'208";a="57754209" Received: from jesse-tab.amr.corp.intel.com (HELO localhost) ([10.166.244.182]) by orsmga001.jf.intel.com with ESMTP; 21 May 2018 09:46:46 -0700 Date: Mon, 21 May 2018 09:46:46 -0700 From: Jesse Brandeburg To: Jason Wang Cc: , , , , , jesse.brandeburg@intel.com Subject: Re: [RFC PATCH net-next 04/12] vhost_net: split out datacopy logic Message-ID: <20180521094646.00002dee@intel.com> In-Reply-To: <1526893473-20128-5-git-send-email-jasowang@redhat.com> References: <1526893473-20128-1-git-send-email-jasowang@redhat.com> <1526893473-20128-5-git-send-email-jasowang@redhat.com> X-Mailer: Claws Mail 3.14.0 (GTK+ 2.24.30; i686-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 21 May 2018 17:04:25 +0800 Jason wrote: > Instead of mixing zerocopy and datacopy logics, this patch tries to > split datacopy logic out. This results for a more compact code and > specific optimization could be done on top more easily. > > Signed-off-by: Jason Wang > --- > drivers/vhost/net.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++----- > 1 file changed, 102 insertions(+), 9 deletions(-) > > diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c > index 4ebac76..4682fcc 100644 > --- a/drivers/vhost/net.c > +++ b/drivers/vhost/net.c > @@ -492,9 +492,95 @@ static bool vhost_has_more_pkts(struct vhost_net *net, > likely(!vhost_exceeds_maxpend(net)); > } > > +static void handle_tx_copy(struct vhost_net *net) > +{ > + struct vhost_net_virtqueue *nvq = &net->vqs[VHOST_NET_VQ_TX]; > + struct vhost_virtqueue *vq = &nvq->vq; > + unsigned out, in; move "out" and "in" down to inside the for loop as well. > + int head; move this "head" declaration inside for-loop below. > + struct msghdr msg = { > + .msg_name = NULL, > + .msg_namelen = 0, > + .msg_control = NULL, > + .msg_controllen = 0, > + .msg_flags = MSG_DONTWAIT, > + }; > + size_t len, total_len = 0; > + int err; > + size_t hdr_size; > + struct socket *sock; > + struct vhost_net_ubuf_ref *uninitialized_var(ubufs); > + int sent_pkts = 0; why do we need so many locals? > + > + mutex_lock(&vq->mutex); > + sock = vq->private_data; > + if (!sock) > + goto out; > + > + if (!vq_iotlb_prefetch(vq)) > + goto out; > + > + vhost_disable_notify(&net->dev, vq); > + vhost_net_disable_vq(net, vq); > + > + hdr_size = nvq->vhost_hlen; > + > + for (;;) { > + head = vhost_net_tx_get_vq_desc(net, vq, vq->iov, > + ARRAY_SIZE(vq->iov), > + &out, &in); > + /* On error, stop handling until the next kick. */ > + if (unlikely(head < 0)) > + break; > + /* Nothing new? Wait for eventfd to tell us they refilled. */ > + if (head == vq->num) { > + if (unlikely(vhost_enable_notify(&net->dev, vq))) { > + vhost_disable_notify(&net->dev, vq); > + continue; > + } > + break; > + } > + if (in) { > + vq_err(vq, "Unexpected descriptor format for TX: " > + "out %d, int %d\n", out, in); don't break strings, keep all the bits between " " together, even if it is longer than 80 chars. > + break; > + } > + > + len = init_iov_iter(vq, &msg.msg_iter, hdr_size, out); > + if (len < 0) > + break; same comment as previous patch, len is a size_t which is unsigned. > + > + total_len += len; > + if (total_len < VHOST_NET_WEIGHT && > + vhost_has_more_pkts(net, vq)) { > + msg.msg_flags |= MSG_MORE; > + } else { > + msg.msg_flags &= ~MSG_MORE; > + } don't need { } here. > + > + /* TODO: Check specific error and bomb out unless ENOBUFS? */ > + err = sock->ops->sendmsg(sock, &msg, len); > + if (unlikely(err < 0)) { > + vhost_discard_vq_desc(vq, 1); > + vhost_net_enable_vq(net, vq); > + break; > + } > + if (err != len) > + pr_debug("Truncated TX packet: " > + " len %d != %zd\n", err, len); single line " " string please