Skip to content

plugins/profiles: add sched-ext (scx) tuned plugin and profile snippets#1

Closed
ptr1337 wants to merge 4 commits intocachyosfrom
sched-ext
Closed

plugins/profiles: add sched-ext (scx) tuned plugin and profile snippets#1
ptr1337 wants to merge 4 commits intocachyosfrom
sched-ext

Conversation

@ptr1337
Copy link
Member

@ptr1337 ptr1337 commented Feb 26, 2026

Add plugin_scx.py — a new tuned plug-in that manages sched-ext schedulers
via the scx_loader D-Bus service (org.scx.Loader).The plug-in exposes
two configuration options:

scheduler— name of the scx scheduler to activate (e.g. scx_bpfland, scx_lavd), or "none" to stop any running scheduler.
mode — operating mode: auto, gaming, lowlatency, powersave, server.

Scheduler state is saved and restored across profile switches using the
standard tuned command_get/command_set framework.When scx_loader is not
present the plug-in logs an informational message and does nothing.

Signed-off-by: Peter Jung admin@ptr1337.dev

Add plugin_scx.py — a new tuned plug-in that manages sched-ext schedulers
via the scx_loader D-Bus service (org.scx.Loader).The plug-in exposes
two configuration options:

  scheduler— name of the scx scheduler to activate (e.g. scx_bpfland, scx_lavd), or "none" to stop any running scheduler.
  mode — operating mode: auto, gaming, lowlatency, powersave, server.

Scheduler state is saved and restored across profile switches using the
standard tuned command_get/command_set framework.When scx_loader is not
present the plug-in logs an informational message and does nothing.

Signed-off-by: Peter Jung <admin@ptr1337.dev>
Signed-off-by: Peter Jung <admin@ptr1337.dev>
@ptr1337 ptr1337 self-assigned this Feb 26, 2026
@ptr1337 ptr1337 added the enhancement New feature or request label Feb 26, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new TuneD plugin to control sched-ext (scx) schedulers through the scx_loader D-Bus service, plus commented profile snippets showing how to enable it in CachyOS profiles.

Changes:

  • Introduce tuned/plugins/plugin_scx.py implementing [scx] options (scheduler, mode) via org.scx.Loader.
  • Persist/restore scheduler state across profile switches using TuneD’s command_get/command_set storage mechanism.
  • Add commented [scx] configuration examples to CachyOS desktop/gaming/laptop/powersave profiles.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tuned/plugins/plugin_scx.py New plugin for selecting/stopping scx schedulers and managing scheduler mode via D-Bus.
profiles/cachyos-powersave/tuned.conf Add commented [scx] example snippet for powersave mode.
profiles/cachyos-laptop/tuned.conf Add commented [scx] example snippet for powersave mode.
profiles/cachyos-gaming/tuned.conf Add commented [scx] example snippet for gaming mode.
profiles/cachyos-desktop/tuned.conf Add commented [scx] example snippet for desktop/auto mode.

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

Comment on lines +183 to +196
@command_set("mode")
def _set_mode(self, value, instance, sim, remove):
# Mode is applied together with the scheduler in _set_scheduler.
# This handler only validates the value.
if value is None:
return None
value = str(value).strip().lower()
if value not in MODE_MAP:
if not sim:
log.warning("scx: invalid mode '%s', expected one of: %s"
% (value, ", ".join(sorted(MODE_MAP.keys()))))
return None
return value

Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

mode is registered as an independent @command_set/@command_get option, but _set_mode explicitly does not apply any tuning. This means profiles that set mode (with or without scheduler) will have the framework save/verify/restore a value that the plugin never enforces, leading to confusing behavior and potential verification failures. Either make mode a non-command auxiliary option (validated/used by _set_scheduler only) or implement mode changes by applying them through scx_loader (e.g., switching the currently running scheduler with the requested mode).

Copilot uses AI. Check for mistakes.
mode_opt = instance.options.get("mode", "auto")
if mode_opt is None:
mode_opt = "auto"
mode_str = str(mode_opt).strip().lower()
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

_set_scheduler reads instance.options.get("mode") directly, so any TuneD variable expansion applied elsewhere (the base class expands per-option values) will not be applied to mode here. Other plugins expand dependent options explicitly (e.g., plugin_irq expands mode in _instance_init). Consider using self._variables.expand(...) when reading the mode option to keep behavior consistent.

Suggested change
mode_str = str(mode_opt).strip().lower()
mode_opt = self._variables.expand(str(mode_opt))
mode_str = mode_opt.strip().lower()

Copilot uses AI. Check for mistakes.
Comment on lines +171 to +176
@command_get("scheduler")
def _get_scheduler(self, instance):
proxy, _ = _get_dbus_proxy()
if proxy is None:
return None
current = _get_property(proxy, "CurrentScheduler")
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

On systems without scx_loader, _get_scheduler/_get_mode return None, which causes tuned-adm verify (ignore_missing=false) to fail for profiles that set [scx] options, even though the plugin is intended to be a no-op when the service is absent. Consider overriding _instance_verify_static to treat missing scx_loader as ignore_missing=True (or short-circuit verification to True) when the D-Bus proxy cannot be obtained, similar to plugins that hardcode ignore_missing for optional facilities.

Copilot uses AI. Check for mistakes.
Signed-off-by: Peter Jung <admin@ptr1337.dev>
Add a new scaling_min_freq option to the cpu plugin that accepts either
a direct Hz value or a sysfs sibling filename (e.g. cpuinfo_min_freq,
amd_pstate_lowest_nonlinear_freq). In the latter case the plugin reads
the numeric value from that file and writes it to scaling_min_freq,
exactly mirroring what power-profiles-daemon does in its AMD P-State
driver.

Wire it up in the four CachyOS PPD-mapped profiles:
  - cachyos-powersave→ cpuinfo_min_freq (absolute minimum, max savings)
  - cachyos-desktop→ amd_pstate_lowest_nonlinear_freq (balanced floor)
  - cachyos-laptop → amd_pstate_lowest_nonlinear_freq (balanced floor)
  - cachyos-gaming → amd_pstate_lowest_nonlinear_freq (perf floor)

On systems where the source file does not exist (Intel, AMD without
amd-pstate active mode) the option is silently skipped. The rollback
path correctly restores the original numeric value saved at apply time.

Signed-off-by: Peter Jung <admin@ptr1337.dev>
@ptr1337 ptr1337 closed this Mar 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants