From f517039cab87fecd6a996695805787ab8f63e6d4 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Wed, 10 Oct 2018 22:28:23 +0100 Subject: [PATCH] kernel: rework usage timers The old UZI code we started from defined the various time fields in both proc and udata but used only the udata one. Perhaps an unfinished attempt to move from proc to udata. While it saves memory keeping it in udata (20 bytes a process or 320 bytes) we were wasting that memory anyway. Go back to keeping it in proc as that avoids some messiness and standards violation in the code, and makes ps work nicely. Possibly we can later move cutime and cstime into udata but that needs review (otoh it would leave us 80 bytes up on where we started) --- Kernel/include/kernel.h | 5 ----- Kernel/process.c | 13 ++++--------- Kernel/start.c | 2 +- Kernel/syscall_proc.c | 11 ++++------- 4 files changed, 9 insertions(+), 22 deletions(-) diff --git a/Kernel/include/kernel.h b/Kernel/include/kernel.h index 0897b967..724b3735 100644 --- a/Kernel/include/kernel.h +++ b/Kernel/include/kernel.h @@ -553,11 +553,6 @@ typedef struct u_data { uint16_t u_euid; uint16_t u_egid; char u_name[8]; /* Name invoked with */ - clock_t u_utime; /* Elapsed ticks in user mode */ - clock_t u_stime; /* Ticks in system mode */ - clock_t u_cutime; /* Total childrens ticks */ - clock_t u_cstime; - clock_t u_time; /* Start time */ /* This section is not written out except as padding */ uint8_t u_files[UFTSIZE]; /* Process file table: indices into open file table, or NO_FILE. */ diff --git a/Kernel/process.c b/Kernel/process.c index c18007e0..d5ccc45c 100644 --- a/Kernel/process.c +++ b/Kernel/process.c @@ -303,9 +303,9 @@ void newproc(regptr ptptr p) udata.u_ptab = p; - memset(&udata.u_utime, 0, 4 * sizeof(clock_t)); /* Clear tick counters */ + memset(&p->p_utime, 0, 4 * sizeof(clock_t)); /* Clear tick counters */ - rdtime32(&udata.u_time); + rdtime32(&p->p_time); if (udata.u_cwd) i_ref(udata.u_cwd); if (udata.u_root) @@ -415,9 +415,9 @@ void timer_interrupt(void) and half of another.. */ if (!inswap && udata.u_ptab->p_status == P_RUNNING) { if (udata.u_insys) - udata.u_stime++; + udata.u_ptab->p_stime++; else - udata.u_utime++; + udata.u_ptab->p_utime++; } /* Do once-per-decisecond things - this doesn't work out well on @@ -852,11 +852,6 @@ void doexit(uint16_t val) sync_clock(); /* Not that these values will be wildly accurate! */ - udata.u_utime += udata.u_cutime; - udata.u_stime += udata.u_cstime; - memcpy(&(udata.u_ptab->p_priority), &udata.u_utime, - 2 * sizeof(clock_t)); - for (p = ptab; p < ptab_end; ++p) { if (p->p_status == P_EMPTY || p == udata.u_ptab) continue; diff --git a/Kernel/start.c b/Kernel/start.c index 0f0d23f4..1abf55fc 100644 --- a/Kernel/start.c +++ b/Kernel/start.c @@ -404,7 +404,7 @@ void fuzix_main(void) udata.u_cwd = i_ref(root); udata.u_root = i_ref(root); - rdtime32(&udata.u_time); + rdtime32(&udata.u_ptab->p_time); exec_or_die(); } diff --git a/Kernel/syscall_proc.c b/Kernel/syscall_proc.c index 17bbc7a0..2f611321 100644 --- a/Kernel/syscall_proc.c +++ b/Kernel/syscall_proc.c @@ -197,7 +197,7 @@ arg_t _times(void) irq = di(); - uput(&udata.u_utime, buf, 4 * sizeof(clock_t)); + uput(&udata.u_ptab->p_utime, buf, 4 * sizeof(clock_t)); uput(&ticks, buf + 4 * sizeof(clock_t), sizeof(clock_t)); @@ -313,12 +313,9 @@ arg_t _waitpid(void) retval = p->p_pid; p->p_status = P_EMPTY; - /* Add in child's time info. It was stored on top */ - /* of p_priority in the childs process table entry. */ - /* FIXME: make these a union so we don't do type - punning and break strict aliasing */ - udata.u_cutime += ((clock_t *)&p->p_priority)[0]; - udata.u_cstime += ((clock_t *)&p->p_priority)[1]; + /* Add in child's cumulative time info */ + udata.u_ptab->p_cutime += p->p_utime + p->p_cutime; + udata.u_ptab->p_cstime += p->p_stime + p->p_cstime; return retval; } if (p->p_event && (options & WUNTRACED)) { -- 2.34.1