From eaf75a312f8063b5f9c0c9e50590061e31adc9c8 Mon Sep 17 00:00:00 2001 From: "George L. Yermulnik" Date: Sun, 6 Apr 2025 15:24:06 +0300 Subject: [PATCH 1/6] chore(_common.sh): Add `WSLInterop-late` file check in `get_cpu_num` --- hooks/_common.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hooks/_common.sh b/hooks/_common.sh index fbd4bc2b4..2ba6220b3 100644 --- a/hooks/_common.sh +++ b/hooks/_common.sh @@ -206,8 +206,13 @@ function common::get_cpu_num { local cpu_quota cpu_period cpu_num + local wslinterop_path = "/proc/sys/fs/binfmt_misc/WSLInterop" + if [[ -f /sys/fs/cgroup/cpu/cpu.cfs_quota_us && - ! -f /proc/sys/fs/binfmt_misc/WSLInterop ]]; then # WSL have cfs_quota_us, but WSL should be checked as usual Linux host + ( # WSL has cfs_quota_us, but WSL should be checked as usual Linux host + ! -f "${wslinterop_path}" && + ! -f "${wslinterop_path}-late" + ) ]]; then # Inside K8s pod or DinD in K8s cpu_quota=$(< /sys/fs/cgroup/cpu/cpu.cfs_quota_us) cpu_period=$(cat /sys/fs/cgroup/cpu/cpu.cfs_period_us 2> /dev/null || echo "$cpu_quota") From 384091b92e505386b682f5f3d0934e65261861d8 Mon Sep 17 00:00:00 2001 From: "George L. Yermulnik" Date: Sun, 6 Apr 2025 15:33:25 +0300 Subject: [PATCH 2/6] Fix typo --- hooks/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/_common.sh b/hooks/_common.sh index 2ba6220b3..5ead76ab1 100644 --- a/hooks/_common.sh +++ b/hooks/_common.sh @@ -206,7 +206,7 @@ function common::get_cpu_num { local cpu_quota cpu_period cpu_num - local wslinterop_path = "/proc/sys/fs/binfmt_misc/WSLInterop" + local wslinterop_path="/proc/sys/fs/binfmt_misc/WSLInterop" if [[ -f /sys/fs/cgroup/cpu/cpu.cfs_quota_us && ( # WSL has cfs_quota_us, but WSL should be checked as usual Linux host From be1051f2aff47ecad2b8bacbf69b94e9fe3482b6 Mon Sep 17 00:00:00 2001 From: pre-commit Date: Sun, 6 Apr 2025 12:33:57 +0000 Subject: [PATCH 3/6] pre-commit fixes --- hooks/_common.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hooks/_common.sh b/hooks/_common.sh index 5ead76ab1..d5d5a8340 100644 --- a/hooks/_common.sh +++ b/hooks/_common.sh @@ -209,10 +209,10 @@ function common::get_cpu_num { local wslinterop_path="/proc/sys/fs/binfmt_misc/WSLInterop" if [[ -f /sys/fs/cgroup/cpu/cpu.cfs_quota_us && - ( # WSL has cfs_quota_us, but WSL should be checked as usual Linux host - ! -f "${wslinterop_path}" && - ! -f "${wslinterop_path}-late" - ) ]]; then + ( + ! -f "${wslinterop_path}" && + ! -f "${wslinterop_path}-late") ]] \ + ; then # WSL has cfs_quota_us, but WSL should be checked as usual Linux host # Inside K8s pod or DinD in K8s cpu_quota=$(< /sys/fs/cgroup/cpu/cpu.cfs_quota_us) cpu_period=$(cat /sys/fs/cgroup/cpu/cpu.cfs_period_us 2> /dev/null || echo "$cpu_quota") From 62953dadaa6a8a58c889aef9d01b4adb59b4071f Mon Sep 17 00:00:00 2001 From: "George L. Yermulnik" Date: Sun, 6 Apr 2025 15:37:39 +0300 Subject: [PATCH 4/6] Streamline condition wrapping --- hooks/_common.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/hooks/_common.sh b/hooks/_common.sh index d5d5a8340..988de5088 100644 --- a/hooks/_common.sh +++ b/hooks/_common.sh @@ -209,10 +209,7 @@ function common::get_cpu_num { local wslinterop_path="/proc/sys/fs/binfmt_misc/WSLInterop" if [[ -f /sys/fs/cgroup/cpu/cpu.cfs_quota_us && - ( - ! -f "${wslinterop_path}" && - ! -f "${wslinterop_path}-late") ]] \ - ; then # WSL has cfs_quota_us, but WSL should be checked as usual Linux host + (! -f "${wslinterop_path}" && ! -f "${wslinterop_path}-late") ]]; then # WSL has cfs_quota_us, but WSL should be checked as usual Linux host # Inside K8s pod or DinD in K8s cpu_quota=$(< /sys/fs/cgroup/cpu/cpu.cfs_quota_us) cpu_period=$(cat /sys/fs/cgroup/cpu/cpu.cfs_period_us 2> /dev/null || echo "$cpu_quota") From d3066b284855af52e737e6222fa158b3f5d1b776 Mon Sep 17 00:00:00 2001 From: "George L. Yermulnik" Date: Sun, 6 Apr 2025 17:17:34 +0300 Subject: [PATCH 5/6] make WSLInterop local var readonly Co-authored-by: Maksym Vlasov --- hooks/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/_common.sh b/hooks/_common.sh index 988de5088..2b7a6f308 100644 --- a/hooks/_common.sh +++ b/hooks/_common.sh @@ -206,7 +206,7 @@ function common::get_cpu_num { local cpu_quota cpu_period cpu_num - local wslinterop_path="/proc/sys/fs/binfmt_misc/WSLInterop" + local -r wslinterop_path="/proc/sys/fs/binfmt_misc/WSLInterop" if [[ -f /sys/fs/cgroup/cpu/cpu.cfs_quota_us && (! -f "${wslinterop_path}" && ! -f "${wslinterop_path}-late") ]]; then # WSL has cfs_quota_us, but WSL should be checked as usual Linux host From 759fcb7f31b5683097eb37b4ac8b23d8f524a6dd Mon Sep 17 00:00:00 2001 From: "George L. Yermulnik" Date: Sun, 6 Apr 2025 17:33:30 +0300 Subject: [PATCH 6/6] Also check `/run/WSL` file does not exist --- hooks/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/_common.sh b/hooks/_common.sh index 2b7a6f308..defc249a8 100644 --- a/hooks/_common.sh +++ b/hooks/_common.sh @@ -209,7 +209,7 @@ function common::get_cpu_num { local -r wslinterop_path="/proc/sys/fs/binfmt_misc/WSLInterop" if [[ -f /sys/fs/cgroup/cpu/cpu.cfs_quota_us && - (! -f "${wslinterop_path}" && ! -f "${wslinterop_path}-late") ]]; then # WSL has cfs_quota_us, but WSL should be checked as usual Linux host + (! -f "${wslinterop_path}" && ! -f "${wslinterop_path}-late" && ! -f "/run/WSL") ]]; then # WSL has cfs_quota_us, but WSL should be checked as usual Linux host # Inside K8s pod or DinD in K8s cpu_quota=$(< /sys/fs/cgroup/cpu/cpu.cfs_quota_us) cpu_period=$(cat /sys/fs/cgroup/cpu/cpu.cfs_period_us 2> /dev/null || echo "$cpu_quota")