system

package
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2024 License: Apache-2.0 Imports: 43 Imported by: 3

Documentation

Index

Constants

View Source
const (
	DefaultCPUCFSPeriod int64 = 100000
	CPUShareKubeBEValue int64 = 2
	CPUShareUnitValue   int64 = 1024
	// MemoryLimitUnlimitedValue denotes the unlimited value of cgroups-v1 memory.limit_in_bytes.
	// It derives from linux PAGE_COUNTER_MAX and may be different according to the PAGE_SIZE (here we suppose `4k`).
	// https://github.com/torvalds/linux/blob/ea4424be16887a37735d6550cfd0611528dbe5d9/mm/memcontrol.c#L5337
	MemoryLimitUnlimitedValue int64 = 0x7FFFFFFFFFFFF000 // 9223372036854771712 < math.MaxInt64

	// CgroupMaxSymbolStr only appears in cgroups-v2 files, we consider the value as MaxInt64
	CgroupMaxSymbolStr string = "max"
	// CgroupUnlimitedSymbolStr indicates value is unlimited. It appears in cfs_quota which regarded as max in comparison.
	CgroupUnlimitedSymbolStr string = "-1"
	// CgroupMaxValueStr math.MaxInt64; writing `memory.high` with this do the same as set as "max"
	CgroupMaxValueStr string = "9223372036854775807"
)
View Source
const (
	Cgroupfs CgroupDriverType = "cgroupfs"
	Systemd  CgroupDriverType = "systemd"

	KubeRootNameSystemd       = "kubepods.slice/"
	KubeBurstableNameSystemd  = "kubepods-burstable.slice/"
	KubeBesteffortNameSystemd = "kubepods-besteffort.slice/"

	KubeRootNameCgroupfs       = "kubepods/"
	KubeBurstableNameCgroupfs  = "burstable/"
	KubeBesteffortNameCgroupfs = "besteffort/"

	RuntimeTypeDocker     = "docker"
	RuntimeTypeContainerd = "containerd"
	RuntimeTypePouch      = "pouch"
	RuntimeTypeCrio       = "cri-o"
	RuntimeTypeUnknown    = "unknown"
)
View Source
const (
	CgroupCPUDir     string = "cpu/"
	CgroupCPUSetDir  string = "cpuset/"
	CgroupCPUAcctDir string = "cpuacct/"
	CgroupMemDir     string = "memory/"
	CgroupBlkioDir   string = "blkio/"

	CgroupV2Dir = ""
)
View Source
const (
	CFSBasePeriodValue int64 = 100000
	CFSQuotaMinValue   int64 = 1000 // min value except `-1`
	CPUSharesMinValue  int64 = 2
	CPUSharesMaxValue  int64 = 262144
	CPUWeightMinValue  int64 = 1
	CPUWeightMaxValue  int64 = 10000

	CPUStatName      = "cpu.stat"
	CPUSharesName    = "cpu.shares"
	CPUCFSQuotaName  = "cpu.cfs_quota_us"
	CPUCFSPeriodName = "cpu.cfs_period_us"
	CPUBVTWarpNsName = "cpu.bvt_warp_ns"
	CPUBurstName     = "cpu.cfs_burst_us"
	CPUTasksName     = "tasks"
	CPUProcsName     = "cgroup.procs"
	CPUThreadsName   = "cgroup.threads"
	CPUMaxName       = "cpu.max"
	CPUMaxBurstName  = "cpu.max.burst"
	CPUWeightName    = "cpu.weight"
	CPUIdleName      = "cpu.idle"

	CPUSetCPUSName          = "cpuset.cpus"
	CPUSetCPUSEffectiveName = "cpuset.cpus.effective"

	CPUAcctStatName           = "cpuacct.stat"
	CPUAcctUsageName          = "cpuacct.usage"
	CPUAcctCPUPressureName    = "cpu.pressure"
	CPUAcctMemoryPressureName = "memory.pressure"
	CPUAcctIOPressureName     = "io.pressure"

	MemoryLimitName            = "memory.limit_in_bytes"
	MemoryUsageName            = "memory.usage_in_bytes"
	MemoryStatName             = "memory.stat"
	MemoryNumaStatName         = "memory.numa_stat"
	MemoryWmarkRatioName       = "memory.wmark_ratio"
	MemoryWmarkScaleFactorName = "memory.wmark_scale_factor"
	MemoryWmarkMinAdjName      = "memory.wmark_min_adj"
	MemoryMinName              = "memory.min"  // anolis os or cgroups-v2
	MemoryLowName              = "memory.low"  // anolis os or cgroups-v2
	MemoryHighName             = "memory.high" // anolis os or cgroups-v2
	MemoryMaxName              = "memory.max"
	MemoryCurrentName          = "memory.current"
	MemoryPriorityName         = "memory.priority"
	MemoryUsePriorityOomName   = "memory.use_priority_oom"
	MemoryOomGroupName         = "memory.oom.group"
	MemoryIdlePageStatsName    = "memory.idle_page_stats"

	BlkioTRIopsName   = "blkio.throttle.read_iops_device"
	BlkioTRBpsName    = "blkio.throttle.read_bps_device"
	BlkioTWIopsName   = "blkio.throttle.write_iops_device"
	BlkioTWBpsName    = "blkio.throttle.write_bps_device"
	BlkioIOWeightName = "blkio.cost.weight"
	BlkioIOQoSName    = "blkio.cost.qos"
	BlkioIOModelName  = "blkio.cost.model"
)
View Source
const (
	DS_MODE   = "dsMode"
	HOST_MODE = "hostMode"
)
View Source
const (
	// SchedFeatureCoreSched is the feature name of the core scheduling in `/sys/kernel/debug/sched_features`.
	SchedFeatureCoreSched = "CORE_SCHED"
	// SchedFeatureNoCoreSched is the feature name that the core scheduling supported but disabled.
	SchedFeatureNoCoreSched = "NO_CORE_SCHED"
)
View Source
const (
	// VirtualCoreSchedCookieName is the name of a virtual system resource for the core scheduling cookie.
	VirtualCoreSchedCookieName = "core_sched_cookie"

	// DefaultCoreSchedCookieID is the default cookie of the core scheduling.
	DefaultCoreSchedCookieID uint64 = 0
)
View Source
const (
	ProcStatName    = "stat"
	ProcMemInfoName = "meminfo"
	ProcCPUInfoName = "cpuinfo"
)
View Source
const (
	ResctrlName string = "resctrl"

	ResctrlDir string = "resctrl/"
	RdtInfoDir string = "info"
	L3CatDir   string = "L3"

	ResctrlSchemataName string = "schemata"
	ResctrlCbmMaskName  string = "cbm_mask"
	ResctrlTasksName    string = "tasks"

	// L3SchemataPrefix is the prefix of l3 cat schemata
	L3SchemataPrefix = "L3"
	// MbSchemataPrefix is the prefix of mba schemata
	MbSchemataPrefix = "MB"

	// other cpu vendor like "GenuineIntel"
	AMD_VENDOR_ID = "AuthenticAMD"
)
View Source
const (
	SysctlSubDir          = "sys"
	KernelCmdlineFileName = "cmdline"
	HugepageDir           = "hugepages"

	KernelSchedGroupIdentityEnable = "kernel/sched_group_identity_enabled"
	KernelSchedCore                = "kernel/sched_core"

	SysNUMASubDir   = "bus/node/devices"
	SysPCIDeviceDir = "bus/pci/devices"

	SysCPUSMTActiveSubPath       = "devices/system/cpu/smt/active"
	SysIntelPStateNoTurboSubPath = "devices/system/cpu/intel_pstate/no_turbo"
)
View Source
const (
	ProcSysVmRelativePath     = "sys/vm/"
	MemcgReaperRelativePath   = "kernel/mm/memcg_reaper/"
	KidledRelativePath        = "kernel/mm/kidled/"
	SchedFeaturesRelativePath = "kernel/debug/"

	MinFreeKbytesFileName             = "min_free_kbytes"
	WatermarkScaleFactorFileName      = "watermark_scale_factor"
	MemcgReapBackGroundFileName       = "reap_background"
	KidledScanPeriodInSecondsFileName = "scan_period_in_seconds"
	KidledUseHierarchyFileFileName    = "use_hierarchy"
	SchedFeaturesFileName             = "sched_features"
)
View Source
const ErrCgroupDir = "cgroup path or file not exist"
View Source
const ErrResourceUnsupportedPrefix = "resource is unsupported"

Variables

