# TX2 has always run one CPU core, no matter how many threads are launched.

**URL:** <https://forums.developer.nvidia.com/t/tx2-has-always-run-one-cpu-core-no-matter-how-many-threads-are-launched/56127>\
**Category:** Jetson TX2\
**Created:** [December 13, 2017, 12:51pm UTC](https://forums.developer.nvidia.com/t/tx2-has-always-run-one-cpu-core-no-matter-how-many-threads-are-launched/56127 "2017-12-13T12:51:59Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![oprell](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@oprell](https://forums.developer.nvidia.com/u/oprell)\
**Post date:** [December 13, 2017, 12:51pm UTC](https://forums.developer.nvidia.com/t/tx2-has-always-run-one-cpu-core-no-matter-how-many-threads-are-launched/56127/1 "2017-12-13T12:51:59Z")

</div>

Hi experts,

Here I encountered a strange problem which is mentioned as the Title.

First, I run ‘lscpu’ command, and It shows as follows:  
[https://pan.baidu.com/s/1nuDHWAt](https://pan.baidu.com/s/1nuDHWAt)

It shows that there are 4 CPU cores on-line.

But when I launched 32 threads in a test program, the system seems to put all threads on only one CPU core. That is very strange. The test program and what the ‘top’ command and system Monitor shows are as follows:

- int main(int argc, char \*argv){  
long result = 0;

---

<div class="post-metadata">

**Author:** ![oprell](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@oprell](https://forums.developer.nvidia.com/u/oprell)\
**Post date:** [December 13, 2017, 1:04pm UTC](https://forums.developer.nvidia.com/t/tx2-has-always-run-one-cpu-core-no-matter-how-many-threads-are-launched/56127/2 "2017-12-13T13:04:05Z")

</div>

Please somebody’s here

---

<div class="post-metadata">

**Author:** ![VickNV](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/vicknv/32/14043_2.png) [@VickNV](https://forums.developer.nvidia.com/u/VickNV)\
**Post date:** [December 14, 2017, 1:27am UTC](https://forums.developer.nvidia.com/t/tx2-has-always-run-one-cpu-core-no-matter-how-many-threads-are-launched/56127/3 "2017-12-14T01:27:18Z")

</div>

Hi oprell,

Please check with below command.

$ ps -o spid,psr -T -p 3140

---

<div class="post-metadata">

**Author:** ![oprell](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@oprell](https://forums.developer.nvidia.com/u/oprell)\
**Post date:** [December 14, 2017, 2:02pm UTC](https://forums.developer.nvidia.com/t/tx2-has-always-run-one-cpu-core-no-matter-how-many-threads-are-launched/56127/4 "2017-12-14T14:02:14Z")

</div>

Hi vickyy,

I run the command you suggested. But it only shows below.

```auto
nvidia@tegra-ubuntu:~$ ps -o spid,psr 3140
 SPID PSR

```

There’s nothing useful.

---

<div class="post-metadata">

**Author:** ![linuxdev](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/linuxdev/32/10243_2.png) [@linuxdev](https://forums.developer.nvidia.com/u/linuxdev)\
**Post date:** [December 14, 2017, 7:41pm UTC](https://forums.developer.nvidia.com/t/tx2-has-always-run-one-cpu-core-no-matter-how-many-threads-are-launched/56127/5 "2017-12-14T19:41:19Z")

</div>

You have to adjust the “-p 3140” to be the PID of the process…which is a moving target.

---

<div class="post-metadata">

**Author:** ![oprell](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@oprell](https://forums.developer.nvidia.com/u/oprell)\
**Post date:** [December 15, 2017, 2:45am UTC](https://forums.developer.nvidia.com/t/tx2-has-always-run-one-cpu-core-no-matter-how-many-threads-are-launched/56127/6 "2017-12-15T02:45:01Z")

</div>

Hi, linuxdev

Thanks for your hint.

I checked command ’ ps -o spid,psr -T -p 3221’, and I got below output.

```auto
SPID PSR
 3221 0
 3222 0
 3223 0
 3224 3
 3225 3
 3226 0
 3227 0
 3228 0
 3229 3
 3230 0
 3231 0
 3232 3
 3233 3
 3234 3
 3235 0
 3236 0
 3237 0
 3238 0
 3239 0
 3240 0
 3241 0
 3242 0
 3243 0
 3244 0
 3245 0
 3246 3
 3247 0
 3248 0
 3249 3
 3250 0
 3251 3
 3252 0

```

I launched 32 threads in my test program.  
It seems to be that the program execute on one CPU core. What’s wrong with it?

---

<div class="post-metadata">

**Author:** ![snarky](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/snarky/32/10446_2.png) [@snarky](https://forums.developer.nvidia.com/u/snarky)\
**Post date:** [December 15, 2017, 5:59am UTC](https://forums.developer.nvidia.com/t/tx2-has-always-run-one-cpu-core-no-matter-how-many-threads-are-launched/56127/7 "2017-12-15T05:59:19Z")

</div>

My guess is that OpenMP is not working as you assume it will.  
This can be because of compiler options, because of runtime options, or because of other problems.

What happens if you use pthreads instead of the OpenMP pragmas?

---

<div class="post-metadata">

**Author:** ![VickNV](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/vicknv/32/14043_2.png) [@VickNV](https://forums.developer.nvidia.com/u/VickNV)\
**Post date:** [December 19, 2017, 3:09am UTC](https://forums.developer.nvidia.com/t/tx2-has-always-run-one-cpu-core-no-matter-how-many-threads-are-launched/56127/8 "2017-12-19T03:09:25Z")

</div>

I’m not familiar with openmp but on my side it looks different from yours. FYI.

```auto
nvidia@tegra-ubuntu:~$ ps -o spid,psr -T -p 30550
 SPID PSR
30550 4
30551 5
30552 3
30553 5
30554 4
30555 4
30556 3
30557 3
30558 5
30559 3
30560 5
30561 5
30562 4
30563 5
30564 3
30565 5
30566 4
30567 3
30568 4
30569 0
30570 5
30571 5
30572 3
30573 5
30574 3
30575 3
30576 4
30577 0
30578 4
30579 3
30580 5
30581 4

```

---

<div class="post-metadata">

**Author:** ![linuxdev](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/linuxdev/32/10243_2.png) [@linuxdev](https://forums.developer.nvidia.com/u/linuxdev)\
**Post date:** [December 19, 2017, 5:05pm UTC](https://forums.developer.nvidia.com/t/tx2-has-always-run-one-cpu-core-no-matter-how-many-threads-are-launched/56127/9 "2017-12-19T17:05:56Z")

</div>

It shows two CPU cores, not one (core 0 and core 3). Performance mode may modify which cores are available (except core 0, which is always available).

Prior to testing try maximizing performance mode:

```auto
# To see what is enabled:
sudo cat /sys/devices/system/cpu/online
# To see available modes:
sudo nvpmodel -p --verbose
# Set performance:
sudo nvpmodel -m0
# Also:
sudo /home/ubuntu/jetson_clocks.sh

```

Try your test when all cores are guaranteed online.

Consider also that unless you specifically force a given core that the scheduler may be picking the best core. The obvious answer to always use all cores may not actually be the correct answer. The problem is that cache has a lot to do with performance, and a cache miss is very expensive relative to a cache hit. If the threads share data it may be a case of the scheduler trying to take advantage of cache. Whether you would want to override this or not might depend on whether you believe it is compute bound or if it is instead data bound as the speed bottleneck. Once all cores are enabled you probably need to profile before you try to outguess the scheduler.

---

<div class="post-metadata">

**Author:** ![autonomousvcet](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@autonomousvcet](https://forums.developer.nvidia.com/u/autonomousvcet)\
**Post date:** [December 20, 2019, 6:17am UTC](https://forums.developer.nvidia.com/t/tx2-has-always-run-one-cpu-core-no-matter-how-many-threads-are-launched/56127/10 "2019-12-20T06:17:15Z")

</div>

I tried this commands, but it doesn’t show any effect. Out of 6 cores only 4 cores are activated in my TX 2. Any suggestion please!!.

---

<div class="post-metadata">

**Author:** ![linuxdev](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/linuxdev/32/10243_2.png) [@linuxdev](https://forums.developer.nvidia.com/u/linuxdev)\
**Post date:** [December 20, 2019, 8:55pm UTC](https://forums.developer.nvidia.com/t/tx2-has-always-run-one-cpu-core-no-matter-how-many-threads-are-launched/56127/11 "2019-12-20T20:55:44Z")

</div>

If you run “sudo nvpmodel -m 0”, then all cores should be active. This doesn’t mean all cores will have software running on them, but it does mean all cores are available.

For a more intuitive test, you can install htop (“sudo apt-get install htop”), then run “htop”. You will see cores listed as bar charts at the top. See if each core varies a bit as you do different things on the system…web browsing is probably a good way to make things jump around.

I do not know about the OpenMP, and there things to consider even about ordinary thread models. The system has a scheduler, and unless something has intervened, then the core the process or thread runs on is entirely up to the scheduler. Core affinity can be used put a process on a single core, but spreading threads out from a single process is a lot more complicated.

The scheduler is aware of cache. Any time you migrate from one core to another you will tend to have a cache miss instead of a cache hit. In cases where the scheduler is keeping things on one core it may in fact be because this is faster due to fewer cache misses.

If you are interested in forcing certain threads or processes to a given core, then you will want to understand process/thread affinity. Here is a good reference to consider:  
[https://www.linuxjournal.com/article/6799](https://www.linuxjournal.com/article/6799)

There are variations on this, e.g., for kernel thread affinity of kthreads (which works with driver modules even though not a user space application).

Not having your threads distribute to all cores is not the same as having inactive cores and can in no way be considered a lack of a working core (cache hit/miss, the scheduler, threading models, so on, is actually a very complicated topic).

---

<div class="post-metadata">

**Author:** ![nadeemm](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/nadeemm/32/367020_2.png) [@nadeemm](https://forums.developer.nvidia.com/u/nadeemm)\
**Post date:** [October 18, 2021, 6:19pm UTC](https://forums.developer.nvidia.com/t/tx2-has-always-run-one-cpu-core-no-matter-how-many-threads-are-launched/56127/12 "2021-10-18T18:19:34Z")

</div>


