357.3. kdos-energyd-0.2.0
Relative per-app Energy Impact from RAPL, attributed by container
| Version | 0.2.0, release 1 |
| Source tree | src/daemons/kdos-energyd/ |
| Phase | 50_desktop (Desktop), 77 of 92 in build order |
| Licence | MIT |
| Homepage | https://github.com/kunaldawn/kdos |
| Build time | 0.1 SBU |
| Installed size | 118.5 KiB in 2 files |
| Recipe | src/daemons/kdos-energyd/kpkgbuild |
About
kdos-energyd attributes the processor’s energy use to applications: it samples the kernel’s RAPL energy counters under /sys/class/powercap, which only root may read, and divides the energy among the running programs, naming a boxed application by the container its processes run in. Every boxed application is its own rootless container under a known name, so the attribution starts from an identity rather than a guess. It reports relative shares, never watt-hours. kdos-energy prints its report, and System Monitor’s KDOS energy and box pages read kdos-energy --json, whose rows carry the app and its box as separate fields beside the display name. What it measures and how it splits the figure is in kdos-energyd.
The port is KDOS’s own C, with no upstream source. build.sh compiles the daemon’s own files with the sources of libkbase and libkproc and nothing else. The daemon walks a process’s parent chain itself; libkproc recognises podman’s per-container supervisor, conmon, where the walk stops, and reads the box’s name from its command line. See How the libraries are built and libkproc.
Why it is in KDOS
The comment above it in script/phases/50_desktop/packages.txt:
Per-app Energy Impact. RAPL is root-only (PLATYPUS), so the sampler is a daemon; identity comes free from the fact that every alien app is already its own container. Relative shares, never watt-hours.
Sources
None: the port builds from its own directory, /kdos/src/daemons/kdos-energyd.
Dependencies
Depends on: nothing a recipe names.
Required by (1): kde-plasma.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/50_desktop/phase.env && kpkg install kdos-energyd'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /kdos/src/daemons/kdos-energyd.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/kdos-energyd
SRC=$SRC_ROOT/kdos-energyd-0.2.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
LIBS="$PORT_SRC/../../libs"
gcc $CFLAGS -O2 -std=gnu11 -D_GNU_SOURCE -Wall -Wextra \
-I"$LIBS/libkbase" -I"$LIBS/libkproc" -I"$PORT_SRC" \
-o kdos-energyd "$PORT_SRC"/*.c "$LIBS"/libkbase/*.c "$LIBS"/libkproc/*.c $LDFLAGS
install -Dm755 kdos-energyd "$PKG/usr/sbin/kdos-energyd"
install -d "$PKG/usr/bin"
ln -s ../sbin/kdos-energyd "$PKG/usr/bin/kdos-energy"
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/kdos-energyd, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf kdos-energyd-0.2.0-1.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/kdos-energyd, and runs the triggers its paths call for.
Other files in the port directory, read by build.sh: attrib.c, energyd.h, main.c, rapl.c, report.c.
Contents
Installed programs: kdos-energy, kdos-energyd.
Notes
One binary has two names: /usr/sbin/kdos-energyd serves /run/kdos-energyd.sock, and the link /usr/bin/kdos-energy runs it as the client. The name it was started under is the whole switch.
/etc/init.d/56_energyd.sh skips the daemon at boot when no energy_uj counter is readable at all. The daemon’s own test is narrower: it refuses to start when the first domain it keeps (the platform’s psys domain, where there is one) cannot be read. A machine with one readable counter but an unreadable first domain passes the script’s check, and the supervisor then restarts the refusing daemon every five seconds; see Supervision and logging.
A ten-second window during which the machine was suspended is left out of the ledger and counted in the report instead: the daemon compares CLOCK_BOOTTIME with CLOCK_MONOTONIC across each window, because the RAPL counter after a resume runs on from wherever the firmware left it, and the difference across the suspend would otherwise be charged to whatever ran around the lid.