Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

427. Power management

This page covers suspending, powering off and rebooting a KDOS machine from the desktop and from a prompt, the power profiles, the power policy TLP applies, Intel thermal management, and the per-application energy report. A laptop’s battery, lid and brightness are on Laptops, and the idle timers that dim, lock and blank the screen are on Screen lock. elogind owns the machine’s power state: it suspends, powers off and reboots for whoever polkit allows, and every program that must act around a suspend hooks into it. Inside a Plasma session, PowerDevil sets the policy.

Installation

Port Provides Service script
elogind org.freedesktop.login1: suspend, power-off and reboot, the inhibitors, the lid and power key outside a session, and loginctl 40_elogind
powerdevil The session’s power policy: idle actions, the lid, power and sleep keys, brightness, and the Power Management page of System Settings none; the session starts it
tlp tlp and tlp-stat: power settings applied to /sys, with no daemon, and its elogind sleep hook 55_tlp
tlp-pd The power profiles service PowerDevil and the battery applet switch between, and tlpctl 56_tlppd
thermald Intel’s thermal daemon 54_thermald
kdos-energyd The per-application energy sampler and its client kdos-energy 56_energyd
powertop An interactive report of wakeups and power use, with tunables none
upower The org.freedesktop.UPower service PowerDevil reads batteries from none; the system bus starts it when asked

All of them are in the base the ISO carries except thermald and powertop, which sudo kdos update install <port> adds (see Installing software). The service scripts in the table are enabled on the live medium and on an installed system alike; 54_thermald is part of the base filesystem and skips itself while thermald is not installed. 54_thermald and 56_energyd skip themselves on a machine with nothing for them to do; see Services that skip themselves.

Configuration

elogind

KDOS’s settings for elogind, from fs/etc/elogind/logind.conf.d/50-kdos.conf:

# Lid and power key at the greeter and on a console login. Inside a Plasma
# session PowerDevil takes the handle-* inhibitors and its own settings decide,
# so these apply only where no session holds them.
HandleLidSwitch=suspend
HandleLidSwitchExternalPower=suspend
HandleLidSwitchDocked=ignore
HandlePowerKey=poweroff

# How long a suspend waits for the delay inhibitors taken before it: the
# screen locker locks on PrepareForSleep and KWin blanks, and a suspend that
# outran them would wake to an unlocked desktop.
InhibitDelayMaxSec=5

fs/etc/elogind/logind.conf.d/50-kdos.conf, lines 37–48

The lid and power key settings apply at the greeter and at a console login; inside a Plasma session PowerDevil holds the key inhibitors and its own settings decide. InhibitDelayMaxSec gives the screen locker time to lock before the machine sleeps. Only suspend to RAM is offered, from fs/etc/elogind/sleep.conf.d/50-kdos.conf:

[Sleep]
# Suspend to RAM only. KDOS swaps to zram (/etc/init.d/12_zram.sh), which is
# memory and holds nothing across a power-off, so there is no disk image to
# resume from. With these off, CanHibernate and the hybrid calls answer `no`
# and PowerDevil and the Leave menu offer no action that would lose the
# session.
AllowHibernation=no
AllowSuspendThenHibernate=no
AllowHybridSleep=no

fs/etc/elogind/sleep.conf.d/50-kdos.conf, lines 14–22

A machine whose display is virtio-gpu, the usual one in QEMU, virt-manager and GNOME Boxes, is offered no suspend at all. The kernel’s virtio-gpu driver has no freeze or restore hook, so after a resume the device has been reset and its queues are never rebuilt: the screen stays dark, the next console mode set (a switch to a text console, or a session ending) blocks holding the console lock, and a reboot or power-off then waits on that lock until the machine is reset. 40_elogind.sh writes AllowSuspend=no to /run/elogind/sleep.conf.d/60-kdos-virtio-gpu.conf before elogind starts when a virtio-gpu device is bound, and elogind reads that directory beside /etc/elogind/sleep.conf.d, so CanSuspend answers no and Plasma, the login screen and PowerDevil’s idle and lid actions offer no Sleep.

What runs around a suspend

Before the machine sleeps, elogind sends PrepareForSleep, on which the screen locker locks and KWin blanks, and runs every program in /usr/lib/elogind/system-sleep/ with pre suspend; after waking, with post suspend. TLP installs its hook there, 49-tlp-sleep, and NetworkManager follows PrepareForSleep itself, built with elogind as its suspend and resume tracker.