View Source
var (
	NaturalInt64Validator = &RangeValidator{min: 0, max: math.MaxInt64}

	CPUSharesValidator                      = &RangeValidator{min: CPUSharesMinValue, max: CPUSharesMaxValue}
	CPUBurstValidator                       = &RangeValidator{min: 0, max: 100 * 10 * 100000}
	CPUBvtWarpNsValidator                   = &RangeValidator{min: -1, max: 2}
	CPUWeightValidator                      = &RangeValidator{min: CPUWeightMinValue, max: CPUWeightMaxValue}
	CPUMaxBurstValidator                    = &RangeValidator{min: 0, max: math.MaxInt64}
	CPUIdleValidator                        = &RangeValidator{min: 0, max: 1}
	MemoryWmarkRatioValidator               = &RangeValidator{min: 0, max: 100}
	MemoryPriorityValidator                 = &RangeValidator{min: 0, max: 12}
	MemoryOomGroupValidator                 = &RangeValidator{min: 0, max: 1}
	MemoryUsePriorityOomValidator           = &RangeValidator{min: 0, max: 1}
	MemoryWmarkMinAdjValidator              = &RangeValidator{min: -25, max: 50}
	MemoryWmarkScaleFactorFileNameValidator = &RangeValidator{min: 1, max: 1000}
	BlkioTRIopsValidator                    = &BlkIORangeValidator{min: 0, max: math.MaxInt64, resource: BlkioTRIopsName}
	BlkioTRBpsValidator                     = &BlkIORangeValidator{min: 0, max: math.MaxInt64, resource: BlkioTRBpsName}
	BlkioTWIopsValidator                    = &BlkIORangeValidator{min: 0, max: math.MaxInt64, resource: BlkioTWIopsName}
	BlkioTWBpsValidator                     = &BlkIORangeValidator{min: 0, max: math.MaxInt64, resource: BlkioTWBpsName}
	BlkioIOWeightValidator                  = &BlkIORangeValidator{min: 1, max: 100, resource: BlkioIOWeightName}
	BlkioIOQoSValidator                     = &BlkIORangeValidator{min: 0, max: math.MaxInt64, resource: BlkioIOQoSName}
	BlkioIOModelValidator                   = &BlkIORangeValidator{min: 1, max: math.MaxInt64, resource: BlkioIOModelName}

	CPUSetCPUSValidator = &CPUSetStrValidator{}
)
View Source
var (
	DefaultFactory = NewCgroupResourceFactory()

	CPUStat      = DefaultFactory.New(CPUStatName, CgroupCPUDir)
	CPUShares    = DefaultFactory.New(CPUSharesName, CgroupCPUDir).WithValidator(CPUSharesValidator)
	CPUCFSQuota  = DefaultFactory.New(CPUCFSQuotaName, CgroupCPUDir)
	CPUCFSPeriod = DefaultFactory.New(CPUCFSPeriodName, CgroupCPUDir)
	CPUBurst     = DefaultFactory.New(CPUBurstName, CgroupCPUDir).WithValidator(CPUBurstValidator).WithCheckSupported(SupportedIfFileExists)
	CPUBVTWarpNs = DefaultFactory.New(CPUBVTWarpNsName, CgroupCPUDir).WithValidator(CPUBvtWarpNsValidator).WithCheckSupported(SupportedIfFileExists)
	CPUIdle      = DefaultFactory.New(CPUIdleName, CgroupCPUDir).WithValidator(CPUIdleValidator).WithCheckSupported(SupportedIfFileExistsInKubepods).WithCheckOnce(true)
	CPUTasks     = DefaultFactory.New(CPUTasksName, CgroupCPUDir)
	CPUProcs     = DefaultFactory.New(CPUProcsName, CgroupCPUDir)

	CPUSet = DefaultFactory.New(CPUSetCPUSName, CgroupCPUSetDir).WithValidator(CPUSetCPUSValidator)

	CPUAcctStat           = DefaultFactory.New(CPUAcctStatName, CgroupCPUAcctDir)
	CPUAcctUsage          = DefaultFactory.New(CPUAcctUsageName, CgroupCPUAcctDir)
	CPUAcctCPUPressure    = DefaultFactory.New(CPUAcctCPUPressureName, CgroupCPUAcctDir).WithCheckSupported(SupportedIfFileExistsInKubepods).WithCheckOnce(true)
	CPUAcctMemoryPressure = DefaultFactory.New(CPUAcctMemoryPressureName, CgroupCPUAcctDir).WithCheckSupported(SupportedIfFileExistsInKubepods).WithCheckOnce(true)
	CPUAcctIOPressure     = DefaultFactory.New(CPUAcctIOPressureName, CgroupCPUAcctDir).WithCheckSupported(SupportedIfFileExistsInKubepods).WithCheckOnce(true)

	MemoryLimit            = DefaultFactory.New(MemoryLimitName, CgroupMemDir)
	MemoryUsage            = DefaultFactory.New(MemoryUsageName, CgroupMemDir)
	MemoryStat             = DefaultFactory.New(MemoryStatName, CgroupMemDir)
	MemoryNumaStat         = DefaultFactory.New(MemoryNumaStatName, CgroupMemDir)
	MemoryWmarkRatio       = DefaultFactory.New(MemoryWmarkRatioName, CgroupMemDir).WithValidator(MemoryWmarkRatioValidator).WithCheckSupported(SupportedIfFileExistsInKubepods).WithCheckOnce(true)
	MemoryWmarkScaleFactor = DefaultFactory.New(MemoryWmarkScaleFactorName, CgroupMemDir).WithValidator(MemoryWmarkScaleFactorFileNameValidator).WithCheckSupported(SupportedIfFileExistsInKubepods).WithCheckOnce(true)
	MemoryWmarkMinAdj      = DefaultFactory.New(MemoryWmarkMinAdjName, CgroupMemDir).WithValidator(MemoryWmarkMinAdjValidator).WithCheckSupported(SupportedIfFileExistsInKubepods).WithCheckOnce(true)
	MemoryMin              = DefaultFactory.New(MemoryMinName, CgroupMemDir).WithValidator(NaturalInt64Validator).WithCheckSupported(SupportedIfFileExistsInKubepods).WithCheckOnce(true)
	MemoryLow              = DefaultFactory.New(MemoryLowName, CgroupMemDir).WithValidator(NaturalInt64Validator).WithCheckSupported(SupportedIfFileExistsInKubepods).WithCheckOnce(true)
	MemoryHigh             = DefaultFactory.New(MemoryHighName, CgroupMemDir).WithValidator(NaturalInt64Validator).WithCheckSupported(SupportedIfFileExistsInKubepods).WithCheckOnce(true)
	MemoryPriority         = DefaultFactory.New(MemoryPriorityName, CgroupMemDir).WithValidator(MemoryPriorityValidator).WithCheckSupported(SupportedIfFileExistsInKubepods).WithCheckOnce(true)
	MemoryUsePriorityOom   = DefaultFactory.New(MemoryUsePriorityOomName, CgroupMemDir).WithValidator(MemoryUsePriorityOomValidator).WithCheckSupported(SupportedIfFileExistsInKubepods).WithCheckOnce(true)
	MemoryOomGroup         = DefaultFactory.New(MemoryOomGroupName, CgroupMemDir).WithValidator(MemoryOomGroupValidator).WithCheckSupported(SupportedIfFileExistsInKubepods).WithCheckOnce(true)
	MemoryIdlePageStats    = DefaultFactory.New(MemoryIdlePageStatsName, CgroupMemDir).WithCheckSupported(SupportedIfFileExistsInKubepods).WithCheckOnce(true)

	BlkioReadIops  = DefaultFactory.New(BlkioTRIopsName, CgroupBlkioDir).WithValidator(BlkioTRIopsValidator).WithCheckSupported(SupportedIfFileExistsInKubepods).WithCheckOnce(true)
	BlkioReadBps   = DefaultFactory.New(BlkioTRBpsName, CgroupBlkioDir).WithValidator(BlkioTRBpsValidator).WithCheckSupported(SupportedIfFileExistsInKubepods).WithCheckOnce(true)
	BlkioWriteIops = DefaultFactory.New(BlkioTWIopsName, CgroupBlkioDir).WithValidator(BlkioTWIopsValidator).WithCheckSupported(SupportedIfFileExistsInKubepods).WithCheckOnce(true)
	BlkioWriteBps  = DefaultFactory.New(BlkioTWBpsName, CgroupBlkioDir).WithValidator(BlkioTWBpsValidator).WithCheckSupported(SupportedIfFileExistsInKubepods).WithCheckOnce(true)
	BlkioIOWeight  = DefaultFactory.New(BlkioIOWeightName, CgroupBlkioDir).WithValidator(BlkioIOWeightValidator).WithCheckSupported(SupportedIfFileExistsInKubepods).WithCheckOnce(true)
	BlkioIOQoS     = DefaultFactory.New(BlkioIOQoSName, CgroupBlkioDir).WithValidator(BlkioIOQoSValidator).WithSupported(SupportedIfFileExistsInRootCgroup(BlkioIOQoSName, CgroupBlkioDir))
	BlkioIOModel   = DefaultFactory.New(BlkioIOModelName, CgroupBlkioDir).WithValidator(BlkioIOModelValidator).WithSupported(SupportedIfFileExistsInRootCgroup(BlkioIOModelName, CgroupBlkioDir))

	CPUCFSQuotaV2  = DefaultFactory.NewV2(CPUCFSQuotaName, CPUMaxName)
	CPUCFSPeriodV2 = DefaultFactory.NewV2(CPUCFSPeriodName, CPUMaxName)
	CPUSharesV2    = DefaultFactory.NewV2(CPUSharesName, CPUWeightName).WithValidator(CPUWeightValidator)
	CPUStatV2      = DefaultFactory.NewV2(CPUStatName, CPUStatName)
	CPUAcctStatV2  = DefaultFactory.NewV2(CPUAcctStatName, CPUStatName)
	CPUAcctUsageV2 = DefaultFactory.NewV2(CPUAcctUsageName, CPUStatName)
	CPUBurstV2     = DefaultFactory.NewV2(CPUBurstName, CPUMaxBurstName).WithValidator(CPUMaxBurstValidator).WithCheckSupported(SupportedIfFileExistsInKubepods).WithCheckOnce(true)
	CPUBVTWarpNsV2 = DefaultFactory.NewV2(CPUBVTWarpNsName, CPUBVTWarpNsName).WithValidator(CPUBvtWarpNsValidator).WithCheckSupported(SupportedIfFileExists)
	CPUIdleV2      = DefaultFactory.NewV2(CPUIdleName, CPUIdleName).WithValidator(CPUIdleValidator).WithCheckSupported(SupportedIfFileExistsInKubepods).WithCheckOnce(true)

	CPUAcctCPUPressureV2    = DefaultFactory.NewV2(CPUAcctCPUPressureName, CPUAcctCPUPressureName).WithCheckSupported(SupportedIfFileExistsInKubepods).WithCheckOnce(true)
	CPUAcctMemoryPressureV2 = DefaultFactory.NewV2(CPUAcctMemoryPressureName, CPUAcctMemoryPressureName).WithCheckSupported(SupportedIfFileExistsInKubepods).WithCheckOnce(true)
	CPUAcctIOPressureV2     = DefaultFactory.NewV2(CPUAcctIOPressureName, CPUAcctIOPressureName).WithCheckSupported(SupportedIfFileExistsInKubepods).WithCheckOnce(true)

	CPUSetV2                 = DefaultFactory.NewV2(CPUSetCPUSName, CPUSetCPUSName).WithValidator(CPUSetCPUSValidator)
	CPUSetEffectiveV2        = DefaultFactory.NewV2(CPUSetCPUSEffectiveName, CPUSetCPUSEffectiveName) // TODO: unify the R/W
	CPUTasksV2               = DefaultFactory.NewV2(CPUTasksName, CPUThreadsName)
	CPUProcsV2               = DefaultFactory.NewV2(CPUProcsName, CPUProcsName)
	MemoryLimitV2            = DefaultFactory.NewV2(MemoryLimitName, MemoryMaxName)
	MemoryUsageV2            = DefaultFactory.NewV2(MemoryUsageName, MemoryCurrentName)
	MemoryStatV2             = DefaultFactory.NewV2(MemoryStatName, MemoryStatName)
	MemoryNumaStatV2         = DefaultFactory.NewV2(MemoryNumaStatName, MemoryNumaStatName)
	MemoryMinV2              = DefaultFactory.NewV2(MemoryMinName, MemoryMinName).WithValidator(NaturalInt64Validator)
	MemoryLowV2              = DefaultFactory.NewV2(MemoryLowName, MemoryLowName).WithValidator(NaturalInt64Validator)
	MemoryHighV2             = DefaultFactory.NewV2(MemoryHighName, MemoryHighName).WithValidator(NaturalInt64Validator)
	MemoryWmarkRatioV2       = DefaultFactory.NewV2(MemoryWmarkRatioName, MemoryWmarkRatioName).WithValidator(MemoryWmarkRatioValidator).WithCheckSupported(SupportedIfFileExists)
	MemoryWmarkScaleFactorV2 = DefaultFactory.NewV2(MemoryWmarkScaleFactorName, MemoryWmarkScaleFactorName).WithValidator(MemoryWmarkScaleFactorFileNameValidator).WithCheckSupported(SupportedIfFileExists)
	MemoryWmarkMinAdjV2      = DefaultFactory.NewV2(MemoryWmarkMinAdjName, MemoryWmarkMinAdjName).WithValidator(MemoryWmarkMinAdjValidator).WithCheckSupported(SupportedIfFileExists)
	MemoryPriorityV2         = DefaultFactory.NewV2(MemoryPriorityName, MemoryPriorityName).WithValidator(MemoryPriorityValidator).WithCheckSupported(SupportedIfFileExists)
	MemoryUsePriorityOomV2   = DefaultFactory.NewV2(MemoryUsePriorityOomName, MemoryUsePriorityOomName).WithValidator(MemoryUsePriorityOomValidator).WithCheckSupported(SupportedIfFileExists)
	MemoryOomGroupV2         = DefaultFactory.NewV2(MemoryOomGroupName, MemoryOomGroupName).WithValidator(MemoryOomGroupValidator).WithCheckSupported(SupportedIfFileExists)
)

