Skip to content
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

Enable kprobe-multi for kmods by default #470

Merged
merged 3 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions internal/pwru/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,9 @@ func GetFuncs(pattern string, spec *btf.Spec, kmods []string, kprobeMulti bool)
}

var availableFuncs map[string]struct{}
if kprobeMulti {
availableFuncs, err = getAvailableFilterFunctions()
if err != nil {
log.Printf("Failed to retrieve available ftrace functions (is /sys/kernel/debug/tracing mounted?): %s", err)
}
availableFuncs, err = getAvailableFilterFunctions()
if err != nil {
log.Printf("Failed to retrieve available ftrace functions (is /sys/kernel/debug/tracing mounted?): %s", err)
}

iters := []iterator{{"", spec.Iterate()}}
Expand Down Expand Up @@ -93,14 +91,12 @@ func GetFuncs(pattern string, spec *btf.Spec, kmods []string, kprobeMulti bool)
continue
}

if kprobeMulti {
availableFnName := fnName
if it.kmod != "" {
availableFnName = fmt.Sprintf("%s [%s]", fnName, it.kmod)
}
if _, ok := availableFuncs[availableFnName]; !ok {
continue
}
availableFnName := fnName
if it.kmod != "" {
availableFnName = fmt.Sprintf("%s [%s]", fnName, it.kmod)
}
if _, ok := availableFuncs[availableFnName]; !ok {
continue
}

fnProto := fn.Type.(*btf.FuncProto)
Expand All @@ -111,7 +107,7 @@ func GetFuncs(pattern string, spec *btf.Spec, kmods []string, kprobeMulti bool)
if strct.Name == "sk_buff" && i <= 5 {
name := fnName
if kprobeMulti && it.kmod != "" {
name = fmt.Sprintf("%s [%s]", fnName, it.kmod)
name = fmt.Sprintf("%s[%s]", fnName, it.kmod)
}
funcs[name] = i
continue
Expand Down
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func main() {
// Until https://lore.kernel.org/bpf/[email protected]/
// has been backported to the stable, kprobe-multi cannot be used when attaching
// to kmods.
if flags.Backend == "" && len(flags.KMods) == 0 {
if flags.Backend == "" {
useKprobeMulti = pwru.HaveBPFLinkKprobeMulti() && pwru.HaveAvailableFilterFunctions()
} else if flags.Backend == pwru.BackendKprobeMulti {
useKprobeMulti = true
Expand All @@ -117,7 +117,6 @@ func main() {
var opts ebpf.CollectionOptions
opts.Programs.KernelTypes = btfSpec
opts.Programs.LogLevel = ebpf.LogLevelInstruction
opts.Programs.LogSize = ebpf.DefaultVerifierLogSize * 100

bpfSpec, err := LoadKProbePWRU()
if err != nil {
Expand Down
Loading