
cpu.cfs_period_us is 100μs by default despite having an "ms" unit for some unfortunate reason. Documentation: https://www.kernel.org/doc/html/latest/scheduler/sched-bwc.html#management The desired effect of that change is more clarity on the default value so users would be aware that the 10ms custom value would be not 0.1x of the default, but 100x of it.
52 lines
1.5 KiB
Go
52 lines
1.5 KiB
Go
//go:build linux
|
|
// +build linux
|
|
|
|
/*
|
|
Copyright 2018 The Kubernetes Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package kuberuntime
|
|
|
|
const (
|
|
milliCPUToCPU = 1000
|
|
|
|
// 100000 is equivalent to 100usec
|
|
quotaPeriod = 100000
|
|
minQuotaPeriod = 1000
|
|
)
|
|
|
|
// milliCPUToQuota converts milliCPU to CFS quota and period values
|
|
func milliCPUToQuota(milliCPU int64, period int64) (quota int64) {
|
|
// CFS quota is measured in two values:
|
|
// - cfs_period_us=100usec (the amount of time to measure usage across given by period)
|
|
// - cfs_quota=20usec (the amount of cpu time allowed to be used across a period)
|
|
// so in the above example, you are limited to 20% of a single CPU
|
|
// for multi-cpu environments, you just scale equivalent amounts
|
|
// see https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt for details
|
|
if milliCPU == 0 {
|
|
return
|
|
}
|
|
|
|
// we then convert your milliCPU to a value normalized over a period
|
|
quota = (milliCPU * period) / milliCPUToCPU
|
|
|
|
// quota needs to be a minimum of 1ms.
|
|
if quota < minQuotaPeriod {
|
|
quota = minQuotaPeriod
|
|
}
|
|
|
|
return
|
|
}
|