for cgroup resources, we use the corresponding cgroups-v1 filename as its resource type

View Source
var (
	CommonRootDir = "" // for uni-test
	PageSize      = int64(syscall.Getpagesize())
)
View Source
var (
	MinFreeKbytesValidator             = &RangeValidator{min: 10 * 1024, max: 10 * 1024 * 1024}
	WatermarkScaleFactorValidator      = &RangeValidator{min: 10, max: 400}
	MemcgReapBackGroundValidator       = &RangeValidator{min: 0, max: 1}
	KidledScanPeriodInSecondsValidator = &RangeValidator{min: 0, max: math.MaxInt64}
	KidledUseHierarchyValidator        = &RangeValidator{min: 0, max: 1}
)
View Source
var AgentMode = DS_MODE
View Source
var (
	CacheIdsCacheFunc func() ([]int, error)
)
View Source
var CgroupPathFormatter = GetCgroupFormatter()

CgroupPathFormatter is the cgroup driver formatter. It is initialized with a fastly looked-up type and will be slowly detected with the kubelet when the daemon starts.

View Source
var DefaultRegistry = NewCgroupResourceRegistry()
View Source
var ExecCmdOnHost = execCmdOnHostFn

If running in container, exec command by 'nsenter --mount=/proc/1/ns/mnt ${cmds}'. return stdout, exitcode, error

View Source
var HostSystemInfo = collectVersionInfo()
View Source
var (
	// Jiffies is the duration unit of CPU stats. Normally, it is 10ms.
	Jiffies = float64(10 * time.Millisecond)
)
View Source
var PidOf = pidOfFn

PidOf finds process(es) with a specified name (regexp match) and return their pid(s).

View Source
var UseCgroupsV2 = atomic.NewBool(false)
View Source
var (
	// VirtualCoreSchedCookie represents a virtual system resource for the core scheduling cookie.
	// It is virtual for denoting the operation on processes' core scheduling cookie, and it is not allowed to do
	// any real read or write on the provided filepath.
	VirtualCoreSchedCookie = NewCommonSystemResource("", VirtualCoreSchedCookieName, GetProcRootDir)
)

Functions

func CalcCPUThrottledRatio

func CalcCPUThrottledRatio(curPoint, prePoint *CPUStatRaw) float64

func CalculateCatL3MaskValue added in v1.1.0

func CalculateCatL3MaskValue(cbm uint, startPercent, endPercent int64) (string, error)

func CheckAndTryEnableResctrlCat

func CheckAndTryEnableResctrlCat() error

CheckAndTryEnableResctrlCat checks if resctrl and l3_cat are enabled; if not, try to enable the features by mount resctrl subsystem; See MountResctrlSubsystem() for the detail. It returns whether the resctrl cat is enabled, and the error if failed to enable or to check resctrl interfaces

func CheckIfAllSupported added in v1.1.0

func CheckIfAllSupported(checkSupportedFns ...func() (bool, string)) func() (bool, string)

func CheckResctrlSchemataValid added in v1.4.0

func CheckResctrlSchemataValid() error

func CommonFileRead

func CommonFileRead(file string) (string, error)

func CommonFileWrite

func CommonFileWrite(file string, data string) error

func CommonFileWriteIfDifferent

