mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2025-03-14 20:56:42 +00:00
source/cpu: detect SST-BF
Detect of the Intel SST-BF (Speed Select Technology - Base Frequency) has been enabled. Adds one new feature label: feature.node.kubernetes.io/cpu-power.sst_bf.enabled=true Based on a patch from kuralamudhan.ramakrishnan@intel.com
This commit is contained in:
parent
86382afe56
commit
ad17e5088b
4 changed files with 121 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -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
76
source/cpu/power_amd64.go
Normal 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
23
source/cpu/power_stub.go
Normal 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
|
||||
}
|
Loading…
Add table
Reference in a new issue