Update the ULE scheduler + thread and kinfo structs to use int for cpuid

rather than u_char.

To try and play nice with the ABI, the u_char CPU ID values are clamped
at 254.  The new fields now contain the full CPU ID, or -1 for no cpu.

Differential Revision:	D955
Reviewed by:	jhb, kib
Sponsored by:	Norse Corp, Inc.
This commit is contained in:
Adrian Chadd 2014-10-18 19:36:11 +00:00
parent 7c26b0a7c8
commit e77f9fed15
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=273266
6 changed files with 57 additions and 9 deletions

View File

@ -431,6 +431,24 @@ kvm_proclist(kvm_t *kd, int what, int arg, struct proc *p,
strlcpy(kp->ki_tdname, mtd.td_name, sizeof(kp->ki_tdname));
kp->ki_pctcpu = 0;
kp->ki_rqindex = 0;
/*
* Note: legacy fields; wraps at NO_CPU_OLD or the
* old max CPU value as appropriate
*/
if (mtd.td_lastcpu == NOCPU)
kp->ki_lastcpu_old = NOCPU_OLD;
else if (mtd.td_lastcpu > MAXCPU_OLD)
kp->ki_lastcpu_old = MAXCPU_OLD;
else
kp->ki_lastcpu_old = mtd.td_lastcpu;
if (mtd.td_oncpu == NOCPU)
kp->ki_oncpu_old = NOCPU_OLD;
else if (mtd.td_oncpu > MAXCPU_OLD)
kp->ki_oncpu_old = MAXCPU_OLD;
else
kp->ki_oncpu_old = mtd.td_oncpu;
} else {
kp->ki_stat = SZOMB;
}

View File

