Documentation
¶
Index ¶
- Constants
- Variables
- func CalcCPUThrottledRatio(curPoint, prePoint *CPUStatRaw) float64
- func CalculateCatL3MaskValue(cbm uint, startPercent, endPercent int64) (string, error)
- func CgroupFileRead(cgroupTaskDir string, r Resource) (string, error)
- func CgroupFileReadInt(cgroupTaskDir string, r Resource) (*int64, error)
- func CgroupFileWrite(cgroupTaskDir string, r Resource, value string) error
- func CgroupFileWriteIfDifferent(cgroupTaskDir string, r Resource, value string) error
- func CheckAndTryEnableResctrlCat() error
- func CheckIfAllSupported(checkSupportedFns ...func() (bool, string)) func() (bool, string)
- func CommonFileRead(file string) (string, error)
- func CommonFileWrite(file string, data string) error
- func CommonFileWriteIfDifferent(file string, value string) error
- func ConvertCPUSharesToWeight(s string) (int64, error)
- func ConvertCPUWeightToShares(v int64) (int64, error)
- func FileExists(path string) bool
- func GetCacheInfo(str string) (string, int32, error)
- func GetCgroupCurTasks(cgroupPath string) ([]int, error)
- func GetCgroupFilePath(cgroupTaskDir string, r Resource) string
- func GetKubeletCommandline(port int) ([]string, error)
- func GetPeriodTicks(start, end time.Time) float64
- func GetProcFilePath(file string) string
- func GetProcSysFilePath(file string) string
- func GetResctrlGroupRootDirPath(groupPath string) string
- func GetResctrlL3CbmFilePath() string
- func GetResctrlSchemataFilePath(groupPath string) string
- func GetResctrlSubsystemDirPath() string
- func GetResctrlTasksFilePath(groupPath string) string
- func InitCatGroupIfNotExist(group string) error
- func IsResourceUnsupportedErr(err error) bool
- func IsSupportResctrl() (bool, error)
- func IsUsingCgroupsV2() bool
- func KubeletPortToPid(port int) (int, error)
- func MountResctrlSubsystem() (bool, error)
- func NewProcSysctl() utilsysctl.Interface
- func ParseCPUAcctUsageV2(content string) (uint64, error)
- func ParseCPUCFSPeriodV2(content string) (int64, error)
- func ParseCPUCFSQuotaV2(content string) (int64, error)
- func ParseKVMap(content string) map[string]string
- func ParseResctrlSchemataMap(content string) map[string]map[int]string
- func PathExists(path string) (bool, error)
- func ProcCmdLine(procRoot string, pid int) ([]string, error)
- func ReadCatL3CbmString() (string, error)
- func ReadCgroupAndParseInt32Slice(parentDir string, r Resource) ([]int32, error)
- func ReadCgroupAndParseInt64(parentDir string, r Resource) (int64, error)
- func ReadCgroupAndParseUint64(parentDir string, r Resource) (uint64, error)
- func ReadFileNoStat(filename string) ([]byte, error)
- func ReadResctrlTasksMap(groupPath string) (map[int32]struct{}, error)
- func ResourceUnsupportedErr(msg string) error
- func SetConf(config Config)
- func SetSchedGroupIdentity(enable bool) error
- func SetupCgroupPathFormatter(driver CgroupDriverType)
- func SupportedIfFileExists(r Resource, parentDir string) (bool, string)
- func SupportedIfFileExistsInKubepods(filename string, subfs string) (bool, string)
- func TCPSocks(fn netstat.AcceptFn) ([]netstat.SockTabEntry, error)
- func ValidateResourceValue(value *int64, parentDir string, r Resource) bool
- func WorkingDirOf(pid int) (string, error)
- type CPUSetStrValidator
- type CPUStatRaw
- type CPUStatV2Raw
- type CgroupDriverType
- type CgroupResource
- func (c *CgroupResource) IsSupported(parentDir string) (bool, string)
- func (c *CgroupResource) IsValid(v string) (bool, string)
- func (c *CgroupResource) Path(parentDir string) string
- func (c *CgroupResource) ResourceType() ResourceType
- func (c *CgroupResource) WithCheckSupported(...) Resource
- func (c *CgroupResource) WithSupported(isSupported bool, msg string) Resource
- func (c *CgroupResource) WithValidator(validator ResourceValidator) Resource
- type CgroupResourceFactory
- type CgroupResourceRegistry
- type CgroupResourceRegistryImpl
- type CgroupVersion
- type Config
- type FileTestUtil
- func (c *FileTestUtil) Cleanup()
- func (c *FileTestUtil) CreateCgroupFile(taskDir string, r Resource)
- func (c *FileTestUtil) CreateFile(fileRelativePath string)
- func (c *FileTestUtil) CreateProcSubFile(fileRelativePath string)
- func (c *FileTestUtil) MkDirAll(dirRelativePath string)
- func (c *FileTestUtil) ReadCgroupFileContents(taskDir string, r Resource) string
- func (c *FileTestUtil) ReadFileContents(fileRelativePath string) string
- func (c *FileTestUtil) ReadProcSubFileContents(relativeFilePath string) string
- func (c *FileTestUtil) SetAnolisOSResourcesSupported(supported bool)
- func (c *FileTestUtil) SetCgroupsV2(useCgroupsV2 bool)
- func (c *FileTestUtil) SetResourcesSupported(supported bool, resources ...Resource)
- func (c *FileTestUtil) WriteCgroupFileContents(taskDir string, r Resource, contents string)
- func (c *FileTestUtil) WriteFileContents(fileRelativePath, contents string)
- func (c *FileTestUtil) WriteProcSubFileContents(relativeFilePath string, contents string)
- type MemoryStatRaw
- type PSILine
- type PSIStats
- type ProcSysctl
- type RangeValidator
- type ResctrlResource
- func (r *ResctrlResource) IsSupported(parentDir string) (bool, string)
- func (r *ResctrlResource) IsValid(v string) (bool, string)
- func (r *ResctrlResource) Path(parentDir string) string
- func (r *ResctrlResource) ResourceType() ResourceType
- func (r *ResctrlResource) WithCheckSupported(...) Resource
- func (r *ResctrlResource) WithSupported(isSupported bool, msg string) Resource
- func (r *ResctrlResource) WithValidator(validator ResourceValidator) Resource
- type ResctrlSchemataRaw
- func (r *ResctrlSchemataRaw) DeepCopy() *ResctrlSchemataRaw
- func (r *ResctrlSchemataRaw) Equal(a *ResctrlSchemataRaw) (bool, string)
- func (r *ResctrlSchemataRaw) L3Number() int
- func (r *ResctrlSchemataRaw) L3String() string
- func (r *ResctrlSchemataRaw) MBString() string
- func (r *ResctrlSchemataRaw) ParseResctrlSchemata(content string, l3Num int) error
- func (r *ResctrlSchemataRaw) Prefix() string
- func (r *ResctrlSchemataRaw) WithL3Mask(mask string) *ResctrlSchemataRaw
- func (r *ResctrlSchemataRaw) WithL3Num(l3Num int) *ResctrlSchemataRaw
- func (r *ResctrlSchemataRaw) WithMBPercent(percent string) *ResctrlSchemataRaw
- type Resource
- type ResourceType
- type ResourceValidator
- type SystemFile
- type VersionInfo
Constants ¶
const ( DefaultCPUCFSPeriod int64 = 100000 CFSQuotaUnlimitedValue int64 = -1 // 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" // CgroupMaxValueStr math.MaxInt64; writing `memory.high` with this do the same as set as "max" CgroupMaxValueStr string = "9223372036854775807" )
const ( CgroupControllersName = "cgroup.controllers" CgroupSubtreeControlName = "cgroup.subtree_control" )
const ( Cgroupfs CgroupDriverType = "cgroupfs" Systemd CgroupDriverType = "systemd" KubeRootNameSystemd = "kubepods.slice/" KubeBurstableNameSystemd = "kubepods-burstable.slice/" KubeBesteffortNameSystemd = "kubepods-besteffort.slice/" KubeRootNameCgroupfs = "kubepods/" KubeBurstableNameCgroupfs = "burstable/" KubeBesteffortNameCgroupfs = "besteffort/" )
const ( CgroupCPUDir string = "cpu/" CgroupCPUSetDir string = "cpuset/" CgroupCPUAcctDir string = "cpuacct/" CgroupMemDir string = "memory/" CgroupBlkioDir string = "blkio/" CgroupV2Dir = "" )
const ( CFSBasePeriodValue int64 = 100000 CFSQuotaMinValue int64 = 1000 // min value except `-1` CPUWeightMinValue int64 = 1 CPUWeightMaxValue int64 = 10000 CPUStatName = "cpu.stat" 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" CPUWeightName = "cpu.weight" 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" 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" BlkioTRIopsName = "blkio.throttle.read_iops_device" BlkioTRBpsName = "blkio.throttle.read_bps_device" BlkioTWIopsName = "blkio.throttle.write_iops_device" BlkioTWBpsName = "blkio.throttle.write_bps_device" )
const ( DS_MODE = "dsMode" HOST_MODE = "hostMode" )
const ( CPUInfoFileName string = "cpuinfo" KernelCmdlineFileName string = "cmdline" 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" )
const ( ProcStatName = "stat" ProcMemInfoName = "meminfo" SysctlSubDir = "sys" KernelSchedGroupIdentityEnable = "kernel/sched_group_identity_enabled" )
const EmptyValueError string = "EmptyValueError"
const ErrResourceUnsupportedPrefix = "resource is unsupported"
Variables ¶
var ( NaturalInt64Validator = &RangeValidator{min: 0, max: math.MaxInt64} CPUBurstValidator = &RangeValidator{min: 0, max: 100 * 10 * 100000} CPUBvtWarpNsValidator = &RangeValidator{min: -1, max: 2} CPUWeightValidator = &RangeValidator{min: CPUWeightMinValue, max: CPUWeightMaxValue} 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} CPUSetCPUSValidator = &CPUSetStrValidator{} )
var ( DefaultFactory = NewCgroupResourceFactory() CPUStat = DefaultFactory.New(CPUStatName, CgroupCPUDir) 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) 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(SupportedIfFileExists) CPUAcctMemoryPressure = DefaultFactory.New(CPUAcctMemoryPressureName, CgroupCPUAcctDir).WithCheckSupported(SupportedIfFileExists) CPUAcctIOPressure = DefaultFactory.New(CPUAcctIOPressureName, CgroupCPUAcctDir).WithCheckSupported(SupportedIfFileExists) MemoryLimit = DefaultFactory.New(MemoryLimitName, CgroupMemDir) MemoryUsage = DefaultFactory.New(MemoryUsageName, CgroupMemDir) MemoryStat = DefaultFactory.New(MemoryStatName, CgroupMemDir) MemoryWmarkRatio = DefaultFactory.New(MemoryWmarkRatioName, CgroupMemDir).WithValidator(MemoryWmarkRatioValidator).WithSupported(SupportedIfFileExistsInKubepods(MemoryWmarkRatioName, CgroupMemDir)) MemoryWmarkScaleFactor = DefaultFactory.New(MemoryWmarkScaleFactorName, CgroupMemDir).WithValidator(MemoryWmarkScaleFactorFileNameValidator).WithSupported(SupportedIfFileExistsInKubepods(MemoryWmarkScaleFactorName, CgroupMemDir)) MemoryWmarkMinAdj = DefaultFactory.New(MemoryWmarkMinAdjName, CgroupMemDir).WithValidator(MemoryWmarkMinAdjValidator).WithSupported(SupportedIfFileExistsInKubepods(MemoryWmarkMinAdjName, CgroupMemDir)) MemoryMin = DefaultFactory.New(MemoryMinName, CgroupMemDir).WithValidator(NaturalInt64Validator).WithSupported(SupportedIfFileExistsInKubepods(MemoryMinName, CgroupMemDir)) MemoryLow = DefaultFactory.New(MemoryLowName, CgroupMemDir).WithValidator(NaturalInt64Validator).WithSupported(SupportedIfFileExistsInKubepods(MemoryLowName, CgroupMemDir)) MemoryHigh = DefaultFactory.New(MemoryHighName, CgroupMemDir).WithValidator(NaturalInt64Validator).WithSupported(SupportedIfFileExistsInKubepods(MemoryHighName, CgroupMemDir)) MemoryPriority = DefaultFactory.New(MemoryPriorityName, CgroupMemDir).WithValidator(MemoryPriorityValidator).WithSupported(SupportedIfFileExistsInKubepods(MemoryPriorityName, CgroupMemDir)) MemoryUsePriorityOom = DefaultFactory.New(MemoryUsePriorityOomName, CgroupMemDir).WithValidator(MemoryUsePriorityOomValidator).WithSupported(SupportedIfFileExistsInKubepods(MemoryUsePriorityOomName, CgroupMemDir)) MemoryOomGroup = DefaultFactory.New(MemoryOomGroupName, CgroupMemDir).WithValidator(MemoryOomGroupValidator).WithSupported(SupportedIfFileExistsInKubepods(MemoryOomGroupName, CgroupMemDir)) BlkioReadIops = DefaultFactory.New(BlkioTRIopsName, CgroupBlkioDir).WithValidator(NaturalInt64Validator) BlkioReadBps = DefaultFactory.New(BlkioTRBpsName, CgroupBlkioDir).WithValidator(NaturalInt64Validator) BlkioWriteIops = DefaultFactory.New(BlkioTWIopsName, CgroupBlkioDir).WithValidator(NaturalInt64Validator) BlkioWriteBps = DefaultFactory.New(BlkioTWBpsName, CgroupBlkioDir).WithValidator(NaturalInt64Validator) CPUCFSQuotaV2 = DefaultFactory.NewV2(CPUCFSQuotaName, CPUMaxName) CPUCFSPeriodV2 = DefaultFactory.NewV2(CPUCFSPeriodName, CPUMaxName) CPUStatV2 = DefaultFactory.NewV2(CPUStatName, CPUStatName) CPUAcctStatV2 = DefaultFactory.NewV2(CPUAcctStatName, CPUStatName) CPUAcctUsageV2 = DefaultFactory.NewV2(CPUAcctUsageName, CPUStatName) 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) MemoryMinV2 = DefaultFactory.NewV2(MemoryMinName, MemoryMinName) MemoryLowV2 = DefaultFactory.NewV2(MemoryLowName, MemoryLowName) MemoryHighV2 = DefaultFactory.NewV2(MemoryHighName, MemoryHighName) 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
var ( ResctrlSchemata = NewCommonResctrlResource(ResctrlSchemataName, "") ResctrlTasks = NewCommonResctrlResource(ResctrlTasksName, "") ResctrlL3CbmMask = NewCommonResctrlResource(ResctrlCbmMaskName, filepath.Join(RdtInfoDir, L3CatDir)) )
var AgentMode = DS_MODE
var CgroupPathFormatter = cgroupPathFormatterInSystemd
default use Systemd cgroup path format
var (
CommonRootDir = "" // for uni-test
)
var Conf = NewDsModeConfig()
var DefaultRegistry = NewCgroupResourceRegistry()
var ExecCmdOnHost = execCmdOnHostFn
If running in container, exec command by 'nsenter --mount=/proc/1/ns/mnt ${cmds}'. return stdout, exitcode, error
var HostSystemInfo = collectVersionInfo()
var ( // Jiffies is the duration unit of CPU stats. Normally, it is 10ms. Jiffies = float64(10 * time.Millisecond) )
var PidOf = pidOfFn
PidOf finds process(es) with a specified name (regexp match) and return their pid(s).
var UseCgroupsV2 bool
Functions ¶
func CalcCPUThrottledRatio ¶
func CalcCPUThrottledRatio(curPoint, prePoint *CPUStatRaw) float64
func CalculateCatL3MaskValue ¶ added in v1.1.0
func CgroupFileRead ¶
CgroupFileRead reads the cgroup file. TODO: moved into resourceexecutor package and marked as private.
func CgroupFileReadInt ¶
CgroupFileReadInt reads the cgroup file and returns an int64 value. TODO: moved into resourceexecutor package and marked as private.
func CgroupFileWrite ¶
CgroupFileWrite writes the cgroup file with the given value. TODO: moved into resourceexecutor package and marked as private.
func CgroupFileWriteIfDifferent ¶
CgroupFileWriteIfDifferent writes the cgroup file if current value is different from the given value. TODO: moved into resourceexecutor package and marked as private.
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 CommonFileRead ¶
func CommonFileWrite ¶
func ConvertCPUSharesToWeight ¶ added in v1.1.0
func ConvertCPUWeightToShares ¶ added in v1.1.0
ConvertCPUWeightToShares converts the value of `cpu.weight` (cgroups-v2) into the value of `cpu.shares` (cgroups-v1)
func FileExists ¶
func GetCacheInfo ¶ added in v1.1.0
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 GetCgroupCurTasks ¶
func GetCgroupFilePath ¶
@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 GetKubeletCommandline ¶ added in v1.1.0
func GetPeriodTicks ¶ added in v1.1.0
func GetProcFilePath ¶ added in v1.1.0
func GetProcSysFilePath ¶ added in v1.1.0
func GetResctrlGroupRootDirPath ¶
@groupPath BE @return /sys/fs/resctrl/BE
func GetResctrlL3CbmFilePath ¶
func GetResctrlL3CbmFilePath() string
@return /sys/fs/resctrl/info/L3/cbm_mask
func GetResctrlSchemataFilePath ¶
@groupPath BE @return /sys/fs/resctrl/BE/schemata
func GetResctrlTasksFilePath ¶
@groupPath BE @return /sys/fs/resctrl/BE/tasks
func InitCatGroupIfNotExist ¶ added in v1.1.0
func IsResourceUnsupportedErr ¶ added in v1.1.0
func IsSupportResctrl ¶ added in v1.1.0
func IsUsingCgroupsV2 ¶ added in v1.1.0
func IsUsingCgroupsV2() bool
func KubeletPortToPid ¶ added in v1.1.0
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 MountResctrlSubsystem ¶
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 ParseCPUCFSPeriodV2 ¶ added in v1.1.0
func ParseCPUCFSQuotaV2 ¶ added in v1.1.0
func ParseKVMap ¶ added in v1.1.0
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
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 ProcCmdLine ¶
CmdLine returns the command line args of a process.
func ReadCatL3CbmString ¶
ReadCatL3CbmString reads and returns the value of cat l3 cbm_mask
func ReadCgroupAndParseInt32Slice ¶ added in v1.1.0
ReadCgroupAndParseInt32Slice reads the given cgroup content and parses it into an int32 slice. e.g. content: "1\n23\n0\n4\n56789" -> []int32{ 1, 23, 0, 4, 56789 }
func ReadCgroupAndParseInt64 ¶ added in v1.1.0
func ReadCgroupAndParseUint64 ¶ added in v1.1.0
func ReadFileNoStat ¶
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 ¶
ReadResctrlTasksMap reads and returns the map of given resctrl group's task ids
func ResourceUnsupportedErr ¶ added in v1.1.0
func SetSchedGroupIdentity ¶ added in v1.1.0
func SetupCgroupPathFormatter ¶
func SetupCgroupPathFormatter(driver CgroupDriverType)
func SupportedIfFileExists ¶ added in v1.1.0
func SupportedIfFileExistsInKubepods ¶ added in v1.1.0
func ValidateResourceValue ¶ added in v1.1.0
func WorkingDirOf ¶ added in v1.1.0
return working dir of process
Types ¶
type CPUSetStrValidator ¶ added in v1.1.0
type CPUSetStrValidator struct{}
type CPUStatRaw ¶
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)
func ReadCPUStatRaw ¶ added in v1.1.0
func ReadCPUStatRaw(cgroupPath string) (*CPUStatRaw, error)
ReadCPUStatRaw reads the cpu.stat under the given cgroup path. DEPRECATED: use NewCgroupReader().ReadCPUStat() instead.
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 GuessCgroupDriverFromCgroupName ¶
func GuessCgroupDriverFromCgroupName() CgroupDriverType
func GuessCgroupDriverFromKubeletPort ¶ added in v1.1.0
func GuessCgroupDriverFromKubeletPort(port int) (CgroupDriverType, error)
Guess Kubelet's cgroup driver from kubelet port.
- use KubeletPortToPid to get kubelet pid.
- If '--cgroup-driver' in args, that's it. else if '--config' not in args, is default driver('cgroupfs'). else go to step-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) Validator ResourceValidator }
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) WithCheckSupported ¶ added in v1.1.0
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 (r *CgroupResourceRegistryImpl) Add(v CgroupVersion, s ...Resource)
func (*CgroupResourceRegistryImpl) Get ¶ added in v1.1.0
func (r *CgroupResourceRegistryImpl) Get(v CgroupVersion, key ResourceType) (Resource, bool)
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 Config ¶
type Config struct { CgroupRootDir string CgroupKubePath string SysRootDir string SysFSRootDir string ProcRootDir string VarRunRootDir string NodeNameOverride string RuntimeHooksConfigDir string ContainerdEndPoint string DockerEndPoint string }
func NewDsModeConfig ¶
func NewDsModeConfig() *Config
func NewHostModeConfig ¶
func NewHostModeConfig() *Config
type FileTestUtil ¶
type FileTestUtil struct { // Temporary directory to store mock cgroup filesystem. TempDir string // contains filtered or unexported fields }
func NewFileTestUtil ¶
func NewFileTestUtil(t *testing.T) *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(fileRelativePath string)
func (*FileTestUtil) CreateProcSubFile ¶
func (c *FileTestUtil) CreateProcSubFile(fileRelativePath string)
func (*FileTestUtil) MkDirAll ¶
func (c *FileTestUtil) MkDirAll(dirRelativePath string)
func (*FileTestUtil) ReadCgroupFileContents ¶
func (c *FileTestUtil) ReadCgroupFileContents(taskDir string, r Resource) string
func (*FileTestUtil) ReadFileContents ¶
func (c *FileTestUtil) ReadFileContents(fileRelativePath string) string
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) SetResourcesSupported ¶ added in v1.1.0
func (c *FileTestUtil) SetResourcesSupported(supported bool, resources ...Resource)
func (*FileTestUtil) WriteCgroupFileContents ¶
func (c *FileTestUtil) WriteCgroupFileContents(taskDir string, r Resource, contents string)
func (*FileTestUtil) WriteFileContents ¶
func (c *FileTestUtil) WriteFileContents(fileRelativePath, contents string)
func (*FileTestUtil) WriteProcSubFileContents ¶
func (c *FileTestUtil) WriteProcSubFileContents(relativeFilePath string, contents string)
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
type ProcSysctl ¶ added in v1.1.0
type ProcSysctl struct{}
ProcSysctl implements Interface by reading and writing files under /proc/sys
type RangeValidator ¶
type RangeValidator struct {
// contains filtered or unexported fields
}
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) WithCheckSupported ¶ added in v1.1.0
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
func NewResctrlSchemataRaw ¶ added in v1.1.0
func NewResctrlSchemataRaw() *ResctrlSchemataRaw
func ReadResctrlSchemataRaw ¶ added in v1.1.0
func ReadResctrlSchemataRaw(schemataFile string, l3Num int) (*ResctrlSchemataRaw, error)
func (*ResctrlSchemataRaw) DeepCopy ¶ added in v1.1.0
func (r *ResctrlSchemataRaw) DeepCopy() *ResctrlSchemataRaw
func (*ResctrlSchemataRaw) Equal ¶ added in v1.1.0
func (r *ResctrlSchemataRaw) Equal(a *ResctrlSchemataRaw) (bool, string)
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. @content `L3:0=fff;1=fff\nMB:0=100;1=100\n` (may have additional lines (e.g. ARM MPAM)) @l3Num 2 @return { L3: ["fff", "fff"], MB: ["100", "100"] }, nil
func (*ResctrlSchemataRaw) Prefix ¶ added in v1.1.0
func (r *ResctrlSchemataRaw) Prefix() 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) WithMBPercent ¶ added in v1.1.0
func (r *ResctrlSchemataRaw) WithMBPercent(percent 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(parentDir string) string // IsSupported checks whether the system resource is supported in current platform IsSupported(parentDir 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, parentDir string) (isSupported bool, msg string)) 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
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
ResourceValidator validates the resource value
type SystemFile ¶
type SystemFile struct { File string Validator RangeValidator }
var (
ProcStatFile SystemFile
)
type VersionInfo ¶
type VersionInfo struct { // Open Anolis OS (kernel): https://github.com/alibaba/cloud-kernel IsAnolisOS bool }