func CommonFileWriteIfDifferent(file string, value string) (bool, error)

func ConvertCPUSharesToWeight added in v1.1.0

func ConvertCPUSharesToWeight(s string) (int64, error)

func ConvertCPUWeightToShares added in v1.1.0

func ConvertCPUWeightToShares(v int64) (int64, error)

ConvertCPUWeightToShares converts the value of `cpu.weight` (cgroups-v2) into the value of `cpu.shares` (cgroups-v1)

func EnableCoreSchedIfSupported added in v1.4.0

func EnableCoreSchedIfSupported() (bool, string)

EnableCoreSchedIfSupported checks if the core scheduling feature is enabled in the kernel sched_features. If kernel supported (available in the latest Anolis OS), it tries to enable the core scheduling feature. The core sched's kernel feature is known set in two places, if both of them are not found, the system is considered unsupported for the core scheduling:

  1. In `/proc/sys/kernel/sched_core`, the value `1` means the feature is enabled while `0` means disabled.
  2. (Older kernel) In `/sys/kernel/debug/sched_features`, the field `CORE_SCHED` means the feature is enabled while `NO_CORE_SCHED` means it is disabled.

func FileExists

func FileExists(path string) bool

func GetCPUInfoPath added in v1.4.0

func GetCPUInfoPath() string

func GetCacheIds added in v1.4.1

func GetCacheIds() ([]int, error)

GetCacheIds get cache ids from schemata file. e.g. schemata=`L3:0=fff;1=fff\nMB:0=100;1=100\n` -> [0, 1]

func GetCacheInfo added in v1.1.0

func GetCacheInfo(str string) (string, int32, error)

GetCacheInfo parses the output of `lscpu -e=CACHE` into l1l2 and l3 infos e.g. - input: "1:1:1:0" - output: "1", 0, nil

func GetCgroupFilePath

func GetCgroupFilePath(cgroupTaskDir string, r Resource) string

GetCgroupFilePath gets the full path of the given cgroup dir and resource. @cgroupTaskDir kubepods.slice/kubepods-pod7712555c_ce62_454a_9e18_9ff0217b8941.slice/ @return /sys/fs/cgroup/cpu/kubepods.slice/kubepods-pod7712555c_ce62_454a_9e18_9ff0217b8941.slice/cpu.shares

func GetContainerPGIDs added in v1.4.0

func GetContainerPGIDs(containerParentDir string) ([]uint32, error)

func GetIsStartColdMemory added in v1.4.0

func GetIsStartColdMemory() bool

func GetIsSupportColdMemory added in v1.4.0

func GetIsSupportColdMemory() bool

func GetKidledColdBoundary added in v1.4.0

func GetKidledColdBoundary() int

func GetKubeletCommandline added in v1.1.0

func GetKubeletCommandline(port int) ([]string, error)

func GetNUMAHugepagesDir added in v1.4.0

func GetNUMAHugepagesDir(numaNodeSubDir string) string

func GetNUMAHugepagesNrPath added in v1.4.0

func GetNUMAHugepagesNrPath(numaNodeSubDir string, page string) string

func GetNUMAMemInfoPath added in v1.3.0

func GetNUMAMemInfoPath(numaNodeSubDir string) string

func GetPCIDeviceDir added in v1.4.0

func GetPCIDeviceDir() string

func GetPGIDForPID added in v1.4.0

func GetPGIDForPID(pid uint32) (uint32, error)

func GetPGIDsForPIDs added in v1.4.0

func GetPGIDsForPIDs(pids []uint32) ([]uint32, error)

GetPGIDsForPIDs gets the PGIDs for a cgroup's PIDs. It will consider the PID as PGID if its PGID does not exist anymore.

func GetPeriodTicks added in v1.1.0

func GetPeriodTicks(start, end time.Time) float64

func GetProcFilePath added in v1.1.0

func GetProcFilePath(procRelativePath string) string

func GetProcPIDStatPath added in v1.4.0

func GetProcPIDStatPath(pid uint32) string

func GetProcRootDir added in v1.2.0

func GetProcRootDir() string

func GetProcSysFilePath added in v1.1.0

func GetProcSysFilePath(file string) string

func GetResctrlGroupRootDirPath

func GetResctrlGroupRootDirPath(groupPath string) string

@groupPath BE @return /sys/fs/resctrl/BE

func GetResctrlL3CbmFilePath

func GetResctrlL3CbmFilePath() string

@return /sys/fs/resctrl/info/L3/cbm_mask

func GetResctrlSchemataFilePath

func GetResctrlSchemataFilePath(groupPath string) string

@groupPath BE @return /sys/fs/resctrl/BE/schemata

func GetResctrlSubsystemDirPath

func GetResctrlSubsystemDirPath() string

@return /sys/fs/resctrl

func GetResctrlTasksFilePath

func GetResctrlTasksFilePath(groupPath string) string

@groupPath BE @return /sys/fs/resctrl/BE/tasks

func GetRootCgroupSubfsDir added in v1.3.0

func GetRootCgroupSubfsDir(subfs string) string

func GetSchedCore added in v1.4.0

func GetSchedCore() (bool, error)

func GetSchedGroupIdentity added in v1.4.1

func GetSchedGroupIdentity() (bool, error)

func GetSysCPUSMTActivePath added in v1.4.0

func GetSysCPUSMTActivePath() string

func GetSysIntelPStateNoTurboPath added in v1.4.0

func GetSysIntelPStateNoTurboPath() string

func GetSysNUMADir added in v1.3.0

func GetSysNUMADir() string

func GetSysRootDir added in v1.2.0

func GetSysRootDir() string

func GetVendorIDByCPUInfo added in v1.2.0

func GetVendorIDByCPUInfo(path string) (string, error)

GetVendorIDByCPUInfo returns vendor_id like AuthenticAMD from cpu info, e.g. vendor_id : AuthenticAMD vendor_id : GenuineIntel

func GoWithNewThread added in v1.4.0

func GoWithNewThread(f func() interface{}) interface{}

GoWithNewThread synchronously runs the function in a new goroutine bound to a new OS thread.

func InitCatGroupIfNotExist added in v1.1.0

func InitCatGroupIfNotExist(group string) (bool, error)

func InitSupportConfigs added in v1.4.1

func InitSupportConfigs()

InitSupportConfigs initializes the system support status. e.g. the cgroup version, resctrl capability

func IsCgroupV2Resource added in v1.2.0

func IsCgroupV2Resource(r Resource) bool

func IsCoreSchedFeatureEnabled added in v1.4.0

func IsCoreSchedFeatureEnabled() (bool, error)

func IsCoreSchedSupported added in v1.4.1

func IsCoreSchedSupported() (bool, string)

IsCoreSchedSupported checks if the kernel supports the core scheduling. Currently, it relies on the interfaces provided by the Anolis OS.

func IsCoreSchedSysctlSupported added in v1.4.1

func IsCoreSchedSysctlSupported() bool

func IsGroupIdentitySysctlSupported added in v1.4.1

func IsGroupIdentitySysctlSupported() bool

func IsKidledSupport added in v1.4.0

func IsKidledSupport() bool

check kidled and set var isSupportColdSupport

func IsResourceUnsupportedErr added in v1.1.0

func IsResourceUnsupportedErr(err error) bool

func IsSupportResctrl added in v1.1.0

func IsSupportResctrl() (bool, error)

func IsUsingCgroupsV2 added in v1.1.0

func IsUsingCgroupsV2() bool

IsUsingCgroupsV2 checks once if the CGroup V2 is in use. modify base: github.com/opencontainers/runc/libcontainer/cgroups/utils.go IsCgroup2UnifiedMode

func KubeletPortToPid added in v1.1.0

func KubeletPortToPid(port int) (int, error)

KubeletPortToPid Query pid by tcp port number with the help of go-netstat note: Due to the low efficiency of full traversal, we cache the result and verify each time

func MilliCPUToQuota added in v1.4.0

func MilliCPUToQuota(milliCPULimit int64) int64

func MilliCPUToShares added in v1.4.0

func MilliCPUToShares(milliCPURequest int64) int64

func MountResctrlSubsystem

func MountResctrlSubsystem() (bool, error)

MountResctrlSubsystem mounts resctrl fs under the sysFSRoot to enable the kernel feature on supported environment NOTE: Linux kernel (>= 4.10), Intel cpu and bare-mental host are required; Also, Intel RDT features should be enabled in kernel configurations and kernel commandline. For more info, please see https://github.com/intel/intel-cmt-cat/wiki/resctrl

func NewProcSysctl added in v1.1.0

func NewProcSysctl() utilsysctl.Interface

func ParseCPUAcctUsageV2 added in v1.1.0

