netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stanislav Fomichev <stfomichev@gmail.com>
To: Mina Almasry <almasrymina@google.com>
Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com, viro@zeniv.linux.org.uk,
	horms@kernel.org, andrew+netdev@lunn.ch, shuah@kernel.org,
	sagi@grimberg.me, willemb@google.com, asml.silence@gmail.com,
	jdamato@fastly.com, kaiyuanz@google.com,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH net-next 2/3] selftests: ncdevmem: make chunking optional
Date: Wed, 21 May 2025 10:39:00 -0700	[thread overview]
Message-ID: <aC4PtKAt5QF655uZ@mini-arch> (raw)
In-Reply-To: <CAHS8izNwpgf3ks1C6SCqDhUPnR=mbo-AdE2kQ3yk4HK-tFUUhg@mail.gmail.com>

On 05/21, Mina Almasry wrote:
> On Tue, May 20, 2025 at 1:30 PM Stanislav Fomichev <stfomichev@gmail.com> wrote:
> >
> > Add new -z argument to specify max IOV size. By default, use
> > single large IOV.
> >
> > Signed-off-by: Stanislav Fomichev <stfomichev@gmail.com>
> > ---
> >  .../selftests/drivers/net/hw/ncdevmem.c       | 49 +++++++++++--------
> >  1 file changed, 29 insertions(+), 20 deletions(-)
> >
> > diff --git a/tools/testing/selftests/drivers/net/hw/ncdevmem.c b/tools/testing/selftests/drivers/net/hw/ncdevmem.c
> > index ca723722a810..fc7ba7d71502 100644
> > --- a/tools/testing/selftests/drivers/net/hw/ncdevmem.c
> > +++ b/tools/testing/selftests/drivers/net/hw/ncdevmem.c
> > @@ -82,6 +82,9 @@
> >  #define MSG_SOCK_DEVMEM 0x2000000
> >  #endif
> >
> > +#define MAX_IOV 1024
> > +
> > +static size_t max_chunk;
> >  static char *server_ip;
> >  static char *client_ip;
> >  static char *port;
> > @@ -834,10 +837,10 @@ static int do_client(struct memory_buffer *mem)
> >         struct sockaddr_in6 server_sin;
> >         struct sockaddr_in6 client_sin;
> >         struct ynl_sock *ys = NULL;
> > +       struct iovec iov[MAX_IOV];
> >         struct msghdr msg = {};
> >         ssize_t line_size = 0;
> >         struct cmsghdr *cmsg;
> > -       struct iovec iov[2];
> >         char *line = NULL;
> >         unsigned long mid;
> >         size_t len = 0;
> > @@ -893,27 +896,29 @@ static int do_client(struct memory_buffer *mem)
> >                 if (line_size < 0)
> >                         break;
> >
> > -               mid = (line_size / 2) + 1;
> > -
> > -               iov[0].iov_base = (void *)1;
> > -               iov[0].iov_len = mid;
> > -               iov[1].iov_base = (void *)(mid + 2);
> > -               iov[1].iov_len = line_size - mid;
> > +               if (max_chunk) {
> > +                       msg.msg_iovlen =
> > +                               (line_size + max_chunk - 1) / max_chunk;
> > +                       if (msg.msg_iovlen > MAX_IOV)
> > +                               error(1, 0,
> > +                                     "can't partition %zd bytes into maximum of %d chunks",
> > +                                     line_size, MAX_IOV);
> >
> > -               provider->memcpy_to_device(mem, (size_t)iov[0].iov_base, line,
> > -                                          iov[0].iov_len);
> > -               provider->memcpy_to_device(mem, (size_t)iov[1].iov_base,
> > -                                          line + iov[0].iov_len,
> > -                                          iov[1].iov_len);
> > +                       for (int i = 0; i < msg.msg_iovlen; i++) {
> > +                               iov[i].iov_base = (void *)(i * max_chunk);
> > +                               iov[i].iov_len = max_chunk;
> 
> Isn't the last iov going to be truncated in the case where line_size
> is not exactly divisible with max_chunk?

I have this for the last iov entry:

   iov[msg.msg_iovlen - 1].iov_len =
           line_size - (msg.msg_iovlen - 1) * max_chunk;

I think that should correctly adjust it to the remaining 1..max_chunk
len?

> > +                       }
> >
> > -               fprintf(stderr,
> > -                       "read line_size=%ld iov[0].iov_base=%lu, iov[0].iov_len=%lu, iov[1].iov_base=%lu, iov[1].iov_len=%lu\n",
> > -                       line_size, (unsigned long)iov[0].iov_base,
> > -                       iov[0].iov_len, (unsigned long)iov[1].iov_base,
> > -                       iov[1].iov_len);
> > +                       iov[msg.msg_iovlen - 1].iov_len =
> > +                               line_size - (msg.msg_iovlen - 1) * max_chunk;
> > +               } else {
> > +                       iov[0].iov_base = 0;
> > +                       iov[0].iov_len = line_size;
> > +                       msg.msg_iovlen = 1;
> > +               }
> 
> Do you need to special case this? Shouldn't this be the same as max_chunk==1?

I might need a better name. max_chunk is the max size of the iov entry
(max iov_len), not the max number of IOVs. And I use max_chunk==0 as
"max size of the iov is not provided -> use line_size", so not sure
I can't make it work without a special case?

  reply	other threads:[~2025-05-21 17:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-20 20:30 [PATCH net-next 1/3] net: devmem: support single IOV with sendmsg Stanislav Fomichev
2025-05-20 20:30 ` [PATCH net-next 2/3] selftests: ncdevmem: make chunking optional Stanislav Fomichev
2025-05-21 17:21   ` Mina Almasry
2025-05-21 17:39     ` Stanislav Fomichev [this message]
2025-05-21 19:08       ` Mina Almasry
2025-05-20 20:30 ` [PATCH net-next 3/3] selftests: ncdevmem: add tx test with multiple IOVs Stanislav Fomichev
2025-05-21 17:22   ` Mina Almasry
2025-05-21 17:41     ` Stanislav Fomichev
2025-05-21 17:16 ` [PATCH net-next 1/3] net: devmem: support single IOV with sendmsg Mina Almasry
2025-05-21 17:33   ` Stanislav Fomichev
2025-05-21 18:44     ` Mina Almasry
2025-05-22  8:31     ` Pavel Begunkov
2025-05-28  1:30 ` Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aC4PtKAt5QF655uZ@mini-arch \
    --to=stfomichev@gmail.com \
    --cc=almasrymina@google.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=asml.silence@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=jdamato@fastly.com \
    --cc=kaiyuanz@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sagi@grimberg.me \
    --cc=shuah@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).