system

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2022 License: Apache-2.0 Imports: 24 Imported by: 3

Documentation

Index

Constants

View Source
const (
	CPUShareKubeBEValue    int64 = 2
	CPUShareUnitValue      int64 = 1024
	CFSQuotaUnlimitedValue int64 = -1
	CPUBvtLSValue          int64 = 2
	CPUBvtBEValue          int64 = -1

	CgroupMaxSymbolStr string = "max"                 // currently only appear in `memory.high`, we consider the value as MaxInt64
	CgroupMaxValueStr  string = "9223372036854775807" // math.MaxInt64; writing `memory.high` with this do the same as set as "max"
)
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 (
	/** subfs name */
	CgroupCPUDir     string = "cpu/"
	CgroupCPUSetDir  string = "cpuset/"
	CgroupCPUacctDir string = "cpuacct/"
	CgroupMemDir     string = "memory/"
	CgroupBlkioDir   string = "blkio/"
	CgroupNetClsDir  string = "net_cls/"
	Devices          string = "devices/"
)
View Source
const (
	CFSBasePeriodValue int64 = 100000
	MemoryUnlimitValue int64 = -1

	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"

	CpuacctStatFileName       = "cpuacct.stat"
	CpuacctProcStatFileName   = "cpuacct.proc_stat"
	CpuacctProcStatV2FileName = "cpuacct.proc_stat_v2"

	MemWmarkRatioFileName       = "memory.wmark_ratio"
	MemWmarkScaleFactorFileName = "memory.wmark_scale_factor"
	MemDroppableFileName        = "memory.droppable"
	MemFlagsFileName            = "memory.coldpgs.flags"
	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"
	MemorySWLimitFileName       = "memory.memsw.limit_in_bytes"
	MemStatFileName             = "memory.stat"

	NetClsIDFileName = "net_cls.classid"

	BlkioTRIopsFileName = "blkio.throttle.read_iops_device"
	BlkioTRBpsFileName  = "blkio.throttle.read_bps_device"
	BlkioTWIopsFileName = "blkio.throttle.write_iops_device"
	BlkioTWBpsFileName  = "blkio.throttle.write_bps_device"
)
View Source
const (
	DS_MODE   = "dsMode"
	HOST_MODE = "hostMode"
)
View Source
const (
	GoldNetClsID   = 0xab5a2010 // net_priority(3)
	GoldDSCP       = 18
	SilverNetClsID = 0xab5a2020 // net_priority(5)
	SilverDSCP     = 17
	CopperNetClsID = 0xab5a2030 // net_priority(7)
	CopperDSCP     = 16
)
View Source
const (
	QosctlPackageName = "aqos"
	QosctlBinaryPath  = "/home/admin/aqos/qosctl"
)
View Source
const (
	ResctrlDir string = "resctrl/"
	RdtInfoDir string = "info"
	L3CatDir   string = "L3"

	SchemataFileName    string = "schemata"
	CbmMaskFileName     string = "cbm_mask"
	ResctrlTaskFileName string = "tasks"

	ResctrlName string = "resctrl"
)
View Source
const (
	ProcSysVmRelativePath = "sys/vm/"

	MinFreeKbytesFileName        = "min_free_kbytes"
	WatermarkScaleFactorFileName = "watermark_scale_factor"
	ProcStatFileName             = "stat"
)
View Source
const BandwidthCtrlQdiscCount = 7

htb * 1 + dsmark * 3 + sfq * 3

View Source
const (
	// 1000 Mbit/s
	DefaultIfaceBandwidth = 1000
)
View Source
const EmptyValueError = "EmptyValueError"

Variables

