-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4374 from kolyshkin/cpu-burst
Fix cpu burst test failure on newer kernels
- Loading branch information
Showing
1 changed file
with
17 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() { | ||
|
@@ -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 | ||
|