kern/85657: [patch] capture and expose per-CPU time accounting
Ben Thomas
bthomas at virtualiron.com
Fri Sep 2 18:00:41 GMT 2005
>Number: 85657
>Category: kern
>Synopsis: [patch] capture and expose per-CPU time accounting
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Fri Sep 02 18:00:37 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator: Ben Thomas
>Release: FreeBSD 5.4-RELEASE i386
>Organization:
Virtual Iron Software
>Environment:
System: FreeBSD bthomas4.katana-technology.com 5.4-RELEASE FreeBSD 5.4-RELEASE #10: Sun Aug 28 13:48:00 EDT 2005 ben at bthomas4.katana-technology.com:/usr/obj/usr/home/ben/BSD/RELENG_5_4_0_RELEASE/src/sys/BEN i386
>Description:
The kernel maintains time accounting information on a global
basis and exposes it via kern.cp_time. There are situations in
which the per-CPU information is useful. Add this accounting
and expose it via kern.cp_time_percpu.
This patch is against 5_4_0_RELEASE code
>How-To-Repeat:
>Fix:
--- kern_clock.c-DIFF begins here ---
--- /usr/src.original/sys/kern/kern_clock.c Tue Mar 1 04:30:16 2005
+++ /usr/src/sys/kern/kern_clock.c Sun Aug 28 13:29:56 2005
@@ -82,6 +82,11 @@
SYSCTL_OPAQUE(_kern, OID_AUTO, cp_time, CTLFLAG_RD, &cp_time, sizeof(cp_time),
"LU", "CPU time statistics");
+long cp_time_percpu[MAXCPU][CPUSTATES];
+
+SYSCTL_OPAQUE(_kern, OID_AUTO, cp_time_percpu, CTLFLAG_RD, &cp_time_percpu, sizeof(cp_time_percpu),
+ "LU", "CPU time statistics per CPU");
+
#ifdef SW_WATCHDOG
#include <sys/watchdog.h>
@@ -375,6 +380,7 @@
struct thread *td;
struct proc *p;
long rss;
+ int cpu = PCPU_GET(cpuid);
td = curthread;
p = td->td_proc;
@@ -387,10 +393,13 @@
if (p->p_flag & P_SA)
thread_statclock(1);
p->p_uticks++;
- if (p->p_nice > NZERO)
+ if (p->p_nice > NZERO) {
cp_time[CP_NICE]++;
- else
+ cp_time_percpu[cpu][CP_NICE]++;
+ } else {
cp_time[CP_USER]++;
+ cp_time_percpu[cpu][CP_USER]++;
+ }
} else {
/*
* Came from kernel mode, so we were:
@@ -407,15 +416,19 @@
if ((td->td_ithd != NULL) || td->td_intr_nesting_level >= 2) {
p->p_iticks++;
cp_time[CP_INTR]++;
+ cp_time_percpu[cpu][CP_INTR]++;
} else {
if (p->p_flag & P_SA)
thread_statclock(0);
td->td_sticks++;
p->p_sticks++;
- if (p != PCPU_GET(idlethread)->td_proc)
+ if (p != PCPU_GET(idlethread)->td_proc) {
cp_time[CP_SYS]++;
- else
+ cp_time_percpu[cpu][CP_SYS]++;
+ } else {
cp_time[CP_IDLE]++;
+ cp_time_percpu[cpu][CP_IDLE]++;
+ }
}
}
CTR4(KTR_SCHED, "statclock: %p(%s) prio %d stathz %d",
--- kern_clock.c-DIFF ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list