Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sysfs: allow non-uniform thread count. #340

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
klihub marked this conversation as resolved.
Show resolved Hide resolved
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