atoonk / go-pktgen

Apache License 2.0
125 stars 8 forks source link

how can i create more xsk socket on same nic ? #1

Closed lddlww closed 3 months ago

lddlww commented 3 months ago

that's great work!!

i have eth0 nic, which have 8 queues, but follow code throws error:

xsk, err := xdp.NewSocket(link.Attrs().Index, 1, nil)
xsk1, err := xdp.NewSocket(link.Attrs().Index, 2, nil)

error is:

error: syscall.Bind SockaddrXDP failed: device or resource busy

how can i do to fix it?

atoonk commented 3 months ago

Hi @lddlww hhmm, that maybe more a question for the xdp library I'm using. I recognized the error from reading the issues there, then I realized you already opened an issue there :)

So not sure how to help with that. I assume you see the same issues when running the tool with multiple streams? --streams 2 ?

lddlww commented 3 months ago

@atoonk thanks for reply

So not sure how to help with that. I assume you see the same issues when running the tool with multiple streams? --streams 2 ?

no,it works normal

i create xsk socket in per goroutine , it works normal also;but create many xsk socket in one goroutine ,it works abnormal

atoonk commented 3 months ago

@lddlww

Ah ok, yah in go-pktgen, if you provide multiple streams, we also create a go routine per stream So a xsp per go routine.

it sounds like that works for you as well. Is there a problem with doing one xsk per go routine? you don't want go routines?

Not sure about your use-case, but to get max value, I imagine that's the best way, ie use go routine per xsk. otherwise how would you write to the multiple descs at the same time? remember you'll like want a descs per xsk

                        descs := xsk.GetDescs(xsk.NumFreeTxSlots(), false)
            for i := range descs {
                descs[i].Len = uint32(frameLen)
            }
            xsk.Transmit(descs)

Also just to make sure, you can only create as many xsk's as you have TX queues. there's a check here: https://github.com/atoonk/go-pktgen/blob/main/main.go#L84-L92

you can check with ethtool -l

Cheers!

lddlww commented 3 months ago

I imagine that's the best way, ie use go routine per xsk. otherwise how would you write to the multiple descs at the same time? remember you'll like want a descs per xsk

ops,you are right; thanks for remind

atoonk commented 3 months ago

Will close for now then. have fun!