Who may suspend

polkit answers: the org.freedesktop.login1 actions for suspend, power-off and reboot are allow_active upstream, so the person at the machine in the active session needs no password, and anyone else is asked for an administrator’s. KDOS adds no rule for them; see sudo, PAM and polkit.

TLP

fs/etc/init.d/55_tlp.sh applies TLP’s boot settings and its shutdown settings; TLP is not a daemon, so nothing is supervised:

. /etc/init.d/service_helper

NAME="tlp"
DAEMON="/usr/sbin/tlp"

case "$1" in
    start)
        if [ ! -x "$DAEMON" ]; then
            echo "[SKIP] $NAME: $DAEMON not found"
            exit 0
        fi
        # NOT supervised: tlp is not a daemon. It applies a set of /sys
        # settings and exits, so handing it to ksvc would make the supervisor
        # respawn it forever.
        #
        # `init start`, not `start`: the init verb is the boot one, and is the
        # only one that applies DEVICES_TO_{DIS,EN}ABLE_ON_STARTUP. USB
        # autosuspend is not applied here — TLP's udev rule sets it per
        # device as coldplug adds them.
        echo "[KDOS] Applying $NAME power policy..."
        "$DAEMON" init start
        ;;
    stop)
        # `init stop` is the shutdown half: it clears the saved profile and
        # re-enables Wi-Fi that a battery or connect rule turned off, so the
        # next boot starts with it on. `tlp start` in its place would
        # re-apply a profile to a machine that is about to lose power.
        [ -x "$DAEMON" ] && "$DAEMON" init stop
        ;;
    status)
        # The first line is the summary, and the STATUS cell of `service
        # list` shows that line; `service status tlp` prints the whole of
        # `tlp-stat -s` under it. The summary reads three of its `key = value`
        # lines and keeps the state word of the `tlp` one, which goes on with
        # the time of the last run. A tlp-stat that prints no `tlp` line, as
        # it does when it refuses a caller without root, has its own first
        # line as the summary instead, so the cell carries its error.
        if [ ! -x /usr/bin/tlp-stat ]; then
            echo "$NAME: not installed"
            exit 0
        fi
        _st=$(tlp-stat -s 2>&1)
        _state=
        _profile=
        _source=
        _first=
        while IFS= read -r _l; do
            [ -z "$_first" ] && [ -n "${_l// }" ] && _first="$_l"
            case "$_l" in
                *=*) ;;
                *) continue ;;
            esac
            _k="${_l%%=*}"
            _v="${_l#*=}"
            _k="${_k%"${_k##*[! ]}"}"
            _v="${_v# }"
            case "$_k" in
                tlp)            _state="${_v%%,*}" ;;
                "TLP profile")  _profile="$_v" ;;
                "Power source") _source="$_v" ;;
            esac
        done <<< "$_st"
        if [ -n "$_state" ]; then
            echo "$NAME: $_state, profile ${_profile:-unknown}, power source ${_source:-unknown}"
        else
            echo "$NAME: ${_first:-tlp-stat printed nothing}"
        fi
        printf '%s\n' "$_st"
        ;;
    *)      echo "Usage: $0 {start|stop|status}"; exit 1 ;;
esac

fs/etc/init.d/55_tlp.sh

The recipe installs TLP without its systemd parts and with its elogind sleep hook in /usr/lib/elogind/system-sleep, with its drop-in directory at /etc/tlp.d:

make TLP_WITH_SYSTEMD=0 TLP_WITH_ELOGIND=1 TLP_SBIN=/usr/sbin TLP_BIN=/usr/bin \
     TLP_TLIB=/usr/share/tlp TLP_ULIB=/usr/lib/udev TLP_CONFDIR=/etc/tlp.d \
     TLP_CONFDEF=/usr/share/tlp/defaults.conf TLP_ELOD=/usr/lib/elogind/system-sleep

