From 740acfb350d668d6d1e60566fe6ae9c3a94a4e8e Mon Sep 17 00:00:00 2001 From: lantz Date: Fri, 28 Apr 2023 18:48:35 -0700 Subject: [PATCH] Unlimit cfs hosts for startup/shutdown config (#1178) We defer cfs cgroup bandwidth limiting until CPULimitedHost.configDefault(), and we change Mininet.stop() to call a new host.unlimit() method if available. --- mininet/net.py | 4 ++++ mininet/node.py | 31 ++++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/mininet/net.py b/mininet/net.py index 55998e1..55349ae 100755 --- a/mininet/net.py +++ b/mininet/net.py @@ -572,6 +572,10 @@ class Mininet( object ): info( controller.name + ' ' ) controller.stop() info( '\n' ) + # Unlimit cfs hosts to speed up shutdown + for h in self.hosts: + if hasattr( h, 'unlimit' ): + h.unlimit() if self.terms: info( '*** Stopping %i terms\n' % len( self.terms ) ) self.stopXterms() diff --git a/mininet/node.py b/mininet/node.py index 0d219c5..f21dfb3 100644 --- a/mininet/node.py +++ b/mininet/node.py @@ -685,8 +685,21 @@ class CPULimitedHost( Host ): "CPU limited host" - def __init__( self, name, sched='cfs', **kwargs ): - Host.__init__( self, name, **kwargs ) + def __init__( self, name, sched='cfs', **params ): + Host.__init__( self, name, **params ) + # BL: Setting the correct period/quota is tricky, particularly + # for RT. RT allows very small quotas, but the overhead + # seems to be high. CFS has a mininimum quota of 1 ms, but + # still does better with larger period values. + self.period_us = params.get( 'period_us', 100000 ) + self.sched = sched + self.cgroupsInited = False + self.cgroup, self.rtprio = None, None + + def initCgroups( self ): + "Deferred cgroup initialization" + if self.cgroupsInited: + return # Initialize class if necessary if not CPULimitedHost.inited: CPULimitedHost.init() @@ -696,13 +709,7 @@ class CPULimitedHost( Host ): # We don't add ourselves to a cpuset because you must # specify the cpu and memory placement first errFail( 'cgclassify -g cpu,cpuacct:/%s %s' % ( self.name, self.pid ) ) - # BL: Setting the correct period/quota is tricky, particularly - # for RT. RT allows very small quotas, but the overhead - # seems to be high. CFS has a mininimum quota of 1 ms, but - # still does better with larger period values. - self.period_us = kwargs.get( 'period_us', 100000 ) - self.sched = sched - if sched == 'rt': + if self.sched == 'rt': self.checkRtGroupSched() self.rtprio = 20 @@ -863,6 +870,7 @@ class CPULimitedHost( Host ): cores: (real) core(s) this host can run on params: parameters for Node.config()""" r = Node.config( self, **params ) + self.initCgroups() # Was considering cpu={'cpu': cpu , 'sched': sched}, but # that seems redundant self.setParam( r, 'setCPUFrac', cpu=cpu ) @@ -878,6 +886,11 @@ class CPULimitedHost( Host ): cls.cgversion = mountCgroups() cls.inited = True + def unlimit( self ): + "Unlimit cpu for cfs" + if self.sched == 'cfs' and self.params.get( 'cpu', -1 ) != -1: + self.setCPUFrac( -1, sched=self.sched ) + # Some important things to note: #