Skip to content

Commit 6005e98

Browse files
committed
WIP: minimal CPU to fit IRQ count
Signed-off-by: Francesco Romani <fromani@redhat.com>
1 parent 877818c commit 6005e98

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

pkg/performanceprofile/profilecreator/autosize/autosize.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ import (
3030
// Objective:
3131
// We want to maximize x_w, or, equivalently, minimize x_c
3232

33+
const (
34+
// x86 limit. 256 hardware entries, of those 32 reserved. 256-32 = 224.
35+
// see: https://en.wikipedia.org/wiki/Interrupt_request
36+
maxIRQsPerPhysicalCore int = 224
37+
)
38+
3339
const (
3440
defaultPenaltyWeight float64 = 100.0
3541
defaultReservedRatioInitial float64 = 0.0625 // 1/16. determined empirically. Use only as initial value.
@@ -65,7 +71,7 @@ type Params struct {
6571
}
6672

6773
func (p Params) String() string {
68-
return fmt.Sprintf("cpus=%d offline=%v SMTLevel=%v devices=%d (userNetworking=%v)", p.totalCPUs, p.OfflinedCPUCount, p.smtLevel, p.DeviceCount, p.UserLevelNetworking)
74+
return fmt.Sprintf("cpus=%d offline=%v SMTLevel=%v devices=%d (req=%v userNetworking=%v)", p.totalCPUs, p.OfflinedCPUCount, p.smtLevel, p.DeviceCount, p.MinCPUs(), p.UserLevelNetworking)
6975
}
7076

7177
func setupMachineData(p *Params) error {
@@ -82,6 +88,13 @@ func setupMachineData(p *Params) error {
8288
return nil
8389
}
8490

91+
func (p Params) MinCPUs() int {
92+
if !p.UserLevelNetworking { // TODO explain why
93+
return 0
94+
}
95+
return (p.DeviceCount + (maxIRQsPerPhysicalCore - 1)) / maxIRQsPerPhysicalCore
96+
}
97+
8598
func (p Params) TotalCPUs() int {
8699
return p.totalCPUs
87100
}
@@ -193,6 +206,9 @@ func objective(p Params, x []float64) float64 {
193206
// Don't exceed total CPUs
194207
hardPenalty += defaultPenaltyWeight * math.Pow(math.Max(0, x_c+x_w-float64(p.TotalCPUs())), 2)
195208

209+
// Allocate as minimum what is needed to fit the desired amount of devices, thus IRQs
210+
hardPenalty += defaultPenaltyWeight * math.Pow(math.Max(0, float64(p.MinCPUs())-x_c), 2)
211+
196212
// Meet the control plane/infra requirement to avoid the workload to starve
197213
hardPenalty += defaultPenaltyWeight * math.Pow(math.Max(0, p.controlPlaneRequirement(x_w)-x_c), 2)
198214

pkg/performanceprofile/profilecreator/cmd/root.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ func NewRootCommand() *cobra.Command {
171171
}
172172
if isAutosizeEnabled(pcArgs) {
173173
params := autosize.Params{
174+
DeviceCount: pcArgs.DeviceCount,
174175
OfflinedCPUCount: pcArgs.OfflinedCPUCount,
175176
UserLevelNetworking: (pcArgs.UserLevelNetworking != nil && *pcArgs.UserLevelNetworking),
176177
MachineData: nodesHandlers[0], // assume all nodes equal, pick the easiest
@@ -433,6 +434,7 @@ type ProfileCreatorArgs struct {
433434
PerPodPowerManagement *bool `json:"per-pod-power-management,omitempty"`
434435
EnableHardwareTuning bool `json:"enable-hardware-tuning,omitempty"`
435436
Autosize *bool `json:"autosize,omitempty"`
437+
DeviceCount int `json:"device-count,omitempty"`
436438
// internal only this argument not passed by the user
437439
// but detected automatically
438440
createForHypershift bool
@@ -454,6 +456,7 @@ func (pca *ProfileCreatorArgs) AddFlags(flags *pflag.FlagSet) {
454456
flags.BoolVar(&pca.EnableHardwareTuning, "enable-hardware-tuning", false, "Enable setting maximum cpu frequencies")
455457
flags.StringVar(&pca.NodePoolName, "node-pool-name", "", "Node pool name corresponding to the target machines (HyperShift only)")
456458
flags.BoolVar(pca.Autosize, "autosize", false, "autosize the control plane")
459+
flags.IntVar(&pca.DeviceCount, "device-count", 0, "Number of expected devices (TODO)")
457460
}
458461

459462
func makePerformanceProfileFrom(profileData ProfileData) (runtime.Object, error) {

0 commit comments

Comments
 (0)