Skip to content

Commit

Permalink
cpuallocator: make idle package allocation core type aware.
Browse files Browse the repository at this point in the history
When allocating idle packages, consider a package idle if all
online cores *with preferred priorities* for that allocation
are idle. Also, from the picked packages take cores with this
same restriction. In particular, on hybrid architectures with
multiple core types, this will exclude
  - E-cores from allocations with Priority{Normal,High} preference
  - P-cores from allocations with PriorityLow preference

Signed-off-by: Krisztian Litkey <[email protected]>
  • Loading branch information
klihub committed Mar 18, 2024
1 parent c1e2852 commit f2065e1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/cpuallocator/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,12 @@ func (a *allocatorHelper) takeIdlePackages() {
// pick idle packages
pkgs := pickIds(a.sys.PackageIDs(),
func(id idset.ID) bool {
// Consider a package idle if all online preferred CPUs are idle.
// In particular, on hybrid core architectures exclude
// - exclude E-cores from allocations with <= PriorityNormal preference
// - exclude P-cores from allocations with > PriorityLow preferences
cset := a.topology.pkg[id].Difference(offline)
cset = cset.Intersection(a.topology.cpuPriorities[a.prefer])
return cset.Intersection(a.from).Equals(cset)
})

Expand All @@ -178,6 +183,7 @@ func (a *allocatorHelper) takeIdlePackages() {
// take as many idle packages as we need/can
for _, id := range pkgs {
cset := a.topology.pkg[id].Difference(offline)
cset = cset.Intersection(a.topology.cpuPriorities[a.prefer])
a.Debug(" => considering package %v (#%s)...", id, cset)
if a.cnt >= cset.Size() {
a.Debug(" => taking package %v...", id)
Expand Down Expand Up @@ -704,9 +710,17 @@ func (c *topologyCache) discoverCPUPriorities(sys sysfs.System) {
cpuPriorities = c.discoverCpufreqPriority(sys, id)
}

ecores := c.kind[sysfs.EfficientCore]
ocores := sys.OnlineCPUs().Difference(ecores)

for p, cpus := range cpuPriorities {
source := map[bool]string{true: "sst", false: "cpufreq"}[sstActive]
cset := sysfs.CPUSetFromIDSet(idset.NewIDSet(cpus...))

if p != int(PriorityLow) && ocores.Size() > 0 {
cset = cset.Difference(ecores)
}

log.Debug("package #%d (%s): %d %s priority cpus (%v)", id, source, len(cpus), CPUPriority(p), cset)
prio[p] = prio[p].Union(cset)
}
Expand Down

0 comments on commit f2065e1

Please sign in to comment.