node: e2e: topology-mgr: Determine threads per core

Signed-off-by: Swati Sehgal <swsehgal@redhat.com>
This commit is contained in:
Swati Sehgal 2023-10-23 12:01:28 +01:00
parent 145b84b0b1
commit e1f5eb3f14
2 changed files with 17 additions and 4 deletions

View File

@ -41,7 +41,7 @@ var _ = SIGDescribe("Topology Manager Metrics [Serial] [Feature:TopologyManager]
ginkgo.Context("when querying /metrics", func() {
var oldCfg *kubeletconfig.KubeletConfiguration
var testPod *v1.Pod
var cpusNumPerNUMA, numaNodes int
var cpusNumPerNUMA, numaNodes, threadsPerCore int
ginkgo.BeforeEach(func(ctx context.Context) {
var err error
@ -50,7 +50,7 @@ var _ = SIGDescribe("Topology Manager Metrics [Serial] [Feature:TopologyManager]
framework.ExpectNoError(err)
}
numaNodes, cpusNumPerNUMA = hostCheck()
numaNodes, cpusNumPerNUMA, threadsPerCore = hostCheck()
// It is safe to assume that the CPUs are distributed equally across
// NUMA nodes and therefore number of CPUs on all NUMA nodes are same
@ -58,6 +58,7 @@ var _ = SIGDescribe("Topology Manager Metrics [Serial] [Feature:TopologyManager]
framework.Logf("numaNodes on the system %d", numaNodes)
framework.Logf("CPUs per NUMA on the system %d", cpusNumPerNUMA)
framework.Logf("Threads per Core on the system %d", threadsPerCore)
policy := topologymanager.PolicySingleNumaNode
scope := podScopeTopology
@ -151,7 +152,7 @@ var _ = SIGDescribe("Topology Manager Metrics [Serial] [Feature:TopologyManager]
})
})
func hostCheck() (int, int) {
func hostCheck() (int, int, int) {
// this is a very rough check. We just want to rule out system that does NOT have
// multi-NUMA nodes or at least 4 cores
@ -165,7 +166,9 @@ func hostCheck() (int, int) {
e2eskipper.Skipf("this test is intended to be run on a system with at least %d cores per socket", minCoreCount)
}
return numaNodes, coreCount
threadsPerCore := detectThreadPerCore()
return numaNodes, coreCount, threadsPerCore
}
func checkMetricValueGreaterThan(value interface{}) types.GomegaMatcher {

View File

@ -88,6 +88,16 @@ func detectCoresPerSocket() int {
return coreCount
}
func detectThreadPerCore() int {
outData, err := exec.Command("/bin/sh", "-c", "lscpu | grep \"Thread(s) per core:\" | cut -d \":\" -f 2").Output()
framework.ExpectNoError(err)
threadCount, err := strconv.Atoi(strings.TrimSpace(string(outData)))
framework.ExpectNoError(err)
return threadCount
}
func makeContainers(ctnCmd string, ctnAttributes []tmCtnAttribute) (ctns []v1.Container) {
for _, ctnAttr := range ctnAttributes {
ctn := v1.Container{