contextswitch上下文切换.docxVIP

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
  4. 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
  5. 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们
  6. 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
  7. 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
contextswitch上下文切换

context_switch( )上下文切换 分类: linux_system 2010-12-14 22:09 2091人阅读 评论(0) 收藏 举报 structthreadloadrunnerdescriptoriolinux(一)/kernel_details/archive/2007/01/11/1479940.aspxcontext_switch( )上下文切换:调用switch_mm(),把虚拟内存从一个进程映射切换到新进程中 调用switch_to(),从上一个进程的处理器状态切换到新进程的处理器状态。这包括保存、恢复栈信息和寄存器信息 The context_switch( ) function sets up the address space of next. the active_mm field of the process descriptor points to the memory descriptor that is used by the process, while the mm field points to the memory descriptor owned by the process. For normal processes, the two fields hold the same address; however, a kernel thread does not have its own address space and its mm field is always set to NULL. The context_switch( ) function ensures that if next is a kernel thread, it uses the address space used by prev. context_switch( )函数建立next的地址空间。进程描述符的active_mm字段指向进程所使用的内存描述符,而mm字段指向进程所拥有的内存描述符。对于一般的进程,这两个字段有相同的地址,但是,内核线程没有它自己的地址空间而且它的 mm字段总是被设置为 NULL。context_switch( )函数保证:如果next是一个内核线程,它使用prev所使用的地址空间:static inlinetask_t * context_switch(runqueue_t *rq, task_t *prev, task_t *next){ struct mm_struct *mm = next-mm; struct mm_struct *oldmm = prev-active_mm;如果next是内核线程,则线程使用prev所使用的地址空;schedule( )函数把该线程设置为懒惰TLB模式事实上,每个内核线程并不拥有自己的页表集(task_struct-mm = NULL);更确切地说,它使用一个普通进程的页表集。不过,没有必要使一个用户态线性地址对应的TLB表项无效,因为内核线程不访问用户态地址空间。|||?? if (unlikely(!mm)) {?????????????? ||?????? next-active_mm = oldmm;?????? ||?????? atomic_inc(oldmm-mm_count);? ||?????? enter_lazy_tlb(oldmm, next);?? |||如果next是一个普通进程,schedule( )函数用next的地址空间替换prev的地址空间|||?? } else???????????????????????????? ||?????? switch_mm(oldmm, mm, next);??? |||如果prev是内核线程或正在退出的进程,context_switch()函数就把指向prev内存描述符的指针保存到运行队列的prev_mm字段中,然后重新设置prev-active_mm|||?? if (unlikely(!prev-mm)) {???? ||?????? prev-active_mm = NULL;??? ||?????? WARN_ON(rq-prev_mm);????? | |?????? rq-prev_mm = oldmm;?????? ||| }context_switch()终于可以调用switch_to()执行prev和next之间的进程切换了|||?? switch_to(prev, next, prev);?? ||| return prev;}??/*?* context_switch - switch to the new MM and t

文档评论(0)

wuyoujun92 + 关注
实名认证
文档贡献者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档