func ParseCPUAcctUsageV2(content string) (uint64, error)

func ParseCPUCFSPeriodV2 added in v1.1.0

func ParseCPUCFSPeriodV2(content string) (int64, error)

func ParseCPUCFSQuotaV2 added in v1.1.0

func ParseCPUCFSQuotaV2(content string) (int64, error)

func ParseCgroupProcs added in v1.4.0

func ParseCgroupProcs(content string) ([]uint32, error)

ParseCgroupProcs parses the content in cgroup.procs. pattern: `7742\n10971\n11049\n11051...` TODO: refactor with readCgroupAndParseInt32Slice via Generics.

func ParseKVMap added in v1.1.0

func ParseKVMap(content string) map[string]string

ParseKVMap parses a file content into a KV map. e.g. `user 100\nsystem 20` -> `{"user": "100", "system": "20"}`

func ParseResctrlSchemataMap added in v1.1.0

func ParseResctrlSchemataMap(content string) map[string]map[int]string

ParseResctrlSchemataMap parses the content of resctrl schemata. e.g. schemata=`L3:0=fff;1=fff\nMB:0=100;1=100\n` -> `{"L3": {0: "fff", 1: "fff"}, "MB": {0: "100", 1: "100"}}`

func PathExists

func PathExists(path string) (bool, error)

func ProcCmdLine

func ProcCmdLine(procRoot string, pid int) ([]string, error)

CmdLine returns the command line args of a process.

func ReadCatL3CbmString

func ReadCatL3CbmString() (string, error)

ReadCatL3CbmString reads and returns the value of cat l3 cbm_mask

func ReadFileNoStat

func ReadFileNoStat(filename string) ([]byte, error)

ReadFileNoStat uses io.ReadAll to read contents of entire file. This is similar to io.ReadFile but without the call to os.Stat, because many files in /proc and /sys report incorrect file sizes (either 0 or 4096). Reads a max file size of 512kB. For files larger than this, a scanner should be used.

func ReadResctrlTasksMap

func ReadResctrlTasksMap(groupPath string) (map[int32]struct{}, error)

ReadResctrlTasksMap reads and returns the map of given resctrl group's task ids

func ResourceUnsupportedErr added in v1.1.0

func ResourceUnsupportedErr(msg string) error

func SetConf

func SetConf(config Config)

func SetCoreSchedFeatureEnabled added in v1.4.0

func SetCoreSchedFeatureEnabled() (bool, string)

SetCoreSchedFeatureEnabled checks if the core scheduling feature can be enabled in the kernel sched_features.

func SetIsStartColdMemory added in v1.4.0

func SetIsStartColdMemory(flag bool)

func SetIsSupportColdMemory added in v1.4.0

func SetIsSupportColdMemory(flag bool)

func SetKidledColdBoundary added in v1.4.0

func SetKidledColdBoundary(boudary int)

func SetKidledScanPeriodInSeconds added in v1.4.0

func SetKidledScanPeriodInSeconds(period uint32) error

func SetKidledUseHierarchy added in v1.4.0

func SetKidledUseHierarchy(useHierarchy uint8) error

func SetSchedCore added in v1.4.0

func SetSchedCore(enable bool) error

func SetSchedGroupIdentity added in v1.1.0

func SetSchedGroupIdentity(enable bool) error

func SetupCgroupPathFormatter

func SetupCgroupPathFormatter(driver CgroupDriverType)

func SupportedIfFileExists added in v1.1.0

func SupportedIfFileExists(r Resource, dynamicPath string) (bool, string)

func SupportedIfFileExistsInKubepods added in v1.1.0

func SupportedIfFileExistsInKubepods(r Resource, _ string) (bool, string)

func SupportedIfFileExistsInRootCgroup added in v1.3.0

func SupportedIfFileExistsInRootCgroup(filename string, subfs string) (bool, string)

func TCPSocks added in v1.1.0

func TCPSocks(fn netstat.AcceptFn) ([]netstat.SockTabEntry, error)

func ValidateResourceValue added in v1.1.0

func ValidateResourceValue(value *int64, dynamicPath string, r Resource) bool

func WorkingDirOf added in v1.1.0

func WorkingDirOf(pid int) (string, error)

return working dir of process

Types

type BlkIORangeValidator added in v1.3.0

type BlkIORangeValidator struct {
	// contains filtered or unexported fields
}

func (*BlkIORangeValidator) Validate added in v1.3.0

func (r *BlkIORangeValidator) Validate(value string) (bool, string)

type CPUSetStrValidator added in v1.1.0

type CPUSetStrValidator struct{}

func (*CPUSetStrValidator) Validate added in v1.1.0

func (c *CPUSetStrValidator) Validate(value string) (bool, string)

type CPUStatRaw

type CPUStatRaw struct {
	NrPeriods            int64
	NrThrottled          int64
	ThrottledNanoSeconds int64
}

func ParseCPUStatRaw added in v1.1.0

func ParseCPUStatRaw(content string) (*CPUStatRaw, error)

func ParseCPUStatRawV2 added in v1.1.0

func ParseCPUStatRawV2(content string) (*CPUStatRaw, error)

type CPUStatV2Raw added in v1.1.0

type CPUStatV2Raw struct {
	UsageUsec  int64
	UserUsec   int64
	SystemUSec int64

	NrPeriods     int64
	NrThrottled   int64
	ThrottledUSec int64
}

func ParseCPUAcctStatRawV2 added in v1.1.0

func ParseCPUAcctStatRawV2(content string) (*CPUStatV2Raw, error)

type CgroupDriverType

type CgroupDriverType string

func GetCgroupDriver added in v1.3.0

func GetCgroupDriver() CgroupDriverType

GetCgroupDriver gets the cgroup driver both from the cgroup directory names and kubelet configs. Check kubelet config can be slow, so it should be called infrequently.

func GetCgroupDriverFromCgroupName added in v1.3.0

func GetCgroupDriverFromCgroupName() CgroupDriverType

func GetCgroupDriverFromKubelet added in v1.3.0

func GetCgroupDriverFromKubelet(nodeName string) (CgroupDriverType, error)

func GetCgroupDriverFromKubeletPort added in v1.3.0

func GetCgroupDriverFromKubeletPort(port int) (CgroupDriverType, error)

GetCgroupDriverFromKubeletPort get Kubelet's cgroup driver from kubelet port.

  1. use KubeletPortToPid to get kubelet pid.
  2. If '--cgroup-driver' in args, that's it. else if '--config' not in args, is default driver('cgroupfs'). else go to step-3.
  3. If kubelet config is relative path, join with /proc/${pidof kubelet}/cwd. search 'cgroupDriver:' in kubelet config file, that's it.

func (CgroupDriverType) Validate

func (c CgroupDriverType) Validate() bool

type CgroupResource added in v1.1.0

type CgroupResource struct {
	Type           ResourceType
	FileName       string
	Subfs          string
	Supported      *bool
	SupportMsg     string
	CheckSupported func(r Resource, parentDir string) (isSupported bool, msg string)
	CheckOnce      bool
	Validator      ResourceValidator
	CgroupVersion  CgroupVersion
}

func (*CgroupResource) GetCgroupVersion added in v1.2.0

func (c *CgroupResource) GetCgroupVersion() CgroupVersion

func (*CgroupResource) IsSupported added in v1.1.0

func (c *CgroupResource) IsSupported(parentDir string) (bool, string)

func (*CgroupResource) IsValid added in v1.1.0

func (c *CgroupResource) IsValid(v string) (bool, string)

func (*CgroupResource) Path added in v1.1.0

func (c *CgroupResource) Path(parentDir string) string

func (*CgroupResource) ResourceType added in v1.1.0

func (c *CgroupResource) ResourceType() ResourceType

func (*CgroupResource) SetCgroupVersion added in v1.2.0

func (c *CgroupResource) SetCgroupVersion(cv CgroupVersion)

func (*CgroupResource) WithCheckOnce added in v1.3.0

func (c *CgroupResource) WithCheckOnce(isCheckOnce bool) Resource

func (*CgroupResource) WithCheckSupported added in v1.1.0

func (c *CgroupResource) WithCheckSupported(checkSupportedFn func(r Resource, parentDir string) (isSupported bool, msg string)) Resource

func (*CgroupResource) WithSupported added in v1.1.0

func (c *CgroupResource) WithSupported(isSupported bool, msg string) Resource

func (*CgroupResource) WithValidator added in v1.1.0

func (c *CgroupResource) WithValidator(validator ResourceValidator) Resource

type CgroupResourceFactory added in v1.1.0

type CgroupResourceFactory interface {
	New(filename string, subfs string) Resource // cgroup-v1 filename represents the resource type
	NewV2(t ResourceType, filename string) Resource
}

