Re: thread safe, lock free AF_XDP setup

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 10 Jul 2023 at 15:51, Július Milan <julius.milan.22@xxxxxxxxx> wrote:
>
> Hi all
>
> I am missing a full understanding of what really is thread safe and
> what is not, when using AF_XDP.
>
> RX and TX operations look obvious as every xsk socket has its own RX
> and TX rings and so I can have multiple threads, as long as they don't
> try to use the same ring of the same socket concurrently, that's the
> only limitation (Am I correct yet?). So I can have for example 1:1
> mapping of thread to xsk socket to avoid locking.

That is correct.

> However what about UMEM rings, i.e. Completion and Fill queue?
> About ring operations as __peek, __reserve ..., it is written (for ex.
> here: https://www.kernel.org/doc/html/latest/networking/af_xdp.html#rings),
> that they are not thread safe.
> So it seems that I should use mutex to access them.
> But I can see in:
> https://github.com/xdp-project/bpf-examples/blob/master/AF_XDP-forwarding/xsk_fwd.c#L526
> That they are filled / drained without locking, how is it then?

The documentation above mentions that there are two shared_umem modes:
one if you want to share the same netdev/queue_id and another one for
all the other cases. The forwarding example uses the latter which has
one fill ring and one completion ring per socket. So no locking
needed. The former only has one fill and completion ring pair per
umem, so you need to take care of mutual exclusion yourself in this
case.

> Does it make a difference if the socket is created by
> xsk_socket__create_shared or xsk_socket__create?

The former one sets the XDP_SHARED_UMEM flag. If you want to share the
umem between several sockets, you need to use this one.

> What is the limitation that cannot be broken, as I described it for RX
> / TX? (if correctly)
>
> Best Regards
> Julius




[Index of Archives]     [Linux Networking Development]     [Fedora Linux Users]     [Linux SCTP]     [DCCP]     [Gimp]     [Yosemite Campsites]

  Powered by Linux