Linux kernel: What process does schedule() run in?

后端 未结 4 560
没有蜡笔的小新
没有蜡笔的小新 2021-02-04 22:24

When you call a system call such as fork in process X, the kernel is said to be executing in process context. So, fork can be said to be running in pro

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-04 22:38

    It really depends upon where the schedule() call is made from; schedule() can be called both from process context or from a work queue. The work queues are kernel-scheduled threads:

    # ps auxw | grep worker
    root      1378  0.0  0.0      0     0 ?        S    20:45   0:00 [kworker/1:0]
    root      1382  0.0  0.0      0     0 ?        S    20:45   0:00 [kworker/2:0]
    root      1384  0.0  0.0      0     0 ?        S    20:45   0:00 [kworker/3:1]
    ...
    

    The [..] signifies that the processes do not execute in userspace.

    The worker_thread() function calls schedule() after handling a work item but before starting all over again.

    schedule() can also be called on behalf of a process, either by a driver or by signal handling code, or filesystem internals, or myriad other options.

提交回复
热议问题