summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>1999-11-17 03:25:54 +0000
committerbde <bde@FreeBSD.org>1999-11-17 03:25:54 +0000
commitc1eced82100afa588581ea4e05d8e672961f6bfa (patch)
tree700adf3d04141c040b3ec75d116b84b097e92b1d
parent3776d08208bf7d6dcba99c148cba092dbc52eb1b (diff)
downloadFreeBSD-src-c1eced82100afa588581ea4e05d8e672961f6bfa.zip
FreeBSD-src-c1eced82100afa588581ea4e05d8e672961f6bfa.tar.gz
Fixed sorting on time. On i386's, time differences of more than 2147
seconds caused overflow. Use a type-safe but slightly slower comparison. Comparisons for other fields are still fragile. Fixed rounding of cputime (don't do extra work to get it slightly wrong by first converting without rounding to milliseconds). Removed dead code for setting cputime. Fixed comments about cputime.
-rw-r--r--usr.bin/top/machine.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c
index a393502..cbd44fd 100644
--- a/usr.bin/top/machine.c
+++ b/usr.bin/top/machine.c
@@ -553,8 +553,7 @@ char *(*get_userid)();
pp = *(hp->next_proc++);
hp->remaining--;
-
- /* get the process's user struct and set cputime */
+ /* get the process's command name */
if ((PP(pp, p_flag) & P_INMEM) == 0) {
/*
* Print swapped processes as <pname>
@@ -570,12 +569,12 @@ char *(*get_userid)();
comm[COMSIZ - 1] = '\0';
}
-#if 0
- /* This does not produce the correct results */
- cputime = PP(pp, p_uticks) + PP(pp, p_sticks) + PP(pp, p_iticks);
-#endif
- /* This does not count interrupts */
- cputime = (PP(pp, p_runtime) / 1000 + 500) / 1000;
+ /*
+ * Convert the process's runtime from microseconds to seconds. This
+ * time includes the interrupt time although that is not wanted here.
+ * ps(1) is similarly sloppy.
+ */
+ cputime = (PP(pp, p_runtime) + 500000) / 1000000;
/* calculate the base for cpu percentages */
pct = pctdouble(PP(pp, p_pctcpu));
@@ -737,7 +736,8 @@ static unsigned char sorted_state[] =
(result = lresult > 0 ? 1 : lresult < 0 ? -1 : 0) == 0)
#define ORDERKEY_CPTICKS \
- if ((result = PP(p2, p_runtime) - PP(p1, p_runtime)) == 0)
+ if ((result = PP(p2, p_runtime) > PP(p1, p_runtime) ? 1 : \
+ PP(p2, p_runtime) < PP(p1, p_runtime) ? -1 : 0) == 0)
#define ORDERKEY_STATE \
if ((result = sorted_state[(unsigned char) PP(p2, p_stat)] - \
OpenPOWER on IntegriCloud