@ -332,8 +332,8 @@ struct kinfo_proc32 {
signed char ki_nice;
char ki_lock;
char ki_rqindex;
u_char ki_oncpu;
u_char ki_lastcpu;
u_char ki_oncpu_old;
u_char ki_lastcpu_old;
char ki_tdname[TDNAMLEN+1];
char ki_wmesg[WMESGLEN+1];
char ki_login[LOGNAMELEN+1];
@ -343,6 +343,8 @@ struct kinfo_proc32 {
char ki_loginclass[LOGINCLASSLEN+1];
char ki_sparestrings[50];
int ki_spareints[KI_NSPARE_INT];
int ki_oncpu;
int ki_lastcpu;
int ki_tracer;
int ki_flag2;
int ki_fibnum;

View File

@ -984,6 +984,25 @@ fill_kinfo_thread(struct thread *td, struct kinfo_proc *kp, int preferthread)
kp->ki_wchan = td->td_wchan;
kp->ki_pri.pri_level = td->td_priority;
kp->ki_pri.pri_native = td->td_base_pri;
/*
* Note: legacy fields; clamp at the old NOCPU value and/or
* the maximum u_char CPU value.
*/
if (td->td_lastcpu == NOCPU)
kp->ki_lastcpu_old = NOCPU_OLD;
else if (td->td_lastcpu > MAXCPU_OLD)
kp->ki_lastcpu_old = MAXCPU_OLD;
else
kp->ki_lastcpu_old = td->td_lastcpu;
if (td->td_oncpu == NOCPU)
kp->ki_oncpu_old = NOCPU_OLD;
else if (td->td_oncpu > MAXCPU_OLD)
kp->ki_oncpu_old = MAXCPU_OLD;
else
kp->ki_oncpu_old = td->td_oncpu;
kp->ki_lastcpu = td->td_lastcpu;
kp->ki_oncpu = td->td_oncpu;
kp->ki_tdflags = td->td_flags;
@ -1164,6 +1183,11 @@ freebsd32_kinfo_proc_out(const struct kinfo_proc *ki, struct kinfo_proc32 *ki32)
CP(*ki, *ki32, ki_rqindex);
CP(*ki, *ki32, ki_oncpu);
CP(*ki, *ki32, ki_lastcpu);
/* XXX TODO: wrap cpu value as appropriate */
CP(*ki, *ki32, ki_oncpu_old);
CP(*ki, *ki32, ki_lastcpu_old);
bcopy(ki->ki_tdname, ki32->ki_tdname, TDNAMLEN + 1);
bcopy(ki->ki_wmesg, ki32->ki_wmesg, WMESGLEN + 1);
bcopy(ki->ki_login, ki32->ki_login, LOGNAMELEN + 1);

View File

@ -90,7 +90,7 @@ dtrace_vtime_switch_func_t dtrace_vtime_switch_func;
struct td_sched {
struct runq *ts_runq; /* Run-queue we're queued on. */
short ts_flags; /* TSF_* flags. */
u_char ts_cpu; /* CPU that we have affinity for. */
int ts_cpu; /* CPU that we have affinity for. */
int ts_rltick; /* Real last tick, for affinity. */
int ts_slice; /* Ticks of slice remaining. */
u_int ts_slptime; /* Number of ticks we vol. slept */

View File

@ -229,8 +229,8 @@ struct thread {
int td_sqqueue; /* (t) Sleepqueue queue blocked on. */
void *td_wchan; /* (t) Sleep address. */
const char *td_wmesg; /* (t) Reason for sleep. */
u_char td_lastcpu; /* (t) Last cpu we were on. */
u_char td_oncpu; /* (t) Which cpu we are on. */
int td_lastcpu; /* (t) Last cpu we were on. */
int td_oncpu; /* (t) Which cpu we are on. */
volatile u_char td_owepreempt; /* (k*) Preempt on last critical_exit */
u_char td_tsqueue; /* (t) Turnstile queue blocked on. */
short td_locks; /* (k) Count of non-spin locks. */
@ -601,7 +601,9 @@ struct proc {
#define p_session p_pgrp->pg_session
#define p_pgid p_pgrp->pg_id
#define NOCPU 0xff /* For when we aren't on a CPU. */
#define NOCPU (-1) /* For when we aren't on a CPU. */
#define NOCPU_OLD (255)
#define MAXCPU_OLD (254)
#define PROC_SLOCK(p) mtx_lock_spin(&(p)->p_slock)
#define PROC_SUNLOCK(p) mtx_unlock_spin(&(p)->p_slock)

View File

@ -84,7 +84,7 @@
* it in two places: function fill_kinfo_proc in sys/kern/kern_proc.c and
* function kvm_proclist in lib/libkvm/kvm_proc.c .
*/
#define KI_NSPARE_INT 6
#define KI_NSPARE_INT 4
#define KI_NSPARE_LONG 12
#define KI_NSPARE_PTR 6
@ -171,8 +171,8 @@ struct kinfo_proc {
signed char ki_nice; /* Process "nice" value */
char ki_lock; /* Process lock (prevent swap) count */
char ki_rqindex; /* Run queue index */
u_char ki_oncpu; /* Which cpu we are on */
u_char ki_lastcpu; /* Last cpu we were on */
u_char ki_oncpu_old; /* Which cpu we are on (legacy) */
u_char ki_lastcpu_old; /* Last cpu we were on (legacy) */
char ki_tdname[TDNAMLEN+1]; /* thread name */
char ki_wmesg[WMESGLEN+1]; /* wchan message */
char ki_login[LOGNAMELEN+1]; /* setlogin name */
@ -187,6 +187,8 @@ struct kinfo_proc {
*/
char ki_sparestrings[50]; /* spare string space */
int ki_spareints[KI_NSPARE_INT]; /* spare room for growth */
int ki_oncpu; /* Which cpu we are on */
int ki_lastcpu; /* Last cpu we were on */
int ki_tracer; /* Pid of tracing process */
int ki_flag2; /* P2_* flags */
int ki_fibnum; /* Default FIB number */