Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to lock a process to a CPU?

Tags:

c

linux

api

I am thinking about developing an application that will, on a six core machine, run six asynchronous tasks, one on each core.

But is it possible to lock the tasks to their own core?

The idea is for them to run mostly by themselves, but to sometimes communicate over a shared memory area. However, I want the tasks to run as undisturbed as possible.

like image 763
Prof. Falken Avatar asked Mar 29 '11 22:03

Prof. Falken


People also ask

What is CPU lock function?

A CPU lock or CPU locking is the process of locking down a CPU's clock multiplier, either permanently or until the lock is removed. The main purpose of this is to prevent users from overclocking the CPUs, making them operate in conditions that they were not designed for, and then possibly damaging them.

How do I dedicate CPU cores to a program?

To set CPU Priority, right-click on any process in Task Manager and select Go to details. Next, right-click on the highlighted process and click on Set Priority. Now, choose priority from the list that pops up. If you want your process to run as soon as it needs, select Realtime.

How do I limit my CPU cores?

Launch the Task Manager and go to the Details tab. Look for the process you wish to modify the affinity, and right-click it. Click on Set affinity in the Context Menu. From the Process affinity window, you can select the cores you wish the process to limit to, and uncheck the boxes next to the rest.

How do I force a program to use multiple cores?

Core Settings In Windows 10Type 'msconfig' into the Windows Search Box and hit Enter. Select the Boot tab and then Advanced options. Check the box next to Number of processors and select the number of cores you want to use (probably 1, if you are having compatibility issues) from the menu. Select OK and then Apply.


1 Answers

The concept you're looking for is called "thread affinity". How it's implemented and the interfaces to ask for it are OS-specific.

Under Linux, try sched_setaffinity(). glibc may also offer pthread_attr_setaffinity_np().

like image 124
metamatt Avatar answered Sep 19 '22 20:09

metamatt