Home | History | Annotate | Download | only in debug
      1 <html devsite>
      2   <head>
      3     <title>Identifying Capacity-Related Jank</title>
      4     <meta name="project_path" value="/_project.yaml" />
      5     <meta name="book_path" value="/_book.yaml" />
      6   </head>
      7   <body>
      8   <!--
      9       Copyright 2017 The Android Open Source Project
     10 
     11       Licensed under the Apache License, Version 2.0 (the "License");
     12       you may not use this file except in compliance with the License.
     13       You may obtain a copy of the License at
     14 
     15           http://www.apache.org/licenses/LICENSE-2.0
     16 
     17       Unless required by applicable law or agreed to in writing, software
     18       distributed under the License is distributed on an "AS IS" BASIS,
     19       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     20       See the License for the specific language governing permissions and
     21       limitations under the License.
     22   -->
     23 
     24 
     25 <p>Capacity is the total amount of some resource (CPU, GPU, etc.) a device
     26 possesses over some amount of time. This page describes how to identify and
     27 address capacity-related jank issues.</p>
     28 
     29 <h2 id="governor">Governor slow to react</h2>
     30 <p>To avoid jank, the CPU frequency governor needs to be able to respond quickly
     31 to bursty workloads. Most UI applications follow the same basic pattern:</p>
     32 <ol>
     33 <li>User is reading the screen.</li>
     34 <li>User touches the screen: taps a button, scrolls, etc.</li>
     35 <li>Screen scrolls, changes activity, or animates in some way in response to
     36 input.</li>
     37 <li>System quiesces as new content is displayed.</li>
     38 <li>User goes back to reading the screen.</li>
     39 </ol>
     40 
     41 <p>Pixel and Nexus devices implement touch boost to modify CPU frequency
     42 governor (and scheduler) behavior on touch. To avoid a slow ramp to a high clock
     43 frequency (which could cause the device to drop frames on touch), touch boost
     44 usually sets a frequency floor on the CPU to ensure plenty of CPU capacity is
     45 available on touch. A floor lasts for some amount of time after touch (usually
     46 around two seconds).</p>
     47 
     48 <p>Pixel also uses the schedtune cgroup provided by Energy Aware Scheduling
     49 (EAS) as an additional touch boost signal: Top applications get additional
     50 weight via schedtune to ensure they get enough CPU capacity to run quickly. The
     51 Nexus 5X and 6P have a much bigger performance gap between the little and big
     52 CPU clusters (A53 and A57, respectively) than the Pixel with the Kryo CPU. We
     53 found that the little CPU cluster was not always adequate for smooth UI
     54 rendering, especially given other sources of jitter on the device.</p>
     55 
     56 <p>Accordingly, on the Nexus 5X and 6P, touch boost modifies the scheduler
     57 behavior to make it more likely for foreground applications to move to the big
     58 cores (this is conceptually similar to the floor on CPU frequency). Without the
     59 scheduler change to make foreground applications more likely to move to the big
     60 CPU cluster, foreground applications may have insufficient CPU capacity to
     61 render until the scheduler decided to load balance the thread to a big CPU core.
     62 By changing the scheduler behavior during touch boost, it is more likely for a
     63 UI thread to immediately run on a big core and avoid jank while not forcing it
     64 to always run on a big core, which could have severe impacts on power
     65 consumption.</p>
     66 
     67 <h2 id="thermal-throttling">Thermal throttling</h2>
     68 <p>Thermal throttling occurs when the device must reduce its overall thermal
     69 output, usually performed by reducing CPU, GPU, and DRAM clocks. Unsurprisingly,
     70 this often results in jank as the system may no longer be able to provide enough
     71 capacity to render within a given timeslice. The only way to avoid thermal
     72 throttling is to use less power. There are not a lot of ways to do this, but
     73 based on our experiences with past SOCs, we have a few recommendations for
     74 system vendors.</p>
     75 
     76 <p>First, when building a new SOC with heterogeneous CPU architectures, ensure
     77 the performance/W curves of the CPU clusters overlap. The overall performance/W
     78 curve for the entire processor should be a continuous line. Discontinuities in
     79 the perf/W curve force the scheduler and frequency governor to guess what a
     80 workload needs; to prevent jank, the scheduler and frequency governor err on
     81 the side of giving the workload more capacity than it requires. This results in
     82 spending too much power, which contributes to thermal throttling.</p>
     83 
     84 <p>Imagine a hypothetical SOC with two CPU clusters:</p>
     85 <ul>
     86 <li>Cluster 1, the little cluster, can spend between 100-300mW and scores
     87 100-300 in a throughput benchmark depending on clocks.</li>
     88 <li>Cluster 2, the big cluster, can spend between 1000 and 1600mW and scores
     89 between 800 and 1200 in the same throughput benchmark depending on clocks.</li>
     90 </ul>
     91 <p>In this benchmark, a higher score is faster. While not more desirable than
     92 slower, faster == greater power consumption.</p>
     93 
     94 <p>If the scheduler believes a UI workload would require the equivalent of a
     95 score of 310 on that throughput benchmark, its best option to avoid jank is to
     96 run the big cluster at the lowest frequency, wasting significant power. (This
     97 depends on cpuidle behavior and race to idle; SOCs with continuous perf/W curves
     98 are easier to optimize for.)</p>
     99 
    100 <p>Second, use cpusets. Ensure you have enabled cpusets in your kernel and in
    101 your <code>BoardConfig.mk</code>. You must also set up the actual cpuset
    102 assignments in your device-specific <code>init.rc</code>. Some vendors leave
    103 this disabled in their BSPs in the hopes they can use other hints to influence
    104 scheduler behavior; we feel this doesn't make sense. cpusets are useful for
    105 ensuring load balancing between CPUs is done in a way that reflects what the
    106 user is actually doing on the device.</p>
    107 
    108 <p>ActivityManager assigns apps to different cpusets based on the relative
    109 importance of those apps (top, foreground, background), with more important
    110 applications getting more access to CPU cores. This helps ensure quality of
    111 service for foreground and top apps.</p>
    112 
    113 <p>cpusets are useful on homogeneous CPU configurations, but you should not ship
    114 a device with a heterogeneous CPU configuration without cpusets enabled. Nexus
    115 6P is a good model for how to use cpusets on heterogeneous CPU configurations;
    116 use that as a basis for your own device's configuration.</p>
    117 
    118 <p>cpusets also offer power advantages by ensuring background threads that are
    119 not performance-critical never get load balanced to big CPU cores, where they
    120 could spend significantly more power without any user-perceived benefit. This
    121 can help to avoid thermal throttling as well. While thermal throttling is a
    122 capacity issue, jitter improvements have an outsize impact on UI performance
    123 when thermal throttling. Because the system will be running closer to its
    124 ability to render 60FPS, it takes less jitter to cause a dropped frame.</p>
    125 
    126 </body>
    127 </html>
    128