CN

Systrace Thread CPU State Analysis Tips - Runnable

Word count: 2.5kReading time: 15 min
2022/01/21
loading

This is the first article in the “Systrace Thread CPU State Analysis Tips” series. It analyzes the causes of the “Runnable” state in Systrace and provides optimization strategies for when Runnable segments are excessively long.

The goal of this series is to use Systrace to view the Android system from a different perspective and to learn the Framework through visualization. While reading Framework source code can be difficult to remember, seeing the flow in Systrace can lead to deeper understanding. You can find the complete Systrace Basics and Action Series here.

Technical review — 2026-10-14: Published in 2022, this article retains its historical Systrace screenshots. The analysis still applies, with corrected scheduling, affinity, and real-time-priority guidance, plus Linux 6.6 EEVDF, Android task profiles, and 32-bit compatibility limits. Prefer Perfetto for new recordings and check the target kernel and system configuration.

Table of Contents

  1. Systrace Thread CPU State Analysis Tips - Runnable
  2. Systrace Thread CPU State Analysis Tips - Running
  3. Systrace Thread CPU State Analysis Tips - Sleep and Uninterruptible Sleep

Runnable State Explanation

Visualizing Runnable in Trace

The Running article covers intervals when a thread executes on a CPU. Here, Runnable means that a thread is eligible to execute but is not currently running. Historical Systrace usually shows this in blue; use the state field rather than color alone. It is not equivalent to Java’s Thread.State.RUNNABLE, a VM state that does not map one-to-one to OS scheduling states. See the Java 17 definition.

Figure 1: Visualizing Runnable in Systrace

Figure 1 is a historical screenshot. The selection is labeled Runnable and shows wakeup from tid: 1515. That is a wakeup relationship, not proof that thread 1515 preempted the target or caused the delay. The complete trace is unavailable here, so the crop cannot quantify the entire wait.

Figure 2: CPU Optimization from Systems Performance Book

Figure 2 is a simplified model. One logical CPU runs one ordinary thread context at a time; a physical core with SMT can expose multiple logical CPUs. Linux has per-CPU run queues and class-specific structures, not one simple FIFO queue containing every task.

Runnable does not mean the thread already holds every I/O resource, lock, or semaphore. A woken thread may have to compete for a lock again and may soon sleep once more. Linux’s TASK_RUNNING covers both runnable and executing tasks, while the viewer distinguishes Running from Runnable.

Perfetto scheduler data, including sched_switch and sched_waking, helps identify execution, descheduling, and wakeups. R+ means runnable after preemption. Wakeup-to-running latency may include wakeup-path and migration costs, rather than just time in one queue. Trace boundaries and lost events can leave intervals incomplete.

Distinguish the scheduling policies:

  1. Fair scheduling: under SCHED_NORMAL (usually called SCHED_OTHER in userspace), nice values influence relative weight. The original article’s CFS means Completely Fair Scheduler; it uses virtual runtime, not simple fixed-quantum rotation. Upstream Linux began moving to EEVDF in 6.6. Check the actual device kernel and vendor changes rather than inferring the implementation from the Android version. See CFS and EEVDF.
  2. Real-time policies: SCHED_FIFO has no round-robin quantum; SCHED_RR rotates among equal-priority tasks. Eligible real-time work normally precedes fair-class work, subject to constraints such as bandwidth limits. Other work may run when the higher-priority task blocks, yields, or is throttled. Linux also has policies such as SCHED_DEADLINE; these two groups are not exhaustive. See Linux scheduling policies.

Figure 3: AOSP Rendering Architecture

Figure 3 is a historical schematic. RenderThread is a CPU thread, not the GPU. Its GPU work executes asynchronously, with BufferQueue, fences, and SurfaceFlinger/HWC composition also involved. 16.6 ms corresponds to roughly 60 Hz, not a universal frame budget or a requirement that all stages execute serially within one refresh period. See the AOSP graphics architecture.

Scheduling delay on a critical dependency can cause a missed deadline, but not every Runnable interval causes a dropped frame. Correlate it with the target frame. On Android 12 / API 31 or later, a recording with FrameTimeline data can help establish the actual frame outcome.

Causes of Long Runnable States and Optimization Strategies

The following seven categories are candidate causes, not diagnoses that follow from a blue interval alone. System policy, app workload, and hardware capacity may all contribute.

Start with a Runnable interval that affects a startup or frame deadline. Confirm the thread identity, preceding state, wakeup source, and next Running interval. Inspect CPU activity over the same window, then check the thread’s allowed CPUs, scheduling policy, priority, and cgroup constraints. Separate “woken but not executing” from “still waiting for a lock or I/O” before investigating the causes below.

Cause 1: Incorrect Priority Settings

Giving non-critical work excessive priority may delay critical work; giving a critical thread too little weight may also increase its wait under contention. Fair-class nice values and real-time priorities are different parameters. Do not compare their numbers directly or assume another running thread is an abnormal preemptor.

