From d66096a4917df758c5b897e5aaaa1ac66c450461 Mon Sep 17 00:00:00 2001 From: Chandan Abhyankar Date: Fri, 13 Jan 2023 01:05:28 -0800 Subject: [PATCH] cpu: support for detecting nx-gzip coprocessor feature Nest accelerator gzip support for IBM Power systems. Signed-off-by: Chandan Abhyankar --- docs/usage/customization-guide.md | 2 ++ docs/usage/features.md | 1 + source/cpu/coprocessor_ppc64le.go | 43 +++++++++++++++++++++++++++++++ source/cpu/coprocessor_stub.go | 24 +++++++++++++++++ source/cpu/cpu.go | 29 ++++++++++++++------- 5 files changed, 89 insertions(+), 10 deletions(-) create mode 100644 source/cpu/coprocessor_ppc64le.go create mode 100644 source/cpu/coprocessor_stub.go diff --git a/docs/usage/customization-guide.md b/docs/usage/customization-guide.md index 820924eb7c..1bdb0799cf 100644 --- a/docs/usage/customization-guide.md +++ b/docs/usage/customization-guide.md @@ -621,6 +621,8 @@ The following features are available for matching: | | | **`enabled`** | bool | **DEPRECATED**: use **`se.enabled`** from **`cpu.security`** instead | **`cpu.topology`** | attribute | | | CPU topology related features | | | **`hardware_multithreading`** | bool | Hardware multithreading, such as Intel HTT, is enabled +| **`cpu.coprocessor`** | attribute | | | CPU Coprocessor related features +| | | **`nx_gzip`** | bool | Nest Accelerator GZIP support is enabled | **`kernel.config`** | attribute | | | Kernel configuration options | | | **``** | string | Value of the kconfig option | **`kernel.loadedmodule`** | flag | | | Loaded kernel modules diff --git a/docs/usage/features.md b/docs/usage/features.md index e27d36de04..7ba8d14845 100644 --- a/docs/usage/features.md +++ b/docs/usage/features.md @@ -48,6 +48,7 @@ option of nfd-worker. | ----------------------- | ------------ | ----------- | **`cpu-cpuid.`** | true | CPU capability is supported. **NOTE:** the capability might be supported but not enabled. | **`cpu-hardware_multithreading`** | true | Hardware multithreading, such as Intel HTT, enabled (number of logical CPUs is greater than physical CPUs) +| **`cpu-coprocessor.nx_gzip`** | true | Nest Accelerator for GZIP is supported(Power). | **`cpu-power.sst_bf.enabled`** | true | Intel SST-BF ([Intel Speed Select Technology][intel-sst] - Base frequency) enabled | **`cpu-pstate.status`** | string | The status of the [Intel pstate][intel-pstate] driver when in use and enabled, either 'active' or 'passive'. | **`cpu-pstate.turbo`** | bool | Set to 'true' if turbo frequencies are enabled in Intel pstate driver, set to 'false' if they have been disabled. diff --git a/source/cpu/coprocessor_ppc64le.go b/source/cpu/coprocessor_ppc64le.go new file mode 100644 index 0000000000..0d1e859f9e --- /dev/null +++ b/source/cpu/coprocessor_ppc64le.go @@ -0,0 +1,43 @@ +//go:build ppc64le +// +build ppc64le + +/* +Copyright 2023 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 ( + "k8s.io/klog/v2" + "os" + "sigs.k8s.io/node-feature-discovery/pkg/utils/hostpath" + "strconv" +) + +/* Detect NX_GZIP */ +func discoverCoprocessor() map[string]string { + features := make(map[string]string) + + nxGzipPath := hostpath.SysfsDir.Path("devices/vio/ibm,compression-v1/nx_gzip_caps") + + _, err := os.Stat(nxGzipPath) + if err != nil { + klog.V(5).Infof("Failed to detect nx_gzip for Nest Accelerator: %v", err) + } else { + features["nx_gzip"] = strconv.FormatBool(true) + } + + return features +} diff --git a/source/cpu/coprocessor_stub.go b/source/cpu/coprocessor_stub.go new file mode 100644 index 0000000000..2370f3963e --- /dev/null +++ b/source/cpu/coprocessor_stub.go @@ -0,0 +1,24 @@ +//go:build !ppc64le +// +build !ppc64le + +/* +Copyright 2023 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 discoverCoprocessor() map[string]string { + return nil +} diff --git a/source/cpu/cpu.go b/source/cpu/cpu.go index d9b77f8e35..48dedfa130 100644 --- a/source/cpu/cpu.go +++ b/source/cpu/cpu.go @@ -34,16 +34,17 @@ import ( const Name = "cpu" const ( - CpuidFeature = "cpuid" - Cpumodel = "model" - CstateFeature = "cstate" - PstateFeature = "pstate" - RdtFeature = "rdt" - SeFeature = "se" // DEPRECATED in v0.12: will be removed in the future - SecurityFeature = "security" - SgxFeature = "sgx" // DEPRECATED in v0.12: will be removed in the future - SstFeature = "sst" - TopologyFeature = "topology" + CpuidFeature = "cpuid" + Cpumodel = "model" + CstateFeature = "cstate" + PstateFeature = "pstate" + RdtFeature = "rdt" + SeFeature = "se" // DEPRECATED in v0.12: will be removed in the future + SecurityFeature = "security" + SgxFeature = "sgx" // DEPRECATED in v0.12: will be removed in the future + SstFeature = "sst" + TopologyFeature = "topology" + CoprocessorFeature = "coprocessor" ) // Configuration file options @@ -192,6 +193,11 @@ func (s *cpuSource) GetLabels() (source.FeatureLabels, error) { labels["hardware_multithreading"] = v } + // NX + if v, ok := features.Attributes[CoprocessorFeature].Elements["nx_gzip"]; ok { + labels["coprocessor.nx_gzip"] = v + } + return labels, nil } @@ -246,6 +252,9 @@ func (s *cpuSource) Discover() error { // Detect hyper-threading s.features.Attributes[TopologyFeature] = nfdv1alpha1.NewAttributeFeatures(discoverTopology()) + // Detect Coprocessor features + s.features.Attributes[CoprocessorFeature] = nfdv1alpha1.NewAttributeFeatures(discoverCoprocessor()) + utils.KlogDump(3, "discovered cpu features:", " ", s.features) return nil