Skip to content

streamer: disable WiFi power-save on wlan0 - #1

Merged
kelchm merged 1 commit into
mainfrom
streamer-wifi-powersave-off
Aug 12, 2026
Merged

kelchm merged 1 commit into
mainfrom
streamer-wifi-powersave-off

Conversation

@kelchm

@kelchm kelchm commented Jul 19, 2026

Copy link
Copy Markdown
Owner

What

Disable WiFi power-save on the workbench streamer's wlan0 via a systemd oneshot bound to the interface appearing.

Why

Random AirPlay dropouts were root-caused (caught live with pw-top + shairport journal) to downlink-delivery stalls, not the DAC:

  • Primary cause: 2.4 GHz microwave interference on channel 6. The AP↔Pi link rate collapsed to 1.0 Mbit/s, RTP timing pings stalled up to ~1.5 s, and shairport's ~0.35 s playout buffer starved → xrun bursts on the source node (the DAC output node had 0 xruns throughout).
  • Primary fix (infra, already applied): retuned the AP 2.4 GHz radio to channel 1 (−57 dBm/1.0 Mbit → −41 dBm/72.2 Mbit).
  • This PR: WiFi power-save is a secondary RX-latency source (DTIM buffering) — nil benefit on a mains-powered receiver — so pin it off.

Notes

  • brcmfmac re-enables power-save on every boot/driver reload, hence the interface-bound oneshot rather than a one-time toggle.
  • Deliberately did not switch the USB controller to dwc2: the DAC runs on FIQ-accelerated dwc_otg (split-transaction FSM / microframe scheduler / NAK holdoff), which is the right path for full-speed isochronous USB audio (0 DAC xruns in 3 weeks).

🤖 Generated with Claude Code

Random AirPlay dropouts were root-caused to downlink-delivery stalls,
not the DAC: 2.4 GHz microwave interference on channel 6 collapsed the
RX rate and starved shairport's ~0.35 s playout buffer. The primary fix
was retuning the AP to channel 1; WiFi power-save is a secondary
RX-latency source (DTIM buffering) worth removing on a mains-powered
receiver.

brcmfmac re-enables power-save on every boot/driver reload, so pin it
off with a systemd oneshot bound to the wlan0 device appearing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HG3QGvyhN8nWR6h7XjDNuq
Copilot AI review requested due to automatic review settings July 19, 2026 23:38
@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Wi-Fi power saving is now automatically disabled whenever the wireless interface comes online, helping maintain a more reliable connection after reboot or driver reload.

Walkthrough

The streamer role adds a systemd oneshot service that runs when wlan0 appears and disables WiFi power saving with iw.

Changes

WiFi power-save control

Layer / File(s) Summary
wlan0 power-save service
modules/roles/streamer.nix
Adds a persistent oneshot unit ordered after wlan0 device availability and executes iw dev wlan0 set power_save off.

Estimated code review effort: 2 (Simple) | ~5 minutes

Suggested reviewers: copilot

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: disabling WiFi power-save on wlan0.
Description check ✅ Passed The description is clearly related to the change and explains both the what and why.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@modules/roles/streamer.nix`:
- Around line 105-111: Update the systemd.services.wifi-powersave-off definition
to add bindsTo for the sys-subsystem-net-devices-wlan0.device unit while
retaining the existing after dependency, so device disappearance and
reappearance reruns the oneshot.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6e5c2833-5197-484b-92f5-fc65aea116b7

📥 Commits

Reviewing files that changed from the base of the PR and between cd1f5d2 and 6fe2a45.

📒 Files selected for processing (1)
  • modules/roles/streamer.nix

Comment on lines +105 to +111
systemd.services.wifi-powersave-off = {
wantedBy = [ "sys-subsystem-net-devices-wlan0.device" ];
after = [ "sys-subsystem-net-devices-wlan0.device" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecStart = "${pkgs.iw}/bin/iw dev wlan0 set power_save off";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

systemctl show wifi-powersave-off.service \
  -p BindsTo -p After -p RemainAfterExit -p ExecStart

Repository: kelchm/rpi-nixos

Length of output: 201


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

# Locate the service definition and related references.
git ls-files | rg 'modules/roles/streamer\.nix|wifi-powersave-off|wlan0'

# Show the relevant section with line numbers.
sed -n '85,130p' modules/roles/streamer.nix

# Search for other device-bound systemd services in the repo for pattern comparison.
rg -n "bindsTo|BindsTo|sys-subsystem-net-devices-wlan0\.device|RemainAfterExit|wifi-powersave-off" .

Repository: kelchm/rpi-nixos

Length of output: 1974


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

# Determine whether this repo contains any NixOS module/tests/docs that spell out
# how `systemd.services.<name>.bindsTo` is translated or used.
rg -n "bindsTo|BindsTo|systemd\.services\..*bindsTo" modules nixos . || true

Repository: kelchm/rpi-nixos

Length of output: 200


Bind wifi-powersave-off to wlan0 so reloads rerun iw.

wantedBy and after only handle the first activation. With RemainAfterExit = true, the oneshot stays active after iw exits, so a wlan0 disappear/reappear cycle during a driver reload will not start it again. Add bindsTo on the device unit and keep after:

Proposed fix
     wantedBy = [ "sys-subsystem-net-devices-wlan0.device" ];
     after = [ "sys-subsystem-net-devices-wlan0.device" ];
+    bindsTo = [ "sys-subsystem-net-devices-wlan0.device" ];
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
systemd.services.wifi-powersave-off = {
wantedBy = [ "sys-subsystem-net-devices-wlan0.device" ];
after = [ "sys-subsystem-net-devices-wlan0.device" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecStart = "${pkgs.iw}/bin/iw dev wlan0 set power_save off";
systemd.services.wifi-powersave-off = {
wantedBy = [ "sys-subsystem-net-devices-wlan0.device" ];
after = [ "sys-subsystem-net-devices-wlan0.device" ];
bindsTo = [ "sys-subsystem-net-devices-wlan0.device" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecStart = "${pkgs.iw}/bin/iw dev wlan0 set power_save off";
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@modules/roles/streamer.nix` around lines 105 - 111, Update the
systemd.services.wifi-powersave-off definition to add bindsTo for the
sys-subsystem-net-devices-wlan0.device unit while retaining the existing after
dependency, so device disappearance and reappearance reruns the oneshot.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Disables WiFi power-save on the streamer’s wlan0 using a systemd oneshot unit triggered by the wlan0 device appearing, with the goal of reducing RX-latency spikes that can contribute to AirPlay dropouts.

Changes:

  • Added a wifi-powersave-off systemd oneshot that runs iw … set power_save off when wlan0 appears.
  • Documented the operational motivation and root-cause notes inline in the NixOS role.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +105 to +112
systemd.services.wifi-powersave-off = {
wantedBy = [ "sys-subsystem-net-devices-wlan0.device" ];
after = [ "sys-subsystem-net-devices-wlan0.device" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecStart = "${pkgs.iw}/bin/iw dev wlan0 set power_save off";
};
@kelchm
kelchm merged commit 54eff8b into main Aug 12, 2026
1 check 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