github.com/kubewharf/katalyst-core@v0.5.3/cmd/katalyst-agent/app/options/util/vendor_aware.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 util 18 19 import ( 20 "fmt" 21 22 cpu "github.com/klauspost/cpuid/v2" 23 ) 24 25 const ( 26 DefaultConfigKey = "default" 27 28 CPUVendorAMD = "AMD" 29 CPUVendorIntel = "Intel" 30 ) 31 32 var supportCPUVendors = map[cpu.Vendor]string{ 33 cpu.AMD: CPUVendorAMD, 34 cpu.Intel: CPUVendorIntel, 35 } 36 37 func GetVendorAwareStringConfiguration(vendorConfMap map[string]string) (string, error) { 38 var result string 39 if defaultValue, ok := vendorConfMap[DefaultConfigKey]; ok { 40 result = defaultValue 41 } else { 42 return "", fmt.Errorf("vendor aware configuration must have a default value") 43 } 44 45 vendorID := cpu.CPU.VendorID 46 if vendorKey, ok := supportCPUVendors[vendorID]; ok { 47 if value, exist := vendorConfMap[vendorKey]; exist { 48 result = value 49 } 50 } 51 return result, nil 52 } 53 54 func GetVendorAwareInt64Configuration(vendorConfMap map[string]int64) (int64, error) { 55 var result int64 56 if defaultValue, ok := vendorConfMap[DefaultConfigKey]; ok { 57 result = defaultValue 58 } else { 59 return 0, fmt.Errorf("vendor aware configuration must have a default value") 60 } 61 62 vendorID := cpu.CPU.VendorID 63 if vendorKey, ok := supportCPUVendors[vendorID]; ok { 64 if value, exist := vendorConfMap[vendorKey]; exist { 65 result = value 66 } 67 } 68 return result, nil 69 }