2

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.

1
  • 1
    You write a script with your command and call the script with sudo (rather then using sudo over and over in the script ).
    – Panther
    Jul 11, 2015 at 1:39

3 Answers 3

1

The reason sudo echo 1 > /sys/devices/system/cpu/cpu0/online doesn't work is because the sudo part applies only to the main command (echo 1); it doesn't apply to the redirection (> /sys/devices/system/cpu/cpu0/online), and so the writing-to-the-file part is done under your user account.

Using something like echo 1 | sudo tee /sys/devices/system/cpu/cpu0/online should work, as the writing part will be done under sudo, while the echo part will be under your account. I'm not sure why it didn't work in your case.

1

Putting su at the top of the script, and then running the commands normally will work just fine. The reason you have to use sudo su instead of just sudo is because sudo only works on the main program, the redirection (>) is run without root privileges.

0

Huh. That's weird.

This should work:

cat | sudo bash << "EOF"
echo 1 > /sys/devices/system/cpu/cpu1/online
echo 1 > /sys/devices/system/cpu/cpu2/online
echo 1 > /sys/devices/system/cpu/cpu3/online
EOF

Perhaps the other stuff was working for you, but because you didn't disable the scaling governor it turned the cores back off before you started using them?

According to http://elinux.org/Jetson/Performance you should also echo 0 > /sys/devices/system/cpu/cpuquiet/tegra_cpuquiet/enable

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .