github.com/kubewharf/katalyst-core@v0.5.3/cmd/katalyst-agent/app/options/qrm/cpu_plugin.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 qrm 18 19 import ( 20 cliflag "k8s.io/component-base/cli/flag" 21 22 "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" 23 qrmconfig "github.com/kubewharf/katalyst-core/pkg/config/agent/qrm" 24 ) 25 26 type CPUOptions struct { 27 PolicyName string 28 ReservedCPUCores int 29 SkipCPUStateCorruption bool 30 31 CPUDynamicPolicyOptions 32 CPUNativePolicyOptions 33 } 34 35 type CPUDynamicPolicyOptions struct { 36 EnableCPUAdvisor bool 37 EnableCPUPressureEviction bool 38 LoadPressureEvictionSkipPools []string 39 EnableSyncingCPUIdle bool 40 EnableCPUIdle bool 41 } 42 43 type CPUNativePolicyOptions struct { 44 EnableFullPhysicalCPUsOnly bool 45 CPUAllocationOption string 46 } 47 48 func NewCPUOptions() *CPUOptions { 49 return &CPUOptions{ 50 PolicyName: "dynamic", 51 ReservedCPUCores: 0, 52 SkipCPUStateCorruption: false, 53 CPUDynamicPolicyOptions: CPUDynamicPolicyOptions{ 54 EnableCPUAdvisor: false, 55 EnableCPUPressureEviction: false, 56 EnableSyncingCPUIdle: false, 57 EnableCPUIdle: false, 58 LoadPressureEvictionSkipPools: []string{ 59 state.PoolNameReclaim, 60 state.PoolNameDedicated, 61 state.PoolNameFallback, 62 state.PoolNameReserve, 63 }, 64 }, 65 CPUNativePolicyOptions: CPUNativePolicyOptions{ 66 EnableFullPhysicalCPUsOnly: false, 67 CPUAllocationOption: "packed", 68 }, 69 } 70 } 71 72 func (o *CPUOptions) AddFlags(fss *cliflag.NamedFlagSets) { 73 fs := fss.FlagSet("cpu_resource_plugin") 74 75 fs.StringVar(&o.PolicyName, "cpu-resource-plugin-policy", 76 o.PolicyName, "The policy cpu resource plugin should use") 77 fs.BoolVar(&o.EnableCPUAdvisor, "cpu-resource-plugin-advisor", 78 o.EnableCPUAdvisor, "Whether cpu resource plugin should enable sys-advisor") 79 fs.IntVar(&o.ReservedCPUCores, "cpu-resource-plugin-reserved", 80 o.ReservedCPUCores, "The total cores cpu resource plugin should reserve") 81 fs.BoolVar(&o.SkipCPUStateCorruption, "skip-cpu-state-corruption", 82 o.SkipCPUStateCorruption, "if set true, we will skip cpu state corruption") 83 fs.BoolVar(&o.EnableCPUPressureEviction, "enable-cpu-pressure-eviction", o.EnableCPUPressureEviction, 84 "if set true, it can enable cpu-related eviction, such as cpu pressure eviction and cpu suppression eviction") 85 fs.StringSliceVar(&o.LoadPressureEvictionSkipPools, "load-pressure-eviction-skip-pools", o.LoadPressureEvictionSkipPools, 86 "the pool in this list will be ignored when check load pressure") 87 fs.BoolVar(&o.EnableSyncingCPUIdle, "enable-syncing-cpu-idle", 88 o.EnableSyncingCPUIdle, "if set true, we will sync specific cgroup paths with value specified by --enable-cpu-idle option") 89 fs.BoolVar(&o.EnableCPUIdle, "enable-cpu-idle", o.EnableCPUIdle, 90 "if set true, we will enable cpu idle for "+ 91 "specific cgroup paths and it requires --enable-syncing-cpu-idle=true to make effect") 92 fs.StringVar(&o.CPUAllocationOption, "cpu-allocation-option", 93 o.CPUAllocationOption, "The allocation option of cpu (packed/distributed). The default value is packed."+ 94 "in cases where more than one NUMA node is required to satisfy the allocation.") 95 fs.BoolVar(&o.EnableFullPhysicalCPUsOnly, "enable-full-physical-cpus-only", 96 o.EnableFullPhysicalCPUsOnly, "if set true, we will enable extra allocation restrictions to "+ 97 "avoid different containers to possibly end up on the same core.") 98 } 99 100 func (o *CPUOptions) ApplyTo(conf *qrmconfig.CPUQRMPluginConfig) error { 101 conf.PolicyName = o.PolicyName 102 conf.EnableCPUAdvisor = o.EnableCPUAdvisor 103 conf.ReservedCPUCores = o.ReservedCPUCores 104 conf.SkipCPUStateCorruption = o.SkipCPUStateCorruption 105 conf.EnableCPUPressureEviction = o.EnableCPUPressureEviction 106 conf.LoadPressureEvictionSkipPools = o.LoadPressureEvictionSkipPools 107 conf.EnableSyncingCPUIdle = o.EnableSyncingCPUIdle 108 conf.EnableCPUIdle = o.EnableCPUIdle 109 conf.EnableFullPhysicalCPUsOnly = o.EnableFullPhysicalCPUsOnly 110 conf.CPUAllocationOption = o.CPUAllocationOption 111 return nil 112 }