Skip to content

Add Auto CPU Scaling Option #44

@nchapman

Description

@nchapman

Feature Request: Auto CPU Scaling

Overview

Add a 4th CPU speed option "Auto" that dynamically scales between existing power levels based on CPU load.

Implementation Strategy

Use existing CPU speed levels (no platform-specific frequency tables needed):

  • CPU_SPEED_POWERSAVE - Base level when idle
  • CPU_SPEED_NORMAL - Standard gaming performance
  • CPU_SPEED_PERFORMANCE - Emergency boost when needed

Simple 3-tier auto-scaling algorithm:

if (cpu_usage > 90%) {
    PWR_setCPUSpeed(CPU_SPEED_PERFORMANCE);  // Max boost
}
else if (cpu_usage > 70%) {
    PWR_setCPUSpeed(CPU_SPEED_NORMAL);       // Standard
}
else {
    PWR_setCPUSpeed(CPU_SPEED_POWERSAVE);    // Low power
}

Platform Opt-In Architecture

Platforms can opt into auto-scaling by implementing:

// In platform.h
#define PLAT_SUPPORTS_AUTO_CPU 1

// In platform.c  
void* PLAT_cpu_monitor(void *arg) {
    // Platform-specific monitoring implementation
}

Platforms without PLAT_SUPPORTS_AUTO_CPU will simply not show the "Auto" option in the menu.

Benefits

  1. Cross-platform compatible - Uses existing CPU_SPEED_* constants
  2. Opt-in - Platforms without support work unchanged
  3. Simple - 3-tier scaling vs NextUI's 33-step approach
  4. Battery friendly - Stays at low power when possible, boosts only when needed
  5. Cool running - Reduces heat during lighter gameplay

Implementation Tasks

  • Add volatile int useAutoCpu global flag
  • Create reference PLAT_cpu_monitor() implementation for tg5040/miyoomini
  • Add CPU usage measurement helpers (CLOCK_PROCESS_CPUTIME_ID)
  • Add "Auto" option to minarch CPU Speed menu (when platform supports it)
  • Add #ifdef PLAT_SUPPORTS_AUTO_CPU guards
  • Test on platforms with auto-scaling support
  • Document platform opt-in requirements

Reference Implementation

NextUI's auto-scaling:

  • workspace/tg5040/platform/platform.c:2234-2345
  • Background pthread monitoring every 20ms
  • Uses POSIX clock_gettime(CLOCK_PROCESS_CPUTIME_ID) for accurate CPU time
  • Mutex-protected shared state

Questions to Answer

  • What threshold percentages work best across platforms? (70%/90% proposed)
  • Should we expose thresholds as config options?
  • What monitoring interval is optimal? (20ms? 50ms? 100ms?)

Related to NextUI investigation in #[TBD]

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions