Skip to content

dbus: add hold/release cookie mechanism for scheduler state management#51

Open
e-tho wants to merge 4 commits into
sched-ext:mainfrom
e-tho:feat/hold-release
Open

dbus: add hold/release cookie mechanism for scheduler state management#51
e-tho wants to merge 4 commits into
sched-ext:mainfrom
e-tho:feat/hold-release

Conversation

@e-tho

@e-tho e-tho commented Apr 23, 2026

Copy link
Copy Markdown

Clients that need to temporarily switch the active scheduler had no safe way to restore the previous state on cleanup, and concurrent clients would silently overwrite each other's scheduler choice.

Introduce HoldScheduler/ReleaseScheduler methods modelled after power-profiles-daemon's HoldProfile/ReleaseProfile API. Acquiring a hold activates the requested scheduler and returns an opaque cookie; the pre-hold state is saved automatically. Releasing the cookie restores it. Multiple concurrent holds are supported with last-write-wins semantics — releasing the active hold falls back to the next most recent one, and releasing the last hold restores the original state.

Active holds are exposed as a new ActiveHolds property for introspection.

scxctl gains hold, release, and holds subcommands to exercise the new interface from the command line.

Clients that need to temporarily switch the active scheduler had no safe
way to restore the previous state on cleanup, and concurrent clients
would silently overwrite each other's scheduler choice.

Introduce HoldScheduler/ReleaseScheduler methods modelled after
power-profiles-daemon's HoldProfile/ReleaseProfile API. Acquiring a hold
activates the requested scheduler and returns an opaque cookie; the
pre-hold state is saved automatically. Releasing the cookie restores it.
Multiple concurrent holds are supported with last-write-wins semantics —
releasing the active hold falls back to the next most recent one, and
releasing the last hold restores the original state.

Active holds are exposed as a new ActiveHolds property for introspection.

scxctl gains hold, release, and holds subcommands to exercise the new
interface from the command line.
@sirlucjan sirlucjan requested review from frap129 and vnepogodin April 23, 2026 21:04

@frap129 frap129 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Overall looks okay, but one issue I noticed. hold_scheduler and release_scheduler manage current_scx, current_mode, and current_args, but nothing prevents a client from calling switch_scheduler, stop_scheduler, restore_default, etc. while holds are active. If a switch happens while holds exist, the hold stack won't be accurate anymore. I think you need to either return an error for other scheduler change methods while !active_holds.is_empty(), or clear all holds (and the pre-hold snapshot) when a different method is called.

Calling switch, stop, restart, or restore while holds are active would
leave the hold stack inconsistent with the running scheduler, making the
pre-hold state unrestorable on release. All mutating methods now return
an error if any holds are active.
@e-tho

e-tho commented Apr 24, 2026

Copy link
Copy Markdown
Author

I went for the conflict error approach since the other one would lead to clients calling release_scheduler with a cookie that no longer exists. It also matches what power-profiles-daemon does.

Comment thread crates/scx_loader/src/dbus.rs Outdated
Comment thread crates/scx_loader/src/dbus.rs Outdated
/// Opaque cookie returned to the caller.
pub cookie: u32,
/// Scheduler name requested by this hold.
pub scheduler: String,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
pub scheduler: String,
pub scheduler: SupportedSched,

Comment thread crates/scx_loader/src/lib.rs
Comment thread crates/scx_loader/src/main.rs
Comment thread crates/scx_loader/src/main.rs Outdated
@sirlucjan sirlucjan requested a review from vnepogodin May 10, 2026 09:29

self.active_holds.push(HoldEntry {
cookie,
scheduler: <SupportedSched as Into<&str>>::into(scheduler.clone()).to_owned(),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why not just store SupportedSched in HoldEntry too? it's smaller and static typed

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It's a zvariant wire type, and zvariant can't derive Value/OwnedValue for SupportedSched.

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.

3 participants