@@ -71,8 +71,7 @@ static __always_inline void update_hist(struct task_struct *task,
71
71
histp = bpf_map_lookup_elem (& hists , & id );
72
72
if (!histp )
73
73
return ;
74
- bpf_probe_read_kernel_str (& histp -> comm , sizeof (task -> comm ),
75
- task -> comm );
74
+ BPF_CORE_READ_STR_INTO (& histp -> comm , task , comm );
76
75
}
77
76
delta = ts - * tsp ;
78
77
if (targ_ms )
@@ -85,12 +84,10 @@ static __always_inline void update_hist(struct task_struct *task,
85
84
__sync_fetch_and_add (& histp -> slots [slot ], 1 );
86
85
}
87
86
88
- SEC ("tp_btf/sched_switch" )
89
- int BPF_PROG (sched_switch , bool preempt , struct task_struct * prev ,
90
- struct task_struct * next )
87
+ static int handle_switch (struct task_struct * prev , struct task_struct * next )
91
88
{
92
- u32 prev_tgid = prev -> tgid , prev_pid = prev -> pid ;
93
- u32 tgid = next -> tgid , pid = next -> pid ;
89
+ u32 prev_tgid = BPF_CORE_READ ( prev , tgid ) , prev_pid = BPF_CORE_READ ( prev , pid ) ;
90
+ u32 tgid = BPF_CORE_READ ( next , tgid ) , pid = BPF_CORE_READ ( next , pid ) ;
94
91
u64 ts = bpf_ktime_get_ns ();
95
92
96
93
if (filter_cg && !bpf_current_task_under_cgroup (& cgroup_map , 0 ))
@@ -107,4 +104,18 @@ int BPF_PROG(sched_switch, bool preempt, struct task_struct *prev,
107
104
return 0 ;
108
105
}
109
106
107
+ SEC ("tp_btf/sched_switch" )
108
+ int BPF_PROG (sched_switch_btf , bool preempt , struct task_struct * prev ,
109
+ struct task_struct * next )
110
+ {
111
+ return handle_switch (prev , next );
112
+ }
113
+
114
+ SEC ("raw_tp/sched_switch" )
115
+ int BPF_PROG (sched_switch_tp , bool preempt , struct task_struct * prev ,
116
+ struct task_struct * next )
117
+ {
118
+ return handle_switch (prev , next );
119
+ }
120
+
110
121
char LICENSE [] SEC ("license" ) = "GPL" ;
0 commit comments