Skip to content

Commit

Permalink
Implement load balance for cgroup2
Browse files Browse the repository at this point in the history
Keep existing functionality for v1, copied from the oslat bench
repo so other benchmarks can reuse this common function.
  • Loading branch information
rafaelfolco committed Nov 14, 2024
1 parent 83a7f68 commit dadde72
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions bash/library/bench-base
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,91 @@ function validate_clocksource() {
return 1
fi
}

function disable_balance_v1()
{
local cpulist="$1"; shift
local cpu=""
local file=
local flags_cur=
for cpu in `echo ${cpulist} | sed -e 's/,/ /g'`; do
for file in $(find /proc/sys/kernel/sched_domain/cpu$cpu -name flags -print); do
flags_cur=$(cat $file)
flags_cur=$((flags_cur & 0xfffe))
echo $flags_cur > $file
done
done
}

function enable_balance_v1()
{
local cpulist="$1"; shift
local cpu=""
local file=
local flags_cur=
for cpu in `echo ${cpulist} | sed -e 's/,/ /g'`; do
for file in $(find /proc/sys/kernel/sched_domain/cpu$cpu -name flags -print); do
flags_cur=$(cat $file)
flags_cur=$((flags_cur | 0x1))
echo $flags_cur > $file
done
done
}

function enable_balance_v2()
{
echo member > /sys/fs/cgroup/user.slice/cpuset.cpus.partition
echo -cpuset > /sys/fs/cgroup/cgroup.subtree_control
}

function disable_balance_v2()
{
local cpulist="$1"; shift
echo +cpuset > /sys/fs/cgroup/cgroup.subtree_control
echo $cpulist > /sys/fs/cgroup/user.slice/cpuset.cpus
echo isolated > /sys/fs/cgroup/user.slice/cpuset.cpus.partition
}

function enable_balance()
{
local cpulist="$1"; shift
local debug="$1"; shift

if [ -n "$debug" ]; then
echo Y > /sys/kernel/debug/sched/verbose
fi

cmd=$(mount | grep cgroup)
if [[ "$cmd" =~ "cgroup2" ]]; then
enable_balance_v2()
else
enable_balance_v1($cpulist)
fi

if [ -n "$debug" ]; then
echo N > /sys/kernel/debug/sched/verbose
fi
}

function disable_balance()
{
local cpulist="$1"; shift
local debug="$1"; shift

if [ -n "$debug" ]; then
echo Y > /sys/kernel/debug/sched/verbose
fi

cmd=$(mount | grep cgroup)
if [[ "$cmd" =~ "cgroup2" ]]; then
disable_balance_v2($cpulist)
else
disable_balance_v1($cpulist)
fi

if [ -n "$debug" ]; then
echo N > /sys/kernel/debug/sched/verbose
fi
}


0 comments on commit dadde72

Please sign in to comment.