scxcli 0.1.1

Command-line tool for sched_ext schedulers, built on scx.service
# scxcli

Command-line tool for `sched_ext` schedulers, built on `scx.service`.

scxcli starts a scheduler from the catalog the scx maintainers keep:
the recommended ones (Default, Cosmos, LAVD, EEVDF, Cake) first, every
other installed scheduler on request, and a hidden set that needs a
configuration of its own. It reports which scheduler is running. It is
the only program that changes what `scx.service` runs: scxtui, desktop
widgets and scripts all go through it.

```
scxcli list [--json]              The recommended schedulers and the
                                  current state
scxcli list recommended [--json]  The same
scxcli list all [--json]          Every installed scheduler: stable,
                                  experimental, then unlisted
  --catalog PATH                  List with this catalog file instead of
                                  the installed one
scxcli get [--json]               Show which scheduler is running
scxcli start ID                   Start an entry of `list`: a profile by id,
                                  a scheduler from `list all` with its
                                  defaults, or `default` for the kernel's
                                  own
scxcli start                      Start the selected scheduler again after
                                  `stop`
scxcli stop                       Stop the scheduler, keep the selection for
                                  the next start
scxcli run SCHED [ARGS...]        Start a scheduler with these options
scxcli catalog show [--shipped]   The catalog in use (or the shipped one)
                                  as JSON, to edit and save back
scxcli catalog save               Install the catalog on standard input as
                                  /etc/scx/catalog.json, whole
scxcli catalog reset              Remove /etc/scx/catalog.json
```

`list` and `get` work for any user. The rest need root, or polkit through
`pkexec scxcli start scx_cosmos`; scxcli does not escalate on its own.
With the shipped policy (`org.sched_ext.scxcli.policy`), starting an
entry of the list (a scheduler with its defaults, or a profile the
administrator put in `/etc/scx/catalog.json` with the options of their
choosing) and stopping it need no password for a user at the console,
and starting a scheduler with options of your own, or changing the
catalog, asks for an administrator's.

To give users a profile with options, say EEVDF with a short slice,
take the catalog in use, add the profile, and save the whole file back:

```
scxcli catalog show > catalog.json
# add to "recommended":
#   { "id": "latency", "label": "Low latency",
#     "sched": "scx_eevdf", "args": ["--slice-us", "1600"] }
sudo scxcli catalog save < catalog.json
```

`start latency` then runs it without a password, as any entry of the
list. The override replaces the shipped catalog whole and does not
follow upstream changes to it; `scxcli catalog reset` returns to the
shipped file, and `catalog show --shipped` prints it for comparison.

The contract (file format, selected state, how the running scheduler is
detected, the JSON output, exit codes) is in
[`services/CATALOG.md`](../../services/CATALOG.md). The rules live in the
[`scx_catalog`](../../rust/scx_catalog) crate; scxcli is a thin wrapper
around it.

## How it works

Starting a scheduler writes `SCX_SCHEDULER` and `SCX_FLAGS` to the unit's
`EnvironmentFile` (`/etc/default/scx`), clears any `SCX_*_OVERRIDE` from
the systemd manager, and runs `systemctl enable` and `restart`. `default`
disables the unit instead. There is no daemon and no D-Bus: the file is
the configuration and the kernel (`/sys/kernel/sched_ext`) is the truth
about what runs, so the choice survives reboots and can be managed with
`systemctl`, configuration management and image builds like any other
unit.

## Install

```
cargo build --release -p scxcli
install -Dm755 target/release/scxcli /usr/bin/scxcli
install -Dm644 tools/scxcli/org.sched_ext.scxcli.policy \
    /usr/share/polkit-1/actions/org.sched_ext.scxcli.policy
install -Dm644 services/catalog.json /usr/share/scx/catalog.json
```

The data files (this policy, the catalog, `scx.service` and
`/etc/default/scx`) can also go in with `xtask install`, which copies
them and nothing else; the binary is still installed as above. See
[`INSTALL.md`](../../INSTALL.md).

## Scripting

```sh
scxcli get --json | jq -r .scheduler
pkexec scxcli start scx_cosmos
scxcli list --json | jq -r '.all[] | .name'
```

Clients refresh on inotify events for `/etc/scx/catalog.json`,
`/usr/share/scx/catalog.json` and `/etc/default/scx`, never on a timer.