Linux - make sure the kernel is kept exclusively for essential tasks

I have a process that runs on a Linux machine with exactly two cores.

Let's assume my process is the only process on the system (I will ignore other processes and even system ones).

My process is split into two parts:

  • Performance critical code
  • Low priority code

Also let's assume my main process was running on Core 0 and I want to exclusively reserve Core 1 for performance critical code.

I would like to split the question into two:

  • How can I make sure that every thread in my process (including third party libraries that I linked my code with with this pthread_create call, etc.) will always open new Core 0 threads?

  • How can I write a test that can verify that Core 1 is doing nothing but the critical performance path?

I am familiar with the API, for example:

pthread_setaffinity_np

      

which can set a specific thread binding, but I want to know if there is a lower level to make sure that even threads created by third party libraries (from within the process) will also bind to Core 0.

Perhaps I can set the default affinity for the process to be Core 0 and for a specific thread - bind it to Core 1?

+3


source to share


2 answers


You have already described the required solution:

Perhaps I can set the default binding to the process as Core 0 and for a specific thread - bind it to Core 1?

But maybe the question is that you don't know how to achieve this.



Linux installs sched_setaffinity

to set the affinity of the current process.

To get only created threads to run on a specific kernel, the easiest way is to initialize pthread_attr_t

and set the desired kernel affinity with pthread_attr_setaffinity_np

.

+1


source


One solution is to install (if you don't already have one) and run the Cpuset utility. Details can be found here



0


source







All Articles