Skip to content
Snippets Groups Projects
Commit 820c3be7 authored by Bob Lantz's avatar Bob Lantz
Browse files

Reorganize CFS and RT default/error conditions.

parent a562ca1b
No related branches found
No related tags found
No related merge requests found
...@@ -689,6 +689,19 @@ def cleanup( self ): ...@@ -689,6 +689,19 @@ def cleanup( self ):
super( CPULimitedHost, self ).cleanup() super( CPULimitedHost, self ).cleanup()
retry( retries=3, delaySecs=1, fn=self.cgroupDel ) retry( retries=3, delaySecs=1, fn=self.cgroupDel )
_rtGroupSched = False # internal class var: Is CONFIG_RT_GROUP_SCHED set?
@classmethod
def checkRtGroupSched( cls ):
"Check (Ubuntu,Debian) kernel config for CONFIG_RT_GROUP_SCHED for RT"
if not cls._rtGroupSched:
release = quietRun( 'uname -r' ).strip('\r\n')
output = quietRun( 'grep CONFIG_RT_GROUP_SCHED /boot/config-%s' % release )
if output == '# CONFIG_RT_GROUP_SCHED is not set\n':
error( '\n*** error: please enable RT_GROUP_SCHED in your kernel\n' )
exit( 1 )
cls._rtGroupSched = True
def chrt( self ): def chrt( self ):
"Set RT scheduling priority" "Set RT scheduling priority"
quietRun( 'chrt -p %s %s' % ( self.rtprio, self.pid ) ) quietRun( 'chrt -p %s %s' % ( self.rtprio, self.pid ) )
...@@ -706,20 +719,7 @@ def rtInfo( self, f ): ...@@ -706,20 +719,7 @@ def rtInfo( self, f ):
quota = int( self.period_us * f ) quota = int( self.period_us * f )
return pstr, qstr, self.period_us, quota return pstr, qstr, self.period_us, quota
_rtGroupSched = False # internal class var: Is CONFIG_RT_GROUP_SCHED set? def cfsInfo( self, f ):
@classmethod
def checkRtGroupSched( cls ):
"Check (Ubuntu,Debian) kernel config for CONFIG_RT_GROUP_SCHED for RT"
if not cls._rtGroupSched:
release = quietRun( 'uname -r' ).strip('\r\n')
output = quietRun( 'grep CONFIG_RT_GROUP_SCHED /boot/config-%s' % release )
if output == '# CONFIG_RT_GROUP_SCHED is not set\n':
error( '\n*** error: please enable RT_GROUP_SCHED in your kernel\n' )
exit( 1 )
cls._rtGroupSched = True
def cfsInfo( self, f):
"Internal method: return parameters for CFS bandwidth" "Internal method: return parameters for CFS bandwidth"
pstr, qstr = 'cfs_period_us', 'cfs_quota_us' pstr, qstr = 'cfs_period_us', 'cfs_quota_us'
# CFS uses wall clock time for period and CPU time for quota. # CFS uses wall clock time for period and CPU time for quota.
...@@ -729,6 +729,9 @@ def cfsInfo( self, f): ...@@ -729,6 +729,9 @@ def cfsInfo( self, f):
debug( '(cfsInfo: increasing default period) ' ) debug( '(cfsInfo: increasing default period) ' )
quota = 1000 quota = 1000
period = int( quota / f / numCores() ) period = int( quota / f / numCores() )
# Reset to unlimited on negative quota
if quota < 0:
quota = -1
return pstr, qstr, period, quota return pstr, qstr, period, quota
# BL comment: # BL comment:
...@@ -740,25 +743,23 @@ def cfsInfo( self, f): ...@@ -740,25 +743,23 @@ def cfsInfo( self, f):
# to CPU seconds per second, essentially assuming that # to CPU seconds per second, essentially assuming that
# all CPUs are the same. # all CPUs are the same.
def setCPUFrac( self, f=-1, sched=None): def setCPUFrac( self, f, sched=None ):
"""Set overall CPU fraction for this host """Set overall CPU fraction for this host
f: CPU bandwidth limit (fraction) f: CPU bandwidth limit (positive fraction, or -1 for cfs unlimited)
sched: 'rt' or 'cfs' sched: 'rt' or 'cfs'
Note 'cfs' requires CONFIG_CFS_BANDWIDTH""" Note 'cfs' requires CONFIG_CFS_BANDWIDTH,
# if cpu fraction is None, reset to default of 0 and 'rt' requires CONFIG_RT_GROUP_SCHED"""
if not f:
f = -1
if not sched: if not sched:
sched = self.sched sched = self.sched
if sched == 'rt': if sched == 'rt':
if not f or f < 0:
raise Exception( 'Please set a positive CPU fraction for sched=rt\n' )
return
pstr, qstr, period, quota = self.rtInfo( f ) pstr, qstr, period, quota = self.rtInfo( f )
elif sched == 'cfs': elif sched == 'cfs':
pstr, qstr, period, quota = self.cfsInfo( f ) pstr, qstr, period, quota = self.cfsInfo( f )
else: else:
return return
if quota < 0:
# Reset to unlimited
quota = -1
# Set cgroup's period and quota # Set cgroup's period and quota
setPeriod = self.cgroupSet( pstr, period ) setPeriod = self.cgroupSet( pstr, period )
setQuota = self.cgroupSet( qstr, quota ) setQuota = self.cgroupSet( qstr, quota )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment