Skip to content

Commit

Permalink
Merge pull request #340 from klihub/fixes/non-uniform-threadcount
Browse files Browse the repository at this point in the history
sysfs: allow non-uniform thread count.
  • Loading branch information
fmuyassarov authored Jun 25, 2024
2 parents b98a12a + f1b7ea0 commit c1bfca2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
10 changes: 5 additions & 5 deletions cmd/plugins/topology-aware/policy/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,11 @@ func (fake *mockSystem) SocketCount() int {
func (fake *mockSystem) NUMANodeCount() int {
return len(fake.nodes)
}
func (fake *mockSystem) ThreadCount() int {
if fake.cpuCount == 0 {
return 1
}
return fake.cpuCount
func (fake *mockSystem) MinThreadCount() int {
return 2
}
func (fake *mockSystem) MaxThreadCount() int {
return 2
}
func (fake *mockSystem) PackageIDs() []idset.ID {
ids := make([]idset.ID, len(fake.nodes))
Expand Down
33 changes: 21 additions & 12 deletions pkg/sysfs/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ type System interface {
SocketCount() int
CPUCount() int
NUMANodeCount() int
ThreadCount() int
MinThreadCount() int
MaxThreadCount() int
CPUSet() cpuset.CPUSet
Package(id idset.ID) CPUPackage
Node(id idset.ID) Node
Expand Down Expand Up @@ -136,7 +137,8 @@ type system struct {
onlineCPUs idset.IDSet // set of online CPUs
isolatedCPUs idset.IDSet // set of isolated CPUs
coreKindCPUs map[CoreKind]idset.IDSet // CPU cores by kind (P-/E-cores)
threads int // hyperthreads per core
minThreads int // min. hyperthreads per core
maxThreads int // max. hyperthreads per core
}

// CPUPackage is a physical package (a collection of CPUs).
Expand Down Expand Up @@ -605,9 +607,14 @@ func (sys *system) NUMANodeCount() int {
return cnt
}

// ThreadCount returns the number of threads per core discovered.
func (sys *system) ThreadCount() int {
return sys.threads
// MinThreadCount returns the minimum number of threads per core discovered.
func (sys *system) MinThreadCount() int {
return sys.minThreads
}

// MaxThreadCount returns the maximum number of threads per core discovered.
func (sys *system) MaxThreadCount() int {
return sys.maxThreads
}

// CPUSet gets the ids of all CPUs present in the system as a CPUSet.
Expand Down Expand Up @@ -913,15 +920,17 @@ func (sys *system) discoverCPU(path string) error {
return fmt.Errorf("exactly one node per cpu allowed")
}

if sys.threads < 1 {
sys.threads = 1
}
if cpu.threads.Size() > sys.threads {
sys.threads = cpu.threads.Size()
}

sys.cpus[cpu.id] = cpu

if threadCnt := cpu.threads.Size(); threadCnt > 0 {
if sys.minThreads == 0 || threadCnt < sys.minThreads {
sys.minThreads = threadCnt
}
if sys.maxThreads == 0 || threadCnt > sys.maxThreads {
sys.maxThreads = threadCnt
}
}

if (sys.flags & DiscoverCache) != 0 {
entries, _ := filepath.Glob(filepath.Join(path, "cache/index[0-9]*"))
for _, entry := range entries {
Expand Down

0 comments on commit c1bfca2

Please sign in to comment.