天下网吧 >> 网吧天地 >> 网吧技术 >> 网吧系统 >> 正文

详解Linux系统内核抢占补丁的相关原理

2013-2-26不详佚名

68239">

  c = weight, next = p;

  }

  }

  /* Do we need to re-calculate counters? */

  if (!c)

  goto recalculate;

  /*

  * from this point on nothing can prevent us from

  * switching to the next task, save this fact in

  * sched_data.

  */

  sched_data->curr = next;

  #ifdef CONFIG_SMP

  next->has_CPU = 1;

  next->processor = this_CPU;

  #endif

  spin_unlock_irq(&runqueue_lock);

  if (prev == next)

  goto same_process;

  #ifdef CONFIG_SMP

  /*

  * maintain the per-process 'last schedule' value.

  * (this has to be recalculated even if we reschedule to

  * the same process) Currently this is only used on SMP,

  * and it's approximate, so we do not have to maintain

  * it while holding the runqueue spinlock.

  */

  sched_data->last_schedule = get_cycles();

  /*

  * We drop the scheduler lock early (it's a global spinlock),

  * thus we have to lock the previous process from getting

  * rescheduled during switch_to().

  */

  #endif /* CONFIG_SMP */

  kstat.context_swtch++;

  /*

  * there are 3 processes which are affected by a context switch:

  *

  * prev == .... ==> (last => next)

  *

  * It's the 'much more previous' 'prev' that is on next's stack,

  * but prev is set to (the just run) 'last' process by switch_to().

  * This might sound slightly confusing but makes tons of sense.

  */

  prepare_to_switch();

  {

  struct mm_struct *mm = next->mm;

  struct mm_struct *oldmm = prev->active_mm;

  if (!mm) {

  if (next->active_mm) BUG();

  next->active_mm = oldmm;

  atomic_inc(&oldmm->mm_count);

  enter_lazy_tlb(oldmm, next, this_CPU);

  } else {

  if (next->active_mm != mm) BUG();

  switch_mm(oldmm, mm, next, this_CPU);

  }

  if (!prev->mm) {

  prev->active_mm = NULL;

  mmdrop(oldmm);

  }

  }

  /*

  * This just switches the register state and the

  * stack.

  */


本文来源:不详 作者:佚名

声明
声明:本站所发表的文章、评论及图片仅代表作者本人观点,与本站立场无关。若文章侵犯了您的相关权益,请及时与我们联系,我们会及时处理,感谢您对本站的支持!联系email:support@txwb.com,系统开号,技术支持,服务联系QQ:1175525021本站所有有注明来源为天下网吧或天下网吧论坛的原创作品,各位转载时请注明来源链接!
天下网吧·网吧天下
  • 本周热门
  • 本月热门
  • 阅读排行