Skip to content

Commit 3c34870

Browse files
committed
feat: enable default cpu burst for shared cores pods
1 parent df748b2 commit 3c34870

6 files changed

Lines changed: 334 additions & 15 deletions

File tree

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ require (
175175
)
176176

177177
replace (
178+
github.com/kubewharf/katalyst-api => github.com/JustinChengLZ/katalyst-api v0.0.0-20260303124341-4bfbcc6e314a
178179
k8s.io/api => k8s.io/api v0.24.6
179180
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.24.6
180181
k8s.io/apimachinery => k8s.io/apimachinery v0.24.6

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ github.com/Djarvur/go-err113 v0.0.0-20200511133814-5174e21577d5/go.mod h1:4UJr5H
6262
github.com/GoogleCloudPlatform/k8s-cloud-provider v1.16.1-0.20210702024009-ea6160c1d0e3/go.mod h1:8XasY4ymP2V/tn2OOV9ZadmiTE1FIB/h3W+yNlPttKw=
6363
github.com/HdrHistogram/hdrhistogram-go v1.0.0/go.mod h1:YzE1EgsuAz8q9lfGdlxBZo2Ma655+PfKp2mlzcAqIFw=
6464
github.com/JeffAshton/win_pdh v0.0.0-20161109143554-76bb4ee9f0ab/go.mod h1:3VYc5hodBMJ5+l/7J4xAyMeuM2PNuepvHlGs8yilUCA=
65+
github.com/JustinChengLZ/katalyst-api v0.0.0-20260303124341-4bfbcc6e314a h1:aU7VkzQaLs7v80uy2tYGOtYHZXSnHbn4lRsUrw8DX+c=
66+
github.com/JustinChengLZ/katalyst-api v0.0.0-20260303124341-4bfbcc6e314a/go.mod h1:BZMVGVl3EP0eCn5xsDgV41/gjYkoh43abIYxrB10e3k=
6567
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
6668
github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd/go.mod h1:64YHyfSL2R96J44Nlwm39UHepQbyR5q10x7iYa1ks2E=
6769
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
@@ -574,8 +576,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
574576
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
575577
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
576578
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
577-
github.com/kubewharf/katalyst-api v0.5.9-0.20260108125536-85e136f5902c h1:ohKHA5TOlW9487menKnKH2M14LeIq1xQ1yW4xp8x9o8=
578-
github.com/kubewharf/katalyst-api v0.5.9-0.20260108125536-85e136f5902c/go.mod h1:BZMVGVl3EP0eCn5xsDgV41/gjYkoh43abIYxrB10e3k=
579579
github.com/kubewharf/kubelet v1.24.6-kubewharf-pre.1 h1:pzU37yZWrOBosNX+Laay9Ess0Bff/rsWanBxbdXnHnM=
580580
github.com/kubewharf/kubelet v1.24.6-kubewharf-pre.1/go.mod h1:MxbSZUx3wXztFneeelwWWlX7NAAStJ6expqq7gY2J3c=
581581
github.com/kyoh86/exportloopref v0.1.7/go.mod h1:h1rDl2Kdj97+Kwh4gdz3ujE7XHmH51Q0lUiZ1z4NLj8=

pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpuburst/manager.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ func (m *managerImpl) UpdateCPUBurst(qosConf *generic.QoSConfiguration, dynamicC
7676

7777
var errList []error
7878

79+
isSoleSharedCoresPod := util.IsSoleSharedCoresPod(qosConf, podList, dynamicConfig)
80+
7981
for _, pod := range podList {
80-
cpuBurstPolicy, err := util.GetPodCPUBurstPolicy(qosConf, pod, dynamicConfig)
82+
cpuBurstPolicy, err := util.GetPodCPUBurstPolicy(qosConf, pod, dynamicConfig, isSoleSharedCoresPod)
8183
if err != nil {
8284
errList = append(errList, fmt.Errorf("error getting cpu burst policy for pod %s: %v", pod.Name, err))
8385
continue

pkg/agent/qrm-plugins/cpu/util/util.go

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ func PopulateHintsByAvailableNUMANodes(
281281
}
282282

283283
// GetPodCPUBurstPolicy gets the cpu burst policy of a given pod.
284-
func GetPodCPUBurstPolicy(qosConf *generic.QoSConfiguration, pod *v1.Pod, dynamicConfig *dynamic.DynamicAgentConfiguration) (string, error) {
284+
func GetPodCPUBurstPolicy(qosConf *generic.QoSConfiguration, pod *v1.Pod, dynamicConfig *dynamic.DynamicAgentConfiguration,
285+
isSoleSharedCoresPod bool,
286+
) (string, error) {
285287
if pod == nil {
286288
return "", fmt.Errorf("got nil pod")
287289
}
@@ -295,15 +297,17 @@ func GetPodCPUBurstPolicy(qosConf *generic.QoSConfiguration, pod *v1.Pod, dynami
295297
// We may override cpu burst policy of dedicated cores pods with default values in dynamic config.
296298
qosLevel, _ := qosConf.GetQoSLevel(pod, map[string]string{})
297299
if qosLevel == consts.PodAnnotationQoSLevelDedicatedCores {
298-
cpuBurstPolicy = getOverriddenPodBurstPolicy(dynamicConfig, cpuBurstPolicy)
300+
cpuBurstPolicy = getOverriddenDedicatedCoresPodBurstPolicy(dynamicConfig, cpuBurstPolicy)
301+
} else if qosLevel == consts.PodAnnotationQoSLevelSharedCores {
302+
cpuBurstPolicy = getOverriddenSharedCoresPodBurstPolicy(dynamicConfig, cpuBurstPolicy, isSoleSharedCoresPod)
299303
}
300304

301305
return cpuBurstPolicy, nil
302306
}
303307

304-
// getOverriddenPodBurstPolicy returns the cpu burst policy for a given pod by checking with dynamic config.
305-
// Only pods with cpu burst policy none from their annotations will be overridden.
306-
func getOverriddenPodBurstPolicy(dynamicConfig *dynamic.DynamicAgentConfiguration, originalBurstPolicy string) string {
308+
// getOverriddenDedicatedCoresPodBurstPolicy returns the cpu burst policy for a given dedicated cores pod by checking with
309+
// dynamic config. Only pods with cpu burst policy default from their annotations will be overridden.
310+
func getOverriddenDedicatedCoresPodBurstPolicy(dynamicConfig *dynamic.DynamicAgentConfiguration, originalBurstPolicy string) string {
307311
// return original burst policy if it is not default
308312
if originalBurstPolicy != consts.PodAnnotationCPUEnhancementCPUBurstPolicyDefault {
309313
return originalBurstPolicy
@@ -321,6 +325,30 @@ func getOverriddenPodBurstPolicy(dynamicConfig *dynamic.DynamicAgentConfiguratio
321325
return consts.PodAnnotationCPUEnhancementCPUBurstPolicyDefault
322326
}
323327

328+
// getOverriddenSharedCoresPodBurstPolicy returns the cpu burst policy for a given shared cores pod by checking with
329+
// dynamic config. Pods will have overridden annotations if
330+
// 1. It is the only shared cores pod in the node.
331+
// 2. It has cpu burst policy default from their annotations.
332+
func getOverriddenSharedCoresPodBurstPolicy(dynamicConfig *dynamic.DynamicAgentConfiguration, originalBurstPolicy string,
333+
isSoleSharedCoresPod bool,
334+
) string {
335+
// return original burst policy if it is not default
336+
if originalBurstPolicy != consts.PodAnnotationCPUEnhancementCPUBurstPolicyDefault {
337+
return originalBurstPolicy
338+
}
339+
340+
if dynamicConfig != nil && dynamicConfig.GetDynamicConfiguration().EnableSharedCoresDefaultCPUBurst != nil {
341+
if *dynamicConfig.GetDynamicConfiguration().EnableSharedCoresDefaultCPUBurst && isSoleSharedCoresPod {
342+
return consts.PodAnnotationCPUEnhancementCPUBurstPolicyStatic
343+
} else {
344+
// If EnableSharedCoresDefaultCPUBurst is explicitly false, we will close the cpu burst policy.
345+
return consts.PodAnnotationCPUEnhancementCPUBurstPolicyClosed
346+
}
347+
}
348+
349+
return consts.PodAnnotationCPUEnhancementCPUBurstPolicyDefault
350+
}
351+
324352
// GetPodCPUBurstPercent gets the cpu burst percent of a given pod.
325353
func GetPodCPUBurstPercent(qosConf *generic.QoSConfiguration, pod *v1.Pod, dynamicConfig *dynamic.DynamicAgentConfiguration) (float64, error) {
326354
if pod == nil {
@@ -354,3 +382,22 @@ func getDefaultCPUBurstPercent(dynamicConfig *dynamic.DynamicAgentConfiguration)
354382
func CalculateCPUBurstFromPercent(percent float64, cpuQuota int64) uint64 {
355383
return uint64(float64(cpuQuota) * percent / 100)
356384
}
385+
386+
// IsSoleSharedCoresPod returns true if there is only one shared cores pod in the node.
387+
func IsSoleSharedCoresPod(qosConfig *generic.QoSConfiguration, podList []*v1.Pod, dynamicConfig *dynamic.DynamicAgentConfiguration) bool {
388+
if dynamicConfig != nil && dynamicConfig.GetDynamicConfiguration().EnableSharedCoresDefaultCPUBurst != nil {
389+
if *dynamicConfig.GetDynamicConfiguration().EnableSharedCoresDefaultCPUBurst {
390+
// only calculate number of shared cores pods if EnableSharedCoresDefaultCPUBurst is explicitly enabled.
391+
numSharedCoresPods := 0
392+
for _, pod := range podList {
393+
qosLevel, _ := qosConfig.GetQoSLevel(pod, map[string]string{})
394+
if qosLevel == consts.PodAnnotationQoSLevelSharedCores {
395+
numSharedCoresPods++
396+
}
397+
}
398+
return numSharedCoresPods == 1
399+
}
400+
}
401+
402+
return false
403+
}

0 commit comments

Comments
 (0)