From ae3d9709645a8b45c3fd7a5dbf5849d8b46ae08d Mon Sep 17 00:00:00 2001 From: Sam Leffler Date: Thu, 3 Feb 1983 17:13:16 -0800 Subject: [PATCH] use high precision time calls SCCS-vsn: bin/csh/csh.c 4.10 SCCS-vsn: bin/csh/csh.h 4.6 SCCS-vsn: bin/csh/proc.c 4.8 SCCS-vsn: bin/csh/proc.h 4.3 SCCS-vsn: bin/csh/time.c 4.3 --- usr/src/bin/csh/csh.c | 4 ++-- usr/src/bin/csh/csh.h | 4 ++-- usr/src/bin/csh/proc.c | 21 ++++++++++++--------- usr/src/bin/csh/proc.h | 10 +++++----- usr/src/bin/csh/time.c | 20 +++++++++++--------- 5 files changed, 32 insertions(+), 27 deletions(-) diff --git a/usr/src/bin/csh/csh.c b/usr/src/bin/csh/csh.c index fb2aa796bd..74370a9944 100644 --- a/usr/src/bin/csh/csh.c +++ b/usr/src/bin/csh/csh.c @@ -1,4 +1,4 @@ -static char *sccsid = "@(#)csh.c 4.9 %G%"; +static char *sccsid = "@(#)csh.c 4.10 %G%"; #include "sh.h" #include @@ -871,7 +871,7 @@ mailchk() for (; *vp; vp++) { if (stat(*vp, &stb) < 0) continue; - new = stb.st_mtime > time0; + new = stb.st_mtime > time0.tv_sec; if (stb.st_size == 0 || stb.st_atime > stb.st_mtime || (stb.st_atime < chktim && stb.st_mtime < chktim) || loginsh && !new) diff --git a/usr/src/bin/csh/csh.h b/usr/src/bin/csh/csh.h index 3f40060752..69d77e12bb 100644 --- a/usr/src/bin/csh/csh.h +++ b/usr/src/bin/csh/csh.h @@ -1,4 +1,4 @@ -/* csh.h 4.5 82/12/30 */ +/* csh.h 4.6 83/02/03 */ #include "sh.local.h" #include @@ -57,7 +57,7 @@ char *file; /* Name of shell file for $0 */ char *err; /* Error message from scanner/parser */ int errno; /* Error from C library routines */ char *shtemp; /* Temp name for << shell files in /tmp */ -time_t time0; /* Time at which the shell started */ +struct timeval time0; /* Time at which the shell started */ struct rusage ru0; /* diff --git a/usr/src/bin/csh/proc.c b/usr/src/bin/csh/proc.c index b92a066f83..aa296f62da 100644 --- a/usr/src/bin/csh/proc.c +++ b/usr/src/bin/csh/proc.c @@ -1,4 +1,4 @@ -static char *sccsid = "@(#)proc.c 4.7 (Berkeley) 82/12/30"; +static char *sccsid = "@(#)proc.c 4.8 (Berkeley) 83/02/03"; #include "sh.h" #include "sh.dir.h" @@ -57,7 +57,7 @@ found: time_t oldcutimes, oldcstimes; oldcutimes = shtimes.tms_cutime; oldcstimes = shtimes.tms_cstime; - time(&pp->p_etime); + gettimeofday(&pp->p_etime, (struct timezone *)0); times(&shtimes); pp->p_utime = shtimes.tms_cutime - oldcutimes; pp->p_stime = shtimes.tms_cstime - oldcstimes; @@ -398,7 +398,7 @@ palloc(pid, t) } pp->p_next = proclist.p_next; proclist.p_next = pp; - time(&pp->p_btime); + gettimeofday(&pp->p_btime, (struct timezone *)0); } padd(t) @@ -621,8 +621,8 @@ prcomd: if (linp != linbuf) printf("\n\t"); { static struct rusage zru; - prusage(&zru, &pp->p_rusage, - pp->p_etime - pp->p_btime); + prusage(&zru, &pp->p_rusage, &pp->p_etime, + &pp->p_btime); } } if (tp == pp->p_friends) { @@ -646,18 +646,21 @@ prcomd: ptprint(tp) register struct process *tp; { - time_t tetime = 0; + struct timeval tetime, diff; + static struct timeval ztime; struct rusage ru; static struct rusage zru; register struct process *pp = tp; ru = zru; + tetime = ztime; do { ruadd(&ru, &pp->p_rusage); - if (pp->p_etime - pp->p_btime > tetime) - tetime = pp->p_etime - pp->p_btime; + tvsub(&diff, &pp->p_etime, &pp->p_btime); + if (timercmp(&diff, &tetime, >)) + tetime = diff; } while ((pp = pp->p_friends) != tp); - prusage(&zru, &ru, tetime); + prusage(&zru, &ru, &tetime, &ztime); } /* diff --git a/usr/src/bin/csh/proc.h b/usr/src/bin/csh/proc.h index 0cb12a4902..45e965e5fe 100644 --- a/usr/src/bin/csh/proc.h +++ b/usr/src/bin/csh/proc.h @@ -1,4 +1,4 @@ -/* proc.h 4.2 %G% */ +/* proc.h 4.3 %G% */ /* * C shell - process structure declarations @@ -22,11 +22,11 @@ struct process { short p_pid; short p_jobid; /* pid of job leader */ /* if a job is stopped/background p_jobid gives its pgrp */ - time_t p_btime; /* begin time */ - time_t p_etime; /* end time */ - long p_stime; /* system cpu time */ - long p_utime; /* user cpu time */ + struct timeval p_btime; /* begin time */ + struct timeval p_etime; /* end time */ struct rusage p_rusage; + long p_utime; /* XXX */ + long p_stime; /* XXX */ char *p_command; /* first PMAXLEN chars of command */ }; diff --git a/usr/src/bin/csh/time.c b/usr/src/bin/csh/time.c index e9ed8b1373..4ce20a9925 100644 --- a/usr/src/bin/csh/time.c +++ b/usr/src/bin/csh/time.c @@ -1,4 +1,4 @@ -/* time.c 4.2 82/12/30 */ +/* time.c 4.3 83/02/03 */ #include "sh.h" @@ -12,7 +12,7 @@ settimes() { struct rusage ruch; - time(&time0); + gettimeofday(&time0, (struct timezone *)0); getrusage(RUSAGE_SELF, &ru0); getrusage(RUSAGE_CHILDREN, &ruch); ruadd(&ru0, &ruch); @@ -24,14 +24,14 @@ settimes() */ dotime() { - time_t timedol; + struct timeval timedol; struct rusage ru1, ruch; getrusage(RUSAGE_SELF, &ru1); getrusage(RUSAGE_CHILDREN, &ruch); ruadd(&ru1, &ruch); - time(&timedol); - prusage(&ru0, &ru1, timedol - time0); + gettimeofday(&timedol, (struct timezone *)0); + prusage(&ru0, &ru1, &timedol, &time0); } /* @@ -75,9 +75,9 @@ ruadd(ru, ru2) while (--cnt > 0); } -prusage(r0, r1, sec) +prusage(r0, r1, e, b) register struct rusage *r0, *r1; - time_t sec; + struct timeval *e, *b; { register time_t t = (r1->ru_utime.tv_sec-r0->ru_utime.tv_sec)*100+ @@ -87,6 +87,8 @@ prusage(r0, r1, sec) register char *cp; register int i; register struct varent *vp = adrof("time"); + int ms = + (e->tv_sec-b->tv_sec)*100 + (e->tv_usec-b->tv_usec)/10000; cp = "%Uu %Ss %E %P %X+%Dk %I+%Oio %Fpf+%Ww"; if (vp && vp->vec[0] && vp->vec[1]) @@ -105,11 +107,11 @@ prusage(r0, r1, sec) break; case 'E': - psecs(sec); + psecs(ms / 100); break; case 'P': - printf("%d%%", (int) (t / ((sec ? sec : 1)))); + printf("%d%%", (int) (t*100 / ((ms ? ms : 1)))); break; case 'W': -- 2.20.1