Skip to content

Commit

Permalink
carry: add support for missing uncore cache
Browse files Browse the repository at this point in the history
no uncore cache can be treated as all CPUs belonging
to the same group, so alignment is implicit and always guaranteed.

Signed-off-by: Francesco Romani <[email protected]>
  • Loading branch information
ffromani committed Oct 1, 2024
1 parent c653eed commit 6a21e34
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/kubelet/cm/cpumanager/cpu_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func NewManager(cpuPolicyName string, cpuPolicyOptions map[string]string, reconc
var policy Policy
var err error

klog.InfoS("LLC alignment available", "version", "2024093001")
klog.InfoS("LLC alignment available", "version", "2024100101")

switch policyName(cpuPolicyName) {

Expand Down
15 changes: 14 additions & 1 deletion pkg/kubelet/cm/cpumanager/topology/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func Discover(machineInfo *cadvisorapi.MachineInfo) (*CPUTopology, error) {
CoreID: coreID,
SocketID: core.SocketID,
NUMANodeID: node.Id,
UnCoreCacheID: core.UncoreCaches[0].Id,
UnCoreCacheID: getUncoreCacheID(core.UncoreCaches),
}
}
} else {
Expand All @@ -357,6 +357,19 @@ func Discover(machineInfo *cadvisorapi.MachineInfo) (*CPUTopology, error) {
}, nil
}

const (
NullUncoreCacheID int = 65535 // TODO: "high enough" value to signal "impossible"
)

func getUncoreCacheID(uncoreCaches []cadvisorapi.Cache) int {
if len(uncoreCaches) < 1 {
return NullUncoreCacheID
}
// Even though cadvisor API returns a slice, we only expect either 0 or 1 uncore caches,
// so everything past first entry should be discarded
return uncoreCaches[0].Id
}

// getUniqueCoreID computes coreId as the lowest cpuID
// for a given Threads []int slice. This will assure that coreID's are
// platform unique (opposite to what cAdvisor reports)
Expand Down
50 changes: 50 additions & 0 deletions pkg/kubelet/cm/cpumanager/topology/topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1379,3 +1379,53 @@ func TestCPUNUMANodeID(t *testing.T) {
})
}
}

func Test_getUncoreCacheID(t *testing.T) {
tests := []struct {
name string
uncoreCaches []cadvisorapi.Cache
expectedID int
}{
{
name: "nil",
expectedID: NullUncoreCacheID,
},
{
name: "empty",
uncoreCaches: []cadvisorapi.Cache{},
expectedID: NullUncoreCacheID,
},
{
name: "one-entry",
uncoreCaches: []cadvisorapi.Cache{
{
Id: 42,
},
},
expectedID: 42,
},
{
name: "multi-entries",
uncoreCaches: []cadvisorapi.Cache{
{
Id: 1,
},
{
Id: 12,
},
{
Id: 42,
},
},
expectedID: 1,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := getUncoreCacheID(tt.uncoreCaches)
if got != tt.expectedID {
t.Errorf("getUncoreCacheID = %v expected %v", got, tt.expectedID)
}
})
}
}

0 comments on commit 6a21e34

Please sign in to comment.