Commit 3d5e27df authored by Michal Berger's avatar Michal Berger Committed by Jim Harris
Browse files

test/cgroups: Add helper functions for more granular setup



Signed-off-by: default avatarMichal Berger <michal.berger@intel.com>
Change-Id: I6b6baae849a472599adc36a04d268a7a65979b41
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13703


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarKarol Latecki <karol.latecki@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 1f7041b3
Loading
Loading
Loading
Loading
+34 −4
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ check_cgroup() {
}

init_cpuset_cgroup() {
	local cgroup
	local cgroup pid
	local -A cgroups=()

	# For cgroup-v2 we need to prepare cpuset subsystem on our own
@@ -26,9 +26,8 @@ init_cpuset_cgroup() {
		# maintaining user's session. To recreate the simple /cpuset setup from
		# v1, move all the threads from all the existing cgroups to the top
		# cgroup / and then migrate it to the /cpuset we created above.
		for cgroup in /proc/+([0-9])/cgroup; do
			cgroup=$(< "$cgroup") || continue
			cgroup=${cgroup##*:}
		for pid in /proc/+([0-9]); do
			cgroup=$(get_cgroup "${pid##*/}") || continue
			[[ $cgroup != / ]] || continue
			cgroups["$cgroup"]=$cgroup
		done 2> /dev/null
@@ -153,5 +152,36 @@ remove_cpuset_cgroup() {
	fi
}

get_cgroup() {
	local pid=${1:-self} cgroup

	[[ -e /proc/$pid/cgroup ]] || return 1
	cgroup=$(< "/proc/$pid/cgroup")
	echo "${cgroup##*:}"
}

get_cgroup_path() {
	local cgroup

	cgroup=$(get_cgroup "$1") || return 1
	echo "$sysfs_cgroup$cgroup"
}

_set_cgroup_attr_top_bottom() {
	local cgroup_path=$1 attr=$2 val=$3

	if [[ -e ${cgroup_path%/*}/$attr ]]; then
		_set_cgroup_attr_top_bottom "${cgroup_path%/*}" "$attr" "$val"
	fi

	if [[ -e $cgroup_path/$attr ]]; then
		echo "$val" > "$cgroup_path/$attr"
	fi
}

set_cgroup_attr_top_bottom() {
	_set_cgroup_attr_top_bottom "$(get_cgroup_path "$1")" "$2" "$3"
}

declare -r sysfs_cgroup=/sys/fs/cgroup
cgroup_version=$(check_cgroup)