From 72e562e8036bc29c76fb5139821712b9c431f764 Mon Sep 17 00:00:00 2001 From: tchernobog Date: Wed, 9 Aug 2006 13:37:42 +0000 Subject: [PATCH] - Try to make CPUPolicy.get_parameters() and RR-Priority work. Won't run. git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@833 3ecf2c5c-341e-0410-92b4-d18e462d057c --- plugins/pyloader/src/CPUPolicy.py | 23 ++--------------- plugins/pyloader/src/ScriptAdapter.py | 1 - plugins/pyloader/src/builtin-policies/fcfs.py | 5 ---- .../src/builtin-policies/rr_priority.py | 25 ++++++++++--------- plugins/pyloader/src/builtin-policies/sjf.py | 5 ---- plugins/pyloader/src/python_cpu_policy.cc | 19 ++++++++++++++ plugins/pyloader/src/python_cpu_policy.hh | 10 ++------ plugins/pyloader/src/sgpem.i | 2 ++ 8 files changed, 38 insertions(+), 52 deletions(-) diff --git a/plugins/pyloader/src/CPUPolicy.py b/plugins/pyloader/src/CPUPolicy.py index b075510..7fa8cdf 100644 --- a/plugins/pyloader/src/CPUPolicy.py +++ b/plugins/pyloader/src/CPUPolicy.py @@ -7,7 +7,8 @@ import sgpem # This class also exposes the method sort(), which can be # used to easily sort the queue of ready process with a # user-defined given compare function. -class CPUPolicy: +# The method get_parameters() is inherited from sgpem.CPUPolicy. +class CPUPolicy(sgpem.CPUPolicy): ## @var Avoid instantiation of an abstract class. # @see Abstract.Metaclass __metaclass__ = Metaclass @@ -91,26 +92,6 @@ class CPUPolicy: # @return -1 If the policy doesn't want to use time slices # @return 0+ To specify a time slice duration for this policy get_time_slice = AbstractMethod('get_time_slice') - - ## @brief Returns wether this policy sorts processes or threads - # - # Should be implemented with signature: - # @code - # def wants(self): - # # function body - # @endcode - # - # @return sgpem.policy_sorts_processes If the policy sorts processes - # @return sgpem.policy_sorts_threads If the policy sorts threads - wants = AbstractMethod('wants') - - ## @brief Returns the PolicyParameters instance you can use in - # Policy::Policy::configure() - # - # @return A sgpem::PolicyParameters instance - def get_parameters(self): - return sgpem.Scheduler.get_instance().get_policy().get_parameters() - ## @brief This function implements an in-place stable sort # using directly ReadyQueue methods diff --git a/plugins/pyloader/src/ScriptAdapter.py b/plugins/pyloader/src/ScriptAdapter.py index fc51ec3..03f0091 100644 --- a/plugins/pyloader/src/ScriptAdapter.py +++ b/plugins/pyloader/src/ScriptAdapter.py @@ -34,7 +34,6 @@ class ScriptAdapter : self._policy = policy() print 'ScriptAdapter for policy ', policy, ' loaded' - ## @brief Asynchronously call Policy.configure() # # @param self The caller object diff --git a/plugins/pyloader/src/builtin-policies/fcfs.py b/plugins/pyloader/src/builtin-policies/fcfs.py index 63c5ab6..4846db6 100644 --- a/plugins/pyloader/src/builtin-policies/fcfs.py +++ b/plugins/pyloader/src/builtin-policies/fcfs.py @@ -36,11 +36,6 @@ class fcfs(CPUPolicy) : def get_time_slice(self): return -2 - # FIXME incorrect, but must be implemented to allow - # loading from the policy manager - def wants(self): - return 0 - def sort_queue(self, queue): cmpf = lambda a, b: \ a.get_arrival_time() < \ diff --git a/plugins/pyloader/src/builtin-policies/rr_priority.py b/plugins/pyloader/src/builtin-policies/rr_priority.py index b905bb2..7942ab6 100644 --- a/plugins/pyloader/src/builtin-policies/rr_priority.py +++ b/plugins/pyloader/src/builtin-policies/rr_priority.py @@ -27,27 +27,28 @@ class rr_priority(CPUPolicy) : pass; def configure(self): - print 'No options to configure for rr_priority' + param = self.get_parameters() + param.register_int("Time slice", 1, 10000, True, 2) + param.register_int("Is preemptive?", 0, 1, True, 0) def is_preemptive(self): - return False + value = self.get_parameters().get_int("Is preemptive?") + if value == 0: + return False + else: + return True # FIXME pass to a configurable amount def get_time_slice(self): - return 2 - - # FIXME incorrect, but must be implemented to allow - # loading from the policy manager - def wants(self): - return 0 + return self.get_parameters().get_int("Time slice") def sort_queue(self, queue): by_prio = lambda a, b: \ a.get_current_priority() < \ b.get_current_priority() - by_ltime = lambda a, b: \ - a.get_last_acquisition() > \ - b.get_last_acquisition() + by_ltime = lambda a, b: \ + a.get_last_acquisition() > \ + b.get_last_acquisition() self.sort(queue,by_ltime) - self.sort(queue,by_prio) + self.sort(queue,by_prio) diff --git a/plugins/pyloader/src/builtin-policies/sjf.py b/plugins/pyloader/src/builtin-policies/sjf.py index b7e40e4..d26991b 100644 --- a/plugins/pyloader/src/builtin-policies/sjf.py +++ b/plugins/pyloader/src/builtin-policies/sjf.py @@ -36,11 +36,6 @@ class sjf(CPUPolicy) : def get_time_slice(self): return -1 - # FIXME incorrect, but must be implemented to allow - # loading from the policy manager - def wants(self): - return 0 - def sort_queue(self, queue): cmpf = lambda a, b: \ a.get_total_cpu_time() - a.get_elapsed_time() < \ diff --git a/plugins/pyloader/src/python_cpu_policy.cc b/plugins/pyloader/src/python_cpu_policy.cc index a3ce2fe..b9bbb19 100644 --- a/plugins/pyloader/src/python_cpu_policy.cc +++ b/plugins/pyloader/src/python_cpu_policy.cc @@ -86,6 +86,25 @@ PythonCPUPolicy::~PythonCPUPolicy() if(_upolicy_dict) Py_DECREF(_upolicy_dict); } +void +PythonCPUPolicy::activate() +{ + // FIXME write the rest, taking away code from constructor + + configure(); +} + + +void +PythonCPUPolicy::deactivate() +{ + // FIXME See if some code has to be moved here from the + // destructor, AFTER having written activate() + + _parameters.clear(); +} + + void PythonCPUPolicy::configure() throw(UserInterruptException) diff --git a/plugins/pyloader/src/python_cpu_policy.hh b/plugins/pyloader/src/python_cpu_policy.hh index dcd7d9d..4c6f489 100644 --- a/plugins/pyloader/src/python_cpu_policy.hh +++ b/plugins/pyloader/src/python_cpu_policy.hh @@ -76,15 +76,9 @@ namespace sgpem */ int get_time_slice() const throw(UserInterruptException); - void activate() - { - //FIXME write code for me - } + void activate(); - void deactivate() - { - //FIXME write code for me - } + void deactivate(); private: PythonCPUPolicy(const PythonCPUPolicy&); diff --git a/plugins/pyloader/src/sgpem.i b/plugins/pyloader/src/sgpem.i index 21312f7..e39ec3f 100644 --- a/plugins/pyloader/src/sgpem.i +++ b/plugins/pyloader/src/sgpem.i @@ -165,6 +165,8 @@ namespace sgpem { virtual unsigned int get_arrival_time() const = 0; virtual unsigned int get_elapsed_time() const = 0; + virtual int get_last_acquisition() const = 0; + virtual int get_last_release() const = 0; virtual int get_base_priority() const = 0; virtual int get_current_priority() const = 0; virtual unsigned int get_total_cpu_time() const = 0;