Skip to content

Commit 33be163

Browse files
committed
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
1 parent 58dd3aa commit 33be163

File tree

3 files changed

+8
-19
lines changed

3 files changed

+8
-19
lines changed

sys/kern/kern_idle.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,7 @@ idle_setup(void *dummy)
8282
#ifdef SMP
8383
}
8484
#endif
85+
PROC_LOCK(p);
86+
p->p_flag |= P_IDLEPROC;
87+
PROC_UNLOCK(p);
8588
}

sys/kern/kern_racct.c

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -322,15 +322,13 @@ racct_getpcpu(struct proc *p, u_int pcpu)
322322
u_int swtime;
323323
#ifdef SCHED_4BSD
324324
fixpt_t pctcpu, pctcpu_next;
325-
#endif
326-
#ifdef SMP
327-
struct pcpu *pc;
328-
int found;
329325
#endif
330326
fixpt_t p_pctcpu;
331327
struct thread *td;
332328

333329
ASSERT_RACCT_ENABLED();
330+
KASSERT((p->p_flag & P_IDLEPROC) == 0,
331+
("racct_getpcpu: idle process %p", p));
334332

335333
swtime = (ticks - p->p_swtick) / hz;
336334

@@ -344,19 +342,6 @@ racct_getpcpu(struct proc *p, u_int pcpu)
344342

345343
p_pctcpu = 0;
346344
FOREACH_THREAD_IN_PROC(p, td) {
347-
if (td == PCPU_GET(idlethread))
348-
continue;
349-
#ifdef SMP
350-
found = 0;
351-
STAILQ_FOREACH(pc, &cpuhead, pc_allcpu) {
352-
if (td == pc->pc_idlethread) {
353-
found = 1;
354-
break;
355-
}
356-
}
357-
if (found)
358-
continue;
359-
#endif
360345
thread_lock(td);
361346
#ifdef SCHED_4BSD
362347
pctcpu = sched_pctcpu(td);
@@ -1252,7 +1237,8 @@ racctd(void)
12521237

12531238
FOREACH_PROC_IN_SYSTEM(p) {
12541239
PROC_LOCK(p);
1255-
if (p->p_state != PRS_NORMAL) {
1240+
if (p->p_state != PRS_NORMAL ||
1241+
(p->p_flag & P_IDLEPROC) != 0) {
12561242
if (p->p_state == PRS_ZOMBIE)
12571243
racct_set(p, RACCT_PCTCPU, 0);
12581244
PROC_UNLOCK(p);

sys/sys/proc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ struct proc {
803803
lock. */
804804
#define P_CONTROLT 0x00000002 /* Has a controlling terminal. */
805805
#define P_KPROC 0x00000004 /* Kernel process. */
806-
#define P_UNUSED3 0x00000008 /* --available-- */
806+
#define P_IDLEPROC 0x00000008 /* Container for system idle threads. */
807807
#define P_PPWAIT 0x00000010 /* Parent is waiting for child to
808808
exec/exit. */
809809
#define P_PROFIL 0x00000020 /* Has started profiling. */

0 commit comments

Comments
 (0)