MCPcopy Create free account
hub / github.com/mininet/mininet / mountCgroups

Function mountCgroups

mininet/util.py:552–570  ·  view source on GitHub ↗

Mount cgroupfs if needed and return cgroup version cgcontrol: cgroup controllers to check ('cpu cpuacct cpuset') Returns: 'cgroup' | 'cgroup2'

( cgcontrol='cpu cpuacct cpuset' )

Source from the content-addressed store, hash-verified

550 # pylint: enable=broad-except
551
552def mountCgroups( cgcontrol='cpu cpuacct cpuset' ):
553 """Mount cgroupfs if needed and return cgroup version
554 cgcontrol: cgroup controllers to check ('cpu cpuacct cpuset')
555 Returns: 'cgroup' | 'cgroup2' """
556 # Try to read the cgroup controllers in cgcontrol
557 cglist = cgcontrol.split()
558 paths = ' '.join( '-g ' + c for c in cglist )
559 cmd = 'cgget -n %s /' % paths
560 result = errRun( cmd )
561 # If it failed, mount cgroupfs and retry
562 if result.ret or result.err or any(
563 c not in result.out for c in cglist ):
564 errFail( 'cgroupfs-mount' )
565 result = errRun( cmd )
566 errFail( cmd )
567 # cpu.cfs_period_us is used for cgroup but not cgroup2
568 if 'cpu.cfs_period_us' in result.out:
569 return 'cgroup'
570 return 'cgroup2'
571
572def natural( text ):
573 "To sort sanely/alphabetically: sorted( l, key=natural )"

Callers 1

initMethod · 0.90

Calls 2

errRunFunction · 0.85
errFailFunction · 0.85

Tested by

no test coverage detected