The branch stable/14 has been updated by jhb:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=5685988838e403843422b5a727ff385a37b4909e

commit 5685988838e403843422b5a727ff385a37b4909e
Author:     John Baldwin <[email protected]>
AuthorDate: 2025-12-08 16:15:20 +0000
Commit:     John Baldwin <[email protected]>
CommitDate: 2025-12-19 15:19:41 +0000

    ruxreset: Add an inline function to reset all the stats in rusage_ext
    
    Use it in proc0_post to reset per-process CPU usage.
    
    Suggested by:   olce
    Reviewed by:    olce, kib
    Differential Revision:  https://reviews.freebsd.org/D54049
    
    (cherry picked from commit 3f8ed605dbd0ee211ce8fe59c0c072b916d6311c)
---
 sys/kern/init_main.c |  5 +----
 sys/sys/proc.h       | 12 ++++++++++++
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index aa541c527a19..47707b4068ad 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -662,10 +662,7 @@ proc0_post(void *dummy __unused)
                microuptime(&p->p_stats->p_start);
                PROC_STATLOCK(p);
                rufetch(p, &ru);        /* Clears thread stats */
-               p->p_rux.rux_runtime = 0;
-               p->p_rux.rux_uticks = 0;
-               p->p_rux.rux_sticks = 0;
-               p->p_rux.rux_iticks = 0;
+               ruxreset(&p->p_rux);
                PROC_STATUNLOCK(p);
                FOREACH_THREAD_IN_PROC(p, td) {
                        td->td_runtime = 0;
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index 06506f7d03ed..53da0baa02e2 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -1338,6 +1338,18 @@ td_get_sched(struct thread *td)
        return ((struct td_sched *)&td[1]);
 }
 
+static __inline void
+ruxreset(struct rusage_ext *rux)
+{
+       rux->rux_runtime = 0;
+       rux->rux_uticks = 0;
+       rux->rux_sticks = 0;
+       rux->rux_iticks = 0;
+       rux->rux_uu = 0;
+       rux->rux_su = 0;
+       rux->rux_tu = 0;
+}
+
 #define        PROC_ID_PID     0
 #define        PROC_ID_GROUP   1
 #define        PROC_ID_SESSION 2

Reply via email to