Linux
程序調度程序在哪裡執行?我可以追踪它嗎?
程序調度程序在使用者空間是否“可見”?可以用ps看嗎?也許它是核心執行緒之一?如果是,它是怎麼稱呼的?我怎樣才能“看到”它?
它不作為單獨的執行緒或模組存在,而是作為函式實現
好的,但是這個函式是如何、在哪里以及以何種方式執行的呢?有沒有辦法跟踪它並看到它?
正如什麼是 Linux 中的程序調度程序中所解釋的那樣?調度器是一個核函式,
__schedule
;它不會顯示為單獨的執行緒或程序。函式註釋解釋了它是如何執行的:
* The main means of driving the scheduler and thus entering this function are: * * 1. Explicit blocking: mutex, semaphore, waitqueue, etc. * * 2. TIF_NEED_RESCHED flag is checked on interrupt and userspace return * paths. For example, see arch/x86/entry_64.S. * * To drive preemption between tasks, the scheduler sets the flag in timer * interrupt handler scheduler_tick(). * * 3. Wakeups don't really cause entry into schedule(). They add a * task to the run-queue and that's it. * * Now, if the new task added to the run-queue preempts the current * task, then the wakeup sets TIF_NEED_RESCHED and schedule() gets * called on the nearest possible occasion: * * - If the kernel is preemptible (CONFIG_PREEMPTION=y): * * - in syscall or exception context, at the next outmost * preempt_enable(). (this might be as soon as the wake_up()'s * spin_unlock()!) * * - in IRQ context, return from interrupt-handler to * preemptible context * * - If the kernel is not preemptible (CONFIG_PREEMPTION is not set) * then at the next: * * - cond_resched() call * - explicit schedule() call * - return from syscall or exception to user-space * - return from interrupt-handler to user-space
功能無法追踪;它的儀器被禁用(參見
notrace
其聲明中的條目)。