kernel: rework usage timers
authorAlan Cox <alan@linux.intel.com>
Wed, 10 Oct 2018 21:28:23 +0000 (22:28 +0100)
committerAlan Cox <alan@linux.intel.com>
Wed, 10 Oct 2018 21:28:23 +0000 (22:28 +0100)
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
Kernel/process.c
Kernel/start.c
Kernel/syscall_proc.c

index 0897b96..724b373 100644 (file)
@@ -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. */
index c18007e..d5ccc45 100644 (file)
@@ -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;
index 0f0d23f..1abf55f 100644 (file)
@@ -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();
 }
 
index 17bbc7a..2f61132 100644 (file)
@@ -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)) {