Skip to content

Commit

Permalink
sysfs: fix order of cpu.cache levels in case of cache override
Browse files Browse the repository at this point in the history
Cache level functions, for instance CPU.GetCachesByLevel(), expect
cpu.caches to be sorted by level, the lowest first. This change
ensures that overridden caches follow this ordering, too, no matter in
which order user has spesified them.

Signed-off-by: Antti Kervinen <[email protected]>
  • Loading branch information
askervin committed Oct 21, 2024
1 parent e898b41 commit 1bf9bcd
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/sysfs/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -1727,6 +1727,14 @@ func (sys *system) discoverCacheFromOverrides(cpu *cpu) (bool, error) {
sys.Error("failed to parse cache overrides: %v", err)
return false, err
}
// cpu.caches must be ordered by cache level, the lowest first.
// Sort caches in each CPU by level, then by kind.
for _, caches := range ceo {
sort.Slice(caches, func(i, j int) bool {
return (caches[i].level < caches[j].level ||
(caches[i].level == caches[j].level && caches[i].kind < caches[j].kind))
})
}
cacheEnvOverrides = ceo
}
if caches, ok := cacheEnvOverrides[cpu.id]; ok {
Expand Down

0 comments on commit 1bf9bcd

Please sign in to comment.