From 57ef8c865ad6116adcee16b39a7340c13d2f8c17 Mon Sep 17 00:00:00 2001 From: Andy Bavier Date: Tue, 23 Jun 2009 14:51:59 +0000 Subject: [PATCH] Use cgroup CPU scheduler --- python/vserver.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/python/vserver.py b/python/vserver.py index a4b063b..fa58beb 100644 --- a/python/vserver.py +++ b/python/vserver.py @@ -41,6 +41,8 @@ RLIMITS = { "NSOCK": VLIMIT_NSOCK, "ANON": VLIMIT_ANON, "SHMEM": VLIMIT_SHMEM} +CPU_SHARE_MULT = 1024 + # add in the platform supported rlimits for entry in resource.__dict__.keys(): if entry.find("RLIMIT_")==0: @@ -332,24 +334,27 @@ class VServer: def set_sched_config(self, cpu_min, cpu_share): """ Write current CPU scheduler parameters to the vserver - configuration file. This method does not modify the kernel CPU - scheduling parameters for this context. """ - - self.config.update('sched/fill-rate', cpu_min) - self.config.update('sched/fill-rate2', cpu_share) - if cpu_share == 0: - self.config.unset('sched/idle-time') - + configuration file. Currently, 'cpu_min' is not supported. """ + self.config.update('cgroup/cpu.shares', cpu_share * CPU_SHARE_MULT) if self.is_running(): self.set_sched(cpu_min, cpu_share) def set_sched(self, cpu_min, cpu_share): - """ Update kernel CPU scheduling parameters for this context. """ - vserverimpl.setsched(self.ctx, cpu_min, cpu_share) + """ Update kernel CPU scheduling parameters for this context. + Currently, 'cpu_min' is not supported. """ + try: + cgroup = open('/dev/cgroup/%s/cpu.shares' % name, 'w') + cgroup.write('%s' % (cpu_share * CPU_SHARE_MULT)) + cgroup.close() + except: + pass def get_sched(self): - # have no way of querying scheduler right now on a per vserver basis - return (-1, False) + try: + cpu_share = int(int(self.config.get('cgroup/cpu.shares')) / CPU_SHARE_MULT) + except: + cpu_share = False + return (-1, cpu_share) def set_bwlimit(self, minrate = bwlimit.bwmin, maxrate = None, exempt_min = None, exempt_max = None, -- 2.43.0