func NewCgroupResourceFactory added in v1.1.0

func NewCgroupResourceFactory() CgroupResourceFactory

type CgroupResourceRegistry added in v1.1.0

type CgroupResourceRegistry interface {
	Add(v CgroupVersion, s ...Resource)
	Get(v CgroupVersion, t ResourceType) (Resource, bool)
}

func NewCgroupResourceRegistry added in v1.1.0

func NewCgroupResourceRegistry() CgroupResourceRegistry

type CgroupResourceRegistryImpl added in v1.1.0

type CgroupResourceRegistryImpl struct {
	// contains filtered or unexported fields
}

func (*CgroupResourceRegistryImpl) Add added in v1.1.0

func (*CgroupResourceRegistryImpl) Get added in v1.1.0

type CgroupVersion added in v1.1.0

type CgroupVersion int32
const (
	CgroupVersionV1 CgroupVersion = 1
	CgroupVersionV2 CgroupVersion = 2
)

func GetCurrentCgroupVersion added in v1.1.0

func GetCurrentCgroupVersion() CgroupVersion

type ColdPageInfoByKidled added in v1.4.0

type ColdPageInfoByKidled struct {
	Version             string   `json:"version"`
	PageScans           uint64   `json:"page_scans"`
	SlabScans           uint64   `json:"slab_scans"`
	ScanPeriodInSeconds uint64   `json:"scan_period_in_seconds"`
	UseHierarchy        uint64   `json:"use_hierarchy"`
	Buckets             []uint64 `json:"buckets"`
	Csei                []uint64 `json:"csei"`
	Dsei                []uint64 `json:"dsei"`
	Cfei                []uint64 `json:"cfei"`
	Dfei                []uint64 `json:"dfei"`
	Csui                []uint64 `json:"csui"`
	Dsui                []uint64 `json:"dsui"`
	Cfui                []uint64 `json:"cfui"`
	Dfui                []uint64 `json:"dfui"`
	Csea                []uint64 `json:"csea"`
	Dsea                []uint64 `json:"dsea"`
	Cfea                []uint64 `json:"cfea"`
	Dfea                []uint64 `json:"dfea"`
	Csua                []uint64 `json:"csua"`
	Dsua                []uint64 `json:"dsua"`
	Cfua                []uint64 `json:"cfua"`
	Dfua                []uint64 `json:"dfua"`
	Slab                []uint64 `json:"slab"`
}

the unit of Csei, Dsei, Cfei ... is byte the detailed description can be seen in https://github.com/alibaba/cloud-kernel/blob/linux-next/Documentation/vm/kidled.rst

func ParseMemoryIdlePageStats added in v1.4.0

func ParseMemoryIdlePageStats(content string) (*ColdPageInfoByKidled, error)

func (*ColdPageInfoByKidled) GetColdPageTotalBytes added in v1.4.0

func (i *ColdPageInfoByKidled) GetColdPageTotalBytes() uint64

boundary is the index of [1,2) [2,5) [5,15) [15,30) [30,60) [60,120) [120,240) [240,+inf). if boundary is equal to 3, it will compute sum([5*scan_period_scands,+inf)) of cold page cache

type Config

type Config struct {
	CgroupRootDir         string
	SysRootDir            string
	SysFSRootDir          string
	ProcRootDir           string
	VarRunRootDir         string
	VarLibKubeletRootDir  string
	RunRootDir            string
	RuntimeHooksConfigDir string

	ContainerdEndPoint string
	PouchEndpoint      string
	DockerEndPoint     string
	CrioEndPoint       string
	DefaultRuntimeType string
}

func NewDsModeConfig

func NewDsModeConfig() *Config

func NewHostModeConfig

func NewHostModeConfig() *Config

func (*Config) InitFlags

func (c *Config) InitFlags(fs *flag.FlagSet)

type CoreSched added in v1.4.0

type CoreSched struct{}

func (*CoreSched) Assign added in v1.4.0

func (s *CoreSched) Assign(pidTypeFrom CoreSchedScopeType, pidFrom uint32, pidTypeTo CoreSchedScopeType, pidsTo ...uint32) ([]uint32, error)

func (*CoreSched) Clear added in v1.4.0

func (s *CoreSched) Clear(pidType CoreSchedScopeType, pids ...uint32) ([]uint32, error)

func (*CoreSched) Create added in v1.4.0

func (s *CoreSched) Create(pidType CoreSchedScopeType, pid uint32) error

func (*CoreSched) Get added in v1.4.0

func (s *CoreSched) Get(pidType CoreSchedScopeType, pid uint32) (uint64, error)

func (*CoreSched) ShareFrom added in v1.4.0

func (s *CoreSched) ShareFrom(pidType CoreSchedScopeType, pid uint32) error

func (*CoreSched) ShareTo added in v1.4.0

func (s *CoreSched) ShareTo(pidType CoreSchedScopeType, pid uint32) error

type CoreSchedExtendedInterface added in v1.4.0

type CoreSchedExtendedInterface interface {
	CoreSchedInterface
	// Clear clears core sched cookie to the default cookie 0, and returns the list of failed pids.
	// It can be implemented with ShareTo(pidType, pid) where the current task's cookie is 0.
	// e.g. Clear(CoreSchedScopeThreadGroup, 10000, 20000) means reset the cookies of pid 10000 and pid 20000 to 0.
	Clear(pidType CoreSchedScopeType, pids ...uint32) ([]uint32, error)
	// Assign assigns core sched cookie of the pidFrom onto pidsTo, and returns the list of failed pidTos.
	// pidFrom only supports thread-level, while the pidsTo can be in other levels.
	// It can be implemented with ShareFrom(pidTypeFrom, pidFrom) and ShareTo(pidTypeTo, pidTo) where the current task's
	// cookie is locked between the two operations.
	// e.g. Assign(CoreSchedScopeThread, 10000, CoreSchedScopeProcessGroup, 10001, 20000) means set the cookies of the
	// process group 10001 and 20000 as the cookie of the thread 10000.
	Assign(pidTypeFrom CoreSchedScopeType, pidFrom uint32, pidTypeTo CoreSchedScopeType, pidsTo ...uint32) ([]uint32, error)
}

CoreSchedExtendedInterface defines the operations of the Linux Core Scheduling including extended OPs. It implements simplified operations Clear and Assign by combining ShareTo and ShareFrom with an empty thread relay.

func NewCoreSchedExtended added in v1.4.0

func NewCoreSchedExtended() CoreSchedExtendedInterface

func NewFakeCoreSchedExtended added in v1.4.0

func NewFakeCoreSchedExtended(pidToCookie map[uint32]uint64, pidToPGID map[uint32]uint32, pidToError map[uint32]bool) CoreSchedExtendedInterface

type CoreSchedExtendedResult added in v1.4.0

type CoreSchedExtendedResult struct {
	FailedPIDs []uint32
	Error      error
}

type CoreSchedInterface added in v1.4.0

type CoreSchedInterface interface {
	// Get gets core sched cookie of pid.
	// The default cookie ID is 0. It only supports thread-level.
	Get(pidType CoreSchedScopeType, pid uint32) (uint64, error)
	// Create creates a new unique cookie to pid.
	// The cookie ID is generated by the kernel and is unique for each group.
	Create(pidType CoreSchedScopeType, pid uint32) error
	// ShareTo push core sched cookie (of the current task) to pid.
	// e.g. ShareTo(CoreSchedScopeThreadGroup, 10000) means set the cookie of the pid 10000 as the current thread's
	// cookie of the agent.
	ShareTo(pidType CoreSchedScopeType, pid uint32) error
	// ShareFrom pull core sched cookie from pid (to the current task).
	// It only supports thread-level.
	// e.g. ShareFrom(CoreSchedScopeThreadGroup, 10000) means set the current thread's cookie of the agent as the
	// cookie of the pid 10000.
	ShareFrom(pidType CoreSchedScopeType, pid uint32) error
}

CoreSchedInterface defines the basic operations of the Linux Core Scheduling that targets on the PID-level by prctl(). https://docs.kernel.org/admin-guide/hw-vuln/core-scheduling.html

func NewCoreSched added in v1.4.0

func NewCoreSched() CoreSchedInterface

type CoreSchedScopeType added in v1.4.0

type CoreSchedScopeType uint

CoreSchedScopeType defines the type of the PID type operated in core sched.

const (
	// CoreSchedScopeThread means the PID type operated in core sched is a thread.
	CoreSchedScopeThread CoreSchedScopeType = iota
	// CoreSchedScopeThreadGroup means the PID type operated in core sched is a thread group.
	CoreSchedScopeThreadGroup
	// CoreSchedScopeProcessGroup means the PID type operated in core sched is a process group.
	CoreSchedScopeProcessGroup
)

