All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
To: Jason Xing <kerneljasonxing@gmail.com>
Cc: Stanislav Fomichev <stfomichev@gmail.com>, <davem@davemloft.net>,
	<edumazet@google.com>, <kuba@kernel.org>, <pabeni@redhat.com>,
	<bjorn@kernel.org>, <magnus.karlsson@intel.com>,
	<jonathan.lemon@gmail.com>, <sdf@fomichev.me>, <ast@kernel.org>,
	<daniel@iogearbox.net>, <hawk@kernel.org>,
	<john.fastabend@gmail.com>, <joe@dama.to>,
	<willemdebruijn.kernel@gmail.com>, <bpf@vger.kernel.org>,
	<netdev@vger.kernel.org>, Jason Xing <kernelxing@tencent.com>
Subject: Re: [PATCH net-next v5 2/2] selftests/bpf: add a new test to check the consumer update case
Date: Thu, 3 Jul 2025 14:37:10 +0200	[thread overview]
Message-ID: <aGZ5dq5P0G8e8A/J@boxer> (raw)
In-Reply-To: <CAL+tcoA8Yhk85mkOBE9jEx7fd1s5rAW+Y8Uf2DAaNR3-9DW0Vg@mail.gmail.com>

On Thu, Jul 03, 2025 at 07:09:09AM +0800, Jason Xing wrote:
> On Thu, Jul 3, 2025 at 12:03 AM Stanislav Fomichev <stfomichev@gmail.com> wrote:
> >
> > On 07/02, Jason Xing wrote:
> > > From: Jason Xing <kernelxing@tencent.com>
> > >
> > > The subtest sends 33 packets at one time on purpose to see if xsk
> > > exitting __xsk_generic_xmit() updates the global consumer of tx queue
> > > when reaching the max loop (max_tx_budget, 32 by default). The number 33
> > > can avoid xskq_cons_peek_desc() updates the consumer when it's about to
> > > quit sending, to accurately check if the issue that the first patch
> > > resolves remains. The new case will not check this issue in zero copy
> > > mode.
> > >
> > > Signed-off-by: Jason Xing <kernelxing@tencent.com>
> > > ---
> > > v5
> > > Link: https://lore.kernel.org/all/20250627085745.53173-1-kerneljasonxing@gmail.com/
> > > 1. use the initial approach to add a new testcase
> > > 2. add a new flag 'check_consumer' to see if the check is needed
> > > ---
> > >  tools/testing/selftests/bpf/xskxceiver.c | 51 +++++++++++++++++++++++-
> > >  tools/testing/selftests/bpf/xskxceiver.h |  1 +
> > >  2 files changed, 51 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/tools/testing/selftests/bpf/xskxceiver.c b/tools/testing/selftests/bpf/xskxceiver.c
> > > index 0ced4026ee44..ed12a55ecf2a 100644
> > > --- a/tools/testing/selftests/bpf/xskxceiver.c
> > > +++ b/tools/testing/selftests/bpf/xskxceiver.c
> > > @@ -109,6 +109,8 @@
> > >
> > >  #include <network_helpers.h>
> > >
> > > +#define MAX_TX_BUDGET_DEFAULT 32
> > > +
> > >  static bool opt_verbose;
> > >  static bool opt_print_tests;
> > >  static enum test_mode opt_mode = TEST_MODE_ALL;
> > > @@ -1091,11 +1093,45 @@ static bool is_pkt_valid(struct pkt *pkt, void *buffer, u64 addr, u32 len)
> > >       return true;
> > >  }
> > >
> > > +static u32 load_value(u32 *counter)
> > > +{
> > > +     return __atomic_load_n(counter, __ATOMIC_ACQUIRE);
> > > +}
> > > +
> > > +static bool kick_tx_with_check(struct xsk_socket_info *xsk, int *ret)
> > > +{
> > > +     u32 max_budget = MAX_TX_BUDGET_DEFAULT;
> > > +     u32 cons, ready_to_send;
> > > +     int delta;
> > > +
> > > +     cons = load_value(xsk->tx.consumer);
> > > +     ready_to_send = load_value(xsk->tx.producer) - cons;
> > > +     *ret = sendto(xsk_socket__fd(xsk->xsk), NULL, 0, MSG_DONTWAIT, NULL, 0);
> > > +
> > > +     delta = load_value(xsk->tx.consumer) - cons;
> > > +     /* By default, xsk should consume exact @max_budget descs at one
> > > +      * send in this case where hitting the max budget limit in while
> > > +      * loop is triggered in __xsk_generic_xmit(). Please make sure that
> > > +      * the number of descs to be sent is larger than @max_budget, or
> > > +      * else the tx.consumer will be updated in xskq_cons_peek_desc()
> > > +      * in time which hides the issue we try to verify.
> > > +      */
> > > +     if (ready_to_send > max_budget && delta != max_budget)
> > > +             return false;
> > > +
> > > +     return true;
> > > +}
> > > +
> > >  static int kick_tx(struct xsk_socket_info *xsk)
> > >  {
> > >       int ret;
> > >
> > > -     ret = sendto(xsk_socket__fd(xsk->xsk), NULL, 0, MSG_DONTWAIT, NULL, 0);
> > > +     if (xsk->check_consumer) {
> > > +             if (!kick_tx_with_check(xsk, &ret))
> > > +                     return TEST_FAILURE;
> > > +     } else {
> > > +             ret = sendto(xsk_socket__fd(xsk->xsk), NULL, 0, MSG_DONTWAIT, NULL, 0);
> > > +     }
> > >       if (ret >= 0)
> > >               return TEST_PASS;
> > >       if (errno == ENOBUFS || errno == EAGAIN || errno == EBUSY || errno == ENETDOWN) {
> > > @@ -2613,6 +2649,18 @@ static int testapp_adjust_tail_grow_mb(struct test_spec *test)
> > >                                  XSK_UMEM__LARGE_FRAME_SIZE * 2);
> > >  }
> > >
> > > +static int testapp_tx_queue_consumer(struct test_spec *test)
> > > +{
> > > +     int nr_packets = MAX_TX_BUDGET_DEFAULT + 1;
> > > +
> > > +     pkt_stream_replace(test, nr_packets, MIN_PKT_SIZE);
> > > +     test->ifobj_tx->xsk->batch_size = nr_packets;
> > > +     if (!(test->mode & TEST_MODE_ZC))
> > > +             test->ifobj_tx->xsk->check_consumer = true;
> >
> > The test looks good to me, thank you!
> 
> Thanks.
> 
> >
> > One question here: why not exit/return for TEST_MODE_ZC instead
> > of conditionally setting check_consumer?
> 
> As you said, yes, we could skip the zc test for this
> testapp_tx_queue_consumer(). It doesn't affect the goal or result of
> the subtest. So do you expect me to respin this patch or just leave it
> as is?

Yes I think it would be worth respinning and skipping it for zc. see how
testapp_stats_rx_dropped() does it.

Otherwise we would probably never change it and just keep on running this
test case for zc which is not beneficial at this point.

Besides LGTM!

> 
> Thanks,
> Jason

  reply	other threads:[~2025-07-03 12:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-02 11:28 [PATCH net-next v5 0/2] net: xsk: update tx queue consumer Jason Xing
2025-07-02 11:28 ` [PATCH net-next v5 1/2] net: xsk: update tx queue consumer immediately after transmission Jason Xing
2025-07-02 11:28 ` [PATCH net-next v5 2/2] selftests/bpf: add a new test to check the consumer update case Jason Xing
2025-07-02 16:03   ` Stanislav Fomichev
2025-07-02 23:09     ` Jason Xing
2025-07-03 12:37       ` Maciej Fijalkowski [this message]
2025-07-03 13:16         ` Jason Xing

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=aGZ5dq5P0G8e8A/J@boxer \
    --to=maciej.fijalkowski@intel.com \
    --cc=ast@kernel.org \
    --cc=bjorn@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hawk@kernel.org \
    --cc=joe@dama.to \
    --cc=john.fastabend@gmail.com \
    --cc=jonathan.lemon@gmail.com \
    --cc=kerneljasonxing@gmail.com \
    --cc=kernelxing@tencent.com \
    --cc=kuba@kernel.org \
    --cc=magnus.karlsson@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@fomichev.me \
    --cc=stfomichev@gmail.com \
    --cc=willemdebruijn.kernel@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.