From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 458FB5A026D for ; Thu, 14 Mar 2024 08:03:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710399797; 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=qes+gJMu/JM2hxJAwt7Re6VIbgwO9rZUFaHjQX/ikio=; b=ZHecsEyhbkJmkAIhzVpuR53ziypuRl19xAj4ZfHJg1FQ+agH0qRLx9K+gZpcUUGP3TSRcJ Pxy+Za9Z8pbZl7FSV67Kz1MSLUj41aT/rG5dOvnpQKGBrkc2p0tXUQnUYtNIVuI8vLsBCN Hi6vSlpvZaT8/w1gljVM652t093KSwg= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-576-OqaQ7gN0PUa5aNHumLQ0bw-1; Thu, 14 Mar 2024 03:03:15 -0400 X-MC-Unique: OqaQ7gN0PUa5aNHumLQ0bw-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a45acc7f191so34338566b.0 for ; Thu, 14 Mar 2024 00:03:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710399794; x=1711004594; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=qes+gJMu/JM2hxJAwt7Re6VIbgwO9rZUFaHjQX/ikio=; b=kA5xMVwCabz53OInUL3PZMkdhFwVAeaJ8915cfa6h7uciQquQGxUn+UJPyQ7o+t5Pe FjV0IfTaGFdvuwtJvpIvdU1BOuGRMrEt//DoHhqBOqvkSZGegxqb/IhsO3BtR913XclN xc3NfpEqFekf9kFkzr70kiEsitHK3kEYTnxSxXkViLNA+XihP41ZEMs83ZlUHizYLN2E 3EwYszVlKwjvGT9ZOukjhi1ZzQgsuc5CeZQs/+Pd1a5frt9jBKfMO04MNGldeYZws020 C29i4bjAziSsUAN5tC3dSoPntUHZHWoQYmYSa0vDQrkwwE4GOM6zxhSWLBdiAVX62kPZ vneQ== X-Gm-Message-State: AOJu0YzueyLYKr2Fwvz0hCG5sp8Tvn5+79l7r063fU7hSkM1YRnT4U8T PKNUYXSf69jN+06peI+elvfTmgxaGnBpIIDvIRd47XoUbDlJprRxrEBE4SohsRgbO3gX0E1kxOV oX0I6v6JX8io7qFa4af/U/FseR86MsXGv6TDl0Sfs6ycPY4uE5A== X-Received: by 2002:a17:907:1606:b0:a45:ed7f:266a with SMTP id cw6-20020a170907160600b00a45ed7f266amr684225ejd.0.1710399793825; Thu, 14 Mar 2024 00:03:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEDbb641/y5u+Tld9qV29Q6qcweXd0A+LnIxJbxEEApVtQPx+JS325WBZFwXLrgepK/U/0Kog== X-Received: by 2002:a17:907:1606:b0:a45:ed7f:266a with SMTP id cw6-20020a170907160600b00a45ed7f266amr684200ejd.0.1710399793228; Thu, 14 Mar 2024 00:03:13 -0700 (PDT) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id gx27-20020a1709068a5b00b00a3e5adf11c7sm392525ejc.157.2024.03.14.00.03.12 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Mar 2024 00:03:12 -0700 (PDT) Date: Thu, 14 Mar 2024 08:02:17 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 1/4] tap: Extend tap_send_frames() to allow multi-buffer frames Message-ID: <20240314080217.5fa84a1e@elisabeth> In-Reply-To: <20240308065325.2181322-2-david@gibson.dropbear.id.au> References: <20240308065325.2181322-1-david@gibson.dropbear.id.au> <20240308065325.2181322-2-david@gibson.dropbear.id.au> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.36; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: JPI2RVB65KYDPOOBAZLAMJHG66TJPRBT X-Message-ID-Hash: JPI2RVB65KYDPOOBAZLAMJHG66TJPRBT X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top, Laurent Vivier X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Fri, 8 Mar 2024 17:53:22 +1100 David Gibson wrote: > tap_send_frames() takes a vector of buffers and requires exactly one frame > per buffer. We have future plans where we want to have multiple buffers > per frame in some circumstances, so extend tap_send_frames() to take the > number of buffers per frame as a parameter. > > Signed-off-by: David Gibson > --- > tap.c | 83 +++++++++++++++++++++++++++++++++++++---------------------- > tap.h | 3 ++- > tcp.c | 8 +++--- > udp.c | 2 +- > 4 files changed, 59 insertions(+), 37 deletions(-) > > diff --git a/tap.c b/tap.c > index f4051cec..f9e2a8d9 100644 > --- a/tap.c > +++ b/tap.c > @@ -309,21 +309,28 @@ void tap_icmp6_send(const struct ctx *c, > > /** > * tap_send_frames_pasta() - Send multiple frames to the pasta tap > - * @c: Execution context > - * @iov: Array of buffers, each containing one frame > - * @n: Number of buffers/frames in @iov > + * @c: Execution context > + * @iov: Array of buffers > + * @bufs_per_frame: Number of buffers (iovec entries) per frame > + * @nframes: Number of frames to send > * > + * @iov must have total length @bufs_per_frame * @nframes, with each set of > + * @bufs_per_frame contiguous buffers representing a single frame. Oh, this does pretty much what I was suggesting as a comment to Laurent's "tcp: Replace TCP buffer structure by an iovec array" -- I should have reviewed this first. > + * > * Return: number of frames successfully sent > * > * #syscalls:pasta write > */ > static size_t tap_send_frames_pasta(const struct ctx *c, > - const struct iovec *iov, size_t n) > + const struct iovec *iov, > + size_t bufs_per_frame, size_t nframes) > { > + size_t nbufs = bufs_per_frame * nframes; > size_t i; > > - for (i = 0; i < n; i++) { > - ssize_t rc = write(c->fd_tap, iov[i].iov_base, iov[i].iov_len); > + for (i = 0; i < nbufs; i += bufs_per_frame) { > + ssize_t rc = writev(c->fd_tap, iov + i, bufs_per_frame); > + size_t framelen = iov_size(iov + i, bufs_per_frame); > > if (rc < 0) { > debug("tap write: %s", strerror(errno)); > @@ -340,32 +347,37 @@ static size_t tap_send_frames_pasta(const struct ctx *c, > default: > die("Write error on tap device, exiting"); > } > - } else if ((size_t)rc < iov[i].iov_len) { > - debug("short write on tuntap: %zd/%zu", > - rc, iov[i].iov_len); > + } else if ((size_t)rc < framelen) { > + debug("short write on tuntap: %zd/%zu", rc, framelen); > break; > } > } > > - return i; > + return i / bufs_per_frame; > } > > /** > * tap_send_frames_passt() - Send multiple frames to the passt tap > - * @c: Execution context > - * @iov: Array of buffers, each containing one frame > - * @n: Number of buffers/frames in @iov > + * @c: Execution context > + * @iov: Array of buffers, each containing one frame > + * @bufs_per_frame: Number of buffers (iovec entries) per frame > + * @nframes: Number of frames to send > * > + * @iov must have total length @bufs_per_frame * @nframes, with each set of > + * @bufs_per_frame contiguous buffers representing a single frame. > + * > * Return: number of frames successfully sent > * > * #syscalls:passt sendmsg > */ > static size_t tap_send_frames_passt(const struct ctx *c, > - const struct iovec *iov, size_t n) > + const struct iovec *iov, > + size_t bufs_per_frame, size_t nframes) > { > + size_t nbufs = bufs_per_frame * nframes; > struct msghdr mh = { > .msg_iov = (void *)iov, > - .msg_iovlen = n, > + .msg_iovlen = nbufs, > }; > size_t buf_offset; > unsigned int i; > @@ -376,44 +388,53 @@ static size_t tap_send_frames_passt(const struct ctx *c, > return 0; > > /* Check for any partial frames due to short send */ > - i = iov_skip_bytes(iov, n, sent, &buf_offset); > + i = iov_skip_bytes(iov, nbufs, sent, &buf_offset); > + > + if (i < nbufs && (buf_offset || (i % bufs_per_frame))) { > + /* Number of not-fully-sent buffers in the frame */ Strictly speaking, this comment is correct, but "not-fully-sent" seems to imply that rembufs only counts partially sent buffers. It also counts the ones that weren't sent at all. What about: /* Number of partially sent or not sent buffers for the frame */ ? The rest of the series looks good to me, I can change this text on merge if you like the proposal, or even apply it as it is (well, it's correct, after all). -- Stefano