Re: [PATCH] taskstats: retain dead thread stats in TGID queries

From: wang.yaxin

Date: Mon Mar 30 2026 - 08:58:10 EST


>fill_stats_for_tgid() builds TGID stats from two sources: the cached

>aggregate in signal->stats and a scan of the live threads in the group.

>

>However, fill_tgid_exit() only accumulates delay accounting into

>signal->stats. This means TGID queries lose the fields that

>fill_stats_for_tgid() adds for live threads once a thread exits,

>including ac_etime, ac_utime, ac_stime, nvcsw and nivcsw.

>

>Factor the per-task TGID accumulation into a helper and use it in both

>fill_stats_for_tgid() and fill_tgid_exit(). This keeps the fields

>retained for dead threads aligned with the fields already accounted for

>live threads, and follows the existing taskstats TGID aggregation model,

>which already accumulates delay accounting in fill_tgid_exit() and

>combines it with a live-thread scan in fill_stats_for_tgid().


1.Capturing the final delay-accounting update before task exit is necessary;

otherwise, cumulative task delay will be underestimated over time.


2.For fixes of this kind, it is best to include the issue/bug ID that is being fixed,

so the change remains clearly traceable.


Thanks,

Yaxin