Documentation ¶
Index ¶
- Constants
- Variables
- func CalcCPUThrottledRatio(curPoint, prePoint *CPUStatRaw) float64
- func CgroupFileRead(cgroupTaskDir string, file CgroupFile) (string, error)
- func CgroupFileReadInt(cgroupTaskDir string, file CgroupFile) (*int64, error)
- func CgroupFileWrite(cgroupTaskDir string, file CgroupFile, data string) error
- func CgroupFileWriteIfDifferent(cgroupTaskDir string, file CgroupFile, value string) error
- func CheckAndTryEnableResctrlCat() error
- func CommonFileRead(file string) (string, error)
- func CommonFileWrite(file string, data string) error
- func CommonFileWriteIfDifferent(file string, value string) error
- func FileExists(path string) bool
- func GetCacheInfo(str string) (string, int32, error)
- func GetCgroupCurTasks(cgroupPath string) ([]int, error)
- func GetCgroupFilePath(cgroupTaskDir string, file CgroupFile) string
- func GetResctrlGroupRootDirPath(groupPath string) string
- func GetResctrlL3CbmFilePath() string
- func GetResctrlSchemataFilePath(groupPath string) string
- func GetResctrlSubsystemDirPath() string
- func GetResctrlTasksFilePath(groupPath string) string
- func IsSupportResctrl() (bool, error)
- func MountResctrlSubsystem() (bool, error)
- func PathExists(path string) (bool, error)
- func ProcCmdLine(procRoot string, pid int) ([]string, error)
- func ReadCatL3CbmString() (string, error)
- func ReadFileNoStat(filename string) ([]byte, error)
- func ReadResctrlTasksMap(groupPath string) (map[int]struct{}, error)
- func SetConf(config Config)
- func SetupCgroupPathFormatter(driver CgroupDriverType)
- func ValidateCgroupValue(value *int64, parentDir string, file CgroupFile) bool
- type CPUStatRaw
- type CgroupDriverType
- type CgroupFile
- type Config
- type FileTestUtil
- func (c *FileTestUtil) CreateCgroupFile(taskDir string, file CgroupFile)
- func (c *FileTestUtil) CreateFile(fileRelativePath string)
- func (c *FileTestUtil) CreateProcSubFile(fileRelativePath string)
- func (c *FileTestUtil) MkDirAll(dirRelativePath string)
- func (c *FileTestUtil) ReadCgroupFileContents(taskDir string, file CgroupFile) string
- func (c *FileTestUtil) ReadFileContents(fileRelativePath string) string
- func (c *FileTestUtil) ReadProcSubFileContents(relativeFilePath string) string
- func (c *FileTestUtil) WriteCgroupFileContents(taskDir string, file CgroupFile, contents string)
- func (c *FileTestUtil) WriteFileContents(fileRelativePath, contents string)
- func (c *FileTestUtil) WriteProcSubFileContents(relativeFilePath string, contents string)
- type RangeValidator
- type SystemFile
- type Validate
- type VersionInfo
Constants ¶
const ( CFSQuotaUnlimitedValue int64 = -1 // CgroupMaxSymbolStr only appears in `memory.high`, 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 ( 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/" )
const ( CFSBasePeriodValue int64 = 100000 CPUStatFileName = "cpu.stat" CPUCFSQuotaName = "cpu.cfs_quota_us" CPUCFSPeriodName = "cpu.cfs_period_us" CPUBVTWarpNsName = "cpu.bvt_warp_ns" CPUBurstName = "cpu.cfs_burst_us" CPUSFileName = "cpuset.cpus" CPUTaskFileName = "tasks" CpuacctUsageFileName = "cpuacct.usage" MemWmarkRatioFileName = "memory.wmark_ratio" MemWmarkScaleFactorFileName = "memory.wmark_scale_factor" MemPriorityFileName = "memory.priority" MemUsePriorityOomFileName = "memory.use_priority_oom" MemOomGroupFileName = "memory.oom.group" MemWmarkMinAdjFileName = "memory.wmark_min_adj" MemMinFileName = "memory.min" MemLowFileName = "memory.low" MemHighFileName = "memory.high" MemoryLimitFileName = "memory.limit_in_bytes" MemStatFileName = "memory.stat" )
const ( DS_MODE = "dsMode" HOST_MODE = "hostMode" )
const ( ResctrlDir string = "resctrl/" RdtInfoDir string = "info" L3CatDir string = "L3" SchemataFileName string = "schemata" CbmMaskFileName string = "cbm_mask" ResctrlTaskFileName string = "tasks" CPUInfoFileName string = "cpuinfo" KernelCmdlineFileName string = "cmdline" ResctrlName string = "resctrl" )
const EmptyValueError string = "EmptyValueError"
const (
ProcStatFileName = "stat"
)
Variables ¶
var ( CPUBurstValidator = &RangeValidator{name: CPUBurstName, min: 0, max: 100 * 10 * 100000} CPUBvtWarpNsValidator = &RangeValidator{name: CPUBVTWarpNsName, min: -1, max: 2} MemWmarkRatioValidator = &RangeValidator{name: MemWmarkRatioFileName, min: 0, max: 100} MemPriorityValidator = &RangeValidator{name: MemPriorityFileName, min: 0, max: 12} MemOomGroupValidator = &RangeValidator{name: MemOomGroupFileName, min: 0, max: 1} MemUsePriorityOomValidator = &RangeValidator{name: MemUsePriorityOomFileName, min: 0, max: 1} MemWmarkMinAdjValidator = &RangeValidator{name: MemWmarkMinAdjFileName, min: -25, max: 50} MemWmarkScaleFactorFileNameValidator = &RangeValidator{name: MemWmarkScaleFactorFileName, min: 1, max: 1000} MemMinValidator = &RangeValidator{name: MemMinFileName, min: 0, max: math.MaxInt64} MemLowValidator = &RangeValidator{name: MemLowFileName, min: 0, max: math.MaxInt64} MemHighValidator = &RangeValidator{name: MemHighFileName, min: 0, max: math.MaxInt64} // write value(>node.total) -> read "max" )
var ( CPUStat = CgroupFile{ResourceFileName: CPUStatFileName, Subfs: CgroupCPUDir, IsAnolisOS: false} CPUCFSQuota = CgroupFile{ResourceFileName: CPUCFSQuotaName, Subfs: CgroupCPUDir, IsAnolisOS: false} CPUCFSPeriod = CgroupFile{ResourceFileName: CPUCFSPeriodName, Subfs: CgroupCPUDir, IsAnolisOS: false} CPUTask = CgroupFile{ResourceFileName: CPUTaskFileName, Subfs: CgroupCPUDir, IsAnolisOS: false} CPUBurst = CgroupFile{ResourceFileName: CPUBurstName, Subfs: CgroupCPUDir, IsAnolisOS: true, Validator: CPUBurstValidator} CPUBVTWarpNs = CgroupFile{ResourceFileName: CPUBVTWarpNsName, Subfs: CgroupCPUDir, IsAnolisOS: true, Validator: CPUBvtWarpNsValidator} CPUSet = CgroupFile{ResourceFileName: CPUSFileName, Subfs: CgroupCPUSetDir, IsAnolisOS: false} CpuacctUsage = CgroupFile{ResourceFileName: CpuacctUsageFileName, Subfs: CgroupCPUacctDir, IsAnolisOS: false} MemStat = CgroupFile{ResourceFileName: MemStatFileName, Subfs: CgroupMemDir, IsAnolisOS: false} MemoryLimit = CgroupFile{ResourceFileName: MemoryLimitFileName, Subfs: CgroupMemDir, IsAnolisOS: false} MemWmarkRatio = CgroupFile{ResourceFileName: MemWmarkRatioFileName, Subfs: CgroupMemDir, IsAnolisOS: true, Validator: MemWmarkRatioValidator} MemPriority = CgroupFile{ResourceFileName: MemPriorityFileName, Subfs: CgroupMemDir, IsAnolisOS: true, Validator: MemPriorityValidator} MemUsePriorityOom = CgroupFile{ResourceFileName: MemUsePriorityOomFileName, Subfs: CgroupMemDir, IsAnolisOS: true, Validator: MemUsePriorityOomValidator} MemOomGroup = CgroupFile{ResourceFileName: MemOomGroupFileName, Subfs: CgroupMemDir, IsAnolisOS: true, Validator: MemOomGroupValidator} MemWmarkMinAdj = CgroupFile{ResourceFileName: MemWmarkMinAdjFileName, Subfs: CgroupMemDir, IsAnolisOS: true, Validator: MemWmarkMinAdjValidator} MemWmarkScaleFactor = CgroupFile{ResourceFileName: MemWmarkScaleFactorFileName, Subfs: CgroupMemDir, IsAnolisOS: true, Validator: MemWmarkScaleFactorFileNameValidator} MemMin = CgroupFile{ResourceFileName: MemMinFileName, Subfs: CgroupMemDir, IsAnolisOS: true, Validator: MemMinValidator} MemLow = CgroupFile{ResourceFileName: MemLowFileName, Subfs: CgroupMemDir, IsAnolisOS: true, Validator: MemLowValidator} MemHigh = CgroupFile{ResourceFileName: MemHighFileName, Subfs: CgroupMemDir, IsAnolisOS: true, Validator: MemHighValidator} )
var AgentMode = DS_MODE
var CgroupPathFormatter = cgroupPathFormatterInSystemd
default use Systemd cgroup path format
var (
CommonRootDir = "" // for uni-test
)
var Conf = NewDsModeConfig()
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 PidOf = pidOfFn
PidOf finds process(es) with a specified name (regexp match) and return their pid(s).
Functions ¶
func CalcCPUThrottledRatio ¶
func CalcCPUThrottledRatio(curPoint, prePoint *CPUStatRaw) float64
func CgroupFileRead ¶
func CgroupFileRead(cgroupTaskDir string, file CgroupFile) (string, error)
func CgroupFileReadInt ¶
func CgroupFileReadInt(cgroupTaskDir string, file CgroupFile) (*int64, error)
func CgroupFileWrite ¶
func CgroupFileWrite(cgroupTaskDir string, file CgroupFile, data string) error
func CgroupFileWriteIfDifferent ¶ added in v0.3.0
func CgroupFileWriteIfDifferent(cgroupTaskDir string, file CgroupFile, value string) error
func CheckAndTryEnableResctrlCat ¶ added in v0.3.0
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 CommonFileRead ¶ added in v0.3.0
func CommonFileWrite ¶ added in v0.3.0
func CommonFileWriteIfDifferent ¶ added in v0.3.0
func FileExists ¶
func GetCacheInfo ¶ added in v0.3.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 ¶ added in v0.3.0
func GetCgroupFilePath ¶
func GetCgroupFilePath(cgroupTaskDir string, file CgroupFile) string
@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 GetResctrlGroupRootDirPath ¶ added in v0.3.0
@groupPath BE @return /sys/fs/resctrl/BE
func GetResctrlL3CbmFilePath ¶ added in v0.3.0
func GetResctrlL3CbmFilePath() string
@return /sys/fs/resctrl/info/L3/cbm_mask
func GetResctrlSchemataFilePath ¶ added in v0.3.0
@groupPath BE @return /sys/fs/resctrl/BE/schemata
func GetResctrlSubsystemDirPath ¶ added in v0.3.0
func GetResctrlSubsystemDirPath() string
@return /sys/fs/resctrl
func GetResctrlTasksFilePath ¶ added in v0.3.0
@groupPath BE @return /sys/fs/resctrl/BE/tasks
func IsSupportResctrl ¶ added in v0.3.0
func MountResctrlSubsystem ¶ added in v0.3.0
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 PathExists ¶
func ProcCmdLine ¶
CmdLine returns the command line args of a process.
func ReadCatL3CbmString ¶ added in v0.3.0
ReadCatL3Cbm reads and returns the value of cat l3 cbm_mask
func ReadFileNoStat ¶
ReadFileNoStat uses ioutil.ReadAll to read contents of entire file. This is similar to ioutil.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 ¶ added in v0.3.0
ReadResctrlTasksMap reads and returns the map of given resctrl group's task ids
func SetupCgroupPathFormatter ¶
func SetupCgroupPathFormatter(driver CgroupDriverType)
func ValidateCgroupValue ¶ added in v0.3.0
func ValidateCgroupValue(value *int64, parentDir string, file CgroupFile) bool
Types ¶
type CPUStatRaw ¶
func GetCPUStatRaw ¶
func GetCPUStatRaw(cgroupPath string) (*CPUStatRaw, error)
type CgroupDriverType ¶
type CgroupDriverType string
func GuessCgroupDriverFromCgroupName ¶
func GuessCgroupDriverFromCgroupName() CgroupDriverType
func GuessCgroupDriverFromKubelet ¶
func GuessCgroupDriverFromKubelet() (CgroupDriverType, error)
Guess Kubelet's cgroup driver from command line args.
- Read kubelet's /proc/${pid}/cmdline.
- 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 CgroupFile ¶
type Config ¶
type Config struct { CgroupRootDir string CgroupKubePath string SysRootDir string SysFSRootDir string ProcRootDir string VarRunRootDir string NodeNameOverride 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
func (*FileTestUtil) CreateCgroupFile ¶
func (c *FileTestUtil) CreateCgroupFile(taskDir string, file CgroupFile)
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, file CgroupFile) string
func (*FileTestUtil) ReadFileContents ¶
func (c *FileTestUtil) ReadFileContents(fileRelativePath string) string
func (*FileTestUtil) ReadProcSubFileContents ¶
func (c *FileTestUtil) ReadProcSubFileContents(relativeFilePath string) string
func (*FileTestUtil) WriteCgroupFileContents ¶
func (c *FileTestUtil) WriteCgroupFileContents(taskDir string, file CgroupFile, contents string)
func (*FileTestUtil) WriteFileContents ¶
func (c *FileTestUtil) WriteFileContents(fileRelativePath, contents string)
func (*FileTestUtil) WriteProcSubFileContents ¶
func (c *FileTestUtil) WriteProcSubFileContents(relativeFilePath string, contents string)
type RangeValidator ¶
type RangeValidator struct {
// contains filtered or unexported fields
}
type SystemFile ¶
var (
ProcStatFile SystemFile
)
type VersionInfo ¶
type VersionInfo struct { // Open Anolis OS (kernel): https://github.com/alibaba/cloud-kernel IsAnolisOS bool }