View Source
var (
	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: -50, max: 50}
	MemWmarkScaleFactorFileNameValidator = &RangeValidator{name: MemWmarkScaleFactorFileName, min: 1, max: 1000}
	MemDroppableValidator                = &RangeValidator{name: MemDroppableFileName, min: 0, max: 1}
	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"
	CPUBvtWarpNsValidator                = &RangeValidator{name: CPUBVTWarpNsName, min: -1, max: 2}
	CPUBurstValidator                    = &RangeValidator{name: CPUBurstName, min: 0, max: 100 * 10 * 100000}
)
View Source
var (
	CPUStat      = CgroupFile{ResourceFileName: CPUStatFileName, Subfs: CgroupCPUDir, IsAliOS: false}
	CPUShares    = CgroupFile{ResourceFileName: CPUSharesFileName, Subfs: CgroupCPUDir, IsAliOS: false}
	CPUCFSQuota  = CgroupFile{ResourceFileName: CPUCFSQuotaName, Subfs: CgroupCPUDir, IsAliOS: false}
	CPUCFSPeriod = CgroupFile{ResourceFileName: CPUCFSPeriodName, Subfs: CgroupCPUDir, IsAliOS: false}
	CPUTask      = CgroupFile{ResourceFileName: CPUTaskFileName, Subfs: CgroupCPUDir, IsAliOS: false}
	CPUBVTWarpNs = CgroupFile{ResourceFileName: CPUBVTWarpNsName, Subfs: CgroupCPUDir, IsAliOS: true, Validator: CPUBvtWarpNsValidator}
	CPUBurst     = CgroupFile{ResourceFileName: CPUBurstName, Subfs: CgroupCPUDir, IsAliOS: true, Validator: CPUBurstValidator}

	CPUSet = CgroupFile{ResourceFileName: CPUSFileName, Subfs: CgroupCPUSetDir, IsAliOS: false}

	CpuacctStat       = CgroupFile{ResourceFileName: CpuacctStatFileName, Subfs: CgroupCPUacctDir, IsAliOS: false}
	CpuacctProcStat   = CgroupFile{ResourceFileName: CpuacctProcStatFileName, Subfs: CgroupCPUacctDir, IsAliOS: true}
	CpuacctProcStatV2 = CgroupFile{ResourceFileName: CpuacctProcStatV2FileName, Subfs: CgroupCPUacctDir, IsAliOS: true}

	MemWmarkRatio       = CgroupFile{ResourceFileName: MemWmarkRatioFileName, Subfs: CgroupMemDir, IsAliOS: true, Validator: MemWmarkRatioValidator}
	MemDroppable        = CgroupFile{ResourceFileName: MemDroppableFileName, Subfs: CgroupMemDir, IsAliOS: true, Validator: MemDroppableValidator}
	MemFlags            = CgroupFile{ResourceFileName: MemFlagsFileName, Subfs: CgroupMemDir, IsAliOS: true}
	MemPriority         = CgroupFile{ResourceFileName: MemPriorityFileName, Subfs: CgroupMemDir, IsAliOS: true, Validator: MemPriorityValidator}
	MemUsePriorityOom   = CgroupFile{ResourceFileName: MemUsePriorityOomFileName, Subfs: CgroupMemDir, IsAliOS: true, Validator: MemUsePriorityOomValidator}
	MemOomGroup         = CgroupFile{ResourceFileName: MemOomGroupFileName, Subfs: CgroupMemDir, IsAliOS: true, Validator: MemOomGroupValidator}
	MemWmarkMinAdj      = CgroupFile{ResourceFileName: MemWmarkMinAdjFileName, Subfs: CgroupMemDir, IsAliOS: true, Validator: MemWmarkMinAdjValidator}
	MemWmarkScaleFactor = CgroupFile{ResourceFileName: MemWmarkScaleFactorFileName, Subfs: CgroupMemDir, IsAliOS: true, Validator: MemWmarkScaleFactorFileNameValidator}
	MemMin              = CgroupFile{ResourceFileName: MemMinFileName, Subfs: CgroupMemDir, IsAliOS: true, Validator: MemMinValidator}
	MemLow              = CgroupFile{ResourceFileName: MemLowFileName, Subfs: CgroupMemDir, IsAliOS: true, Validator: MemLowValidator}
	MemHigh             = CgroupFile{ResourceFileName: MemHighFileName, Subfs: CgroupMemDir, IsAliOS: true, Validator: MemHighValidator}
	MemoryLimit         = CgroupFile{ResourceFileName: MemoryLimitFileName, Subfs: CgroupMemDir, IsAliOS: false}
	MemorySWLimit       = CgroupFile{ResourceFileName: MemorySWLimitFileName, Subfs: CgroupMemDir, IsAliOS: false}
	MemStat             = CgroupFile{ResourceFileName: MemStatFileName, Subfs: CgroupMemDir, IsAliOS: false}

	NetClsID = CgroupFile{ResourceFileName: NetClsIDFileName, Subfs: CgroupNetClsDir, IsAliOS: false}

	BlkioReadIops  = CgroupFile{ResourceFileName: BlkioTRIopsFileName, Subfs: CgroupBlkioDir, IsAliOS: false}
	BlkioReadBps   = CgroupFile{ResourceFileName: BlkioTRBpsFileName, Subfs: CgroupBlkioDir, IsAliOS: false}
	BlkioWriteIops = CgroupFile{ResourceFileName: BlkioTWIopsFileName, Subfs: CgroupBlkioDir, IsAliOS: false}
	BlkioWriteBps  = CgroupFile{ResourceFileName: BlkioTWBpsFileName, Subfs: CgroupBlkioDir, IsAliOS: false}
)
View Source
var (
	MinFreeKbytesValidator        = &RangeValidator{name: MinFreeKbytesFileName, min: 10, max: 400}
	WatermarkScaleFactorValidator = &RangeValidator{name: WatermarkScaleFactorFileName, min: 10, max: 400}
)
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 EnsureQosctlReady = ensureQosctlReadyFn
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 GetHostDefaultIface = getHostDefaultIfaceFn
View Source
var GetIfaceSpeedMbit = getIfaceSpeedMbitFn
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).