make TLP_WITH_SYSTEMD=0 TLP_WITH_ELOGIND=1 TLP_SBIN=/usr/sbin TLP_BIN=/usr/bin \
     TLP_TLIB=/usr/share/tlp TLP_ULIB=/usr/lib/udev TLP_CONFDIR=/etc/tlp.d \
     TLP_CONFDEF=/usr/share/tlp/defaults.conf TLP_ELOD=/usr/lib/elogind/system-sleep TLP_NO_INIT=1 \
     DESTDIR=$PKG install-tlp install-man-tlp install-rdw install-man-rdw

ports/core/hardware/tlp/build.sh, lines 12–19

Battery charge thresholds are TLP’s: /etc/polkit-1/rules.d/50-kdos.rules refuses PowerDevil’s helper the two writes, so the battery page shows the limits TLP sets rather than one TLP would undo; see Laptops.

KDOS ships no TLP settings of its own, so upstream’s defaults apply. TLP reads them in this order, each overriding the one before:

File From
/usr/share/tlp/defaults.conf TLP’s built-in defaults; do not edit
/etc/tlp.d/*.conf Drop-in files, read in name order; 00-template.conf is upstream’s example
/etc/tlp.conf Upstream’s full file, every setting commented out

thermald

fs/etc/init.d/54_thermald.sh starts thermald only on an Intel processor, and treats its exit status 2, an Intel model it does not know, as final:

. /etc/init.d/service_helper

NAME="thermald"
DAEMON="/usr/sbin/thermald"

case "$1" in
    start)
        if [ ! -x "$DAEMON" ]; then
            echo "[SKIP] $NAME: $DAEMON not found"
            exit 0
        fi
        # INTEL ONLY, AND IT SAYS SO RATHER THAN RESPAWNING. A machine that
        # is not Intel is skipped here, before any supervisor exists. An
        # Intel model thermald does not know, with no thermal-conf.xml for
        # the platform — older parts, most virtual machines — passes this
        # check and is found out by thermald itself, which then exits 2.
        # `--final-exit 2` makes that exit the supervisor's last, where
        # without it ksvc would restart a refusing daemon every five seconds
        # for as long as the machine is up.
        if ! grep -qi 'GenuineIntel' /proc/cpuinfo 2>/dev/null; then
            echo "[SKIP] $NAME: not an Intel processor"
            exit 0
        fi
        echo "[KDOS] Starting $NAME..."
        # --no-daemon: ksvc owns the process, so forking would hand the
        # supervisor a pid that exits immediately and be respawned for ever.
        # --adaptive uses the firmware's own DPTF tables where the machine
        # ships them, which is what makes it match the vendor's tuning
        # rather than override it.
        supervise --final-exit 2 "$NAME" "$DAEMON" --no-daemon --adaptive
        ;;
    stop)
        stop_service "$NAME"
        ;;
    status)
        check_status "$NAME"
        ;;
    *)
        echo "Usage: $0 {start|stop|status}"
        exit 1
        ;;
esac

fs/etc/init.d/54_thermald.sh

kdos-energyd

fs/etc/init.d/56_energyd.sh starts the sampler only where the processor has a readable RAPL energy counter:

        FOUND=0
        for D in /sys/class/powercap/*/energy_uj; do
            [ -r "$D" ] && FOUND=1
        done
        if [ "$FOUND" = "0" ]; then
            echo "[SKIP] $NAME: no readable RAPL energy domain"
            exit 0
        fi
        echo "[KDOS] Starting $NAME..."
        supervise "$NAME" "$DAEMON"

fs/etc/init.d/56_energyd.sh, lines 18–27

The daemon has no configuration, and its sampling interval cannot be changed. See kdos-energyd.

Usage

Suspending, powering off and rebooting

From the desktop, the Application Launcher’s Leave buttons, and Ctrl+Alt+Del, which opens the logout screen with Sleep, Restart, Shut Down and Log Out. The battery and brightness applet in the tray switches the power profile. The sleep key suspends and the power button opens the logout screen, as System Settings → Power Management sets them; see Laptops.

From a prompt:

loginctl suspend
loginctl poweroff
loginctl reboot

kdos-power suspend, poweroff and reboot are the same three, run through loginctl. Over SSH, where polkit asks for an administrator, sudo loginctl poweroff or sudo poweroff work as well.

Hibernation is not offered: sleep.conf.d turns it off, and the initramfs sets up no resume device.

Switching the power profile

tlpctl list               # power-saver, balanced, performance, and which is in force
tlpctl set power-saver

