Can someone tell me what the dependencies are, for a Linux installation to support setting the CPU affinity of a process via sched_setaffinity(…), or thread via pthread_setaffinity_np(…)?
In the manpages of sched_setaffinity, this page is referenced: cpuset. There it says, there should be a “nodev cpuset” in /proc/filesystems, if CPUSET is supported.
On both systems I tested, the iMX6 (kernel 4.1) and the TK1 (kernel 3.10), it’s not there. Then I found that the option CONFIG_CPUSET is disabled in the linux config (according to /proc/config.gz), of both systems.
So it should be not supported on both, right?
But on the iMX6, both setaffinity calls above succeed and I do see the effect in htop, the second core doig much more than without the call.
But on the TK1, the call returns unsuccessfully.
Normally my guess would be I’d need to build a new Linux image with that option enabled. But the relation between the presence indicator for CPUSET support, and it actually working seems to be different than I so far gathered from the manpages.
Hence, I’d be glad if someone could tell me definitely what’s really going on here, before I go to such efforts in vain
Thanks for that test program.
What Linux image did you use on the TK1?
I am using the L4T one (the smaller of the two, without the computervision stuff).
And am getting “Invalid argument” with perror(“”) after sched_setaffinity(…) returns a negative number, while this works fine on the iMX6 with LXDE image.
If you use an image with the downstream kernel usually the cpu hotplug feature is used in a way that in idle all but CPU 0 is switched off to save power.
You have to make sure that at least one of the CPUs to which you want migrate to are switched on. The following would disable the automatic hotplug feature and enable additionally CPU 1-3. After that the hello_affinity works.