aboutsummaryrefslogtreecommitdiff
path: root/pkg/util/utils.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-11-02 16:02:55 +0100
committerGitHub <noreply@github.com>2020-11-02 16:02:55 +0100
commit7375a55757fe7615f133db5b097bb4db9a244888 (patch)
tree6d29d221f696c3aabfa1e847d92f55da41cb27e9 /pkg/util/utils.go
parent8bc0f51e330185bed1be4bcfffd04729b4bc9cd4 (diff)
parent03579649063d669f9f57d534f74136befef98c62 (diff)
downloadpodman-7375a55757fe7615f133db5b097bb4db9a244888.tar.gz
podman-7375a55757fe7615f133db5b097bb4db9a244888.tar.bz2
podman-7375a55757fe7615f133db5b097bb4db9a244888.zip
Merge pull request #8207 from xordspar0/common-period-quota
Centralize cores and period/quota conversion code
Diffstat (limited to 'pkg/util/utils.go')
-rw-r--r--pkg/util/utils.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/pkg/util/utils.go b/pkg/util/utils.go
index a9aad657d..415fd169b 100644
--- a/pkg/util/utils.go
+++ b/pkg/util/utils.go
@@ -653,3 +653,26 @@ func CreateCidFile(cidfile string, id string) error {
cidFile.Close()
return nil
}
+
+// DefaultCPUPeriod is the default CPU period is 100us, which is the same default
+// as Kubernetes.
+const DefaultCPUPeriod uint64 = 100000
+
+// CoresToPeriodAndQuota converts a fraction of cores to the equivalent
+// Completely Fair Scheduler (CFS) parameters period and quota.
+//
+// Cores is a fraction of the CFS period that a container may use. Period and
+// Quota are in microseconds.
+func CoresToPeriodAndQuota(cores float64) (uint64, int64) {
+ return DefaultCPUPeriod, int64(cores * float64(DefaultCPUPeriod))
+}
+
+// PeriodAndQuotaToCores takes the CFS parameters period and quota and returns
+// a fraction that represents the limit to the number of cores that can be
+// utilized over the scheduling period.
+//
+// Cores is a fraction of the CFS period that a container may use. Period and
+// Quota are in microseconds.
+func PeriodAndQuotaToCores(period uint64, quota int64) float64 {
+ return float64(quota) / float64(period)
+}