hp@vmars.tuwien.ac.at (Peter Holzer) (11/08/90)
These patches fix a problem with the times(2) system call. It always returned 0, which caused my benchmark programs to dump core on a division by zero. To do this I had to change message format 4 from 4 to 5 longs. As far as I have seen this message format is used nowhere else, so it should not cause any problems. WARNING: Check the Index: lines before applying the patch. I have added them by hand after cat'ing the cdiffs together, and I am not sure if people who have derived 1.5 from earlier versions have the same directory layout as the version PH sells. ---8<------8<------8<------8<------8<------8<------8<------8<--- Index: /usr/src/kernel/clock.c *** orig/clock.c Sat Oct 27 15:45:24 1990 --- clock.c Fri Nov 2 18:16:15 1990 *************** *** 16,21 **** --- 16,23 ---- * |------------+----------+---------+---------| * | GET_TIME | | | | * |------------+----------+---------+---------| + * | GET_TICK | | | | + * |------------+----------+---------+---------| * | SET_TIME | | | newtime | * --------------------------------------------- * *************** *** 32,38 **** #include "proc.h" /* Constant definitions. */ ! #define MILLISEC 100 /* how often to call the scheduler (msec) */ #define SCHED_RATE (MILLISEC*HZ/1000) /* number of ticks per schedule */ /* Clock parameters. */ --- 34,40 ---- #include "proc.h" /* Constant definitions. */ ! #define MILLISEC 40 /* how often to call the scheduler (msec) */ #define SCHED_RATE (MILLISEC*HZ/1000) /* number of ticks per schedule */ /* Clock parameters. */ *************** *** 61,67 **** PRIVATE void (*watch_dog[NR_TASKS+1])(); /* watch_dog functions to call */ FORWARD void do_clocktick(); ! FORWARD void do_get_time(); FORWARD void do_set_time(); FORWARD void do_setalarm(); FORWARD void init_clock(); --- 63,70 ---- PRIVATE void (*watch_dog[NR_TASKS+1])(); /* watch_dog functions to call */ FORWARD void do_clocktick(); ! FORWARD void do_time(); ! FORWARD void do_ticks(); FORWARD void do_set_time(); FORWARD void do_setalarm(); FORWARD void init_clock(); *************** *** 91,97 **** switch (opcode) { case SET_ALARM: do_setalarm(&mc); break; ! case GET_TIME: do_get_time(); break; case SET_TIME: do_set_time(&mc); break; case HARD_INT: do_clocktick(); break; default: panic("clock task got bad message", mc.m_type); --- 94,101 ---- switch (opcode) { case SET_ALARM: do_setalarm(&mc); break; ! case GET_TIME: do_time(); break; ! case GET_TICK: do_ticks(); break; case SET_TIME: do_set_time(&mc); break; case HARD_INT: do_clocktick(); break; default: panic("clock task got bad message", mc.m_type); *************** *** 138,148 **** /*===========================================================================* ! * do_get_time * ! *===========================================================================*/ ! PRIVATE void do_get_time() ! { ! /* Get and return the current clock time in ticks. */ mc.m_type = REAL_TIME; /* set message type for reply */ mc.NEW_TIME = boot_time + realtime/HZ; /* current real time */ --- 142,152 ---- /*===========================================================================* ! * do_time * ! *===========================================================================*/ ! PRIVATE void do_time() ! { ! /* Get and return the current clock time in seconds. */ mc.m_type = REAL_TIME; /* set message type for reply */ mc.NEW_TIME = boot_time + realtime/HZ; /* current real time */ *************** *** 150,167 **** /*===========================================================================* ! * do_set_time * ! *===========================================================================*/ ! PRIVATE void do_set_time(m_ptr) ! message *m_ptr; /* pointer to request message */ ! { ! /* Set the real time clock. Only the superuser can use this call. */ ! ! boot_time = m_ptr->NEW_TIME - realtime/HZ; } /*===========================================================================* * do_clocktick * *===========================================================================*/ PRIVATE void do_clocktick() --- 154,183 ---- /*===========================================================================* ! * do_ticks * ! *===========================================================================*/ ! PRIVATE void do_ticks() ! { ! /* Get and return the time since startup in ticks. */ ! ! mc.m_type = UP_TICKS; /* set message type for reply */ ! mc.NEW_TIME = realtime; /* current real time */ } /*===========================================================================* + * do_set_time * + *===========================================================================*/ + PRIVATE void do_set_time(m_ptr) + message *m_ptr; /* pointer to request message */ + { + /* Set the real time clock. Only the superuser can use this call. */ + + boot_time = m_ptr->NEW_TIME - realtime/HZ; + } + + + /*===========================================================================* * do_clocktick * *===========================================================================*/ PRIVATE void do_clocktick() Index: /usr/include/minix/com.h *** orig/com.h Fri Nov 2 12:27:19 1990 --- com.h Fri Nov 2 16:46:57 1990 *************** *** 74,80 **** # define SET_ALARM 1 /* fcn code to CLOCK, set up alarm */ # define GET_TIME 3 /* fcn code to CLOCK, get real time */ # define SET_TIME 4 /* fcn code to CLOCK, set real time */ ! # define REAL_TIME 1 /* reply from CLOCK: here is real time */ #define SYSTASK -2 /* internal functions */ # define SYS_XIT 1 /* fcn code for sys_xit(parent, proc) */ --- 74,82 ---- # define SET_ALARM 1 /* fcn code to CLOCK, set up alarm */ # define GET_TIME 3 /* fcn code to CLOCK, get real time */ # define SET_TIME 4 /* fcn code to CLOCK, set real time */ ! # define GET_TICK 5 /* fcn code to CLOCK, get uptime ticks */ ! # define REAL_TIME 1 /* reply from CLOCK: here is real time */ ! # define UP_TICKS 2 /* reply from CLOCK: here is uptime ticks */ #define SYSTASK -2 /* internal functions */ # define SYS_XIT 1 /* fcn code for sys_xit(parent, proc) */ *************** *** 134,139 **** --- 136,142 ---- #define SYSTEM_TIME m4_l2 /* system time consumed by process */ #define CHILD_UTIME m4_l3 /* user time consumed by process' children */ #define CHILD_STIME m4_l4 /* sys time consumed by process' children */ + #define UP_TIME m4_l5 /* system up time */ #define PROC1 m1_i1 /* indicates a process */ #define PROC2 m1_i2 /* indicates a process */ Index: /usr/include/minix/param.h *** orig/param.h Fri Nov 2 12:16:56 1990 --- param.h Fri Nov 2 12:16:10 1990 *************** *** 51,53 **** --- 51,54 ---- #define reply_t2 m1.m4_l2 #define reply_t3 m1.m4_l3 #define reply_t4 m1.m4_l4 + #define reply_t5 m1.m4_l5 Index: /usr/src/fs/time.c *** orig/time.c Sat Oct 27 15:46:08 1990 --- time.c Fri Nov 2 18:23:00 1990 *************** *** 83,93 **** /* Perform the times(buffer) system call. */ time_t t[4]; sys_times(who, t); reply_t1 = t[0]; reply_t2 = t[1]; reply_t3 = t[2]; reply_t4 = t[3]; ! return(OK); ! } --- 83,97 ---- /* Perform the times(buffer) system call. */ time_t t[4]; + int k; sys_times(who, t); reply_t1 = t[0]; reply_t2 = t[1]; reply_t3 = t[2]; reply_t4 = t[3]; ! clock_mess.m_type = GET_TICK; ! if ( (k = sendrec(CLOCK, &clock_mess)) != OK) panic("do_tims err", k); ! reply_t5 = clock_mess.NEW_TIME; ! return(OK); ! } Index: /usr/src/lib/posix/times.c *** orig/times.c Mon Nov 5 10:14:37 1990 --- times.c Fri Nov 2 19:24:40 1990 *************** *** 12,16 **** buf->tms_stime = _M.m4_l2; buf->tms_cutime = _M.m4_l3; buf->tms_cstime = _M.m4_l4; ! return(k); ! } --- 12,19 ---- buf->tms_stime = _M.m4_l2; buf->tms_cutime = _M.m4_l3; buf->tms_cstime = _M.m4_l4; ! if (k >= 0) { ! k = _M.m4_l5; ! } ! return(k); ! } Index: /usr/include/minix/type.h *** orig/type.h Fri Nov 2 12:28:07 1990 --- type.h Fri Nov 2 12:31:43 1990 *************** *** 45,51 **** typedef struct {int m1i1, m1i2, m1i3; char *m1p1, *m1p2, *m1p3;} mess_1; typedef struct {int m2i1, m2i2, m2i3; long m2l1, m2l2; char *m2p1;} mess_2; typedef struct {int m3i1, m3i2; char *m3p1; char m3ca1[M3_STRING];} mess_3; ! typedef struct {long m4l1, m4l2, m4l3, m4l4;} mess_4; typedef struct {char m5c1, m5c2; int m5i1, m5i2; long m5l1, m5l2, m5l3;} mess_5; typedef struct {int m6i1, m6i2, m6i3; long m6l1; void (*m6f1)();} mess_6; --- 45,51 ---- typedef struct {int m1i1, m1i2, m1i3; char *m1p1, *m1p2, *m1p3;} mess_1; typedef struct {int m2i1, m2i2, m2i3; long m2l1, m2l2; char *m2p1;} mess_2; typedef struct {int m3i1, m3i2; char *m3p1; char m3ca1[M3_STRING];} mess_3; ! typedef struct {long m4l1, m4l2, m4l3, m4l4, m4l5;} mess_4; typedef struct {char m5c1, m5c2; int m5i1, m5i2; long m5l1, m5l2, m5l3;} mess_5; typedef struct {int m6i1, m6i2, m6i3; long m6l1; void (*m6f1)();} mess_6; *************** *** 90,95 **** --- 90,96 ---- #define m4_l2 m_u.m_m4.m4l2 #define m4_l3 m_u.m_m4.m4l3 #define m4_l4 m_u.m_m4.m4l4 + #define m4_l5 m_u.m_m4.m4l5 #define m5_c1 m_u.m_m5.m5c1 #define m5_c2 m_u.m_m5.m5c2 ---8<------8<------8<------8<------8<------8<------8<------8<--- -- | _ | Peter J. Holzer | Think of it | | |_|_) | Technical University Vienna | as evolution | | | | | Dept. for Real-Time Systems | in action! | | __/ | hp@vmars.tuwien.ac.at | Tony Rand |