Skip to content

Commit

Permalink
Merge pull request opencontainers#4374 from kolyshkin/cpu-burst
Browse files Browse the repository at this point in the history
Fix cpu burst test failure on newer kernels
  • Loading branch information
rata authored Aug 14, 2024
2 parents e531ebb + a7c8d86 commit 94eda74
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions tests/integration/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -260,29 +260,30 @@ function get_cgroup_value() {
cat "$cgroup/$1"
}

# Helper to check a if value in a cgroup file matches the expected one.
# Check if a value in a cgroup file $1 matches $2 or $3 (if specified).
function check_cgroup_value() {
local current
current="$(get_cgroup_value "$1")"
local expected=$2
local got
got="$(get_cgroup_value "$1")"
local want=$2
local want2="${3:-}"

echo "current $current !? $expected"
[ "$current" = "$expected" ]
echo "$1: got $got, want $want $want2"
[ "$got" = "$want" ] || [[ -n "$want2" && "$got" = "$want2" ]]
}

# Helper to check a value in systemd.
# Check if a value of systemd unit property $1 matches $2 or $3 (if specified).
function check_systemd_value() {
[ ! -v RUNC_USE_SYSTEMD ] && return
local source="$1"
[ "$source" = "unsupported" ] && return
local expected="$2"
local expected2="${3:-}"
local want="$2"
local want2="${3:-}"
local user=""
[ $EUID -ne 0 ] && user="--user"

current=$(systemctl show $user --property "$source" "$SD_UNIT_NAME" | awk -F= '{print $2}')
echo "systemd $source: current $current !? $expected $expected2"
[ "$current" = "$expected" ] || [[ -n "$expected2" && "$current" = "$expected2" ]]
got=$(systemctl show $user --property "$source" "$SD_UNIT_NAME" | awk -F= '{print $2}')
echo "systemd $source: got $got, want $want $want2"
[ "$got" = "$want" ] || [[ -n "$want2" && "$got" = "$want2" ]]
}

function check_cpu_quota() {
Expand Down Expand Up @@ -316,8 +317,10 @@ function check_cpu_quota() {
function check_cpu_burst() {
local burst=$1
if [ -v CGROUP_V2 ]; then
burst=$((burst / 1000))
check_cgroup_value "cpu.max.burst" "$burst"
# Due to a kernel bug (fixed by commit 49217ea147df, see
# https://lore.kernel.org/all/[email protected]/),
# older kernels printed value divided by 1000. Check for both.
check_cgroup_value "cpu.max.burst" "$burst" "$((burst / 1000))"
else
check_cgroup_value "cpu.cfs_burst_us" "$burst"
fi
Expand Down

0 comments on commit 94eda74

Please sign in to comment.