Optimization strategies:

  1. Inspect scheduling transitions and the actual policies to identify competitors and dependencies. Raising a waiter’s priority does not necessarily help a lower-priority dependency complete sooner.
  2. Arrange deadlines, concurrency, and thread roles first, then use appropriate priority APIs within their contracts and compare representative devices. FIFO/RT is not a general app fix: it needs suitable privileges and platform configuration and can starve other work.
  3. A platform real-time policy needs bounded work, dependency analysis, bandwidth planning, and checks for effects on other threads. Labeling a thread “critical” is not sufficient.

We’ve seen quite a few apps become more laggy after changing priorities. A setting may work on the developer’s phone and clash with another manufacturer’s scheduling policy. Do not raise priorities on intuition alone. Process.setThreadPriority is a public nice-adjustment API, subject to permissions and parameter limits; validate its effect on dependent work.

Keep deadline-sensitive work from sitting behind an unbounded background queue. This does not prohibit worker threads or justify moving expensive work onto the UI thread. For sustained workloads with a target duration, evaluate PerformanceHintManager, introduced in Android 12 / API 31, on supported devices. Reporting target and actual work durations provides a hint, not a guarantee of a particular core or deadline.

Cause 2: Improper CPU Affinity (Core Binding)

CPU affinity restricts the logical CPUs on which a thread may run; it does not guarantee faster execution. Restricting a thread to one busy core can increase waiting even while other cores are idle. A cluster-wide mask may still be too narrow. Ordinary apps should generally let the system schedule work before considering evidence-backed restrictions.

Checks:

  1. Identify the actual CPU topology. 4–7 is not a universal big-core range, and an eight-core device need not have four big and four little cores.
  2. Check affinity, cpuset, online CPUs, and instruction-set compatibility together. The effective set may be smaller than requested and can change with process state, policy, or hotplug.
  3. Standard Linux sched_setaffinity can silently narrow a partially overlapping mask to its permitted intersection. An empty permitted set can return EINVAL; insufficient privilege can return EPERM. Check the result and effective mask rather than describing failure as an inevitable crash. See the API definition.
  4. Also check cgroup CPU quotas. Exhausted bandwidth can throttle runnable work even when another CPU is idle. See CPU bandwidth control.

Cause 3: Poor Software Architecture Design

A critical operation with repeated thread handoffs can incur wakeup-to-running latency more than once. If A hands work to B and waits for completion, A is normally sleeping or blocked during that wait. The Runnable interval begins after it is woken; the entire dependency wait is not Runnable time.

Don’t design as though your app has the whole phone to itself. Other processes need those resources too. Thread count alone is not the diagnosis. Useful parallelism can shorten completion time. Investigate unnecessary serial handoffs, unbounded queues, and excessive concurrency.

Optimization strategies:

  1. Build the dependency chain from scheduling, Binder, futex, or application markers. A wakeup is a clue, not complete business-level causality. CPU stack sampling alone cannot reconstruct every wait.
  2. Remove unnecessary handoffs, shorten critical dependencies, and bound concurrency and queues. Do not replace background cooperation with a synchronous main-thread wait.
  3. Validate platform scheduling changes against real dependencies and multiple workloads rather than simply boosting a whole thread group.

Cause 4: High Application or System Load

Many runnable tasks competing for allowed CPUs can increase scheduling latency. Fair scheduling is not strict first-in-first-out service, so queue position alone does not explain a long wait.

Dense CPU tracks can reflect frequent switches or the selected zoom level. They do not prove system-wide utilization above 90%. Measure non-idle execution over a defined window, per CPU, and explain the denominator using the relevant CPUs and online time. Interrupt accounting also needs care. Average utilization, run-queue pressure, and one thread’s latency are different quantities; a low average can hide short bursts of contention.

1. High App-Specific Load

Concurrent CPU-intensive work can delay rendering or startup tasks. Many threads do not necessarily imply high CPU use: many may be sleeping.

Optimization suggestions:

  1. Identify the app’s high-CPU threads within the same problem window and look for redundant computation, obsolete work, or uncontrolled concurrency.
  2. Use a sampling tool such as simpleperf to locate execution hotspots, and scheduling data to distinguish computation from waiting. Sample weight is not invocation count.
  3. Bound concurrency, cancel obsolete work, and defer work outside the critical window. Do not mask excess load with FIFO/RT.
  4. Separate critical and non-critical work without mechanically binding every background task to little cores. A background worker may be producing the result the UI needs; follow the dependency chain when evaluating the outcome.

2. High System Service Load

System services or other apps may consume the CPUs available to the target. Measure the actual running threads in the same window, then inspect call paths, process identity, and workload before calling the activity abnormal. Background execution alone does not prove abusive keep-alive behavior; music, navigation, and calls can require legitimate ongoing work.

3. Manufacturer “Magic” Technologies

