Browse Source

CPU accounting

master
Ralph Rönnquist 4 months ago
parent
commit
2f7c23b5e0
  1. 22
      control

22
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

Loading…
Cancel
Save