From 8a3973e46941b6a8c88a49594364a04ee4b1d84e Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Wed, 16 Jul 2025 20:48:35 -0400 Subject: kernel: accnt: Keep track of per-cpu stats Signed-off-by: Ian Moffett --- sys/arch/amd64/amd64/mp.c | 18 ++++++++++++++++++ sys/arch/amd64/amd64/proc_machdep.c | 5 +++++ 2 files changed, 23 insertions(+) (limited to 'sys/arch') diff --git a/sys/arch/amd64/amd64/mp.c b/sys/arch/amd64/amd64/mp.c index dbee32c..21881b2 100644 --- a/sys/arch/amd64/amd64/mp.c +++ b/sys/arch/amd64/amd64/mp.c @@ -81,6 +81,24 @@ cpu_get(uint32_t index) return ci_list[index]; } +/* + * Grab the CPU stat structured of a specified + * processor + * + * @cpu_index: CPU index number + */ +struct sched_cpu * +cpu_get_stat(uint32_t cpu_index) +{ + struct cpu_info *ci; + + if ((ci = cpu_get(cpu_index)) == NULL) { + return NULL; + } + + return &ci->stat; +} + uint32_t cpu_count(void) { diff --git a/sys/arch/amd64/amd64/proc_machdep.c b/sys/arch/amd64/amd64/proc_machdep.c index 72c2b56..ad807fe 100644 --- a/sys/arch/amd64/amd64/proc_machdep.c +++ b/sys/arch/amd64/amd64/proc_machdep.c @@ -245,6 +245,7 @@ static void sched_switch_to(struct trapframe *tf, struct proc *td) { struct cpu_info *ci; + struct sched_cpu *cpustat; struct pcb *pcbp; ci = this_cpu(); @@ -253,6 +254,10 @@ sched_switch_to(struct trapframe *tf, struct proc *td) memcpy(tf, &td->tf, sizeof(*tf)); } + /* Update stats */ + cpustat = &ci->stat; + cpustat->nswitch++; + ci->curtd = td; pcbp = &td->pcb; pmap_switch_vas(pcbp->addrsp); -- cgit v1.2.3