diff --git a/source/cpu/cpu.go b/source/cpu/cpu.go index d9b77f8e35..6aa68c097d 100644 --- a/source/cpu/cpu.go +++ b/source/cpu/cpu.go @@ -44,6 +44,7 @@ const ( SgxFeature = "sgx" // DEPRECATED in v0.12: will be removed in the future SstFeature = "sst" TopologyFeature = "topology" + NXFeature = "nx" ) // Configuration file options @@ -192,6 +193,11 @@ func (s *cpuSource) GetLabels() (source.FeatureLabels, error) { labels["hardware_multithreading"] = v } + // NX + if v, ok := features.Attributes[NXFeature].Elements["nx_gzip"]; ok { + labels["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 nx-gzip + s.features.Attributes[NXFeature] = nfdv1alpha1.NewAttributeFeatures(discoverNxGzip()) + utils.KlogDump(3, "discovered cpu features:", " ", s.features) return nil diff --git a/source/cpu/nx_ppc64le.go b/source/cpu/nx_ppc64le.go new file mode 100644 index 0000000000..dc0a863b0d --- /dev/null +++ b/source/cpu/nx_ppc64le.go @@ -0,0 +1,43 @@ +//go:build ppc64le +// +build ppc64le + +/* +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 ( + "k8s.io/klog/v2" + "os" + "strconv" + "sigs.k8s.io/node-feature-discovery/pkg/utils/hostpath" +) + +/* Detect NX_GZIP */ +func discoverNxGzip() 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/nx_stub.go b/source/cpu/nx_stub.go new file mode 100644 index 0000000000..ecd90593a8 --- /dev/null +++ b/source/cpu/nx_stub.go @@ -0,0 +1,24 @@ +//go:build !ppc64le +// +build !ppc64le + +/* +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 discoverNxGzip() map[string]string { + return nil +}