From cb56579bf238a4c09e55349c6b5dca23d69f4295 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Mon, 22 Nov 2004 06:50:12 +0000 Subject: [PATCH] Fix the PRI field to not display bogus process priorities for pure threads. Add TDPRI (-o tdpri) to display the actual thread priority and critical section count. --- bin/ps/extern.h | 3 ++- bin/ps/keyword.c | 3 ++- bin/ps/print.c | 21 +++++++++++++++++++-- bin/ps/ps.1 | 6 ++++-- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/bin/ps/extern.h b/bin/ps/extern.h index eb727570fb..1f88895363 100644 --- a/bin/ps/extern.h +++ b/bin/ps/extern.h @@ -32,7 +32,7 @@ * * @(#)extern.h 8.3 (Berkeley) 4/2/94 * $FreeBSD: src/bin/ps/extern.h,v 1.9 1999/08/27 23:14:50 peter Exp $ - * $DragonFly: src/bin/ps/extern.h,v 1.10 2004/11/16 12:16:36 joerg Exp $ + * $DragonFly: src/bin/ps/extern.h,v 1.11 2004/11/22 06:50:12 dillon Exp $ */ struct kinfo; @@ -67,6 +67,7 @@ void pcpu(const KINFO *, const struct varent *); void pnice(const KINFO *, const struct varent *); void pmem(const KINFO *, const struct varent *); void pri(const KINFO *, const struct varent *); +void tdpri(const KINFO *, const struct varent *); void rtprior(const KINFO *, const struct varent *); void printheader(void); void pvar(const KINFO *, const struct varent *); diff --git a/bin/ps/keyword.c b/bin/ps/keyword.c index 6b313eda2c..83eb88df72 100644 --- a/bin/ps/keyword.c +++ b/bin/ps/keyword.c @@ -32,7 +32,7 @@ * * @(#)keyword.c 8.5 (Berkeley) 4/2/94 * $FreeBSD: src/bin/ps/keyword.c,v 1.24.2.3 2002/10/10 20:05:32 jmallett Exp $ - * $DragonFly: src/bin/ps/keyword.c,v 1.16 2004/11/16 12:38:04 joerg Exp $ + * $DragonFly: src/bin/ps/keyword.c,v 1.17 2004/11/22 06:50:12 dillon Exp $ */ #include @@ -177,6 +177,7 @@ static const VAR var[] = { {"svuid", "SVUID", NULL, 0, evar, NULL, UIDLEN, EOFF(e_ucred.cr_svuid), UINT, UIDFMT, NULL}, {"tdev", "TDEV", NULL, 0, tdev, NULL, 4, 0, 0, NULL, NULL}, + {"tdpri", "TDPRI", NULL, 0, tdpri, NULL, 5, 0, 0, NULL, NULL}, {"time", "TIME", NULL, USER, cputime, NULL, 9, 0, 0, NULL, NULL}, {"tpgid", "TPGID", NULL, 0, evar, NULL, 4, EOFF(e_tpgid), UINT, PIDFMT, NULL}, {"tsess", "TSESS", NULL, 0, evar, NULL, 6, EOFF(e_tsess), KPTR, "lx", NULL}, diff --git a/bin/ps/print.c b/bin/ps/print.c index 4ac9f92e98..b8a5091e8a 100644 --- a/bin/ps/print.c +++ b/bin/ps/print.c @@ -32,7 +32,7 @@ * * @(#)print.c 8.6 (Berkeley) 4/16/94 * $FreeBSD: src/bin/ps/print.c,v 1.36.2.4 2002/11/30 13:00:14 tjr Exp $ - * $DragonFly: src/bin/ps/print.c,v 1.17 2004/11/16 12:16:36 joerg Exp $ + * $DragonFly: src/bin/ps/print.c,v 1.18 2004/11/22 06:50:12 dillon Exp $ */ #include @@ -232,10 +232,27 @@ state(const KINFO *k, const struct varent *vent) printf("%-*s", vent->width, buf); } +/* + * Normalized priority (lower is better). For pure threads + * output a negated LWKT priority (so lower still means better). + */ void pri(const KINFO *k, const struct varent *vent) { - printf("%*d", vent->width, KI_PROC(k)->p_priority); + if (KI_THREAD(k)->td_proc) + printf("%*d", vent->width, KI_PROC(k)->p_priority); + else + printf("%*d", vent->width, -(KI_THREAD(k)->td_pri & TDPRI_MASK)); +} + +void +tdpri(const KINFO *k, const struct varent *vent) +{ + char buf[32]; + int val = KI_THREAD(k)->td_pri; + + snprintf(buf, sizeof(buf), "%02d/%d", val & TDPRI_MASK, val / TDPRI_CRIT); + printf("%*s", vent->width, buf); } void diff --git a/bin/ps/ps.1 b/bin/ps/ps.1 index 76e5c95357..d113a62baa 100644 --- a/bin/ps/ps.1 +++ b/bin/ps/ps.1 @@ -31,7 +31,7 @@ .\" .\" @(#)ps.1 8.3 (Berkeley) 4/18/94 .\" $FreeBSD: src/bin/ps/ps.1,v 1.24.2.7 2002/06/20 22:43:33 charnier Exp $ -.\" $DragonFly: src/bin/ps/ps.1,v 1.4 2004/09/14 07:52:03 dillon Exp $ +.\" $DragonFly: src/bin/ps/ps.1,v 1.5 2004/11/22 06:50:12 dillon Exp $ .\" .Dd April 18, 1994 .Dt PS 1 @@ -418,7 +418,7 @@ pageouts in progress parent process .Tn ID .It pri -scheduling priority +scheduling priority (lower == better) .It re core residency time (in seconds; 127 = infinity) .It rgid @@ -459,6 +459,8 @@ saved gid from a setgid executable saved uid from a setuid executable .It tdev control terminal device number +.It tdpri +LWKT thread priority (0-31, 31 highest), and critical section count .It time accumulated cpu time, user + system (alias cputime) .It tpgid -- 2.28.0