Platforms can coordinate foreground and background resources, but distinguish the mechanism from a product’s configuration. A limitation observed on one ROM is not automatically an AOSP-wide defect.

  1. cpuset restricts eligible CPUs; it is neither a fixed priority nor a guarantee of exclusive hardware. Children generally inherit cgroup membership and may subsequently be reassigned by framework or service policy. Java-forked children are not inherently unmanaged.
  2. CPU controllers can provide weights and quotas, depending on kernel and configuration. Weight is not a hard cap, and cpuset is not a CPU-time quota. Tight quotas can themselves increase Runnable latency.
  3. Task profiles: Android 10 introduced the cgroup abstraction layer; Android 11 provides SetTaskProfiles / SetProcessProfiles. In Android 12, init’s task_profiles replaces deprecated writepid migration. Platform code must follow the actual cgroups.json, task_profiles.json, and vendor overrides. These are not ordinary application APIs. See the AOSP cgroup documentation.
  4. Cached-app freezing: Android 11 / API 30 and later supports a freezer for eligible cached processes, with kernel cgroup v2 and system configuration requirements. This is not an instruction to freeze every app immediately upon backgrounding or stop ongoing music/navigation. Binder interactions, thawing, and process relationships require system coordination. See the AOSP freezer documentation.
  5. On-demand work: reduce unnecessary system tasks and background starts while preserving services the user is using. Validate across devices, thermal conditions, and foreground/background transitions.

Cause 5: CPU Capacity Limits, Throttling, and State Anomalies

To use an example familiar in 2022: queues for COVID tests grew when there were fewer testing stations or each station worked more slowly. The same workload can take longer at lower effective CPU capacity, leaving other tasks waiting. Investigate these separately:

  1. Whether thermal, power-saving, or scenario policy changed frequency limits, available cores, or task placement. Identically named vendor modes need not use the same mechanism.
  2. Whether frequency, online CPUs, load, and thermal state correlate in the problem window. Low frequency alone does not prove thermal throttling or directly quantify lost capacity.
  3. Whether CPU-idle wakeup latency matters. C0/C1/C2 are illustrative names, not a universal state table for ARM SoCs; consult the target’s idle states and exit latency. See Linux CPU idle documentation.
  4. Whether a lower-performance device needs reduced work or a different experience. Price, core count, and brand do not establish capacity by themselves.

For apps, our advice is still: do less work and give the platform less trouble. Reduce unnecessary work and adapt load to thermal conditions; platforms must validate the power/latency tradeoff. Hardware failure needs independent diagnostic evidence and cannot be inferred from a long Runnable interval. See the Running article for execution-time analysis.

Cause 6: Scheduler Anomalies

Scheduler or vendor-policy bugs are possible, but an idle CPU beside a waiting task is not sufficient evidence. First rule out affinity, cpuset, instruction-set compatibility, quota throttling, and offline cores; then consider migration costs, energy policy, interrupts, and non-preemptible regions.

Frequency governors, idle governors, and task scheduling are different mechanisms. Record the kernel version, policy configuration, event completeness, and reproducible workload, then compare expected and observed placement before changing the scheduler.

Cause 7: 32-bit vs. 64-bit Process Handling

The original Snapdragon 8 Gen 1 and Dimensity 9000 examples belong to the 2021–2022 transition period, not recent releases. The mechanism of interest is asymmetric AArch32 support: on some systems only a subset of cores can execute 32-bit userspace code. That can concentrate 32-bit tasks on a smaller set, not necessarily one core.

The Linux asymmetric 32-bit documentation describes affinity restrictions when this compatibility mode is enabled and the supported aarch32_el0 CPU set. Check the actual phone’s kernel, system ABIs, and permitted mask. A 64-bit task is still subject to cpuset, affinity, quotas, and thermal policy; it does not run without restrictions.

  1. Follow the Android 64-bit guide to check the app and third-party native libraries, supply compatible 64-bit versions, and validate installation, loading, and functionality. Changing an ABI setting does not convert a missing 32-bit library to 64-bit, and migration does not guarantee every workload gets faster.
  2. Platforms should manage the actual compatibility set and work with app developers on migration. A 64-bit-only system may not run an old 32-bit native app at all; that differs from an app which runs but faces more contention.

About Me && Blog

Below is my personal intro and related links. I look forward to exchanging ideas with fellow professionals. “When three walk together, one can always be my teacher!”

  1. Blogger Intro
  2. Blog Content Navigation: A guide for my blog content.
  3. Curated Excellent Blog Articles - Android Performance Optimization Must-Knows
  4. Android Performance Optimization Knowledge Planet: The paid community stopped operating in 2026 and no longer accepts new members; this link preserves its history.

One walks faster alone, but a group walks further together.

Scan WeChat QR Code

CATALOG
  1. 1. Table of Contents
  • Runnable State Explanation
    1. 1. Visualizing Runnable in Trace
  • Causes of Long Runnable States and Optimization Strategies
    1. 1. Cause 1: Incorrect Priority Settings
    2. 2. Cause 2: Improper CPU Affinity (Core Binding)
    3. 3. Cause 3: Poor Software Architecture Design
    4. 4. Cause 4: High Application or System Load
      1. 4.1. 1. High App-Specific Load
      2. 4.2. 2. High System Service Load
      3. 4.3. 3. Manufacturer “Magic” Technologies
    5. 5. Cause 5: CPU Capacity Limits, Throttling, and State Anomalies
    6. 6. Cause 6: Scheduler Anomalies
    7. 7. Cause 7: 32-bit vs. 64-bit Process Handling
  • About Me && Blog