type FakeCoreSchedExtended added in v1.4.0

type FakeCoreSchedExtended struct {
	PIDToCookie  map[uint32]uint64
	PIDToPGID    map[uint32]uint32
	PIDToTGID    map[uint32]uint32
	PIDToError   map[uint32]bool
	CurPID       uint32
	NextCookieID uint64
}

FakeCoreSchedExtended implements the fake CoreSchedExtendedInterface for testing.

func (*FakeCoreSchedExtended) Assign added in v1.4.0

func (f *FakeCoreSchedExtended) Assign(pidTypeFrom CoreSchedScopeType, pidFrom uint32, pidTypeTo CoreSchedScopeType, pidsTo ...uint32) ([]uint32, error)

func (*FakeCoreSchedExtended) Clear added in v1.4.0

func (f *FakeCoreSchedExtended) Clear(pidType CoreSchedScopeType, pids ...uint32) ([]uint32, error)

func (*FakeCoreSchedExtended) Create added in v1.4.0

func (f *FakeCoreSchedExtended) Create(pidType CoreSchedScopeType, pid uint32) error

func (*FakeCoreSchedExtended) Get added in v1.4.0

func (*FakeCoreSchedExtended) SetCurPID added in v1.4.0

func (f *FakeCoreSchedExtended) SetCurPID(pid uint32)

func (*FakeCoreSchedExtended) SetNextCookieID added in v1.4.0

func (f *FakeCoreSchedExtended) SetNextCookieID(id uint64)

func (*FakeCoreSchedExtended) ShareFrom added in v1.4.0

func (f *FakeCoreSchedExtended) ShareFrom(pidType CoreSchedScopeType, pid uint32) error

func (*FakeCoreSchedExtended) ShareTo added in v1.4.0

func (f *FakeCoreSchedExtended) ShareTo(pidType CoreSchedScopeType, pid uint32) error

type FileTestUtil

type FileTestUtil struct {
	// Temporary directory to store mock cgroup filesystem.
	TempDir string
	// whether to validate when writing cgroups resources
	ValidateResource bool
	// additional cleanup function for Config to be invoked in Cleanup()
	CleanupFn func(config *Config)
	// contains filtered or unexported fields
}

func NewFileTestUtil

func NewFileTestUtil(t testing.TB) *FileTestUtil

NewFileTestUtil creates a new test util for the specified subsystem. NOTE: this function should be called only for testing purposes.

func (*FileTestUtil) Cleanup

func (c *FileTestUtil) Cleanup()

func (*FileTestUtil) CreateCgroupFile

func (c *FileTestUtil) CreateCgroupFile(taskDir string, r Resource)

func (*FileTestUtil) CreateFile

func (c *FileTestUtil) CreateFile(testFilePath string)

if filePath contain TempDir, createFile direct, else join with TempDir and create

func (*FileTestUtil) CreateProcSubFile

func (c *FileTestUtil) CreateProcSubFile(fileRelativePath string)

func (*FileTestUtil) MkDirAll

func (c *FileTestUtil) MkDirAll(testDir string)

if dir contain TempDir, mkdir direct, else join with TempDir and mkdir

func (*FileTestUtil) ReadCgroupFileContents

func (c *FileTestUtil) ReadCgroupFileContents(taskDir string, r Resource) string

func (*FileTestUtil) ReadCgroupFileContentsInt added in v1.2.0

func (c *FileTestUtil) ReadCgroupFileContentsInt(taskDir string, r Resource) *int64

func (*FileTestUtil) ReadFileContents

func (c *FileTestUtil) ReadFileContents(testFilePath string) string

if filePath contain TempDir, read direct, else join with TempDir and read

func (*FileTestUtil) ReadProcSubFileContents

func (c *FileTestUtil) ReadProcSubFileContents(relativeFilePath string) string

func (*FileTestUtil) SetAnolisOSResourcesSupported added in v1.1.0

func (c *FileTestUtil) SetAnolisOSResourcesSupported(supported bool)

func (*FileTestUtil) SetCgroupsV2 added in v1.1.0

func (c *FileTestUtil) SetCgroupsV2(useCgroupsV2 bool)

func (*FileTestUtil) SetConf added in v1.4.0

func (c *FileTestUtil) SetConf(setFn, cleanupFn func(conf *Config))

func (*FileTestUtil) SetResourcesSupported added in v1.1.0

func (c *FileTestUtil) SetResourcesSupported(supported bool, resources ...Resource)

func (*FileTestUtil) SetValidateResource added in v1.3.0

func (c *FileTestUtil) SetValidateResource(enabled bool)

func (*FileTestUtil) WriteCgroupFileContents

func (c *FileTestUtil) WriteCgroupFileContents(taskDir string, r Resource, contents string)

WriteCgroupFileContents is only intended for test functions. For specific read/write functionalities, please refer to the executor package.

func (*FileTestUtil) WriteFileContents

func (c *FileTestUtil) WriteFileContents(testFilePath, contents string)

if filePath contain TempDir, write direct, else join with TempDir and write

func (*FileTestUtil) WriteProcSubFileContents

func (c *FileTestUtil) WriteProcSubFileContents(relativeFilePath string, contents string)

type Formatter added in v1.3.0

type Formatter struct {
	ParentDir string
	QOSDirFn  func(qos corev1.PodQOSClass) string
	PodDirFn  func(qos corev1.PodQOSClass, podUID string) string
	// containerID format: "containerd://..." or "docker://...", return (containerd, HashID)
	ContainerDirFn func(id string) (string, string, error)

	PodIDParser       func(basename string) (string, error)
	ContainerIDParser func(basename string) (string, error)
}

func GetCgroupFormatter added in v1.3.0

func GetCgroupFormatter() Formatter

GetCgroupFormatter gets the cgroup formatter simply looking up the cgroup directory names.

func GetCgroupPathFormatter added in v1.3.0

func GetCgroupPathFormatter(driver CgroupDriverType) Formatter

type KidledConfig added in v1.4.0

type KidledConfig struct {
	ScanPeriodInseconds uint32
	UseHierarchy        uint8
	KidledColdBoundary  int
}

func NewDefaultKidledConfig added in v1.4.0

func NewDefaultKidledConfig() *KidledConfig

type MemoryStatRaw added in v1.1.0

type MemoryStatRaw struct {
	Cache        int64
	RSS          int64
	InactiveFile int64
	ActiveFile   int64
	InactiveAnon int64
	ActiveAnon   int64
	Unevictable  int64
}

func ParseMemoryStatRaw added in v1.1.0

func ParseMemoryStatRaw(content string) (*MemoryStatRaw, error)

func ParseMemoryStatRawV2 added in v1.1.0

func ParseMemoryStatRawV2(content string) (*MemoryStatRaw, error)

func (*MemoryStatRaw) Usage added in v1.1.0

func (m *MemoryStatRaw) Usage() int64

func (*MemoryStatRaw) UsageWithPageCache added in v1.4.0

func (m *MemoryStatRaw) UsageWithPageCache() int64

type NumaMemoryPages added in v1.2.0

type NumaMemoryPages struct {
	NumaId   int
	PagesNum uint64
}

func ParseMemoryNumaStat added in v1.2.0

func ParseMemoryNumaStat(content string) ([]NumaMemoryPages, error)

func ParseMemoryNumaStatV2 added in v1.2.0

func ParseMemoryNumaStatV2(content string) ([]NumaMemoryPages, error)

type PSIByResource added in v1.5.0

type PSIByResource struct {
	CPU PSIStats
	Mem PSIStats
	IO  PSIStats
}

func GetPSIByResource added in v1.5.0

func GetPSIByResource(paths PSIPath) (*PSIByResource, error)

type PSILine added in v1.1.0

type PSILine struct {
	Avg10  float64
	Avg60  float64
	Avg300 float64
	Total  uint64
}

type PSIPath added in v1.5.0

type PSIPath struct {
	CPU string
	Mem string
	IO  string
}

type PSIStats added in v1.1.0

type PSIStats struct {
	Some *PSILine
	Full *PSILine

	FullSupported bool
}

func ParsePSIStats added in v1.5.0

func ParsePSIStats(r io.Reader) (PSIStats, error)

parsePSIStats parses the specified file for pressure stall information.

type ProcStat added in v1.4.0

type ProcStat struct {
	Pid   uint32
	Comm  string
	State byte
	Ppid  uint32
	Pgrp  uint32
}

ProcStat is the content of /proc/<pid>/stat. https://manpages.ubuntu.com/manpages/xenial/en/man5/proc.5.html

func ParseProcPIDStat added in v1.4.0

func ParseProcPIDStat(content string) (*ProcStat, error)

