system

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CPUShareKubeBEValue    int64 = 2
	CPUShareUnitValue      int64 = 1024
	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"
)
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/"
)
View Source
const (
	CgroupCPUDir     string = "cpu/"
	CgroupCPUSetDir  string = "cpuset/"
	CgroupCPUacctDir string = "cpuacct/"
	CgroupMemDir     string = "memory/"
)
View Source
const (
	CFSBasePeriodValue int64 = 100000

	CPUStatFileName   = "cpu.stat"
	CPUSharesFileName = "cpu.shares"
	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"
)
View Source
const (
	DS_MODE   = "dsMode"
	HOST_MODE = "hostMode"
)
View Source
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"
)
View Source
const EmptyValueError string = "EmptyValueError"
View Source
const (
	ProcStatFileName = "stat"
)

Variables

View Source
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"
)
View Source
var (
	CPUStat      = CgroupFile{ResourceFileName: CPUStatFileName, Subfs: CgroupCPUDir, IsAnolisOS: false}
	CPUShares    = CgroupFile{ResourceFileName: CPUSharesFileName, 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}
)
View Source
var AgentMode = DS_MODE
View Source
var CgroupPathFormatter = cgroupPathFormatterInSystemd

default use Systemd cgroup path format

View Source
var (
	CommonRootDir = "" // for uni-test
)
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 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 CommonFileRead(file string) (string, error)

func CommonFileWrite added in v0.3.0

func CommonFileWrite(file string, data string) error

func CommonFileWriteIfDifferent added in v0.3.0

func CommonFileWriteIfDifferent(file string, value string) error

func FileExists

func FileExists(path string) bool

func GetCacheInfo added in v0.3.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 GetCgroupCurTasks added in v0.3.0

func GetCgroupCurTasks(cgroupPath string) ([]int, error)

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

func GetResctrlGroupRootDirPath(groupPath string) string

@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

func GetResctrlSchemataFilePath(groupPath string) string

@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

func GetResctrlTasksFilePath(groupPath string) string

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

func IsSupportResctrl added in v0.3.0

func IsSupportResctrl() (bool, error)

func MountResctrlSubsystem added in v0.3.0

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 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 added in v0.3.0

func ReadCatL3CbmString() (string, error)

ReadCatL3Cbm reads and returns the value of cat l3 cbm_mask

func ReadFileNoStat

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

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

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

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

func SetConf

func SetConf(config Config)

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

type CPUStatRaw struct {
	NrPeriod             int64
	NrThrottled          int64
	ThrottledNanoSeconds int64
}

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.

  1. Read kubelet's /proc/${pid}/cmdline.
  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 CgroupFile

type CgroupFile struct {
	ResourceFileName string
	Subfs            string
	IsAnolisOS       bool
	Validator        Validate
}

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

func (*Config) InitFlags

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

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
}

func (*RangeValidator) Validate

func (r *RangeValidator) Validate(value *int64) (isValid bool, msg string)

type SystemFile

type SystemFile struct {
	File      string
	Validator Validate
}
var (
	ProcStatFile SystemFile
)

type Validate

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

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