A customer is trying a multithreaded approach where they want to set different threads to different cores using the
set_cpu_affinity function. They state that in x86 the function works correctly but when they execute it in our module, the core is not correctly choosen. I’ve attached an example of the source code used.
I’ve did the test myself and confirmed with htop that indeed, every thread is correctly associated to different cores (CPU column on the left).
$ gcc main_edited.c -o test -lpthread $ gcc --version gcc (Ubuntu 7.3.0-16ubuntu3) 7.3.0
Then did the same proccedure cross-compiling for the T30:
$ /home/alvaro/gcc-linaro/bin/arm-linux-gnueabihf-gcc main_edited.c -o testarm -lpthread $ /home/alvaro/gcc-linaro/bin/arm-linux-gnueabihf-gcc --version arm-linux-gnueabihf-gcc (Linaro GCC 5.2-2015.11-2) 5.2.1 20151005
But at running the application, I got the following error and got all the threads running in the same core (Also, the 0% in the other 3 cores give it away as well).
pthread_setaffinity_np: Invalid argument a_cpu = 1 pthread_setaffinity_np: Invalid argument a_cpu = 2
I’ve tried with the newest version of the toolchain (7.3.1 I believe) with the same outcome.
Do you know if there is an issue with this approach? Do you know if there is an alternative solution?
Thanks and best regards,