View Source
var (
	QosctlKModsRegex = []*regexp.Regexp{
		regexp.MustCompile(`sch_sfq\s`),
		regexp.MustCompile(`sch_dsmark\s`),
		regexp.MustCompile(`sch_htb\s`),
	}
)
View Source
var SetupBandwidthCtrl = setupBandwidthCtrlFn

Functions

func CPUIdentityEnabled

func CPUIdentityEnabled() (bool, error)

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

func CgroupFileWriteIfDifferent(cgroupTaskDir string, file CgroupFile, value 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 CommonFileRead

func CommonFileRead(file string) (string, error)

func CommonFileWrite

func CommonFileWrite(file string, data string) error

func CommonFileWriteIfDifferent

func CommonFileWriteIfDifferent(file string, value string) error

func FileExists

func FileExists(path string) bool

func GetCgroupCurTasks

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

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 HasBandwidthCtrlSetup

func HasBandwidthCtrlSetup(iface *net.Interface) bool

TODO: 'aqos' add sub command to check itself setup

func Int64Ptr

func Int64Ptr(v int64) *int64

Int64Ptr returns a int64 pointer for given value

func MountResctrlSubsystem

func MountResctrlSubsystem() (bool, error)

MountResctrlSubsystem mounts resctrl fs under the sysFSRoot to enable the kernel feature on supported environment NOTE: linux kernel (Alibaba Cloud Linux 2, >= 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 or

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 ReadCatL3Cbm

func ReadCatL3Cbm() (uint, error)

ReadCatL3Cbm reads and returns the value of cat l3 cbm_mask

func ReadCatL3CbmString

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

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

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

func ResetBandwidthCtrl

func ResetBandwidthCtrl(iface *net.Interface)

func SetConf

func SetConf(config Config)

func SetupCgroupPathFormatter

func SetupCgroupPathFormatter(driver CgroupDriverType)

func ValidateCgroupValue

func ValidateCgroupValue(value *int64, parentDir string, file CgroupFile) bool

func ValidateValue

func ValidateValue(value *int64, file SystemFile) bool

Types

type BandwidthConfig

type BandwidthConfig struct {
	GatewayIfaceName string
	GatewayLimit     uint64

	RootLimit uint64

	GoldRequest uint64
	GoldLimit   uint64
	GoldDSCP    uint64

	SilverRequest uint64
	SilverLimit   uint64
	SilverDSCP    uint64

	CopperRequest uint64
	CopperLimit   uint64
	CopperDSCP    uint64
}

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
	IsAliOS          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

Creates a new test util for the specified subsystem

func (*FileTestUtil) Cleanup

func (c *FileTestUtil) Cleanup()

func (*FileTestUtil) CreateCgroupFile

func (c *FileTestUtil) CreateCgroupFile(taskDir string, file CgroupFile)

func (*FileTestUtil) CreateFile

func (c *FileTestUtil) CreateFile(fileRelativePath string)

func (*FileTestUtil) CreateFiles

func (c *FileTestUtil) CreateFiles(files []string)

func (*FileTestUtil) CreateProcSubFile

func (c *FileTestUtil) CreateProcSubFile(fileRelativePath string)

func (*FileTestUtil) GetAbsoluteFilePath

func (c *FileTestUtil) GetAbsoluteFilePath(fileRelativePath string) string

func (*FileTestUtil) MkDirAll

func (c *FileTestUtil) MkDirAll(dirRelativePath string)

func (*FileTestUtil) MkProcSubDirAll

func (c *FileTestUtil) MkProcSubDirAll(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 NetworkTestUtil

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

func NewNetworkTestUtil

func NewNetworkTestUtil(t *testing.T) *NetworkTestUtil

func (*NetworkTestUtil) Cleanup

func (n *NetworkTestUtil) Cleanup()

func (*NetworkTestUtil) SetupDummyLinkWithAddr

func (n *NetworkTestUtil) SetupDummyLinkWithAddr() *netlink.Dummy

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 (
	MinFreeKbytesFile        SystemFile
	WatermarkScaleFactorFile SystemFile
	ProcStatFile             SystemFile
)

type Validate

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

type VersionInfo

type VersionInfo struct {
	IsAliOS bool
}

Jump to

Keyboard shortcuts

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