Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 08 Dec 2025 16:16:32 +0000
Message-ID:  <6936f9e0.3a8b7.62869968@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help

The branch main has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=3f8ed605dbd0ee211ce8fe59c0c072b916d6311c

commit 3f8ed605dbd0ee211ce8fe59c0c072b916d6311c
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2025-12-08 16:15:20 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2025-12-08 16:16:13 +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
---
 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 3075b2224963..6495340578da 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -660,10 +660,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 23b052e21063..b27b67999e8b 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -1326,6 +1326,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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6936f9e0.3a8b7.62869968>