1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2025-03-28 02:37:11 +00:00

Merge pull request #235 from marquiz/devel/sst-bf

source/cpu: detect SST-BF
This commit is contained in:
Kubernetes Prow Robot 2019-04-12 05:24:46 -07:00 committed by GitHub
commit b3c942e47a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 157 additions and 23 deletions

View file

@ -213,9 +213,10 @@ discovers CPU related features that are actually enabled, whereas CPUID only
reports *supported* CPU capabilities (i.e. a capability might be supported but
not enabled) as reported by the `cpuid` instruction.
| Feature name | Description |
| ----------------------- | -------------------------------------------------- |
| hardware_multithreading | Hardware multithreading, such as Intel HTT, enabled (number of locical CPUs is greater than physical CPUs)
| Feature | Attribute | Description |
| ----------------------- | -------------- | ----------------------------------|
| hardware_multithreading | <br> | Hardware multithreading, such as Intel HTT, enabled (number of locical CPUs is greater than physical CPUs)
| power | sst_bf.enabled | Intel SST-BF ([Intel Speed Select Technology][intel-sst] - Base frequency) enabled
### X86 CPUID Features (Partial List)
@ -643,6 +644,7 @@ A demo on the benefits of using node feature discovery can be found in [demo](de
[cpuid]: http://man7.org/linux/man-pages/man4/cpuid.4.html
[intel-rdt]: http://www.intel.com/content/www/us/en/architecture-and-technology/resource-director-technology.html
[intel-pstate]: https://www.kernel.org/doc/Documentation/cpu-freq/intel-pstate.txt
[intel-sst]: https://www.intel.com/content/www/us/en/architecture-and-technology/speed-select-technology-article.html
[sriov]: http://www.intel.com/content/www/us/en/pci-express/pci-sig-sr-iov-primer-sr-iov-technology-paper.html
[docker-down]: https://docs.docker.com/engine/installation
[golang-down]: https://golang.org/dl

29
pkg/cpuid/cpuid_amd64.go Normal file
View file

@ -0,0 +1,29 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cpuid
type CpuidRet struct {
EAX, EBX, ECX, EDX uint32
}
func Cpuid(eax, ecx uint32) *CpuidRet {
r := &CpuidRet{}
r.EAX, r.EBX, r.ECX, r.EDX = cpuidAsm(eax, ecx)
return r
}
func cpuidAsm(eax_arg, ecx_arg uint32) (eax, ebx, ecx, edx uint32)

View file

@ -17,13 +17,17 @@ limitations under the License.
package cpu
import (
"fmt"
"io/ioutil"
"log"
"path"
"sigs.k8s.io/node-feature-discovery/source"
)
const (
cpuDevicesBaseDir = "/sys/bus/cpu/devices"
)
// Implement FeatureSource interface
type Source struct{}
@ -35,24 +39,32 @@ func (s Source) Discover() (source.Features, error) {
// Check if hyper-threading seems to be enabled
found, err := haveThreadSiblings()
if err != nil {
return nil, fmt.Errorf("Failed to detect hyper-threading: %v", err)
log.Printf("ERROR: failed to detect hyper-threading: %v", err)
} else if found {
features["hardware_multithreading"] = true
}
// Check SST-BF
found, err = discoverSSTBF()
if err != nil {
log.Printf("ERROR: failed to detect SST-BF: %v", err)
} else if found {
features["power.sst_bf.enabled"] = true
}
return features, nil
}
// Check if any (online) CPUs have thread siblings
func haveThreadSiblings() (bool, error) {
const baseDir = "/sys/bus/cpu/devices"
files, err := ioutil.ReadDir(baseDir)
files, err := ioutil.ReadDir(cpuDevicesBaseDir)
if err != nil {
return false, err
}
for _, file := range files {
// Try to read siblings from topology
siblings, err := ioutil.ReadFile(path.Join(baseDir, file.Name(), "topology/thread_siblings_list"))
siblings, err := ioutil.ReadFile(path.Join(cpuDevicesBaseDir, file.Name(), "topology/thread_siblings_list"))
if err != nil {
return false, err
}

76
source/cpu/power_amd64.go Normal file
View file

@ -0,0 +1,76 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cpu
import (
"fmt"
"io/ioutil"
"os"
"path"
"strconv"
"strings"
"sigs.k8s.io/node-feature-discovery/pkg/cpuid"
)
const (
// CPUID EAX input values
LEAF_PROCESSOR_FREQUENCY_INFORMATION = 0x16
)
func discoverSSTBF() (bool, error) {
// Get processor's "nominal base frequency" (in MHz) from CPUID
freqInfo := cpuid.Cpuid(LEAF_PROCESSOR_FREQUENCY_INFORMATION, 0)
nominalBaseFrequency := int(freqInfo.EAX)
// Loop over all CPUs in the system
files, err := ioutil.ReadDir(cpuDevicesBaseDir)
if err != nil {
return false, err
}
for _, file := range files {
// Try to read effective base frequency of each cpu in the system
filePath := path.Join(cpuDevicesBaseDir, file.Name(), "cpufreq/base_frequency")
data, err := ioutil.ReadFile(filePath)
if os.IsNotExist(err) {
// Ignore missing file and continue to check other CPUs
continue
} else if err != nil {
return false, err
}
effectiveBaseFreq, err := strconv.Atoi(strings.TrimSpace(string(data)))
if err != nil {
return false, fmt.Errorf("non-integer value of %q: %v", filePath, err)
}
// Sanity check: Return an error (we don't have enough information to
// make a decision) if we were able to read effective base frequency,
// but, CPUID didn't support frequency info
if nominalBaseFrequency == 0 {
return false, fmt.Errorf("failed to determine if SST-BF is enabled: nominal base frequency info is missing")
}
// If the effective base freq of a CPU is greater than the nominal
// base freq, we determine that SST-BF has been enabled
if effectiveBaseFreq/1000 > nominalBaseFrequency {
return true, nil
}
}
return false, nil
}

23
source/cpu/power_stub.go Normal file
View file

@ -0,0 +1,23 @@
// +build !amd64
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cpu
func discoverSSTBF() (bool, error) {
return false, nil
}

View file

@ -18,9 +18,9 @@ limitations under the License.
package rdt
type CpuidRet struct {
EAX, EBX, ECX, EDX uint32
}
import (
"sigs.k8s.io/node-feature-discovery/pkg/cpuid"
)
const (
// CPUID EAX input values
@ -47,10 +47,10 @@ func discoverRDT() []string {
features := []string{}
// Read cpuid information
extFeatures := cpuid(LEAF_EXT_FEATURE_FLAGS, 0)
rdtMonitoring := cpuid(LEAF_RDT_MONITORING, 0)
rdtL3Monitoring := cpuid(LEAF_RDT_MONITORING, RDT_MONITORING_SUBLEAF_L3)
rdtAllocation := cpuid(LEAF_RDT_ALLOCATION, 0)
extFeatures := cpuid.Cpuid(LEAF_EXT_FEATURE_FLAGS, 0)
rdtMonitoring := cpuid.Cpuid(LEAF_RDT_MONITORING, 0)
rdtL3Monitoring := cpuid.Cpuid(LEAF_RDT_MONITORING, RDT_MONITORING_SUBLEAF_L3)
rdtAllocation := cpuid.Cpuid(LEAF_RDT_ALLOCATION, 0)
// Detect RDT monitoring capabilities
if extFeatures.EBX&EXT_FEATURE_FLAGS_EBX_RDT_M != 0 {
@ -88,11 +88,3 @@ func discoverRDT() []string {
return features
}
func cpuid(eax, ecx uint32) CpuidRet {
r := CpuidRet{}
r.EAX, r.EBX, r.ECX, r.EDX = cpuidAsm(eax, ecx)
return r
}
func cpuidAsm(eax_arg, ecx_arg uint32) (eax, ebx, ecx, edx uint32)