I am using the Jetson TK1 development board from NVIDIA which has Ubuntu 14.04 on it. It is a 4-core ARM system and by default, 3 of them are "offline" -
ubuntu@tegra-ubuntu ~ $ lscpu
Architecture: armv7l
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0
Off-line CPU(s) list: 1-3
Thread(s) per core: 1
Core(s) per socket: 3
Socket(s): 1
While they are supposed to automatically wake up when the scheduler detects enough load, they do not (at least for our workload). The workaround is to write a "1" into a location inside of /sys -
/sys/devices/system/cpu/cpu1/online
The documentation says to follow these commands, in order -
sudo su
echo 1 > /sys/devices/system/cpu/cpu1/online
and repeat for cpus 2 and 3. This works -
ubuntu@tegra-ubuntu ~ $ sudo su
[sudo] password for ubuntu:
root@tegra-ubuntu:/home/ubuntu# echo 1 > /sys/devices/system/cpu/cpu1/online
root@tegra-ubuntu:/home/ubuntu# lscpu
Architecture: armv7l
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0,1
Off-line CPU(s) list: 2,3
Thread(s) per core: 1
Core(s) per socket: 3
Socket(s): 1
root@tegra-ubuntu:/home/ubuntu#
I don't want to use sudo su
, personally, because it hurts my eyes but mainly because we need a script that can wake up all CPUs and then execute the command to start our workload. Ideally, I'd put it in /etc/rc.local
. That does not work. May be the kernel powers the CPUs down after rc.local is executed at boot?
In any case, here is my script -
#!/bin/bash
sudo bash -c "echo '1' > /sys/devices/system/cpu/cpu1/online"
sudo bash -c "echo '1' > /sys/devices/system/cpu/cpu2/online"
sudo bash -c "echo '1' > /sys/devices/system/cpu/cpu3/online"
<some command>
The problem is, <some command>
runs and the echo lines above do not give anything on stdout. However, lscpu
shows only 1 CPU active. Pasting these lines into the terminal directly does not work. That was not the puzzling part for me. I assumed I messed something up. Here's what is puzzling. Doing sudo su
followed by the echo
command works, as I said earlier. Now, exiting out of root and running
sudo bash -c "echo '1' > /sys/devices/system/cpu/cpu2/online"
sudo bash -c "echo '1' > /sys/devices/system/cpu/cpu3/online"
in my user shell (user is sudoer) works. So if I do not do sudo su
, 1 is never echoed for any of the CPUs. But echoing after sudo su
for one CPU lets me echo the others outside the root shell.
Finally, tee
used like so does not work either -
echo 1 | sudo tee /sys/devices/system/cpu/cpu1/online
Any help as to why this is happening and how I could use sudo bash -c
from within a script in the user terminal would be appreciated.