开发者

Restricting CPU scheduling

开发者 https://www.devze.com 2023-02-21 10:26 出处:网络
(Running on recent Ubuntu linux...) So I have a multithreaded program which I want to get reliable timing numbers for.I can use sched_setaffinity to pin each thread to a particular core (say, all on

(Running on recent Ubuntu linux...)

So I have a multithreaded program which I want to get reliable timing numbers for. I can use sched_setaffinity to pin each thread to a particular core (say, all on the same socket) in the way I like.

But I'm worried ab开发者_Python百科out other processes in the system getting scheduled on those CPUs and displacing my code...I need highly accurate numbers. Moreover, the system has hyperthreaded processors and if I have a thread on core 0, I don't want to allow anyone to schedule on core 0's hyperthreaded sibling. Is there a way I can tell the kernel "nothing but this processes is allowed on this set of processors?"

One idea is renice -20, which will make it more likely that nothing goes wrong, at least, but it does nothing about hyperthreaded siblings, and I'd prefer something that lets me diretly control what schedules where.


I think what you are looking for is the control groups system of the Linux kernel, and more specifically its cpusets subsystem. It allows you to use specific CPUs (or percentages of their time) for specific tasks.


Boot your Ubuntu machine into single-user mode. Then you can be guaranteed nothing else is running at the time.

If your program needs other system services then this won't work.


If you really, really want to give absolute priority to a process, you can put it under the SCHED_FIFO or SCHED_RR scheduling policy using sched_setscheduler().

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号