现在的位置: 首页 >> 操作系统 >> FreeBSD >> FreeBSD 5内核源代码分析之系统调用过程
添加时间:2005-8-21 来源:网教中国 作者:
FreeBSD 5内核源代码分析之系统调用过程


处理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


上一篇:FreeBSD 5内核源代码分析之copyin()实现原理 下一篇:FreeBSD 5 内核源代码分析之中断处理
大部分文章摘自网上,如有侵犯您的权益请与我们联系,我们会第一时间进行处理,谢谢! [ 打印文章 ] [ 关闭窗口 ]
推荐文章
·FreeBSD handbook中文版 9 配制F
·FreeBSD 升级系统
·Ports & Package
·FreeBSD kernel 编译大法(二)ker
·FreeBSD 上使用Kerberos 5认证
·FreeBSD 5.x 中 gbfs 的修正,及
·FreeBSD 安装Linuxigd
·FreeBSD 使用cvsd创建安全的cvs
·FreeBSD trafcount命令介绍
·FreeBSD入门安装及汉化
相关文章
·FreeBSD 5内核源代码分析之copyi
最新文章
·FreeBSD连载(94):基于NAT的负载
·FreeBSD连载(93):反向代理负载
·FreeBSD连载(92):基于DNS的负载
·FreeBSD连载(91):提升静态网页
·FreeBSD连载(90):单服务器性能
·FreeBSD连载(89):CGI和SSI的安
·FreeBSD连载(88):安全连接方式S
·FreeBSD连载(87):基于用户的访
·FreeBSD连载(86):对IP地址和域
·FreeBSD连载(85):配置Apache服(
Google