Second stage of unbreaking thr formatting of the NICE field: decode the
priority class and use this to: - print "-" instead of a garbage value for ithreads. Print "-" instead of the unused nice value for kthreads which are (mis)classified as PRI_TIMESHARE. For such threads, the nice value can be set to nonzero by root, but it is never used (at least by the 4bsd scheduler). For ithreads, we didn't even print the unused value. - print "i<priority>" and "r<priority>" instead of a biased "<priority>" for idletime and realtime threads, Here <priority> is the priority parameter to idprio/rtprio(1). Just add the prefix and remove the bias for now. <priority> has been stored indirectly in the kernel since 2001/02/12, and even the kernel cannot recover the original value in all cases. Here we need to handle more cases than pri_to_rtp(), but actually handle fewer cases, and end up printing garbage after a thread changes its current priority while in the kernel. - for idletime and realtime threads, if they are kthreads then add a prefix of "k" to the previous string. - for idletime and realtime threads, if they in the FIFO scheduling class then add a suffix of "F" to the previous string (if it fits; the other parts of the string are sure to fit unless <priority> is garbage).
This commit is contained in:
parent
b9e58fd6df
commit
95c27ab845
@ -800,22 +800,36 @@ getsysctl(const char *name, void *ptr, size_t len)
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
const char *format_nice(const struct kinfo_proc *pp)
|
||||
static const char *
|
||||
format_nice(const struct kinfo_proc *pp)
|
||||
{
|
||||
static char nicebuf[5];
|
||||
const char *fifo, *kthread;
|
||||
int rtpri;
|
||||
static char nicebuf[4 + 1];
|
||||
|
||||
snprintf(nicebuf, sizeof(nicebuf), "%4d",
|
||||
/*
|
||||
* normal time -> nice value -20 - +20
|
||||
* real time 0 - 31 -> nice value -52 - -21
|
||||
* idle time 0 - 31 -> nice value +21 - +52
|
||||
*/
|
||||
(pp->ki_pri.pri_class == PRI_TIMESHARE ?
|
||||
pp->ki_nice - NZERO :
|
||||
(PRI_IS_REALTIME(pp->ki_pri.pri_class) ?
|
||||
(PRIO_MIN - 1 - (PRI_MAX_REALTIME - pp->ki_pri.pri_level)) :
|
||||
(PRIO_MAX + 1 + pp->ki_pri.pri_level - PRI_MIN_IDLE))));
|
||||
fifo = PRI_NEED_RR(pp->ki_pri.pri_class) ? "" : "F";
|
||||
kthread = (pp->ki_flag & P_KTHREAD) ? "k" : "";
|
||||
switch (PRI_BASE(pp->ki_pri.pri_class)) {
|
||||
case PRI_ITHD:
|
||||
return ("-");
|
||||
case PRI_REALTIME:
|
||||
rtpri = pp->ki_pri.pri_level - PRI_MIN_REALTIME;
|
||||
snprintf(nicebuf, sizeof(nicebuf), "%sr%d%s",
|
||||
kthread, rtpri, fifo);
|
||||
break;
|
||||
case PRI_TIMESHARE:
|
||||
if (pp->ki_flag & P_KTHREAD)
|
||||
return ("-");
|
||||
snprintf(nicebuf, sizeof(nicebuf), "%d", pp->ki_nice - NZERO);
|
||||
break;
|
||||
case PRI_IDLE:
|
||||
rtpri = pp->ki_pri.pri_level - PRI_MIN_IDLE;
|
||||
snprintf(nicebuf, sizeof(nicebuf), "%si%d%s",
|
||||
kthread, rtpri, fifo);
|
||||
break;
|
||||
default:
|
||||
return ("?");
|
||||
}
|
||||
return (nicebuf);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user