How does sched_setaffinity() work?

后端 未结 4 1048
生来不讨喜
生来不讨喜 2020-12-08 22:49

I am trying to understand how the linux syscall sched_setaffinity() works. This is a follow-on from my question here.

I have this guide, which explains how to use th

4条回答
  •  旧时难觅i
    2020-12-08 23:28

    Where, in the assembly code, are we specifying which core performs that operation?

    There is no assembly involved here. Every task (thread) is assigned to a single CPU (or core in your terms) at a time. To stop running on a given CPU and resume on another, the task has to "migrate" (also this). When a task migrates from one CPU to another, the scheduler picks the CPU which is more idle among the CPUs allowed by sched_setaffinity().

    There is no magic assembly instructions issued. The kernel has a more low-level view of the hardware, each CPU is a separate object, very different than how it looks like for user-space processes (in user-space, CPUs are almost invisible).

提交回复
热议问题