From: Ralph Ronnquist Date: Mon, 28 Feb 2022 10:21:29 +0000 (+1100) Subject: CPU accounting X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=2f7c23b5e01627ef7e9cd5073da1b74d0e030ec2;p=rrq%2Fsubhost.git CPU accounting --- diff --git a/control b/control index c2901f1..304c93b 100755 --- a/control +++ b/control @@ -102,6 +102,26 @@ setup_rootfs() { fi } +# Set up cgroup CPU accounting (cpuacct) +accounting() { + # 1-- once, system wide + grep -q "/sys/fs/cgroup cgroup" /proc/mounts || \ + mount -t cgroup -ocpuacct none /sys/fs/cgroup + if [ -d /sys/fs/cgroup/$NAME ] ; then + : # reset? + else + mkdir /sys/fs/cgroup/$NAME + # the following fixes things that sometimes are broken? + for f in cpuset.mems cpuset.cpus ; do + [ -z "$(cat /sys/fs/cgroups/$NAME/$F)" ] && \ + echo 0 > /sys/fs/cgroups/$NAME/$F + done + + fi + # Register this task for subhost accounting + echo $$ > /sys/fs/cgroup/$NAME/tasks +} + case "$CMD" in start) [ -e "/run/netns/$NSNAME" ] || setup_network @@ -109,6 +129,7 @@ case "$CMD" in setup_rootfs START=/bin/bash [ -x $TARGET/startup ] && START=/startup + accounting exec ip netns exec $NSNAME unshare \ --fork --pid --mount-proc --kill-child \ --uts --ipc --mount --cgroup \ @@ -118,6 +139,7 @@ case "$CMD" in umount $TARGET [ -e $IMAGE ] && umount $MOUNT ip netns del $NSNAME + rmdir /sys/fs/cgroup/$NAME ;; *) usage