xref: /linux/Documentation/translations/zh_CN/scheduler/sched-arch.rst (revision 0ea5c948cb64bab5bc7a5516774eb8536f05aa0d)
16f87c519SYanteng Si.. include:: ../disclaimer-zh_CN.rst
26f87c519SYanteng Si
36f87c519SYanteng Si:Original: Documentation/scheduler/sched-arch.rst
46f87c519SYanteng Si
56f87c519SYanteng Si:翻译:
66f87c519SYanteng Si
76f87c519SYanteng Si 司延腾 Yanteng Si <siyanteng@loongson.cn>
86f87c519SYanteng Si
96f87c519SYanteng Si:校译:
106f87c519SYanteng Si
116f87c519SYanteng Si
126f87c519SYanteng Si
136f87c519SYanteng Si===============================
146f87c519SYanteng Si架构特定代码的CPU调度器实现提示
156f87c519SYanteng Si===============================
166f87c519SYanteng Si
176f87c519SYanteng Si	Nick Piggin, 2005
186f87c519SYanteng Si
196f87c519SYanteng Si上下文切换
206f87c519SYanteng Si==========
216f87c519SYanteng Si1. 运行队列锁
226f87c519SYanteng Si默认情况下,switch_to arch函数在调用时锁定了运行队列。这通常不是一个问题,除非
23*94483490SArd Biesheuvelswitch_to可能需要获取运行队列锁。这通常是由于上下文切换中的唤醒操作造成的。
246f87c519SYanteng Si
256f87c519SYanteng Si为了要求调度器在运行队列解锁的情况下调用switch_to,你必须在头文件
266f87c519SYanteng Si中`#define __ARCH_WANT_UNLOCKED_CTXSW`(通常是定义switch_to的那个文件)。
276f87c519SYanteng Si
286f87c519SYanteng Si在CONFIG_SMP的情况下,解锁的上下文切换对核心调度器的实现只带来了非常小的性能损
296f87c519SYanteng Si失。
306f87c519SYanteng Si
316f87c519SYanteng SiCPU空转
326f87c519SYanteng Si=======
336f87c519SYanteng Si你的cpu_idle程序需要遵守以下规则:
346f87c519SYanteng Si
356f87c519SYanteng Si1. 现在抢占应该在空闲的例程上禁用。应该只在调用schedule()时启用,然后再禁用。
366f87c519SYanteng Si
376f87c519SYanteng Si2. need_resched/TIF_NEED_RESCHED 只会被设置,并且在运行任务调用 schedule()
386f87c519SYanteng Si   之前永远不会被清除。空闲线程只需要查询need_resched,并且永远不会设置或清除它。
396f87c519SYanteng Si
406f87c519SYanteng Si3. 当cpu_idle发现(need_resched() == 'true'),它应该调用schedule()。否则
416f87c519SYanteng Si   它不应该调用schedule()。
426f87c519SYanteng Si
436f87c519SYanteng Si4. 在检查need_resched时,唯一需要禁用中断的情况是,我们要让处理器休眠到下一个中
446f87c519SYanteng Si   断(这并不对need_resched提供任何保护,它可以防止丢失一个中断):
456f87c519SYanteng Si
466f87c519SYanteng Si	4a. 这种睡眠类型的常见问题似乎是::
476f87c519SYanteng Si
486f87c519SYanteng Si	        local_irq_disable();
496f87c519SYanteng Si	        if (!need_resched()) {
506f87c519SYanteng Si	                local_irq_enable();
516f87c519SYanteng Si	                *** resched interrupt arrives here ***
526f87c519SYanteng Si	                __asm__("sleep until next interrupt");
536f87c519SYanteng Si	        }
546f87c519SYanteng Si
556f87c519SYanteng Si5. 当need_resched变为高电平时,TIF_POLLING_NRFLAG可以由不需要中断来唤醒它们
566f87c519SYanteng Si   的空闲程序设置。换句话说,它们必须定期轮询need_resched,尽管做一些后台工作或
576f87c519SYanteng Si   进入低CPU优先级可能是合理的。
586f87c519SYanteng Si
596f87c519SYanteng Si      - 5a. 如果TIF_POLLING_NRFLAG被设置,而我们确实决定进入一个中断睡眠,那
606f87c519SYanteng Si            么需要清除它,然后发出一个内存屏障(接着测试need_resched,禁用中断,如3中解释)。
616f87c519SYanteng Si
626f87c519SYanteng Siarch/x86/kernel/process.c有轮询和睡眠空闲函数的例子。
636f87c519SYanteng Si
646f87c519SYanteng Si
656f87c519SYanteng Si可能出现的arch/问题
666f87c519SYanteng Si===================
676f87c519SYanteng Si
686f87c519SYanteng Si我发现的可能的arch问题(并试图解决或没有解决)。:
696f87c519SYanteng Si
706f87c519SYanteng Sisparc - 在这一点上,IRQ是开着的(?),把local_irq_save改为_disable。
716f87c519SYanteng Si      - 待办事项: 需要第二个CPU来禁用抢占 (参考 #1)
72