Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions recipes-ni/cgroups-v2/files/cgroupv2-common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh

# Common cgroup v2 paths
CGROUP2_ROOT="/sys/fs/cgroup"
NI_GROUP="${CGROUP2_ROOT}/ni"
SUBGROUPS="irq scanengine system time-critical timed-structures"

setup_mount_and_chown() {
if ! mountpoint -q "${CGROUP2_ROOT}"; then
mount -t cgroup2 none "${CGROUP2_ROOT}"
fi

cd "${CGROUP2_ROOT}"

echo "+cpuset" > cgroup.subtree_control

mkdir -p "${NI_GROUP}"
chown lvuser:ni "${NI_GROUP}"

cd "${NI_GROUP}"

echo "+cpuset" > cgroup.subtree_control

for group in $SUBGROUPS; do
mkdir -p "$group"
chown lvuser:ni "$group"
done

echo "Mount and chown setup done."
}

assign_tasks() {
if [ -f "../tasks" ]; then
while read TASK; do
echo "$TASK" > system/cgroup.procs 2>/dev/null || true
done < "../tasks"
fi
}
21 changes: 21 additions & 0 deletions recipes-ni/cgroups-v2/files/createcpuacctgroups
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: createcpuacctgroups
# Required-Start: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Assign tasks for cpuacct groups
### END INIT INFO

set -e

. /usr/lib/cgroupv2-common.sh

setup_mount_and_chown

cd "${NI_GROUP}"

assign_tasks

echo "createcpuacctgroups done."
exit 0
30 changes: 30 additions & 0 deletions recipes-ni/cgroups-v2/files/createcpusets
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: createcpusets
# Required-Start: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Setup cpuset controller & assign tasks
### END INIT INFO

set -e

. /usr/lib/cgroupv2-common.sh

setup_mount_and_chown

cd "${NI_GROUP}"

for group in $SUBGROUPS; do
if [ -f "../cpuset.cpus" ]; then
cat ../cpuset.cpus > "$group/cpuset.cpus"
fi
if [ -f "../cpuset.mems" ]; then
cat ../cpuset.mems > "$group/cpuset.mems"
fi
done

assign_tasks

echo "createcpusets done."
exit 0
55 changes: 55 additions & 0 deletions recipes-ni/cgroups-v2/nicreatecgroupsv2_1.0.bb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
SUMMARY = "NI cgroup v2 setup (mount/chown, cpusets, cpuacctgroups)"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

SRC_URI = "file://cgroupv2-common.sh \
file://createcpusets \
file://createcpuacctgroups"

S = "${WORKDIR}"

inherit update-rc.d

INITSCRIPT_PACKAGES = "${PN}-cpusets ${PN}-cpuacct"

INITSCRIPT_NAME:${PN}-cpusets = "createcpusets"
INITSCRIPT_PARAMS:${PN}-cpusets = "start 01 1 4 5 . stop 99 0 6 ."

INITSCRIPT_NAME:${PN}-cpuacct = "createcpuacctgroups"
INITSCRIPT_PARAMS:${PN}-cpuacct = "start 02 2 4 5 . stop 99 0 6 ."

FILES:${PN} = "/usr/lib/cgroupv2-common.sh \
${sysconfdir}/init.d/createcpusets \
${sysconfdir}/init.d/createcpuacctgroups"

RDEPENDS_${PN} += "update-rc.d"

do_install () {
# Install the common helper script in /usr/lib
install -Dm755 ${WORKDIR}/cgroupv2-common.sh ${D}/usr/lib/cgroupv2-common.sh

# Install SysVinit scripts in /etc/init.d/
install -Dm755 ${WORKDIR}/createcpusets ${D}${sysconfdir}/init.d/createcpusets
install -Dm755 ${WORKDIR}/createcpuacctgroups ${D}${sysconfdir}/init.d/createcpuacctgroups
}

pkg_postinst:${PN} () {
if [ -x /usr/sbin/update-rc.d ]; then
update-rc.d createcpusets defaults
fi

if [ -x /usr/sbin/update-rc.d ]; then
update-rc.d createcpuacctgroups defaults
fi
exit 0
}

pkg_postrm:${PN} () {
if [ -x /usr/sbin/update-rc.d ]; then
update-rc.d -f createcpusets remove
fi
if [ -x /usr/sbin/update-rc.d ]; then
update-rc.d -f createcpuacctgroups remove
fi
exit 0
}