Index: sys/proc.h =================================================================== RCS file: /cvs/src/sys/sys/proc.h,v diff -u -p -r1.376 proc.h --- sys/proc.h 22 Oct 2024 11:54:05 -0000 1.376 +++ sys/proc.h 8 Dec 2024 12:09:11 -0000 @@ -95,11 +95,20 @@ struct pgrp { * generation counter. Code should use tu_enter() and tu_leave() for this. * The process ps_tu structure is locked by the ps_mtx. */ +#define TU_UTICKS 0 /* Statclock hits in user mode. */ +#define TU_STICKS 1 /* Statclock hits in system mode. */ +#define TU_ITICKS 2 /* Statclock hits processing intr. */ +#define TU_TICKS_COUNT 3 + struct tusage { uint64_t tu_gen; /* generation counter */ - uint64_t tu_uticks; /* Statclock hits in user mode. */ - uint64_t tu_sticks; /* Statclock hits in system mode. */ - uint64_t tu_iticks; /* Statclock hits processing intr. */ + uint64_t tu_ticks[TU_TICKS_COUNT]; +#define tu_uticks tu_ticks[TU_UTICKS] +#define tu_sticks tu_ticks[TU_STICKS] +#define tu_iticks tu_ticks[TU_ITICKS] + uint64_t tu_ixrss; + uint64_t tu_idrss; + uint64_t tu_isrss; struct timespec tu_runtime; /* Realtime. */ }; Index: kern/kern_clock.c =================================================================== RCS file: /cvs/src/sys/kern/kern_clock.c,v diff -u -p -r1.124 kern_clock.c --- kern/kern_clock.c 8 Jul 2024 13:17:11 -0000 1.124 +++ kern/kern_clock.c 8 Dec 2024 12:09:11 -0000 @@ -49,6 +49,7 @@ #include #include #include +#include /* * Clock handling routines. @@ -267,6 +268,8 @@ statclock(struct clockrequest *cr, void struct schedstate_percpu *spc = &ci->ci_schedstate; struct proc *p = curproc; struct process *pr; + int tu_tick = -1; + int cp_time; if (statclock_is_randomized) { count = clockrequest_advance_random(cr, statclock_min, @@ -281,13 +284,8 @@ statclock(struct clockrequest *cr, void * Came from user mode; CPU was in user state. * If this process is being profiled record the tick. */ - tu_enter(&p->p_tu); - p->p_tu.tu_uticks += count; - tu_leave(&p->p_tu); - if (pr->ps_nice > NZERO) - spc->spc_cp_time[CP_NICE] += count; - else - spc->spc_cp_time[CP_USER] += count; + tu_tick = TU_UTICKS; + cp_time = (pr->ps_nice > NZERO) ? CP_NICE : CP_USER; } else { /* * Came from kernel mode, so we were: @@ -303,26 +301,39 @@ statclock(struct clockrequest *cr, void * in ``non-process'' (i.e., interrupt) work. */ if (CLKF_INTR(frame)) { - if (p != NULL) { - tu_enter(&p->p_tu); - p->p_tu.tu_iticks += count; - tu_leave(&p->p_tu); - } - spc->spc_cp_time[spc->spc_spinning ? - CP_SPIN : CP_INTR] += count; + tu_tick = TU_ITICKS; + cp_time = CP_INTR; } else if (p != NULL && p != spc->spc_idleproc) { - tu_enter(&p->p_tu); - p->p_tu.tu_sticks += count; - tu_leave(&p->p_tu); - spc->spc_cp_time[spc->spc_spinning ? - CP_SPIN : CP_SYS] += count; + tu_tick = TU_STICKS; + cp_time = CP_SYS; } else - spc->spc_cp_time[spc->spc_spinning ? - CP_SPIN : CP_IDLE] += count; + cp_time = CP_IDLE; + + if (spc->spc_spinning) + cp_time = CP_SPIN; } + spc->spc_cp_time[cp_time] += count; + if (p != NULL) { p->p_cpticks += count; + + if (!ISSET(p->p_flag, P_SYSTEM) && tu_tick != -1) { + struct vmspace *vm = p->p_vmspace; + struct tusage *tu = &p->p_tu; + + tu_enter(tu); + tu->tu_ticks[tu_tick] += count; + + /* maxrss is handled by uvm */ + if (tu_tick != TU_ITICKS) { + tu->tu_ixrss += (vm->vm_tsize << (PAGE_SHIFT - 10)) * count; + tu->tu_idrss += (vm->vm_dused << (PAGE_SHIFT - 10)) * count; + tu->tu_isrss += (vm->vm_ssize << (PAGE_SHIFT - 10)) * count; + } + tu_leave(tu); + } + /* * schedclock() runs every fourth statclock(). */ Index: kern/kern_exit.c =================================================================== RCS file: /cvs/src/sys/kern/kern_exit.c,v diff -u -p -r1.239 kern_exit.c --- kern/kern_exit.c 15 Oct 2024 13:49:26 -0000 1.239 +++ kern/kern_exit.c 8 Dec 2024 12:09:11 -0000 @@ -346,6 +346,9 @@ exit1(struct proc *p, int xexit, int xsi * and calculate the total times. */ calcru(&pr->ps_tu, &rup->ru_utime, &rup->ru_stime, NULL); + rup->ru_ixrss = pr->ps_tu.tu_ixrss; + rup->ru_idrss = pr->ps_tu.tu_idrss; + rup->ru_isrss = pr->ps_tu.tu_isrss; ruadd(rup, &pr->ps_cru); /* Index: kern/kern_resource.c =================================================================== RCS file: /cvs/src/sys/kern/kern_resource.c,v diff -u -p -r1.93 kern_resource.c --- kern/kern_resource.c 10 Nov 2024 06:45:36 -0000 1.93 +++ kern/kern_resource.c 8 Dec 2024 12:09:11 -0000 @@ -395,6 +395,9 @@ tuagg_sumup(struct tusage *tu, const str tu->tu_uticks += tmp.tu_uticks; tu->tu_sticks += tmp.tu_sticks; tu->tu_iticks += tmp.tu_iticks; + tu->tu_ixrss += tmp.tu_ixrss; + tu->tu_idrss += tmp.tu_idrss; + tu->tu_isrss += tmp.tu_isrss; timespecadd(&tu->tu_runtime, &tmp.tu_runtime, &tu->tu_runtime); } @@ -440,6 +443,7 @@ tuagg_add_process(struct process *pr, st /* Now reset CPU time usage for the thread. */ timespecclear(&p->p_tu.tu_runtime); p->p_tu.tu_uticks = p->p_tu.tu_sticks = p->p_tu.tu_iticks = 0; + p->p_tu.tu_ixrss = p->p_tu.tu_idrss = p->p_tu.tu_isrss = 0; } void @@ -567,6 +571,10 @@ dogetrusage(struct proc *p, int who, str } calcru(&tu, &rup->ru_utime, &rup->ru_stime, NULL); + + rup->ru_ixrss = tu.tu_ixrss; + rup->ru_idrss = tu.tu_idrss; + rup->ru_isrss = tu.tu_isrss; break; case RUSAGE_THREAD: