@@ -55,6 +55,13 @@ const (
5555 probProfilingDisable = - 1
5656)
5757
58+ // Names of tracepoint hooks for sched_process_free. There are two hooks
59+ // as the tracepoint format has changed for kernel versions 6.16+.
60+ const (
61+ schedProcessFreeV1 = "tracepoint__sched_process_free_pre616"
62+ schedProcessFreeV2 = "tracepoint__sched_process_free"
63+ )
64+
5865// Intervals is a subset of config.IntervalsAndTimers.
5966type Intervals interface {
6067 MonitorInterval () time.Duration
@@ -171,6 +178,16 @@ type progLoaderHelper struct {
171178 noTailCallTarget bool
172179}
173180
181+ // schedProcessFreeHookName returns the name of the tracepoint hook to use.
182+ // This function requires that only one of (schedProcessFreeV1, schedProcessFreeV2)
183+ // be present in progNames.
184+ func schedProcessFreeHookName (progNames libpf.Set [string ]) string {
185+ if _ , ok := progNames [schedProcessFreeV1 ]; ok {
186+ return schedProcessFreeV1
187+ }
188+ return schedProcessFreeV2
189+ }
190+
174191// NewTracer loads eBPF code and map definitions from the ELF module at the configured path.
175192func NewTracer (ctx context.Context , cfg * Config ) (* Tracer , error ) {
176193 kernelSymbolizer , err := kallsyms .NewSymbolizer ()
@@ -290,6 +307,13 @@ func initializeMapsAndPrograms(kmod *kallsyms.Module, cfg *Config) (ebpfMaps map
290307 return nil , nil , nil , fmt .Errorf ("failed to load specification for tracers: %v" , err )
291308 }
292309
310+ if major > 6 || (major == 6 && minor >= 16 ) {
311+ // Tracepoint format for sched_process_free has changed in v6.16+.
312+ delete (coll .Programs , schedProcessFreeV1 )
313+ } else {
314+ delete (coll .Programs , schedProcessFreeV2 )
315+ }
316+
293317 if cfg .VerboseMode {
294318 if err = coll .Variables ["with_debug_output" ].Set (uint32 (1 )); err != nil {
295319 return nil , nil , nil , fmt .Errorf ("failed to set debug output: %v" , err )
@@ -546,9 +570,11 @@ func loadPerfUnwinders(coll *cebpf.CollectionSpec, ebpfProgs map[string]*cebpf.P
546570
547571 progs := make ([]progLoaderHelper , len (tailCallProgs )+ 2 )
548572 copy (progs , tailCallProgs )
573+
574+ schedProcessFree := schedProcessFreeHookName (libpf .MapKeysToSet (coll .Programs ))
549575 progs = append (progs ,
550576 progLoaderHelper {
551- name : "tracepoint__sched_process_free" ,
577+ name : schedProcessFree ,
552578 noTailCallTarget : true ,
553579 enable : true ,
554580 },
0 commit comments