Skip to content

perf(network): poll Wi-Fi status only while it can be seen - #244

Merged
dianjixz merged 1 commit into
CardputerZero:masterfrom
guohui85:fix/wifi-status-poll-when-hidden
Nov 13, 2026
Merged

dianjixz merged 1 commit into
CardputerZero:masterfrom
guohui85:fix/wifi-status-poll-when-hidden

Conversation

@guohui85

@guohui85 guohui85 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The Wi-Fi status worker in cp0_lvgl_network.cpp starts two nmcli processes every 3 s for the launcher's whole lifetime. It does this even when nobody can see the status: when the screen is locked, or when another app owns the display. With this PR it refreshes every 3 s only while the status is visible, and every 60 s otherwise.

Change

  • poll_loop() still wakes every 3 s. It now calls update_status_cache() only when one of these holds:
    • this is the first poll;
    • the launcher owns the screen (LVGL_RUN_FLAGE == 1) and /sys/class/backlight/backlight/brightness is above 0;
    • 60 s have passed since the last refresh.
  • Since the worker still wakes every 3 s, the status catches up within 3 s after the screen comes back.
  • test_wifi_connection.cpp defines LVGL_RUN_FLAGE, as the keyboard tests do, because the network source now reads it.

Measurements

One polling round (dev status plus dev wifi list --rescan no) costs about 0.18 s of CPU on the device (user + sys, averaged over 5 rounds). NetworkManager and dbus-daemon also do work for every call.

These were taken on a CardputerZero (0.6.105 plus the system-sound idle fix from the companion PR). Conditions: screen locked, on battery, 60 s of 2 s samples.

mean current median context switches
before 212 mA 203 mA 818 /s
after 204 mA 202 mA 516 /s

No nmcli process showed up in 30 one-second samples while locked. The saving in current is small. Most of the effect is fewer CPU bursts and less work in NetworkManager and the system bus.

Testing

  • sh ext_components/cp0_lvgl/tests/run_tests.sh passes.
  • On the device:
    • the Wi-Fi icon updates within a few seconds after waking;
    • Settings → Wi-Fi still lists networks and connects.

Note

I prepared this with AI assistance (Claude) and tested it on my own device. The backlight path is the same one cp0_lvgl_settings.cpp uses. If you would rather not read sysfs here, the poll could instead be driven by a "status visible" flag set from the UI side.

- The status worker started two nmcli processes every 3 s for the
  launcher's lifetime, also while the screen was locked or another app
  owned the display. Each round costs ~0.2 s of CPU on the device, plus
  work in NetworkManager and the system bus.
- It now refreshes every 3 s only while the launcher is in the foreground
  (LVGL_RUN_FLAGE == 1) and the backlight is on, and every 60 s
  otherwise. The worker still wakes every 3 s, so the status catches up
  within one interval after the screen comes back.
- test_wifi_connection defines LVGL_RUN_FLAGE, as the keyboard tests do.
- Measured on a CardputerZero (screen locked, on battery, on top of the
  system-sound idle fix): 212 -> 204 mA mean (median 203 -> 202 mA),
  context switches 818/s -> 516/s, no nmcli process seen in 30 one-second
  samples while locked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0135vUaG2FpgpGRJfB9LEPvZ
@dianjixz
dianjixz merged commit ce8c46b into CardputerZero:master Nov 13, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants