Difference between revisions of "Jetson/Performance"

From eLinux.org
Jump to: navigation, search
(Redesigned the performance sections)
(Limiting the main CPU cores to run at low speed: Shown how to read & set CPU freq)
Line 45: Line 45:
 
You can limit the max clock-rate of the 4 main "GP" (general-purpose) cores in the CPU to a low speed to reduce the power (it will still automatically switch to the 5th "LP" (low-power) shadow companion core when suitable).
 
You can limit the max clock-rate of the 4 main "GP" (general-purpose) cores in the CPU to a low speed to reduce the power (it will still automatically switch to the 5th "LP" (low-power) shadow companion core when suitable).
  
(TODO)
+
To see the available CPU frequencies (measured in kHz, so "51000" refers to 51MHz):
 +
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
 +
    51000 102000 204000 312000 564000 696000 828000 960000 1092000 1122000 1224000 1326000 1428000 1530000 1632000 1734000 1836000 1938000 2014500 2116500 2218500 2320500
 +
And the current CPU frequencies (note that you will see errors for the cores that are currently sleeping):
 +
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
 +
cat /sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq
 +
cat /sys/devices/system/cpu/cpu2/cpufreq/scaling_cur_freq
 +
cat /sys/devices/system/cpu/cpu3/cpufreq/scaling_cur_freq
 +
Then you can set the min & max frequencies of each CPU core.
 +
 
 +
For example, to limit the speed of the 4 main CPU cores to just 564MHz, run this as root (as shown above):
 +
echo 564000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
 +
echo 564000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq
 +
echo 564000 > /sys/devices/system/cpu/cpu2/cpufreq/scaling_max_freq
 +
echo 564000 > /sys/devices/system/cpu/cpu3/cpufreq/scaling_max_freq
 +
Note that it will only work for the cores that weren't sleeping at the time, so you might want to run a multi-threaded program in the background for it to fully work.
  
 
=== Turning some CPU cores on and some off ===
 
=== Turning some CPU cores on and some off ===

Revision as of 19:13, 21 October 2014

Introduction

This page discusses various Tegra CPU & GPU performance topics. The power draw of the Tegra processor and the overall embedded board are very tightly related to the performance of the Tegra processor, so you will often want to choose carefully between which things should be running at high performance settings (for max speed) and which should be running at low performance settings (for low power draw & heat) or disabled completely. Read the power draw page for more details on power-specific topics.

Controlling the CPU performance

Note: Debugfs and non-upstream sysfs nodes aren't guaranteed to remain unchanged in future L4T releases.

Tegra K1 is designed for mobile use-cases and thus contains a significant number of power reduction systems to control when parts of the hardware should run faster or slower or be turned off, based on runtime use. This is good for most use cases, since the default settings will give high performance for many intense projects and low power draw for many light tasks. But you might want to force a lower or higher performance of some parts of the hardware such as to run benchmarks of the peak performance or enforce lower power draw. The automatic turning on/off of the 4 main CPU cores & 5th companion core is mostly done in the L4T kernel using "cpuquiet", a mechanism for dynamically hot-plugging CPU cores based upon workload/policy. There are many ways to adjust the performance & power behavior at runtime or always on bootup (all requiring root privileges, mentioned below).


As a general guide, the different options for CPU perf/power (sorted from highest power draw to lowest power draw) are:

  • Force all 4 CPU cores to max performance by disabling the hot-plug scaling mechanism.
  • Just use everything with default settings (it will automatically switch on/off each of the 4 main CPU cores & the 5th low-power companion core, at runtime).
  • Limit the max clock-rate of the 4 main CPU cores to a low speed to reduce the power (it will still automatically switch them on/off and switch to the 5th low-power companion core when suitable).
  • Turn some CPU cores on and some off, based on what you know works best for a particular use-case.
  • Turn off all 4 main CPU cores to force all CPU code to run on the 5th "LP" low-power shadow companion core instead, for maximum power reduction.


How to run a command with root privileges temporarily or on every bootup

There are various commands listed below that you can run to reduce or increase the performance or power draw, and they must be executed with root privileges. To execute some of the commands with root privileges just until you reboot your device, you can simply run "su" to login as root user, run the commands, then run "exit" to return to regular user, eg:

sudo su
    (enter your password, typically "ubuntu" by default)
    # Run a command that requires root privileges
    echo Hello > /TEST.txt
    exit

To execute commands automatically on every bootup, you can put your commands into the "/etc/rc.local" bootup script. For example, run this on your board:

sudo nano /etc/rc.local

Then add this near the bottom of the file but before the "exit" line:

# Disable USB auto-suspend, since it disconnects some devices such as webcams on Jetson TK1.
echo -1 > /sys/module/usbcore/parameters/autosuspend 

Save the file by hitting Ctrl+X then Y then Enter, then reboot the device:

sudo reboot


Maximizing CPU performance

To obtain full performance on the CPU (eg: for performance measurements or benchmarking or when you don't care about power draw), you can disable CPU scaling and force the 4 main CPU cores to always run at max performance until reboot:

echo 0 > /sys/devices/system/cpu/cpuquiet/tegra_cpuquiet/enable
echo 1 > /sys/devices/system/cpu/cpu0/online
echo 1 > /sys/devices/system/cpu/cpu1/online
echo 1 > /sys/devices/system/cpu/cpu2/online
echo 1 > /sys/devices/system/cpu/cpu3/online
echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

Limiting the main CPU cores to run at low speed

You can limit the max clock-rate of the 4 main "GP" (general-purpose) cores in the CPU to a low speed to reduce the power (it will still automatically switch to the 5th "LP" (low-power) shadow companion core when suitable).

To see the available CPU frequencies (measured in kHz, so "51000" refers to 51MHz):

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
    51000 102000 204000 312000 564000 696000 828000 960000 1092000 1122000 1224000 1326000 1428000 1530000 1632000 1734000 1836000 1938000 2014500 2116500 2218500 2320500

And the current CPU frequencies (note that you will see errors for the cores that are currently sleeping):

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
cat /sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq
cat /sys/devices/system/cpu/cpu2/cpufreq/scaling_cur_freq
cat /sys/devices/system/cpu/cpu3/cpufreq/scaling_cur_freq

Then you can set the min & max frequencies of each CPU core.

For example, to limit the speed of the 4 main CPU cores to just 564MHz, run this as root (as shown above):

echo 564000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
echo 564000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq
echo 564000 > /sys/devices/system/cpu/cpu2/cpufreq/scaling_max_freq
echo 564000 > /sys/devices/system/cpu/cpu3/cpufreq/scaling_max_freq

Note that it will only work for the cores that weren't sleeping at the time, so you might want to run a multi-threaded program in the background for it to fully work.

Turning some CPU cores on and some off

You can turn each CPU core online manually:

echo 1 > /sys/devices/system/cpu/cpu0/online
   bash: echo: write error: Invalid argument
echo 1 > /sys/devices/system/cpu/cpu1/online
echo 1 > /sys/devices/system/cpu/cpu2/online
echo 1 > /sys/devices/system/cpu/cpu3/online

(The 'invalid argument' error above can be ignored, this occurs when it is requested to change online/offline state to the current state.)

Restricting to low-power core only

Restricting the CPU to the low-power companion core can significantly reduce peak power (if running on a power-limited battery pack, for example). The 5th companion core in Tegra K1 is still a Cortex-A15 core with NEON and 32KB L1 cache and 512KB L2 private cache, but obviously at lower performance than the 4 main cores. To use just the low-power core, run this as root:

echo 0 > /sys/devices/system/cpu/cpuquiet/tegra_cpuquiet/enable
echo LP > /sys/kernel/cluster/active


Controlling GPU performance

To manually control the clock frequencies of the GPU, first determine the rates supported (listed by sysfs in kHz):

 cat /sys/kernel/debug/clock/gbus/possible_rates
 72000 108000 180000 252000 324000 396000 468000 540000 612000 648000 684000 708000 756000 804000 852000 (kHz)

Then set a rate (eg. the maximum of 852000kHz), specified in Hz:

 echo 852000000 > /sys/kernel/debug/clock/override.gbus/rate
 echo 1 > /sys/kernel/debug/clock/override.gbus/state

Finally verify the rate:

 cat /sys/kernel/debug/clock/gbus/rate
 852000

The gbus sysfs nodes control the GPU's core clock. To control the GPU's memory clock, substitute emc for gbus.