@@ -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.
325353func 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)
354382func 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