xdp-newbies.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ferenc Fejes <fejes@inf.elte.hu>
To: Magnus Karlsson <magnus.karlsson@gmail.com>
Cc: Xdp <xdp-newbies@vger.kernel.org>
Subject: Re: xsk_fwd.c usage
Date: Fri, 15 Jan 2021 10:41:13 +0100	[thread overview]
Message-ID: <CAAej5Nb+aSsX42eFPmeNZcasuuuXAepcO3M2wHJWffzmJBPmYw@mail.gmail.com> (raw)
In-Reply-To: <CAJ8uoz1EF-U4Lk2UZ=eKO-CqTzJssV0GS5UcYdezF-yriM63zg@mail.gmail.com>

Magnus Karlsson <magnus.karlsson@gmail.com> ezt írta (időpont: 2021.
jan. 14., Cs, 15:28):
>
>
>
> On Wed, Jan 13, 2021 at 9:32 PM Ferenc Fejes <fejes@inf.elte.hu> wrote:
>>
>> Hi!
>>
>> I wanted to try out the xsk_fwd.c [0] sample with Mininet. This sample
>> is capable of forwarding between network interfaces with AF_XDP. My
>> topology is very simple:
>> host1 <-----> switch <-----> host2
>> sudo mn --switch=lxbr
>> I started the xsk_fwd to forward between the two veth interface of the switch:
>> sudo ./xsk_fwd -i s1-eth1 -q0 -i s1-eth2 -q0 -c 0
>>
>> This is failed with EOPNOTSUPP error first. Then I looked into the
>> xsk_bind function and soon after I found this (at there [1]):
>> if (force_copy)
>>     /* For copy-mode, we are done. */
>>     return 0;
>>
>> if (!netdev->netdev_ops->ndo_bpf ||
>>     !netdev->netdev_ops->ndo_xsk_wakeup) {
>>     err = -EOPNOTSUPP;
>>     goto err_unreg_pool;
>> }
>>
>> After that just like the code said, I removed the XDP_ZEROCOPY from
>> the bind flags [2] at the xsk_fwd.c which solved the problem and the
>> program started successfully, but without any traffic between host1
>> and host2.
>>
>
> The xsk_fwd app was written with zero-copy in mind. We should probably add an "-S" option to it to start it in skb mode that should work with all netdev drivers. You need to change both these lines:
>
>                 .xdp_flags = XDP_FLAGS_DRV_MODE,
>                 .bind_flags = XDP_USE_NEED_WAKEUP | XDP_ZEROCOPY,
>
> XDP_FLAGS_DRV_MODE -> XDP_FLAGS_SKB_MODE
> XDP_ZEROCOPY -> XDP_COPY
>
> Please try this. If not, try simpler programs first and see if they work to get some hints.

Thank you for the quick answer! It turned out both SKB and DRV mode
works very well with veth devices. The XDP_COPY required however.

I finally managed to forward traffic between the namespaces: there is
a MAX_BURST_TX 64 define and I simply tested with ping (not some
traffic generator) and it required 64 sec to catch the first TX
transmission because of that. If I set MAX_BURST_RX and MAX_BURST_TX
to 1, ping works well (but TCP dont for some reason).

I working with DPDK for a while and I would like to do a migration to
AF_XDP because I love the fact that's already in the kernel and I only
have to install libbpf for make it work.

>
>>
>> My main question: removing XDP_ZEROCOPY requires any semantical
>> modification in the forwarding code? For example I should have to
>> memcopy the xdp buffer manually? Or the kernel do the copy
>> automatically and I have to look for the problem elsewhere? I have
>> 5.10.5 kernel version which supports shared UMEMs.
>
>
> From a programmatic perspective, it does not matter if you are using zero-copy or not. It will work the same way in both cases. The performance will be different of course.
>
Thank you for the answer, this is very convenient.
>>
>>
>> [0] https://elixir.bootlin.com/linux/v5.11-rc3/source/samples/bpf/xsk_fwd.c
>> [1] https://elixir.bootlin.com/linux/v5.10.5/source/net/xdp/xsk_buff_pool.c#L158
>> [2] https://elixir.bootlin.com/linux/v5.11-rc3/source/samples/bpf/xsk_fwd.c#L732
>>
>> Thanks for the help!
>> Ferenc

      parent reply	other threads:[~2021-01-15  9:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-13 20:28 xsk_fwd.c usage Ferenc Fejes
     [not found] ` <CAJ8uoz1EF-U4Lk2UZ=eKO-CqTzJssV0GS5UcYdezF-yriM63zg@mail.gmail.com>
2021-01-15  9:41   ` Ferenc Fejes [this message]

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=CAAej5Nb+aSsX42eFPmeNZcasuuuXAepcO3M2wHJWffzmJBPmYw@mail.gmail.com \
    --to=fejes@inf.elte.hu \
    --cc=magnus.karlsson@gmail.com \
    --cc=xdp-newbies@vger.kernel.org \
    /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).