type ProcSysctl added in v1.1.0

type ProcSysctl struct{}

ProcSysctl implements Interface by reading and writing files under /proc/sys

func (*ProcSysctl) GetSysctl added in v1.1.0

func (*ProcSysctl) GetSysctl(sysctl string) (int, error)

func (*ProcSysctl) SetSysctl added in v1.1.0

func (*ProcSysctl) SetSysctl(sysctl string, newVal int) error

SetSysctl modifies the specified sysctl flag to the new value

type RangeValidator

type RangeValidator struct {
	// contains filtered or unexported fields
}

func (*RangeValidator) Validate

func (r *RangeValidator) Validate(value string) (bool, string)

type ResctrlResource added in v1.1.0

type ResctrlResource struct {
	Type           ResourceType
	FileName       string
	Subdir         string
	CheckSupported func(r Resource, parentDir string) (isSupported bool, msg string)
	Validator      ResourceValidator
}

func (*ResctrlResource) IsSupported added in v1.1.0

func (r *ResctrlResource) IsSupported(parentDir string) (bool, string)

func (*ResctrlResource) IsValid added in v1.1.0

func (r *ResctrlResource) IsValid(v string) (bool, string)

func (*ResctrlResource) Path added in v1.1.0

func (r *ResctrlResource) Path(parentDir string) string

func (*ResctrlResource) ResourceType added in v1.1.0

func (r *ResctrlResource) ResourceType() ResourceType

func (*ResctrlResource) WithCheckOnce added in v1.3.0

func (r *ResctrlResource) WithCheckOnce(isCheckOnce bool) Resource

func (*ResctrlResource) WithCheckSupported added in v1.1.0

func (r *ResctrlResource) WithCheckSupported(checkSupportedFn func(r Resource, parentDir string) (isSupported bool, msg string)) Resource

func (*ResctrlResource) WithSupported added in v1.1.0

func (r *ResctrlResource) WithSupported(isSupported bool, msg string) Resource

func (*ResctrlResource) WithValidator added in v1.1.0

func (r *ResctrlResource) WithValidator(validator ResourceValidator) Resource

type ResctrlSchemataRaw added in v1.1.0

type ResctrlSchemataRaw struct {
	L3    map[int]int64
	MB    map[int]int64
	L3Num int
}

func NewResctrlSchemataRaw added in v1.1.0

func NewResctrlSchemataRaw(cacheids []int) *ResctrlSchemataRaw

func ReadResctrlSchemataRaw added in v1.1.0

func ReadResctrlSchemataRaw(schemataFile string, l3Num int) (*ResctrlSchemataRaw, error)

func (*ResctrlSchemataRaw) CacheIds added in v1.4.1

func (r *ResctrlSchemataRaw) CacheIds() []int

func (*ResctrlSchemataRaw) DeepCopy added in v1.1.0

func (r *ResctrlSchemataRaw) DeepCopy() *ResctrlSchemataRaw

func (*ResctrlSchemataRaw) Equal added in v1.1.0

func (*ResctrlSchemataRaw) L3Number added in v1.1.0

func (r *ResctrlSchemataRaw) L3Number() int

func (*ResctrlSchemataRaw) L3String added in v1.1.0

func (r *ResctrlSchemataRaw) L3String() string

func (*ResctrlSchemataRaw) MBString added in v1.1.0

func (r *ResctrlSchemataRaw) MBString() string

func (*ResctrlSchemataRaw) ParseResctrlSchemata added in v1.1.0

func (r *ResctrlSchemataRaw) ParseResctrlSchemata(content string, l3Num int) error

ParseResctrlSchemata parses the resctrl schemata of given cgroup, and returns the l3_cat masks and mba masks. Set l3Num=-1 to use the read L3 number from the schemata. @content `L3:0=fff;1=fff\nMB:0=100;1=100\n` (may have additional lines (e.g. ARM MPAM)) @l3Num 2 @return {L3: {0: "fff", 1: "fff"}, MB: {0: "100", 1: "100"}}, nil

func (*ResctrlSchemataRaw) Prefix added in v1.1.0

func (r *ResctrlSchemataRaw) Prefix() string

func (*ResctrlSchemataRaw) Validate added in v1.4.0

func (r *ResctrlSchemataRaw) Validate() (bool, string)

func (*ResctrlSchemataRaw) ValidateL3 added in v1.4.0

func (r *ResctrlSchemataRaw) ValidateL3() (bool, string)

func (*ResctrlSchemataRaw) ValidateMB added in v1.4.0

func (r *ResctrlSchemataRaw) ValidateMB() (bool, string)

func (*ResctrlSchemataRaw) WithL3Mask added in v1.1.0

func (r *ResctrlSchemataRaw) WithL3Mask(mask string) *ResctrlSchemataRaw

func (*ResctrlSchemataRaw) WithL3Num added in v1.1.0

func (r *ResctrlSchemataRaw) WithL3Num(l3Num int) *ResctrlSchemataRaw

func (*ResctrlSchemataRaw) WithMB added in v1.2.0

func (r *ResctrlSchemataRaw) WithMB(valueOrPercent string) *ResctrlSchemataRaw

type Resource added in v1.1.0

type Resource interface {
	// ResourceType is the type of system resource. e.g. "cpu.cfs_quota_us", "cpu.cfs_period_us", "schemata"
	ResourceType() ResourceType
	// Path is the generated system file path according to the given parent directory.
	// e.g. "/host-cgroup/kubepods/kubepods-podxxx/cpu.shares"
	Path(dynamicPath string) string
	// IsSupported checks whether the system resource is supported in current platform
	IsSupported(dynamicPath string) (bool, string)
	// IsValid checks whether the given value is valid for the system resource's content
	IsValid(v string) (bool, string)
	// WithValidator sets the ResourceValidator for the resource
	WithValidator(validator ResourceValidator) Resource
	// WithSupported sets the Supported status of the resource when it is initialized.
	WithSupported(supported bool, msg string) Resource
	// WithCheckSupported sets the check function for the Supported status of given resource and parent directory.
	WithCheckSupported(checkSupportedFn func(r Resource, dynamicPath string) (isSupported bool, msg string)) Resource
	// WithCheckOnce sets the check function only checking once and then use the result as the Supported status.
	WithCheckOnce(isCheckOnce bool) Resource
}

func GetCgroupResource added in v1.1.0

func GetCgroupResource(resourceType ResourceType) (Resource, error)

func NewCommonCgroupResource added in v1.1.0

func NewCommonCgroupResource(resourceType ResourceType, filename string, subfs string) Resource

func NewCommonResctrlResource added in v1.1.0

func NewCommonResctrlResource(filename string, subdir string) Resource

func NewCommonSystemResource added in v1.2.0

func NewCommonSystemResource(relativePath, fileName string, Rootdir func() string) Resource

type ResourceType added in v1.1.0

type ResourceType string

func GetDefaultResourceType added in v1.1.0

func GetDefaultResourceType(subfs string, filename string) ResourceType

type ResourceValidator added in v1.1.0

type ResourceValidator interface {
	Validate(value string) (isValid bool, msg string)
}

ResourceValidator validates the resource value

type SystemResource added in v1.2.0

type SystemResource struct {
	Type         ResourceType
	RootDir      func() string
	RelativePath string
	FileName     string
	Validator    ResourceValidator

	Supported      *bool
	SupportMsg     string
	CheckSupported func(r Resource, dynamicPath string) (isSupported bool, msg string)
	CheckOnce      bool
}

func (*SystemResource) IsSupported added in v1.2.0

func (c *SystemResource) IsSupported(dynamicPath string) (bool, string)

func (*SystemResource) IsValid added in v1.2.0

func (c *SystemResource) IsValid(v string) (bool, string)

func (*SystemResource) Path added in v1.2.0

func (c *SystemResource) Path(dynamicPath string) string

func (*SystemResource) ResourceType added in v1.2.0

func (c *SystemResource) ResourceType() ResourceType

func (*SystemResource) WithCheckOnce added in v1.3.0

func (c *SystemResource) WithCheckOnce(isCheckOnce bool) Resource

func (*SystemResource) WithCheckSupported added in v1.2.0

func (c *SystemResource) WithCheckSupported(checkSupportedFn func(r Resource, parentDir string) (isSupported bool, msg string)) Resource

func (*SystemResource) WithSupported added in v1.2.0

func (c *SystemResource) WithSupported(isSupported bool, msg string) Resource

func (*SystemResource) WithValidator added in v1.2.0

func (c *SystemResource) WithValidator(validator ResourceValidator) Resource

type VersionInfo

type VersionInfo struct {
	// Open Anolis OS (kernel): https://github.com/alibaba/cloud-kernel
	IsAnolisOS bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL