-
Notifications
You must be signed in to change notification settings - Fork 574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is AF_XDP socket thread-safe #388
Comments
Yes, but there is no point in doing this. You will likely just slow down your application somewhat. |
Thanks for your reply and suggestions and sorry for reply late! I am considering separating the rx && tx task into two threads. I am creating two sockets(one for rx and one for tx) and assigning them to two threads.
But I get the error when I init 2 eth(which means that init 4 socket). And the errno is 22. It's happened at bind in xsk_socket__create_shared. I search errno 22 and seems it indicates that the socket is already bound to an address or the address is invalid.
|
It all depends on what exact combination of netdev and queue id you are trying to bind to in the two processes. There are two modes: one if they are both the same, and another one if they differ. Take a look at the documentation in Documentation/networking/af_xdp.rst in the kernel sources. For examples you can look at these two from the bpf-examples repo: https://github.com/xdp-project/bpf-examples/tree/master/AF_XDP-example (when they are the same) |
Thanks for your help! I think what I try to do is that use two mode both. E.g. I have two veth: veth1, veth2, both of them have one queue 0. And I try to bind 4 sockets for them. I do this successfully by a little trick because seems the interface
And seems the way I solve this is to modify the |
No need to use the shared version here as there is nothing to share with.
It is correct that you do not need to use the shared version of the call here as that call is for the case when you share a umem between different netdevs and/or queue ids.
Mixing the two modes is not supported by bind, but there is a trick you can apply. Create a new umem here, but have it overlap the first umem area perfectly. Then repeat step 2 and 3 but with veth2 and the new umem.
|
Thanks! |
I'm curious about the difference between this way and the |
The same restrictions apply. xsk_socket__create_shared() is just xsk_socket__create() with the ability to specify fill and completion rings. |
Can I run multiple threads and call
sendto()
for a same AF_XDP socket concurrently?The text was updated successfully, but these errors were encountered: