Why does using taskset to run a multi-threaded Linux program on a set of isolated cores cause all threads to run on one core?

前端 未结 1 1845
执念已碎
执念已碎 2021-02-13 10:02

Desired behaviour: run a multi-threaded Linux program on a set of cores which have been isolated using isolcpus.

Here\'s a small program we can use as an ex

相关标签:
1条回答
  • 2021-02-13 10:41

    From the Linux Kernel Parameter Doc:

    This option can be used to specify one or more CPUs to isolate from the general SMP balancing and scheduling algorithms.

    So this options would effectively prevent scheduler doing thread migration from one core to another less contended core (SMP balancing). As typical isolcpus are used together with pthread affinity control to pin threads with knowledge of CPU layout to gain predictable performance.

    https://www.kernel.org/doc/Documentation/kernel-parameters.txt

    --Edit--

    Ok I see why you are confused. Yeah personally I would assume consistent behavior on this option. The problem lies around two functions, select_task_rq_fair and select_task_rq_rt, which is responsible for selecting new run_queue (which is essentially selecting which next_cpu to run on). I did a quick trace (Systemtap) of both functions, for CFS it would always return the same first core in the mask; for RT, it would return other cores. I haven't got a chance to look into the logic in each selection algorithm but you can send an email to the maintainer in Linux devel mailing list for fix.

    0 讨论(0)
提交回复
热议问题