Example Hyperflow Example

Is there an example code that illustrates Intel Hyperthreading performance? Is it generally accessible from user space, or is this processor doing all the work transparently for the programmer? This is for C, Linux.

+4
source share
1 answer

Hyperthreading performance depends on many factors and is difficult to evaluate.

To briefly explain Hyperthreading:

  • Each core has more than one set of registers, but no additional execution blocks
  • Hyperthreads are planned more or less evenly

Thus, you really get additional performance from hyperthreads if two threads running on the same core use different actuators and each thread on it will have too many dependencies on adatas. For example, one stream has integer operators, and the other only has floating point. Then you can see additional performance because you are using more execution units per cycle.

But this, in turn, depends on how your OS schedules threads for hyperthreads. From an OS point of view, each hyper-thread is a logical processor. So it completely depends on the scheduler what to put there and when.

In practice, hyperthreads will give you a maximum of 10-20% extra performance. At our HPC, we disabled them (for licensing reasons, mostly though).

To answer your actual question: you cannot deploy hyperthreads code yourself. OS will do it for you. You can configure schedule similarities for your user threads, but for the scheduler, you still need to deploy the threads. This is done transparently for the programmer. A good scheduler will deploy your code evenly first on the kernels and only resort to hyperthreads if all the kernels are busy.

The custom coltrol syscalls you are looking for is sched_setaffinity and pthread_setaffinity_np .

In the following code example, two threads will be deployed on logical processors 0 and 1, which will correspond to two hyperthreads in the first logical core of the first socket , if hypertexts are enabled. However, it is up to the planner to actually put them there. If these hyperthreads are busy, then your code will sleep:

 #define _GNU_SOURCE #include <pthread.h> #include <sched.h> #include <stdlib.h> void * my_thread(intptr_t cput_o_run_on) { cpuset_t cpuset; CPU_ZERO(&cpuset); CPU_SET(cput_o_run_on, &cpuset); pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset); // force a rescheduling sched_yield(); // do something useful return NULL; } int main() { pthread_t thread; pthread_create(&thread, NULL, my_thread, 0); pthread_create(&thread, NULL, my_thread, 1); for (;;); return 0; } 
+4
source

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


All Articles