|
|
|
| |
添加时间:2005-8-21 来源:网教中国 作者: |
|
|
|
|
|
处理Traced系统调用。
| 代码: |
/*
* Handle reschedule and other end-of-syscall issues
*/
userret(td, &frame, sticks);
|
做一些调度处理等,后面另分析。
| 代码: |
#ifdef KTRACE
if (KTRPOINT(td, KTR_SYSRET))
ktrsysret(code, error, td->td_retval[0]);
#endif
/*
* This works because errno is findable through the
* register set. If we ever support an emulation where this
* is not the case, this code will need to be revisited.
*/
STOPEVENT(p, S_SCX, code);
PTRACESTOP_SC(p, td, S_PT_SCX);
#ifdef DIAGNOSTIC
cred_free_thread(td);
#endif
WITNESS_WARN(WARN_PANIC, NULL, "System call %s returning",
(code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[_code] : "???");
mtx_assert(&sched_lock, MA_NOTOWNED);
mtx_assert(&Giant, MA_NOTOWNED);
}
|
4, userret()函数
-----------------
简要地看一下userret()函数。
| 代码: |
/*
* Define the code needed before returning to user mode, for
* trap and syscall.
*
* MPSAFE
*/
void
userret(td, frame, oticks)
struct thread *td;
struct trapframe *frame;
u_int oticks;
{
struct proc *p = td->td_proc;
CTR3(KTR_SYSC, "userret: thread %p (pid %d, %s)", td, p->p_pid,
p->p_comm);
#ifdef INVARIANTS
/* Check that we called signotify() enough. */
PROC_LOCK(p);
mtx_lock_spin(&sched_lock);
if (SIGPENDING(td) && ((td->td_flags & TDF_NEEDSIGCHK) == 0 ||
(td->td_flags & TDF_ASTPENDING) == 0))
printf("failed to set signal flags properly for ast()\n");
mtx_unlock_spin(&sched_lock);
PROC_UNLOCK(p);
#endif
/*
* Let the scheduler adjust our priority etc.
*/
sched_userret(td);
|
调度器处理。
| 代码: |
/*
* We need to check to see if we have to exit or wait due to a
* single threading requirement or some other STOP condition.
* Don't bother doing all the work if the stop bits are not set
* at this time.. If we miss it, we miss it.. no big deal.
*/
if (P_SHOULDSTOP(p)) {
PROC_LOCK(p);
thread_suspend_check(0); /* Can suspend or kill */
PROC_UNLOCK(p);
}
|
是否需要停住?系统的某些时候只允许单个线程运行。
| 代码: |
/*
* Do special thread processing, e.g. upcall tweaking and such.
*/
if (p->p_flag & P_SA) {
thread_userret(td, frame);
}
|
又是scheduler activation的东西,通知用户态的thread manager。
(FIXME)
| 代码: |
/*
* Charge system time if profiling.
*/
if (p->p_flag & P_PROFIL) {
quad_t ticks;
mtx_lock_spin(&sched_lock);
ticks = td->td_sticks - oticks;
mtx_unlock_spin(&sched_lock);
addupc_task(td, TRAPF_PC(frame), (u_int)ticks * psratio);
}
}
|
最后是profiling的东西。
上一页 [1] [2] [3] [4]
|