Update vendored files

Signed-off-by: Markus Lehtonen <markus.lehtonen@intel.com>
This commit is contained in:
Markus Lehtonen
2022-09-09 20:27:23 +03:00
parent d845b2a9c2
commit 3612915596
94 changed files with 3548 additions and 8135 deletions

View File

@@ -44,7 +44,7 @@ func OciLinuxBlockIO(class string) (*oci.LinuxBlockIO, error) {
}
func ociLinuxWeightDevices(dws cgroups.DeviceWeights) []oci.LinuxWeightDevice {
if dws == nil || len(dws) == 0 {
if len(dws) == 0 {
return nil
}
olwds := make([]oci.LinuxWeightDevice, len(dws))
@@ -58,7 +58,7 @@ func ociLinuxWeightDevices(dws cgroups.DeviceWeights) []oci.LinuxWeightDevice {
}
func ociLinuxThrottleDevices(drs cgroups.DeviceRates) []oci.LinuxThrottleDevice {
if drs == nil || len(drs) == 0 {
if len(drs) == 0 {
return nil
}
oltds := make([]oci.LinuxThrottleDevice, len(drs))

View File

@@ -231,19 +231,21 @@ func (s catSchema) toStr(typ catSchemaType, baseSchema catSchema) (string, error
sep := ""
// Get a sorted slice of cache ids for deterministic output
ids := make([]uint64, 0, len(baseSchema.Alloc))
for id := range baseSchema.Alloc {
ids = append(ids, id)
}
ids := append([]uint64{}, info.cat[s.Lvl].cacheIds...)
utils.SortUint64s(ids)
minBits := info.cat[s.Lvl].minCbmBits()
for _, id := range ids {
baseMask, ok := baseSchema.Alloc[id].getEffective(typ).(catAbsoluteAllocation)
if !ok {
return "", fmt.Errorf("BUG: basemask not of type catAbsoluteAllocation")
// Default to 100%
bmask := info.cat[s.Lvl].cbmMask()
if base, ok := baseSchema.Alloc[id]; ok {
baseMask, ok := base.getEffective(typ).(catAbsoluteAllocation)
if !ok {
return "", fmt.Errorf("BUG: basemask not of type catAbsoluteAllocation")
}
bmask = bitmask(baseMask)
}
bmask := bitmask(baseMask)
if s.Alloc != nil {
var err error
@@ -416,14 +418,19 @@ func (s mbSchema) toStr(base map[uint64]uint64) string {
sep := ""
// Get a sorted slice of cache ids for deterministic output
ids := make([]uint64, 0, len(base))
for id := range base {
ids = append(ids, id)
}
ids := append([]uint64{}, info.mb.cacheIds...)
utils.SortUint64s(ids)
for _, id := range ids {
baseAllocation := base[id]
baseAllocation, ok := base[id]
if !ok {
if info.mb.mbpsEnabled {
baseAllocation = math.MaxUint32
} else {
baseAllocation = 100
}
}
value := uint64(0)
if info.mb.mbpsEnabled {
value = math.MaxUint32
@@ -547,6 +554,10 @@ func (c *Config) resolvePartitions() (partitionSet, error) {
// resolveCatPartitions tries to resolve requested cache allocations between partitions
func (c *Config) resolveCatPartitions(lvl cacheLevel, conf partitionSet) error {
if len(c.Partitions) == 0 {
return nil
}
// Resolve partitions in sorted order for reproducibility
names := make([]string, 0, len(c.Partitions))
for name := range c.Partitions {

View File

@@ -206,10 +206,6 @@ func Initialize(resctrlGroupPrefix string) error {
return fmt.Errorf("failed to initialize classes from resctrl fs: %v", err)
}
if err := r.pruneMonGroups(); err != nil {
return err
}
rdt = r
return nil

View File

@@ -129,7 +129,7 @@ func (s IDSet) String() string {
// StringWithSeparator returns the set as a string, separated with the given separator.
func (s IDSet) StringWithSeparator(args ...string) string {
if s == nil || len(s) == 0 {
if len(s) == 0 {
return ""
}

53
vendor/github.com/intel/goresctrl/pkg/utils/msr.go generated vendored Normal file
View File

@@ -0,0 +1,53 @@
/*
Copyright 2021 Intel Corporation
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 utils
import (
"encoding/binary"
"fmt"
"os"
)
func ReadMSR(cpu ID, msr int64) (uint64, error) {
str := fmt.Sprintf("/dev/cpu/%d/msr", cpu)
file, err := os.Open(str)
if err != nil {
return 0, err
}
defer file.Close()
// Whence is the point of reference for offset
// 0 = Beginning of file
// 1 = Current position
// 2 = End of file
var whence int = 0
_, err = file.Seek(msr, whence)
if err != nil {
return 0, err
}
data := make([]byte, 8)
_, err = file.Read(data)
if err != nil {
return 0, err
}
return binary.LittleEndian.Uint64(data), nil
}

136
vendor/github.com/intel/goresctrl/pkg/utils/sysfs.go generated vendored Normal file
View File

@@ -0,0 +1,136 @@
/*
Copyright 2022 Intel Corporation
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 utils
import (
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
)
const (
SysfsUncoreBasepath = "/sys/devices/system/cpu/intel_uncore_frequency/"
)
func setCPUFreqValue(cpu ID, setting string, value int) error {
path := fmt.Sprintf("/sys/devices/system/cpu/cpu%d/cpufreq/%s", cpu, setting)
return writeFileInt(path, value)
}
// GetCPUFreqValue returns information of the currently used CPU frequency
func GetCPUFreqValue(cpu ID, setting string) (int, error) {
str := fmt.Sprintf("/sys/devices/system/cpu/cpu%d/cpufreq/%s", cpu, setting)
raw, err := ioutil.ReadFile(str)
if err != nil {
return 0, err
}
value, err := strconv.Atoi(strings.TrimSpace(string(raw)))
if err != nil {
return 0, err
}
return value, nil
}
// SetCPUScalingMinFreq sets the scaling_min_freq value of a given CPU
func SetCPUScalingMinFreq(cpu ID, freq int) error {
return setCPUFreqValue(cpu, "scaling_min_freq", freq)
}
// SetCPUScalingMaxFreq sets the scaling_max_freq value of a given CPU
func SetCPUScalingMaxFreq(cpu ID, freq int) error {
return setCPUFreqValue(cpu, "scaling_max_freq", freq)
}
// SetCPUsScalingMinFreq sets the scaling_min_freq value of a given set of CPUs
func SetCPUsScalingMinFreq(cpus []ID, freq int) error {
for _, cpu := range cpus {
if err := SetCPUScalingMinFreq(cpu, freq); err != nil {
return err
}
}
return nil
}
// SetCPUsScalingMaxFreq sets the scaling_max_freq value of a given set of CPUs
func SetCPUsScalingMaxFreq(cpus []ID, freq int) error {
for _, cpu := range cpus {
if err := SetCPUScalingMaxFreq(cpu, freq); err != nil {
return err
}
}
return nil
}
// UncoreFreqAvailable returns true if the uncore frequency control functions are available.
func UncoreFreqAvailable() bool {
_, err := os.Stat(SysfsUncoreBasepath)
return err == nil
}
// SetUncoreMinFreq sets the minimum uncore frequency of a CPU die. Frequency is specified in kHz.
func SetUncoreMinFreq(pkg, die ID, freqKhz int) error {
return setUncoreFreqValue(pkg, die, "min_freq_khz", freqKhz)
}
// SetUncoreMaxFreq sets the maximum uncore frequency of a CPU die. Frequency is specified in kHz.
func SetUncoreMaxFreq(pkg, die ID, freqKhz int) error {
return setUncoreFreqValue(pkg, die, "max_freq_khz", freqKhz)
}
func uncoreFreqPath(pkg, die ID, attribute string) string {
return fmt.Sprintf(SysfsUncoreBasepath+"package_%02d_die_%02d/%s", pkg, die, attribute)
}
func getUncoreFreqValue(pkg, die ID, attribute string) (int, error) {
return readFileInt(uncoreFreqPath(pkg, die, attribute))
}
func setUncoreFreqValue(pkg, die ID, attribute string, value int) error {
// Bounds checking
if hwMinFreq, err := getUncoreFreqValue(pkg, die, "initial_min_freq_khz"); err != nil {
return err
} else if value < hwMinFreq {
value = hwMinFreq
}
if hwMaxFreq, err := getUncoreFreqValue(pkg, die, "initial_max_freq_khz"); err != nil {
return err
} else if value > hwMaxFreq {
value = hwMaxFreq
}
return writeFileInt(uncoreFreqPath(pkg, die, attribute), value)
}
func writeFileInt(path string, value int) error {
return ioutil.WriteFile(path, []byte(strconv.Itoa(value)), 0644)
}
func readFileInt(path string) (int, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
return 0, err
}
i, err := strconv.ParseInt(strings.TrimSpace(string(data)), 10, 32)
return int(i), err
}