-
Notifications
You must be signed in to change notification settings - Fork 91
/
util_based.go
71 lines (60 loc) · 2.96 KB
/
util_based.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
Copyright 2022 The Katalyst Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cpuheadroom
import (
"github.com/spf13/pflag"
"github.com/kubewharf/katalyst-core/pkg/config/agent/dynamic/adminqos/reclaimedresource/cpuheadroom"
)
const (
defaultEnable = false
defaultTargetReclaimedCoreUtilization = 0.6
defaultMaxReclaimedCoreUtilization = 0
defaultMaxOversoldRate = 1.2
defaultMaxHeadroomCapacityRate = 1.
)
type CPUHeadroomUtilBasedOptions struct {
Enable bool
TargetReclaimedCoreUtilization float64
MaxReclaimedCoreUtilization float64
MaxOversoldRate float64
MaxHeadroomCapacityRate float64
}
func NewCPUHeadroomUtilBasedOptions() *CPUHeadroomUtilBasedOptions {
return &CPUHeadroomUtilBasedOptions{
Enable: defaultEnable,
TargetReclaimedCoreUtilization: defaultTargetReclaimedCoreUtilization,
MaxReclaimedCoreUtilization: defaultMaxReclaimedCoreUtilization,
MaxOversoldRate: defaultMaxOversoldRate,
MaxHeadroomCapacityRate: defaultMaxHeadroomCapacityRate,
}
}
func (o *CPUHeadroomUtilBasedOptions) AddFlags(fs *pflag.FlagSet) {
fs.BoolVar(&o.Enable, "cpu-headroom-util-based-enable", o.Enable,
"show whether enable utilization based cpu headroom policy")
fs.Float64Var(&o.TargetReclaimedCoreUtilization, "cpu-headroom-target-reclaimed-core-utilization", o.TargetReclaimedCoreUtilization,
"the target reclaimed core utilization to be used for calculating the oversold cpu headroom")
fs.Float64Var(&o.MaxReclaimedCoreUtilization, "cpu-headroom-max-reclaimed-core-utilization", o.MaxReclaimedCoreUtilization,
"the max reclaimed core utilization to be used for calculating the oversold cpu headroom, if zero means no limit")
fs.Float64Var(&o.MaxOversoldRate, "cpu-headroom-max-oversold-rate", o.MaxOversoldRate,
"the max oversold rate of cpu headroom to the actual size of reclaimed_cores pool")
fs.Float64Var(&o.MaxHeadroomCapacityRate, "cpu-headroom-max-capacity-rate", o.MaxHeadroomCapacityRate,
"the max headroom capacity rate of cpu headroom to the total cpu capacity of node")
}
func (o *CPUHeadroomUtilBasedOptions) ApplyTo(c *cpuheadroom.CPUUtilBasedConfiguration) error {
c.Enable = o.Enable
c.TargetReclaimedCoreUtilization = o.TargetReclaimedCoreUtilization
c.MaxReclaimedCoreUtilization = o.MaxReclaimedCoreUtilization
c.MaxOversoldRate = o.MaxOversoldRate
c.MaxHeadroomCapacityRate = o.MaxHeadroomCapacityRate
return nil
}