Linux内核调度程序
这里已经提出了一些类似的问题,但我无法回答以下问题:当内核调度进程 P 在处理器 S 上运行时,调度程序如何发出这种亲和力信号?谢谢。
A few questions like this have been asked here, but I've not been able to answer the following one: when the kernel schedules process P to run on processor S, how does the scheduler signal this affinity? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
内核的每个 CPU 都有一个运行队列。将任务从一个核心移动到另一个核心涉及将其从一个队列中删除并将其放入另一个队列中。例如,请参见 http://lxr.linux.no /#linux+v2.6.37/kernel/sched.c#L5859。
The kernel has a run-queue per CPU. Moving a task from one core to another involves removing it from one queue and putting it into the other. See, for example, http://lxr.linux.no/#linux+v2.6.37/kernel/sched.c#L5859.
查看
sched_getaffinity()
和pthread_getaffinity_np()
。Look at
sched_getaffinity()
andpthread_getaffinity_np()
.假设我们要运行一个普通的用户任务,每当一个新任务被安排在SMP系统中运行时,它首先在负载均衡器的帮助下放入每个CPU的运行队列中(每个CPU维护自己的struct rq类型的运行队列),基于proirity、load wieght、vruntime属性,它将被分配给CPU,这是通过称为scheduler_tick()的周期性定时器完成的,它内部调用pick_next_task()来运行,周期性定时器以HZ/秒的速率运行,一旦它完成它的时间量,它的上下文切换和其他任务将被安排。
Let's consider we want to run a normal user task,Whenever a new task is scheduled to run in SMP system,It first put in one of per cpu runqueue with the help of load balancer(Each cpu maintain's own runqueue of type struct rq), based on the proirity, load wieght,vruntime attributes it will get allocated to the cpu, this is done by periodic timer called scheduler_tick() which internally calls pick_next_task() to run, periodic timer runs at a rate of HZ/sec, once it completes it's time quantum it's context switched and other task will be scheduled.
在某些情况下,内核将 cpu 绑定到任务。
1)当任务被fork时
2)当任务休眠后被唤醒时
2)任务迁移时
In a few scenario, kernel bind a cpu to task.
1) when a task is forked
2) when a task is woken up after sleep
2) when a task is migrated