@@ -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
@@ -180,6 +187,16 @@ func goString(cstr []byte) string {
180187 return strings .Clone (unsafe .String (unsafe .SliceData (cstr ), index ))
181188}
182189
190+ // schedProcessFreeHookName returns the name of the tracepoint hook to use.
191+ // This function requires that only one of (schedProcessFreeV1, schedProcessFreeV2)
192+ // be present in progNames.
193+ func schedProcessFreeHookName (progNames libpf.Set [string ]) string {
194+ if _ , ok := progNames [schedProcessFreeV1 ]; ok {
195+ return schedProcessFreeV1
196+ }
197+ return schedProcessFreeV2
198+ }
199+
183200// NewTracer loads eBPF code and map definitions from the ELF module at the configured path.
184201func NewTracer (ctx context.Context , cfg * Config ) (* Tracer , error ) {
185202 kernelSymbolizer , err := kallsyms .NewSymbolizer ()
@@ -302,11 +319,23 @@ func initializeMapsAndPrograms(kmod *kallsyms.Module, cfg *Config) (ebpfMaps map
302319 // References to eBPF maps in the eBPF programs are just placeholders that need to be
303320 // replaced by the actual loaded maps later on with RewriteMaps before loading the
304321 // programs into the kernel.
322+ major , minor , patch , err := util .GetCurrentKernelVersion ()
323+ if err != nil {
324+ return nil , nil , nil , fmt .Errorf ("failed to get kernel version: %v" , err )
325+ }
326+
305327 coll , err = support .LoadCollectionSpec ()
306328 if err != nil {
307329 return nil , nil , nil , fmt .Errorf ("failed to load specification for tracers: %v" , err )
308330 }
309331
332+ if major > 6 || (major == 6 && minor >= 16 ) {
333+ // Tracepoint format for sched_process_free has changed in v6.16+.
334+ delete (coll .Programs , schedProcessFreeV1 )
335+ } else {
336+ delete (coll .Programs , schedProcessFreeV2 )
337+ }
338+
310339 if cfg .VerboseMode {
311340 if err = coll .Variables ["with_debug_output" ].Set (uint32 (1 )); err != nil {
312341 return nil , nil , nil , fmt .Errorf ("failed to set debug output: %v" , err )
@@ -336,11 +365,6 @@ func initializeMapsAndPrograms(kmod *kallsyms.Module, cfg *Config) (ebpfMaps map
336365 }
337366
338367 if cfg .KernelVersionCheck {
339- var major , minor , patch uint32
340- major , minor , patch , err = util .GetCurrentKernelVersion ()
341- if err != nil {
342- return nil , nil , nil , fmt .Errorf ("failed to get kernel version: %v" , err )
343- }
344368 if hasProbeReadBug (major , minor , patch ) {
345369 if err = checkForMaccessPatch (coll , ebpfMaps , kmod ); err != nil {
346370 return nil , nil , nil , fmt .Errorf ("your kernel version %d.%d.%d may be " +
@@ -568,9 +592,11 @@ func loadPerfUnwinders(coll *cebpf.CollectionSpec, ebpfProgs map[string]*cebpf.P
568592
569593 progs := make ([]progLoaderHelper , len (tailCallProgs )+ 2 )
570594 copy (progs , tailCallProgs )
595+
596+ schedProcessFree := schedProcessFreeHookName (libpf .MapKeysToSet (coll .Programs ))
571597 progs = append (progs ,
572598 progLoaderHelper {
573- name : "tracepoint__sched_process_free" ,
599+ name : schedProcessFree ,
574600 noTailCallTarget : true ,
575601 enable : true ,
576602 },
0 commit comments