Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
Signed-off-by: Rouzip <1226015390@qq.com>
  • Loading branch information
Rouzip committed May 29, 2024
1 parent 2904004 commit c28c849
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 35 deletions.
7 changes: 7 additions & 0 deletions pkg/features/koordlet_features.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ const (
// Libpfm4 enables libpfm4 feature of koordlet.
Libpfm4 featuregate.Feature = "Libpfm4"

// owner: @Rouzip
// alpha: v0.1
//
// ResctrlCollector enables resctrl collector feature of koordlet.
ResctrlCollector featuregate.Feature = "ResctrlCollector"

// owner: @songtao98 @zwzhang0107
// alpha: v1.0
//
Expand Down Expand Up @@ -161,6 +167,7 @@ var (
CPUBurst: {Default: true, PreRelease: featuregate.Beta},
SystemConfig: {Default: false, PreRelease: featuregate.Alpha},
RdtResctrl: {Default: true, PreRelease: featuregate.Beta},
ResctrlCollector: {Default: false, PreRelease: featuregate.Alpha},
CgroupReconcile: {Default: false, PreRelease: featuregate.Alpha},
NodeTopologyReport: {Default: true, PreRelease: featuregate.Beta},
Accelerators: {Default: false, PreRelease: featuregate.Alpha},
Expand Down
8 changes: 4 additions & 4 deletions pkg/koordlet/metrics/resctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ const (
ResourceTypeLLC = "llc"
ResourceTypeMB = "mb"

ResctrlResourceType = "resctrl_resource_type"
ResctrlCacheId = "resctrl_cacheid"
ResctrlQos = "resctrl_qos"
ResctrlMbType = "resctrl_mb_type"
ResctrlResourceType = "resource_type"
ResctrlCacheId = "cache_id"
ResctrlQos = "qos"
ResctrlMbType = "mb_type"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"

"github.com/koordinator-sh/koordinator/pkg/features"
"github.com/koordinator-sh/koordinator/pkg/koordlet/metriccache"
"github.com/koordinator-sh/koordinator/pkg/koordlet/metrics"
"github.com/koordinator-sh/koordinator/pkg/koordlet/metricsadvisor/framework"
Expand All @@ -47,16 +48,26 @@ type resctrlCollector struct {

func New(opt *framework.Options) framework.Collector {
return &resctrlCollector{
collectInterval: opt.Config.ResctrlCollectorInterval,
statesInformer: opt.StatesInformer,
metricCache: opt.MetricCache,
resctrlReader: opt.ResctrlReader,
started: atomic.NewBool(false),
collectInterval: opt.Config.ResctrlCollectorInterval,
statesInformer: opt.StatesInformer,
metricCache: opt.MetricCache,
resctrlReader: resourceexecutor.NewResctrlReader(),
resctrlCollectorGate: opt.Config.EnableResctrlCollector,
started: atomic.NewBool(false),
}
}

// 1. config enable resctrl collector
// 2. cmdline, os, cpuid enable resctrl collector
// 3. check CPU vendor(Intel&AMD)
// 4. check resctrl collector feature gate
func (r *resctrlCollector) Enabled() bool {
return r.resctrlCollectorGate
isResctrlEnabled, _ := system.IsSupportResctrl()
isResctrlCollectorEnabled, _ := system.IsResctrlCollectorAvailableByCpuInfo()
return r.resctrlCollectorGate &&
isResctrlEnabled && isResctrlCollectorEnabled &&
system.IsVendorSupportResctrl() &&
features.DefaultKoordletFeatureGate.Enabled(features.ResctrlCollector)
}

func (r *resctrlCollector) Setup(c *framework.Context) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func TestNewResctrlCollector(t *testing.T) {
cfg *framework.Config
statesInformer statesinformer.StatesInformer
metricCache metriccache.MetricCache
resctrlReader resourceexecutor.ResctrlReader
}
tests := []struct {
name string
Expand All @@ -48,7 +47,6 @@ func TestNewResctrlCollector(t *testing.T) {
cfg: framework.NewDefaultConfig(),
statesInformer: nil,
metricCache: nil,
resctrlReader: resourceexecutor.NewResctrlReader(),
},
},
}
Expand All @@ -58,7 +56,6 @@ func TestNewResctrlCollector(t *testing.T) {
Config: tt.args.cfg,
StatesInformer: tt.args.statesInformer,
MetricCache: tt.args.metricCache,
ResctrlReader: tt.args.resctrlReader,
}
if got := New(opt); got == nil {
t.Errorf("NewResctrlCollector() = %v", got)
Expand Down Expand Up @@ -152,7 +149,6 @@ func Test_collectQosResctrlStatNoErr(t *testing.T) {
Config: framework.NewDefaultConfig(),
StatesInformer: mockStatesInformer,
MetricCache: mockMetricCache,
ResctrlReader: resourceexecutor.NewResctrlReader(),
CgroupReader: resourceexecutor.NewCgroupReader(),
})

Expand Down
1 change: 0 additions & 1 deletion pkg/koordlet/metricsadvisor/framework/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ type Options struct {
StatesInformer statesinformer.StatesInformer
MetricCache metriccache.MetricCache
CgroupReader resourceexecutor.CgroupReader
ResctrlReader resourceexecutor.ResctrlReader
PodFilters map[string]PodFilter
}
1 change: 0 additions & 1 deletion pkg/koordlet/metricsadvisor/metrics_advisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func NewMetricAdvisor(cfg *framework.Config, statesInformer statesinformer.State
MetricCache: metricCache,
CgroupReader: resourceexecutor.NewCgroupReader(),
PodFilters: podFilters,
ResctrlReader: resourceexecutor.NewResctrlReader(),
}
ctx := &framework.Context{
DeviceCollectors: make(map[string]framework.DeviceCollector, len(devicePlugins)),
Expand Down
8 changes: 4 additions & 4 deletions pkg/koordlet/resourceexecutor/resctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ const CacheIdIndex = 2

func NewResctrlReader() ResctrlReader {
if vendorId, err := system.GetVendorIDByCPUInfo(system.GetCPUInfoPath()); err != nil {
// FIXME: should we panic there?
klog.V(0).ErrorS(err, "get cpu vendor error")
return nil
klog.V(0).ErrorS(err, "get cpu vendor error, stop start resctrl collector")
return &fakeReader{}
} else {
switch vendorId {
case system.INTEL_VENDOR_ID:
Expand All @@ -52,7 +51,7 @@ func NewResctrlReader() ResctrlReader {

type CacheId int

// parent for resctrl is like: ``, `BE`, `LS`
// parent for resctrl is like: `BE`, `LS`
type ResctrlReader interface {
ReadResctrlL3Stat(parent string) (map[CacheId]uint64, error)
ReadResctrlMBStat(parent string) (map[CacheId]system.MBStatData, error)
Expand Down Expand Up @@ -84,6 +83,7 @@ func (rr *ResctrlRDTReader) ReadResctrlL3Stat(parent string) (map[CacheId]uint64
if err != nil {
return nil, fmt.Errorf(ErrResctrlDir)
}
defer fd.Close()
// read all l3-memory domains
domains, err := fd.ReadDir(-1)
if err != nil {
Expand Down
38 changes: 23 additions & 15 deletions pkg/koordlet/util/system/resctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"strings"
"sync"

"go.uber.org/multierr"
"k8s.io/klog/v2"

"github.com/koordinator-sh/koordinator/pkg/util"
Expand Down Expand Up @@ -65,6 +66,7 @@ var (
isInit bool
isSupportResctrl bool
CacheIdsCacheFunc func() ([]int, error)
ARM_VENDOR_ID_MAP = map[string]struct{}{} // support MPAM ARM vendor ids
)

func init() {
Expand Down Expand Up @@ -96,6 +98,18 @@ func isKernelSupportResctrl() (bool, error) {
return isCatFlagSet && isMbaFlagSet, nil
}

func IsVendorSupportResctrl() bool {
vendorID, err := GetVendorIDByCPUInfo(GetCPUInfoPath())
if err != nil {
klog.V(4).Infof("GetVendorIDByCPUInfo error: %v", err)
return false
}
if _, ok := ARM_VENDOR_ID_MAP[vendorID]; ok {
return true
}
return vendorID == AMD_VENDOR_ID || vendorID == INTEL_VENDOR_ID
}

func IsSupportResctrl() (bool, error) {
initLock.Lock()
defer initLock.Unlock()
Expand All @@ -117,6 +131,15 @@ func IsSupportResctrl() (bool, error) {
return isSupportResctrl, nil
}

func IsResctrlCollectorAvailableByCpuInfo() (bool, error) {
initLock.Lock()
defer initLock.Unlock()
path := GetCPUInfoPath()
mbm, err1 := isResctrlMBMAvailableByCpuInfo(path)
cqm, err2 := isResctrlCQMAvailableByCpuInfo(path)
return mbm && cqm, multierr.Append(err1, err2)
}

var (
ResctrlSchemata = NewCommonResctrlResource(ResctrlSchemataName, "")
ResctrlTasks = NewCommonResctrlResource(ResctrlTasksName, "")
Expand Down Expand Up @@ -575,21 +598,6 @@ func CheckAndTryEnableResctrlCat() error {
return nil
}

func InitCatGroupIfNotExist(group string) error {
path := GetResctrlGroupRootDirPath(group)
_, err := os.Stat(path)
if err == nil {
return nil
} else if !os.IsNotExist(err) {
return fmt.Errorf("check dir %v for group %s but got unexpected err: %v", path, group, err)
}
err = os.Mkdir(path, 0755)
if err != nil {
return fmt.Errorf("create dir %v failed for group %s, err: %v", path, group, err)
}
return nil
}

func CheckResctrlSchemataValid() error {
schemataPath := GetResctrlSchemataFilePath("")
schemataRaw, err := ReadResctrlSchemataRaw(schemataPath, -1)
Expand Down

0 comments on commit c28c849

Please sign in to comment.