Is there a way to establish the similarity of threads with the processor core using the thread acceleration library?

And it would be nice to do this if I need processor cores that are 100% working for a dozen seconds, or will I get better performance if I let the system decide how to handle the threads?

I need fast execution, and I am worried that the system may spend several seconds before using all the kernels, but I did not find a way to do this using boost-stream.

+4
source share
4 answers

First you need to call the get_native_handle function, and then pass the resulting handle to a specific platform function to set the affinity thread processor (i.e. pthread_setaffinity_np / SetThreadAffinityMask / ...).

Regarding a good idea: profile and find out ...

+4
source

On very high-performance systems, performance improves if you assign tasks with less memory that are cache-sensitive to a specific kernel, and the kernel does only that task to a large extent. The effect is to improve cache hit rates, which can be of great importance. If this is not the case, leave things to the OS scheduler. This (as noted above) is a rather specialized situation, but when they arise, interest in the processor is worth exploring.

+5
source

The scheduler of your operating system should take care of this for you in milliseconds, not seconds. The details depend on which OS you are running on, but one general approach is that when the scheduler is running on an idle processor, it checks to see if it can steal a thread from another processor with too many. This quickly balances the threads of all processors.

As a rule, if you need to establish the proximity of the processor, either you have a very specific and unusual use case, or your operating system has an error.

+4
source

There is another reason for affinity. For some modern systems (for example, ARM-based SOCs), energy-saving technology significantly affects the scheduler. The system runs at least the cpu kernel as much as possible. If all current tasks can live on one core, only the other cores are asleep. If the load suddenly rises (a new difficult task is being performed), one or more cores must be woken up. This process is relatively slow, so it can give your task the lack of processor shortages, while the scheduler balances the load for more cores. When manually configuring multiple threads / processes, you can support all cores (and always be prepared for a sharp increase in load). This seems like good for pseudo real-time tasks.

0
source

Source: https://habr.com/ru/post/959058/