Added CKRM compatibility for set_sched.
authorMarc Fiuczynski <mef@cs.princeton.edu>
Mon, 11 Jul 2005 20:26:19 +0000 (20:26 +0000)
committerMarc Fiuczynski <mef@cs.princeton.edu>
Mon, 11 Jul 2005 20:26:19 +0000 (20:26 +0000)
python/vserver.py

index bfc5c93..e5d9d2f 100644 (file)
@@ -13,6 +13,7 @@ import linuxcaps
 import passfdimpl
 import utmp
 import vserverimpl, vduimpl
+import cpulimit
 
 from util_vserver_vars import *
 
@@ -110,25 +111,38 @@ class VServer:
         return blocktotal
 
     def set_sched(self, shares, besteffort = True):
-        global SCHED_TOKENS_MIN, SCHED_TOKENS_MAX
-        tokensmin = SCHED_TOKENS_MIN
-        tokensmax = SCHED_TOKENS_MAX
-
-        if besteffort is True:
-            # magic "interval" value for Andy's scheduler to denote besteffort
-            interval = 1000
-            fillrate = shares
-        else:
-            interval = 1001
-            fillrate = shares
+        # for the old CKRM scheduler
+        if cpulimit.checkckrm() is True:
+            cpulimit.cpuinit()
+            cpulimit.vs2ckrm_on(self.name)
+            try:
+                cpulimit.cpulimit(self.name,shares)
+            except OSError, ex:
+                if ex.errno == 22:
+                    print "invalid shares argument"
+                    # should re-raise exception?!
 
-        try:
-            vserverimpl.setsched(self.ctx,fillrate,interval,tokensmin,tokensmax)
-        except OSError, ex:
-            if ex.errno == 22:
-                print "kernel does not support vserver scheduler"
+        # for the new vserver scheduler
+        else:
+            global SCHED_TOKENS_MIN, SCHED_TOKENS_MAX
+            tokensmin = SCHED_TOKENS_MIN
+            tokensmax = SCHED_TOKENS_MAX
+
+            if besteffort is True:
+                # magic "interval" value for Andy's scheduler to denote besteffort
+                interval = 1000
+                fillrate = shares
             else:
-                raise ex
+                interval = 1001
+                fillrate = shares
+
+            try:
+                vserverimpl.setsched(self.ctx,fillrate,interval,tokensmin,tokensmax)
+            except OSError, ex:
+                if ex.errno == 22:
+                    print "kernel does not support vserver scheduler"
+                else:
+                    raise ex
 
     def get_sched(self):
         # have no way of querying scheduler right now on a per vserver basis