diff options
author | jhb <jhb@FreeBSD.org> | 2001-01-20 23:03:20 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2001-01-20 23:03:20 +0000 |
commit | bf9da1eab7d31db915d88e35dad4638d4c47b3ca (patch) | |
tree | bf4357f78a7e6668cd6a0c13426b1e7fd9b55f6f /sys/kern/tty.c | |
parent | b1328b8ed8e368e742d6b3dea2ba288def69f9a9 (diff) | |
download | FreeBSD-src-bf9da1eab7d31db915d88e35dad4638d4c47b3ca.zip FreeBSD-src-bf9da1eab7d31db915d88e35dad4638d4c47b3ca.tar.gz |
- All of proc_compare needs sched_lock, so hold it for the for loop that
calls it rather than obtaining and releasing it a lot in proc_compare.
- Collect all of the data gathering and stick it just after the
proc_compare loop. This way, we only have to grab sched_lock once now
when handling SIGINFO. All the printf's are done after the values are
calculated.
Submitted mostly by: bde
Diffstat (limited to 'sys/kern/tty.c')
-rw-r--r-- | sys/kern/tty.c | 60 |
1 files changed, 20 insertions, 40 deletions
diff --git a/sys/kern/tty.c b/sys/kern/tty.c index 3f11c4f..4d52586 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -2233,9 +2233,9 @@ ttyinfo(tp) { register struct proc *p, *pick; struct timeval utime, stime; + const char *stmp; + long ltmp; int tmp; - const char *s; - long l; if (ttycheckoutq(tp,0) == 0) return; @@ -2251,46 +2251,34 @@ ttyinfo(tp) else if ((p = LIST_FIRST(&tp->t_pgrp->pg_members)) == 0) ttyprintf(tp, "empty foreground process group\n"); else { + mtx_enter(&sched_lock, MTX_SPIN); + /* Pick interesting process. */ for (pick = NULL; p != 0; p = LIST_NEXT(p, p_pglist)) if (proc_compare(pick, p)) pick = p; - mtx_enter(&sched_lock, MTX_SPIN); - s = pick->p_stat == SRUN ? "running" : + stmp = pick->p_stat == SRUN ? "running" : pick->p_wmesg ? pick->p_wmesg : "iowait"; + calcru(pick, &utime, &stime, NULL); + ltmp = pick->p_stat == SIDL || pick->p_stat == SWAIT || + pick->p_stat == SZOMB ? 0 : + pgtok(vmspace_resident_count(pick->p_vmspace)); mtx_exit(&sched_lock, MTX_SPIN); + ttyprintf(tp, " cmd: %s %d [%s] ", pick->p_comm, pick->p_pid, - s); - mtx_enter(&sched_lock, MTX_SPIN); - if (pick->p_flag & P_INMEM) { - mtx_exit(&sched_lock, MTX_SPIN); - calcru(pick, &utime, &stime, NULL); - - /* Print user time. */ - ttyprintf(tp, "%ld.%02ldu ", - utime.tv_sec, utime.tv_usec / 10000); - - /* Print system time. */ - ttyprintf(tp, "%ld.%02lds ", - stime.tv_sec, stime.tv_usec / 10000); - } else { - mtx_exit(&sched_lock, MTX_SPIN); - ttyprintf(tp, "?.??u ?.??s "); - } + stmp); + + /* Print user time. */ + ttyprintf(tp, "%ld.%02ldu ", + utime.tv_sec, utime.tv_usec / 10000); + + /* Print system time. */ + ttyprintf(tp, "%ld.%02lds ", + stime.tv_sec, stime.tv_usec / 10000); /* Print percentage cpu, resident set size. */ - mtx_enter(&sched_lock, MTX_SPIN); - tmp = (pick->p_pctcpu * 10000 + FSCALE / 2) >> FSHIFT; - if (pick->p_stat == SIDL || pick->p_stat == SWAIT || - pick->p_stat == SZOMB) { - mtx_exit(&sched_lock, MTX_SPIN); - l = 0; - } else { - mtx_exit(&sched_lock, MTX_SPIN); - l = pgtok(vmspace_resident_count(pick->p_vmspace)); - } - ttyprintf(tp, "%d%% %ldk\n", tmp / 100, l); + ttyprintf(tp, "%d%% %ldk\n", tmp / 100, ltmp); } tp->t_rocount = 0; /* so pending input will be retyped if BS */ } @@ -2322,19 +2310,15 @@ proc_compare(p1, p2) if (p1 == NULL) return (1); - mtx_enter(&sched_lock, MTX_SPIN); /* * see if at least one of them is runnable */ switch (TESTAB(ISRUN(p1), ISRUN(p2))) { case ONLYA: - mtx_exit(&sched_lock, MTX_SPIN); return (0); case ONLYB: - mtx_exit(&sched_lock, MTX_SPIN); return (1); case BOTH: - mtx_exit(&sched_lock, MTX_SPIN); /* * tie - favor one with highest recent cpu utilization */ @@ -2349,16 +2333,12 @@ proc_compare(p1, p2) */ switch (TESTAB(p1->p_stat == SZOMB, p2->p_stat == SZOMB)) { case ONLYA: - mtx_exit(&sched_lock, MTX_SPIN); return (1); case ONLYB: - mtx_exit(&sched_lock, MTX_SPIN); return (0); case BOTH: - mtx_exit(&sched_lock, MTX_SPIN); return (p2->p_pid > p1->p_pid); /* tie - return highest pid */ } - mtx_exit(&sched_lock, MTX_SPIN); /* * pick the one with the smallest sleep time |