or the profile slider in the battery and brightness applet. Each switch runs tlp power-saver, tlp balanced or tlp performance, so TLP’s own settings stay the tuning under every profile.

Reading what TLP has applied

  1. sudo tlp-stat -s prints TLP’s state and the power source it detected. service status tlp prints the same summary. Its last block:

    +++ TLP Status
    tlp            = enabled, last run: 19:08:32, 108 sec(s) ago
    tlp-rdw        = enabled
    tlp-pd         = installed, running
    TLP profile    = performance/AC
    Power source   = unknown

    A virtual machine reports its power source as unknown, and TLP then applies its mains profile.

  2. sudo tlp-stat -c prints the configuration TLP is using.

  3. sudo tlp-stat -b prints the battery’s state and any charge thresholds; sudo tlp-stat -p the processor’s.

Changing a TLP setting

  1. Create a drop-in, for example /etc/tlp.d/50-local.conf, and put the settings there, one KEY=value per line. The names are those in /etc/tlp.conf, such as CPU_ENERGY_PERF_POLICY_ON_BAT=power.
  2. Apply it: sudo tlp start. It answers TLP started using profile performance/AC (auto)., or the battery profile on battery.
  3. Check: sudo tlp-stat -c. Each setting is listed with the file and line it came from, so the drop-in’s shows as /etc/tlp.d/50-local.conf L0001: CPU_ENERGY_PERF_POLICY_ON_BAT="power" among the defaults.conf lines.

sudo tlp power-saver, sudo tlp balanced and sudo tlp performance apply one of TLP’s three profiles by hand. TLP assigns balanced to battery and performance to mains (TLP_PROFILE_BAT and TLP_PROFILE_AC), and its default smart switching (TLP_AUTO_SWITCH=2) changes to the new source’s profile, when the machine moves between battery and mains, only if the profile in force is the one assigned to the source being left; a profile chosen by hand otherwise stays. sudo tlp bat and sudo tlp ac apply the profile assigned to battery or to mains in manual mode, which TLP reports as balanced/BAT (manual): that profile stays whatever the power source, until the next tlp start or boot. sudo tlp-stat -s shows which profile is in force.

Checking thermald

  1. service status thermald. A machine that is not Intel reports [DOWN] thermald, and its boot log, /run/kdos-init.thermald.log, says [SKIP] thermald: not an Intel processor.

  2. On an Intel model thermald does not support, it exits with status 2 and the supervisor leaves it stopped, saying so once in the system log:

    sudo grep thermald /var/log/messages

Seeing which application uses the processor’s power

  1. kdos-energy prints the report: each application’s share of the energy that could be attributed, over the time the daemon has been sampling. kdos-energy --json prints it as JSON.
  2. System Monitor’s KDOS page shows the same report, from the ksystemstats-kdos sensors.

The answer is a share, never watt-hours, and it covers the processor package only. Root and members of wheel may read it.

Finding wakeups with powertop

  1. sudo powertop opens its report. The Overview tab lists what wakes the processor most.
  2. The Tunables tab lists settings that are marked Bad. Changing one there lasts until the next boot, and TLP applies its own values again at boot and whenever a change between battery and mains changes its profile.

Tips

Troubleshooting

loginctl suspend is refused, or asks for a password. The caller is not in the active local session: an SSH login, or a session switched away from. Use sudo, or suspend from the desktop.

Suspend does nothing. Something holds a sleep inhibitor; list them as in Tips. Read elogind’s log: sudo grep elogind /var/log/messages.

The machine suspends but the network is gone after waking. NetworkManager follows elogind’s PrepareForSleep; check that both run (service status networkmanager, service status elogind).

The session wakes unlocked. The screen locker had no time to lock: check that InhibitDelayMaxSec in /etc/elogind/logind.conf.d/50-kdos.conf is not lowered, and see Screen lock.

kdos-energy says the daemon is not running. The message is kdos-energy: no kdos-energyd — `service start energyd`. Check service status energyd ([DOWN] kdos-energyd when it is not running), and start it with sudo service start energyd. On a machine with no /sys/class/powercap/*/energy_uj it cannot run.

The fan runs hard on an Intel laptop. Check that thermald runs (service status thermald) and what TLP set for the processor (sudo tlp-stat -p).

Known gaps

See also