Skip to content

functions: use iw for Wi-Fi power saving - #868

Merged
yarda merged 1 commit into
redhat-performance:masterfrom
Junjie650:fix-wifi-power-save
Aug 7, 2026
Merged

yarda merged 1 commit into
redhat-performance:masterfrom
Junjie650:fix-wifi-power-save

Conversation

@Junjie650

@Junjie650 Junjie650 commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

The powersave profiles currently use iwpriv, which Fedora no longer
installs. Consequently, applying those profiles does not enable Wi-Fi
power saving.

Use the nl80211-based iw dev IFACE set power_save on|off command for
modern drivers. If iw is unavailable or rejects an interface, retain
the existing iwpriv path for legacy Wireless Extensions drivers. The
existing sysfs fallback is unchanged.

This also adds iw to the RPM requirements and covers the following
cases with unit tests:

  • enabling and disabling power saving;
  • multiple wireless interfaces;
  • missing iw;
  • per-interface iw failure and iwpriv fallback;
  • missing tools;
  • systems with no wireless interfaces.

Validation:

  • all 116 unit tests pass;
  • the modified shell helper passes ShellCheck;
  • the new test passes the project's error-only pylint check;
  • tuned.spec expands successfully with Fedora 45 RPM macros;
  • a local nl80211 interface reports its power-save state through the
    same iw command family.

Fixes #836

Resolves: rhbz#2372365

@coderabbitai

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Improved Wi‑Fi power-save configuration across supported wireless interfaces.
    • Added compatibility with modern iw tools and fallback support for legacy drivers.
    • Gracefully handles missing wireless interfaces or configuration tools without failing.
    • Correctly applies enabled and disabled power-save states, including legacy settings.
  • Tests

    • Added coverage for Wi‑Fi power-save behavior, fallback handling, interface compatibility, and unavailable environments.

Walkthrough

_wifi_set_power_level now prefers iw, falls back to iwpriv, handles missing wireless support, and writes quoted sysfs values. The package requires iw. Unit tests cover enable, disable, fallback, and absent-resource cases.

Changes

Wi-Fi power-save configuration

Layer / File(s) Summary
Power-save command selection and packaging
functions, tuned.spec
The function maps levels 0 and 6 to off, uses iw when available, falls back to iwpriv, and updates sysfs with quoted values. The package adds iw as a runtime requirement.
Power-save behavior validation
tests/unit/test_functions.py
Tests validate command selection for all interfaces, fallback after unavailable or failed iw, missing tools, missing interfaces, and the test entry point.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant _wifi_set_power_level
  participant iw
  participant iwpriv
  participant sysfs
  _wifi_set_power_level->>iw: Set power_save for each interface
  iw-->>_wifi_set_power_level: Unavailable or command failure
  _wifi_set_power_level->>iwpriv: Apply legacy configuration
  _wifi_set_power_level->>sysfs: Write quoted power_level value
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The description clearly explains the Wi-Fi power-saving change, fallback behavior, dependency update, tests, and validation.
Linked Issues check ✅ Passed The description links issue #836 and rhbz#2372365, and the changes directly address the reported Wi-Fi power-saving problem.
Out of Scope Changes check ✅ Passed The implementation, tests, and RPM dependency update directly support the stated Wi-Fi power-saving objective.
Title check ✅ Passed The title clearly and concisely identifies the main change: using iw for Wi-Fi power saving.

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 `@functions`:
- Around line 312-317: Update the power_save assignment near the iw interface
loop so level 6 produces off, matching its definition in the surrounding
configuration instead of enabling power saving. Preserve existing mappings for
other levels and add coverage invoking _run(6) to verify the resulting
power-save setting is off.
🪄 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 Plus

Run ID: 34c8c78c-7214-40f6-9b6b-e0bffe4a5be0

📥 Commits

Reviewing files that changed from the base of the PR and between 0eb28ac and 44c05df.

📒 Files selected for processing (3)
  • functions
  • tests/unit/test_functions.py
  • tuned.spec

Comment thread functions Outdated
@Junjie650
Junjie650 force-pushed the fix-wifi-power-save branch from 44c05df to 57530ba Compare August 1, 2026 11:58
The powersave profiles still use the Wireless Extensions iwpriv tool,
which Fedora no longer installs. As a result, enabling these profiles
leaves Wi-Fi power saving unchanged.

Prefer the nl80211-based iw command and translate the profile actions to
explicit on and off states. Fall back to iwpriv per interface for legacy
drivers, and retain the existing sysfs fallback. Require iw in the RPM
spec and cover the modern and legacy paths with unit tests.

Fixes redhat-performance#836

Resolves: rhbz#2372365

Signed-off-by: Junjie Cao 
@Junjie650
Junjie650 force-pushed the fix-wifi-power-save branch from 57530ba to f5e0632 Compare August 3, 2026 02:49
@yarda

yarda commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Thanks, LGTM.

@yarda
yarda merged commit e6f41b6 into redhat-performance:master Aug 7, 2026
14 of 16 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.

iwpriv is used by tuned but not shipped by default

2 participants