Implement the D "cpu" variable, which returns curcpu. I have chosen not

to follow the example of OpenSolaris and its descendants, which implemented
cpu as an inline that took a value out of curthread.  At certain points in
the FreeBSD scheduler curthread->td_oncpu will no longer be valid (in
particukar, just before the thread gets descheduled) so instead I have
implemented this as its own built-in variable.

Sponsored by:	Sandvine Inc.
MFC after:	1 week
This commit is contained in:
Ryan Stone 2012-04-26 01:07:03 +00:00
parent 5293615570
commit c6024848dd
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=234691
3 changed files with 15 additions and 0 deletions

View File

@ -497,6 +497,12 @@ static const dt_ident_t _dtrace_globals[] = {
{ "zonename", DT_IDENT_SCALAR, 0, DIF_VAR_ZONENAME,
DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" },
#endif
#if !defined(sun)
{ "cpu", DT_IDENT_SCALAR, 0, DIF_VAR_CPU,
DT_ATTR_STABCMN, DT_VERS_1_6_3, &dt_idops_type, "int" },
#endif
{ NULL, 0, 0, 0, { 0, 0, 0 }, 0, NULL, NULL }
};

View File

@ -3143,6 +3143,11 @@ dtrace_dif_variable(dtrace_mstate_t *mstate, dtrace_state_t *state, uint64_t v,
return (curthread->td_errno);
#endif
}
#if !defined(sun)
case DIF_VAR_CPU: {
return curcpu;
}
#endif
default:
DTRACE_CPUFLAG_SET(CPU_DTRACE_ILLOP);
return (0);

View File

@ -251,6 +251,10 @@ typedef enum dtrace_probespec {
#define DIF_VAR_ERRNO 0x0120 /* thread errno */
#define DIF_VAR_EXECARGS 0x0121 /* process arguments */
#if !defined(sun)
#define DIF_VAR_CPU 0x0200
#endif
#define DIF_SUBR_RAND 0
#define DIF_SUBR_MUTEX_OWNED 1
#define DIF_SUBR_MUTEX_OWNER 2