TX2, how can I assign a thread to a specific CPU, which CPU is the best?

I have 5 threads in my c++ program.
cthread[0] = thread(function0, paramerters);
cthread[1] = thread(function1, paramerters);
cthread[2] = thread(function2, paramerters);
cthread[3] = thread(function3, paramerters);

  1. Will Ubuntu of tx2 automatically assign 5 threads to 5 CPUs(each CPU for each thread)? So each thread can run at full speed compared with the case that several threads are stuck on CPU.

  2. From Ubuntu System Monitor, I can see there are 6 CPU, how can I know the performance of each CPU if I need to know which one is the most powerful.

  3. Let’s say thread2 and thread3 need more computation ability, how can I assign thread 2 and thread 3 to the two most powerful CPUs?
    Or do I need to do this manually? I doubt Ubuntu of tx2 is so intelligent to give the best CPU to the thread with most computation.

Before you force separate cores consider your data. One reason why threads are more efficient than separate processes is that there is less information which must be copied and restored at each context change, e.g., threads don’t need to preserve some of the ownership/security information when going from one thread to another thread of the same process, but processes can be owned by different users, thus need this copied to a backup location prior to context switching. Within threads there is more sharing of data, and if you want to take advantage of cache hits then all threads involved must run on the same core. Ask yourself first if this is data bound or CPU bound. There is a reason why the scheduler may put multiple threads of a single process on a single core…unless the system loads download and it determines it is time to move a second thread to a second core. Also note that threads accessing hardware I/O (e.g., ethernet, USB, GPIO) may require CPU0 core.

The topic is “CPU affinity”. There is a lot on the internet about this. One example:

Here’s one using C++11 extensions on threading (I haven’t tried this…it looks much simpler than threading in C…and I prefer C++ in user space):

The pthread interface is probably available on the most minimal of systems: