1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-17 10:26:15 +00:00

- Add a td_pflags field to struct thread for private flags accessed only by

curthread.  Unlike td_flags, this field does not need any locking.
- Replace the td_inktr and td_inktrace variables with equivalent private
  thread flags.
- Move TDF_OLDMASK over to the private flags field so it no longer requires
  sched_lock.
This commit is contained in:
John Baldwin 2003-06-09 17:38:32 +00:00
parent b981655c08
commit 5e26dcb560
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=116101
5 changed files with 27 additions and 29 deletions

View File

@ -188,9 +188,9 @@ ktr_tracepoint(u_int mask, const char *file, int line, const char *format,
return;
#if defined(KTR_VERBOSE) || defined(KTR_ALQ)
td = curthread;
if (td->td_inktr)
if (td->td_pflags & TDP_INKTR)
return;
td->td_inktr++;
td->td_pflags |= TDP_INKTR;
#endif
#ifdef KTR_ALQ
if (ktr_alq_enabled &&
@ -247,7 +247,7 @@ ktr_tracepoint(u_int mask, const char *file, int line, const char *format,
done:
#endif
#if defined(KTR_VERBOSE) || defined(KTR_ALQ)
td->td_inktr--;
td->td_pflags &= ~TDP_INKTR;
#endif
}

View File

@ -157,12 +157,12 @@ sysctl_kern_ktrace_request_pool(SYSCTL_HANDLER_ARGS)
if (error)
return (error);
td = curthread;
td->td_inktrace = 1;
td->td_pflags |= TDP_INKTRACE;
mtx_lock(&ktrace_mtx);
oldsize = ktr_requestpool;
newsize = ktrace_resize_pool(wantsize);
mtx_unlock(&ktrace_mtx);
td->td_inktrace = 0;
td->td_pflags &= ~TDP_INKTRACE;
error = SYSCTL_OUT(req, &oldsize, sizeof(uint));
if (error)
return (error);
@ -215,11 +215,11 @@ ktr_getrequest(int type)
struct proc *p = td->td_proc;
int pm;
td->td_inktrace = 1;
td->td_pflags |= TDP_INKTRACE;
mtx_lock(&ktrace_mtx);
if (!KTRCHECK(td, type)) {
mtx_unlock(&ktrace_mtx);
td->td_inktrace = 0;
td->td_pflags &= ~TDP_INKTRACE;
return (NULL);
}
req = STAILQ_FIRST(&ktr_free);
@ -248,7 +248,7 @@ ktr_getrequest(int type)
mtx_unlock(&ktrace_mtx);
if (pm)
printf("Out of ktrace request objects.\n");
td->td_inktrace = 0;
td->td_pflags &= ~TDP_INKTRACE;
}
return (req);
}
@ -261,7 +261,7 @@ ktr_submitrequest(struct ktr_request *req)
STAILQ_INSERT_TAIL(&ktr_todo, req, ktr_list);
sema_post(&ktrace_sema);
mtx_unlock(&ktrace_mtx);
curthread->td_inktrace = 0;
curthread->td_pflags &= ~TDP_INKTRACE;
}
static void
@ -514,7 +514,7 @@ ktrace(td, uap)
if (ops != KTROP_CLEARFILE && facs == 0)
return (EINVAL);
td->td_inktrace = 1;
td->td_pflags |= TDP_INKTRACE;
if (ops != KTROP_CLEAR) {
/*
* an operation which requires a file argument.
@ -525,7 +525,7 @@ ktrace(td, uap)
error = vn_open(&nd, &flags, 0);
if (error) {
mtx_unlock(&Giant);
td->td_inktrace = 0;
td->td_pflags &= ~TDP_INKTRACE;
return (error);
}
NDFREE(&nd, NDF_ONLY_PNBUF);
@ -534,7 +534,7 @@ ktrace(td, uap)
if (vp->v_type != VREG) {
(void) vn_close(vp, FREAD|FWRITE, td->td_ucred, td);
mtx_unlock(&Giant);
td->td_inktrace = 0;
td->td_pflags &= ~TDP_INKTRACE;
return (EACCES);
}
mtx_unlock(&Giant);
@ -623,7 +623,7 @@ ktrace(td, uap)
(void) vn_close(vp, FWRITE, td->td_ucred, td);
mtx_unlock(&Giant);
}
td->td_inktrace = 0;
td->td_pflags &= ~TDP_INKTRACE;
return (error);
#else /* !KTRACE */
return (ENOSYS);

View File

@ -874,7 +874,7 @@ kern_sigtimedwait(struct thread *td, sigset_t set, siginfo_t *info,
mtx_unlock(&ps->ps_mtx);
#ifdef KTRACE
if (KTRPOINT(td, KTR_PSIG))
ktrpsig(sig, action, td->td_flags & TDF_OLDMASK ?
ktrpsig(sig, action, td->td_pflags & TDP_OLDMASK ?
&td->td_oldsigmask : &td->td_sigmask, 0);
#endif
_STOPEVENT(p, S_SIG, sig);
@ -1089,9 +1089,7 @@ kern_sigsuspend(struct thread *td, sigset_t mask)
*/
PROC_LOCK(p);
td->td_oldsigmask = td->td_sigmask;
mtx_lock_spin(&sched_lock);
td->td_flags |= TDF_OLDMASK;
mtx_unlock_spin(&sched_lock);
td->td_pflags |= TDP_OLDMASK;
SIG_CANTMASK(mask);
td->td_sigmask = mask;
signotify(td);
@ -1122,9 +1120,7 @@ osigsuspend(td, uap)
PROC_LOCK(p);
td->td_oldsigmask = td->td_sigmask;
mtx_lock_spin(&sched_lock);
td->td_flags |= TDF_OLDMASK;
mtx_unlock_spin(&sched_lock);
td->td_pflags |= TDP_OLDMASK;
OSIG2SIG(uap->mask, mask);
SIG_CANTMASK(mask);
SIGSETLO(td->td_sigmask, mask);
@ -2136,7 +2132,7 @@ postsig(sig)
action = ps->ps_sigact[_SIG_IDX(sig)];
#ifdef KTRACE
if (KTRPOINT(td, KTR_PSIG))
ktrpsig(sig, action, td->td_flags & TDF_OLDMASK ?
ktrpsig(sig, action, td->td_pflags & TDP_OLDMASK ?
&td->td_oldsigmask : &td->td_sigmask, 0);
#endif
_STOPEVENT(p, S_SIG, sig);
@ -2164,11 +2160,9 @@ postsig(sig)
* mask from before the sigsuspend is what we want
* restored after the signal processing is completed.
*/
if (td->td_flags & TDF_OLDMASK) {
if (td->td_pflags & TDP_OLDMASK) {
returnmask = td->td_oldsigmask;
mtx_lock_spin(&sched_lock);
td->td_flags &= ~TDF_OLDMASK;
mtx_unlock_spin(&sched_lock);
td->td_pflags &= ~TDP_OLDMASK;
} else
returnmask = td->td_sigmask;

View File

@ -70,7 +70,8 @@ struct ktr_header {
* is the public interface.
*/
#define KTRCHECK(td, type) ((td)->td_proc->p_traceflag & (1 << type))
#define KTRPOINT(td, type) (KTRCHECK((td), (type)) && !(td)->td_inktrace)
#define KTRPOINT(td, type) \
(KTRCHECK((td), (type)) && !((td)->td_pflags & TDP_INKTRACE))
/*
* ktrace record types

View File

@ -269,14 +269,13 @@ struct thread {
#define td_startzero td_flags
int td_flags; /* (j) TDF_* flags. */
int td_inhibitors; /* (j) Why can not run */
int td_pflags; /* (k) Private thread (TDP_*) flags. */
struct kse *td_last_kse; /* (j) Previous value of td_kse */
struct kse *td_kse; /* (j) Current KSE if running. */
int td_dupfd; /* (k) Ret value from fdopen. XXX */
void *td_wchan; /* (j) Sleep address. */
const char *td_wmesg; /* (j) Reason for sleep. */
u_char td_lastcpu; /* (j) Last cpu we were on. */
u_char td_inktr; /* (k) Currently handling a KTR. */
u_char td_inktrace; /* (k) Currently handling a KTRACE. */
u_char td_oncpu; /* (j) Which cpu we are on. */
short td_locks; /* (k) DEBUG: lockmgr count of locks */
struct mtx *td_blocked; /* (j) Mutex process is blocked on. */
@ -333,7 +332,6 @@ struct thread {
struct td_sched *td_sched; /* (*) Scheduler specific data */
};
/* flags kept in td_flags */
#define TDF_OLDMASK 0x000001 /* Need to restore mask after suspend. */
#define TDF_INPANIC 0x000002 /* Caused a panic, let it drive crashdump. */
#define TDF_CAN_UNBIND 0x000004 /* Only temporarily bound. */
#define TDF_SINTR 0x000008 /* Sleep is interruptible. */
@ -352,6 +350,11 @@ struct thread {
#define TDF_NEEDSIGCHK 0x020000 /* Thread may need signal delivery. */
#define TDF_DEADLKTREAT 0x800000 /* Lock aquisition - deadlock treatment. */
/* "private" flags kept in td_pflags */
#define TDP_OLDMASK 0x0001 /* Need to restore mask after suspend. */
#define TDP_INKTR 0x0002 /* Thread is currently in KTR code. */
#define TDP_INKTRACE 0x0004 /* Thread is currently in KTRACE code. */
#define TDI_SUSPENDED 0x0001 /* On suspension queue. */
#define TDI_SLEEPING 0x0002 /* Actually asleep! (tricky). */
#define TDI_SWAPPED 0x0004 /* Stack not in mem.. bad juju if run. */