@@ -289,16 +289,15 @@ fill_oom_mark_victim(struct event *e,
289289 { \
290290 /* --------------------------- common prologue --------------------------- */ \
291291 u64 id = bpf_get_current_pid_tgid (); \
292- u32 pid = id >> 32 ; \
293- u32 tid = (u32 )id ; \
292+ u32 tgid = id >> 32 ; /* thread-group id (the process id) */ \
293+ u32 pid = (u32 )id ; /* actual kernel thread id (tid) */ \
294294 \
295- /* For EXIT events, we want to capture thread group leader exits */ \
296- /* For EXEC events, ignore threads */ \
297- if (EVENT__ ##name != EVENT__SCHED__SCHED_PROCESS_EXIT && pid != tid ) \
295+ /* For non-exit events, ignore non-leader threads (only consider group leader) */ \
296+ if (EVENT__ ##name != EVENT__SCHED__SCHED_PROCESS_EXIT && tgid != pid ) \
298297 return 0 ; \
299298 \
300- /* For EXIT, only report when the main thread (pid == tid ) exits */ \
301- if (EVENT__ ##name == EVENT__SCHED__SCHED_PROCESS_EXIT && pid != tid ) \
299+ /* For EXIT, only report when the main thread (tgid == pid ) exits */ \
300+ if (EVENT__ ##name == EVENT__SCHED__SCHED_PROCESS_EXIT && tgid != pid ) \
302301 return 0 ; \
303302 \
304303 struct event * e = bpf_ringbuf_reserve (& rb , sizeof (* e ), 0 ); \
@@ -311,21 +310,24 @@ fill_oom_mark_victim(struct event *e,
311310 \
312311 e -> event_type = EVENT__ ##name ; \
313312 e -> timestamp_ns = bpf_ktime_get_ns () + system_boot_ns ; \
314- e -> pid = pid ; \
313+ /* store the process id (tgid) as the logical PID for events */ \
314+ e -> pid = tgid ; \
315315 e -> ppid = BPF_CORE_READ (parent , tgid ); \
316316 \
317+ /* Use the leader/start-time pairing that makes upid unique: */ \
317318 u64 start_ns = BPF_CORE_READ (task , start_time ); \
318319 u64 pstart_ns = BPF_CORE_READ (parent , start_time ); \
319320 e -> upid = make_upid (e -> pid , start_ns ); \
320321 e -> uppid = make_upid (e -> ppid , pstart_ns ); \
321322 \
322- /* ---------------------- variant‑ specific section ----------------------- */ \
323+ /* ---------------------- variant- specific section ----------------------- */ \
323324 fill_fn (e , ctx ); \
324325 \
325326 bpf_ringbuf_submit (e , 0 ); \
326327 return 0 ; \
327328 }
328329
330+
329331/* Instantiate one handler per EVENT_LIST entry */
330332EVENT_LIST (HANDLER_DECL )
331333#undef HANDLER_DECL
0 commit comments