Skip to content

Commit 58c0c5f

Browse files
committed
WIP: profilecreator: autosize: scaffolding
WIP TBD Signed-off-by: Francesco Romani <fromani@redhat.com>
1 parent 2f5a44d commit 58c0c5f

File tree

2 files changed

+52
-5
lines changed

2 files changed

+52
-5
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package autosize
2+
3+
import "github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/profilecreator"
4+
5+
// shortcut
6+
var Alert = profilecreator.Alert
7+
8+
type Params struct {
9+
NodePoolSize int
10+
OfflinedCPUCount int
11+
}
12+
13+
type Values struct {
14+
ReservedCPUCount int
15+
}
16+
17+
type Env struct{}
18+
19+
func DefaultEnv() Env {
20+
return Env{}
21+
}
22+
23+
type Score struct{}
24+
25+
func Compute(env Env, params Params) (Values, Score, error) {
26+
return Values{}, Score{}, nil
27+
}

pkg/performanceprofile/profilecreator/cmd/root.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
machineconfigv1 "github.com/openshift/api/machineconfiguration/v1"
3838
performancev2 "github.com/openshift/cluster-node-tuning-operator/pkg/apis/performanceprofile/v2"
3939
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/profilecreator"
40+
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/profilecreator/autosize"
4041
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/profilecreator/cmd/hypershift"
4142
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/profilecreator/serialize"
4243
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/profilecreator/toleration"
@@ -116,10 +117,10 @@ func NewRootCommand() *cobra.Command {
116117
pcArgs := &ProfileCreatorArgs{
117118
UserLevelNetworking: ptr.To(false),
118119
PerPodPowerManagement: ptr.To(false),
120+
EnableAutosizing: ptr.To(false),
119121
}
120122

121123
var requiredFlags = []string{
122-
"reserved-cpu-count",
123124
"rt-kernel",
124125
"must-gather-dir-path",
125126
}
@@ -164,10 +165,26 @@ func NewRootCommand() *cobra.Command {
164165
if err != nil {
165166
return fmt.Errorf("targeted nodes differ: %w", err)
166167
}
168+
169+
sizing := autosize.Values{
170+
ReservedCPUCount: pcArgs.ReservedCPUCount,
171+
}
172+
if pcArgs.EnableAutosizing != nil && *pcArgs.EnableAutosizing {
173+
params := autosize.Params{
174+
OfflinedCPUCount: pcArgs.OfflinedCPUCount,
175+
UserLevelNetworking: (pcArgs.UserLevelNetworking != nil && *pcArgs.UserLevelNetworking),
176+
MachineData: nodesHandlers[0], // assume all nodes equal, pick the easiest
177+
}
178+
sizing, _, err = autosize.Compute(autosize.DefaultEnv(), params)
179+
if err != nil {
180+
return fmt.Errorf("failed to autosize the cluster values: %v", err)
181+
}
182+
}
183+
167184
// We make sure that the matched Nodes are the same
168185
// Assumption here is moving forward matchedNodes[0] is representative of how all the nodes are
169186
// same from hardware topology point of view
170-
profileData, err := makeProfileDataFrom(nodesHandlers[0], pcArgs)
187+
profileData, err := makeProfileDataFrom(nodesHandlers[0], pcArgs, sizing)
171188
if err != nil {
172189
return fmt.Errorf("failed to make profile data from node handler: %w", err)
173190
}
@@ -299,12 +316,13 @@ func makeClusterData(mustGatherDirPath string, createForHypershift bool) (Cluste
299316
return clusterData, nil
300317
}
301318

302-
func makeProfileDataFrom(nodeHandler *profilecreator.GHWHandler, args *ProfileCreatorArgs) (*ProfileData, error) {
319+
func makeProfileDataFrom(nodeHandler *profilecreator.GHWHandler, args *ProfileCreatorArgs, sizing autosize.Values) (*ProfileData, error) {
303320
systemInfo, err := nodeHandler.GatherSystemInfo()
304321
if err != nil {
305322
return nil, fmt.Errorf("failed to compute get system information: %v", err)
306323
}
307-
reservedCPUs, isolatedCPUs, offlinedCPUs, err := profilecreator.CalculateCPUSets(systemInfo, args.ReservedCPUCount, args.OfflinedCPUCount, args.SplitReservedCPUsAcrossNUMA, args.DisableHT, args.PowerConsumptionMode == ultraLowLatency)
324+
325+
reservedCPUs, isolatedCPUs, offlinedCPUs, err := profilecreator.CalculateCPUSets(systemInfo, sizing.ReservedCPUCount, args.OfflinedCPUCount, args.SplitReservedCPUsAcrossNUMA, args.DisableHT, args.PowerConsumptionMode == ultraLowLatency)
308326
if err != nil {
309327
return nil, fmt.Errorf("failed to compute the reserved and isolated CPUs: %v", err)
310328
}
@@ -407,13 +425,14 @@ type ProfileCreatorArgs struct {
407425
TMPolicy string `json:"topology-manager-policy"`
408426
PerPodPowerManagement *bool `json:"per-pod-power-management,omitempty"`
409427
EnableHardwareTuning bool `json:"enable-hardware-tuning,omitempty"`
428+
EnableAutosizing *bool `json:"enable-autosizing,omitempty"`
410429
// internal only this argument not passed by the user
411430
// but detected automatically
412431
createForHypershift bool
413432
}
414433

415434
func (pca *ProfileCreatorArgs) AddFlags(flags *pflag.FlagSet) {
416-
flags.IntVar(&pca.ReservedCPUCount, "reserved-cpu-count", 0, "Number of reserved CPUs (required)")
435+
flags.IntVar(&pca.ReservedCPUCount, "reserved-cpu-count", 0, "Number of reserved CPUs")
417436
flags.IntVar(&pca.OfflinedCPUCount, "offlined-cpu-count", 0, "Number of offlined CPUs")
418437
flags.BoolVar(&pca.SplitReservedCPUsAcrossNUMA, "split-reserved-cpus-across-numa", false, "Split the Reserved CPUs across NUMA nodes")
419438
flags.StringVar(&pca.MCPName, "mcp-name", "", "MCP name corresponding to the target machines (required)")
@@ -427,6 +446,7 @@ func (pca *ProfileCreatorArgs) AddFlags(flags *pflag.FlagSet) {
427446
flags.BoolVar(pca.PerPodPowerManagement, "per-pod-power-management", false, "Enable Per Pod Power Management")
428447
flags.BoolVar(&pca.EnableHardwareTuning, "enable-hardware-tuning", false, "Enable setting maximum cpu frequencies")
429448
flags.StringVar(&pca.NodePoolName, "node-pool-name", "", "Node pool name corresponding to the target machines (HyperShift only)")
449+
flags.BoolVar(pca.EnableAutosizing, "autosize", false, "autosize the control plane")
430450
}
431451

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

0 commit comments

Comments
 (0)