2017-09-06 10:48:10 +08:00
|
|
|
/*
|
|
|
|
Copyright 2017 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 rdt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os/exec"
|
|
|
|
|
|
|
|
"github.com/golang/glog"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Source implements FeatureSource.
|
|
|
|
type Source struct{}
|
|
|
|
|
2018-03-05 17:51:47 +02:00
|
|
|
// Name returns an identifier string for this feature source.
|
2017-09-06 10:48:10 +08:00
|
|
|
func (s Source) Name() string { return "rdt" }
|
|
|
|
|
2018-10-02 21:58:29 +08:00
|
|
|
// Discover returns feature names for CMT and CAT if supported.
|
2017-09-06 10:48:10 +08:00
|
|
|
func (s Source) Discover() ([]string, error) {
|
|
|
|
features := []string{}
|
|
|
|
|
2018-03-16 18:56:35 +02:00
|
|
|
cmd := exec.Command("bash", "-c", "mon-discovery")
|
2017-09-06 10:48:10 +08:00
|
|
|
if err := cmd.Run(); err != nil {
|
|
|
|
glog.Errorf("support for RDT monitoring was not detected: %v", err)
|
|
|
|
} else {
|
|
|
|
// RDT monitoring detected.
|
|
|
|
features = append(features, "RDTMON")
|
|
|
|
}
|
|
|
|
|
2018-05-25 02:49:00 +03:00
|
|
|
cmd = exec.Command("bash", "-c", "mon-cmt-discovery")
|
|
|
|
if err := cmd.Run(); err != nil {
|
|
|
|
glog.Errorf("support for RDT CMT monitoring was not detected: %v", err)
|
|
|
|
} else {
|
|
|
|
// RDT CMT monitoring detected.
|
|
|
|
features = append(features, "RDTCMT")
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd = exec.Command("bash", "-c", "mon-mbm-discovery")
|
|
|
|
if err := cmd.Run(); err != nil {
|
|
|
|
glog.Errorf("support for RDT MBM monitoring was not detected: %v", err)
|
|
|
|
} else {
|
|
|
|
// RDT MBM monitoring detected.
|
|
|
|
features = append(features, "RDTMBM")
|
|
|
|
}
|
|
|
|
|
2018-03-16 18:56:35 +02:00
|
|
|
cmd = exec.Command("bash", "-c", "l3-alloc-discovery")
|
2017-09-06 10:48:10 +08:00
|
|
|
if err := cmd.Run(); err != nil {
|
|
|
|
glog.Errorf("support for RDT L3 allocation was not detected: %v", err)
|
|
|
|
} else {
|
|
|
|
// RDT L3 cache allocation detected.
|
|
|
|
features = append(features, "RDTL3CA")
|
|
|
|
}
|
|
|
|
|
2018-03-16 18:56:35 +02:00
|
|
|
cmd = exec.Command("bash", "-c", "l2-alloc-discovery")
|
2017-09-06 10:48:10 +08:00
|
|
|
if err := cmd.Run(); err != nil {
|
|
|
|
glog.Errorf("support for RDT L2 allocation was not detected: %v", err)
|
|
|
|
} else {
|
|
|
|
// RDT L2 cache allocation detected.
|
|
|
|
features = append(features, "RDTL2CA")
|
|
|
|
}
|
|
|
|
|
2018-05-25 02:49:00 +03:00
|
|
|
cmd = exec.Command("bash", "-c", "mem-bandwidth-alloc-discovery")
|
|
|
|
if err := cmd.Run(); err != nil {
|
|
|
|
glog.Errorf("support for RDT Memory bandwidth allocation was not detected: %v", err)
|
|
|
|
} else {
|
|
|
|
// RDT Memory bandwidth allocation detected.
|
|
|
|
features = append(features, "RDTMBA")
|
|
|
|
}
|
|
|
|
|
2017-09-06 10:48:10 +08:00
|
|
|
return features, nil
|
|
|
|
}
|