The branch stable/14 has been updated by olce:

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

commit fd404e957dd93d0e8525e4bc37df3f66610ca19d
Author:     Mark Johnston <[email protected]>
AuthorDate: 2025-05-01 13:59:55 +0000
Commit:     Olivier Certner <[email protected]>
CommitDate: 2025-12-19 09:16:46 +0000

    racct: Fix accounting of CPU time for the system idle process
    
    - Add a flag which cleanly indicates that a given process is the system
      idle process.
    - Modify racctd() to skip over the idle proc when aggregating CPU time
      and other metrics which don't apply to the idle thread.
    - Remove handling for idle threads from racct_getpcpu().
    
    PR:             269097
    Reviewed by:    olce, kib
    Sponsored by:   Klara, Inc.
    Differential Revision:  https://reviews.freebsd.org/D50073
    
    (cherry picked from commit 33be1632047c05dbfcc139476e05f49c3a86d560)
---
 sys/kern/kern_idle.c  |  3 +++
 sys/kern/kern_racct.c | 22 ++++------------------
 sys/sys/proc.h        |  2 +-
 3 files changed, 8 insertions(+), 19 deletions(-)

diff --git a/sys/kern/kern_idle.c b/sys/kern/kern_idle.c
index 0569659bdc73..0d0f496a1a03 100644
--- a/sys/kern/kern_idle.c
+++ b/sys/kern/kern_idle.c
@@ -83,4 +83,7 @@ idle_setup(void *dummy)
 #ifdef SMP
        }
 #endif
+       PROC_LOCK(p);
+       p->p_flag |= P_IDLEPROC;
+       PROC_UNLOCK(p);
 }
diff --git a/sys/kern/kern_racct.c b/sys/kern/kern_racct.c
index b121e24b9354..13df4724f860 100644
--- a/sys/kern/kern_racct.c
+++ b/sys/kern/kern_racct.c
@@ -322,15 +322,13 @@ racct_getpcpu(struct proc *p, u_int pcpu)
        u_int swtime;
 #ifdef SCHED_4BSD
        fixpt_t pctcpu, pctcpu_next;
-#endif
-#ifdef SMP
-       struct pcpu *pc;
-       int found;
 #endif
        fixpt_t p_pctcpu;
        struct thread *td;
 
        ASSERT_RACCT_ENABLED();
+       KASSERT((p->p_flag & P_IDLEPROC) == 0,
+           ("racct_getpcpu: idle process %p", p));
 
        /*
         * If the process is swapped out, we count its %cpu usage as zero.
@@ -350,19 +348,6 @@ racct_getpcpu(struct proc *p, u_int pcpu)
 
        p_pctcpu = 0;
        FOREACH_THREAD_IN_PROC(p, td) {
-               if (td == PCPU_GET(idlethread))
-                       continue;
-#ifdef SMP
-               found = 0;
-               STAILQ_FOREACH(pc, &cpuhead, pc_allcpu) {
-                       if (td == pc->pc_idlethread) {
-                               found = 1;
-                               break;
-                       }
-               }
-               if (found)
-                       continue;
-#endif
                thread_lock(td);
 #ifdef SCHED_4BSD
                pctcpu = sched_pctcpu(td);
@@ -1258,7 +1243,8 @@ racctd(void)
 
                FOREACH_PROC_IN_SYSTEM(p) {
                        PROC_LOCK(p);
-                       if (p->p_state != PRS_NORMAL) {
+                       if (p->p_state != PRS_NORMAL ||
+                           (p->p_flag & P_IDLEPROC) != 0) {
                                if (p->p_state == PRS_ZOMBIE)
                                        racct_set(p, RACCT_PCTCPU, 0);
                                PROC_UNLOCK(p);
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index a094af09a21a..06506f7d03ed 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -807,7 +807,7 @@ struct proc {
                                           lock. */
 #define        P_CONTROLT      0x00000002      /* Has a controlling terminal. 
*/
 #define        P_KPROC         0x00000004      /* Kernel process. */
-#define        P_UNUSED3       0x00000008      /* --available-- */
+#define        P_IDLEPROC      0x00000008      /* Container for system idle 
threads. */
 #define        P_PPWAIT        0x00000010      /* Parent is waiting for child 
to
                                           exec/exit. */
 #define        P_PROFIL        0x00000020      /* Has started profiling. */

Reply via email to