-
I try to load a TC_CLS prog and update it in a tail_call map in usersapce via cilium/ebpf. So I am wondering whether there is a possible to cancel modifying the maxEntries of perf event array when it is larger than num of CPU. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hey 👋 With the linked check we make sure that the compatibility of loading programs is guaranteed (as explained in the comment) as well as following the approaches libbpf is doing. If you have loaded the program and perf event array with iproute2/tc before, then it should be possible to just use them via NewMapFromID or NewMapFromFD. |
Beta Was this translation helpful? Give feedback.
-
@SirHao Since you're using ip2, I assume you're pinning the perf event array to bpffs, which ebpf-go complains about since the pinned map has a different MaxEntries than the one in the CollectionSpec. First, I'd like to suggest loading and attaching everything using ebpf-go instead of ip2, that will make sure the loading behaviour is at least consistent across the board, though I assume you're dealing with a legacy app or non-Go app you want to integrate with. Flo's other response only offered you a partial solution; I think in this case you always want to use the existing pinned map instead of potentially creating a new one. Try this: // Open existing pinned map. [ebpf.NewMapFromID] can also be used,
// but since you're using ip2 you'll probably be pinning maps anyway.
m, err := ebpf.LoadPinnedMap("/sys/fs/bpf/tc/globals/my_perf_array", nil)
if err != nil {
panic(err)
}
defer m.Close()
// Load your CollectionSpec as usual.
spec, err := ebpf.LoadCollectionSpec("my_obj.o")
if err != nil {
panic(err)
}
// Manually provide fd of pinned map during Collection loading.
opts := &ebpf.CollectionOptions{
MapReplacements: map[string]*Map{
"my_perf_array": m,
}
}
// Alternatively, use LoadAndAssign here, e.g. if you're using bpf2go.
coll, err := ebpf.NewCollectionWithOptions(spec, opts)
if err != nil {
panic(err)
}
defer coll.Close() |
Beta Was this translation helpful? Give feedback.
@SirHao Since you're using ip2, I assume you're pinning the perf event array to bpffs, which ebpf-go complains about since the pinned map has a different MaxEntries than the one in the CollectionSpec.
First, I'd like to suggest loading and attaching everything using ebpf-go instead of ip2, that will make sure the loading behaviour is at least consistent across the board, though I assume you're dealing with a legacy app or non-Go app you want to integrate with.
Flo's other response only offered you a partial solution; I think in this case you always want to use the existing pinned map instead of potentially creating a new one. Try this:
// Open existing pinned map. [ebpf.NewMapFromID] can …