github.com/kubewharf/katalyst-core@v0.5.3/pkg/agent/orm/topology/topologyhint.go (about) 1 /* 2 Copyright 2022 The Katalyst Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package topology 18 19 import "github.com/kubewharf/katalyst-core/pkg/util/bitmask" 20 21 type podTopologyHints map[string]map[string]TopologyHint 22 23 // TopologyHint is a struct containing the NUMANodeAffinity for a Container 24 type TopologyHint struct { 25 NUMANodeAffinity bitmask.BitMask 26 // Preferred is set to true when the NUMANodeAffinity encodes a preferred 27 // allocation for the Container. It is set to false otherwise. 28 Preferred bool 29 } 30 31 // IsEqual checks if TopologyHint are equal 32 func (th *TopologyHint) IsEqual(topologyHint TopologyHint) bool { 33 if th.Preferred == topologyHint.Preferred { 34 if th.NUMANodeAffinity == nil || topologyHint.NUMANodeAffinity == nil { 35 return th.NUMANodeAffinity == topologyHint.NUMANodeAffinity 36 } 37 return th.NUMANodeAffinity.IsEqual(topologyHint.NUMANodeAffinity) 38 } 39 return false 40 } 41 42 // LessThan checks if TopologyHint `a` is less than TopologyHint `b` 43 // this means that either `a` is a preferred hint and `b` is not 44 // or `a` NUMANodeAffinity attribute is narrower than `b` NUMANodeAffinity attribute. 45 func (th *TopologyHint) LessThan(other TopologyHint) bool { 46 if th.Preferred != other.Preferred { 47 return th.Preferred 48 } 49 return th.NUMANodeAffinity.IsNarrowerThan(other.NUMANodeAffinity) 50 } 51 52 // DeepCopyTopologyHints returns deep copied hints of source hints 53 func DeepCopyTopologyHints(srcHints []TopologyHint) []TopologyHint { 54 if srcHints == nil { 55 return nil 56 } 57 58 dstHints := make([]TopologyHint, 0, len(srcHints)) 59 60 return append(dstHints, srcHints...) 61 }