- 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
This commit is contained in:
tchernobog 2006-08-09 13:37:42 +00:00
parent addad6aa26
commit 72e562e803
8 changed files with 38 additions and 52 deletions

View File

@ -7,7 +7,8 @@ import sgpem
# This class also exposes the method sort(), which can be # This class also exposes the method sort(), which can be
# used to easily sort the queue of ready process with a # used to easily sort the queue of ready process with a
# user-defined given compare function. # 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. ## @var Avoid instantiation of an abstract class.
# @see Abstract.Metaclass # @see Abstract.Metaclass
__metaclass__ = Metaclass __metaclass__ = Metaclass
@ -92,26 +93,6 @@ class CPUPolicy:
# @return 0+ To specify a time slice duration for this policy # @return 0+ To specify a time slice duration for this policy
get_time_slice = AbstractMethod('get_time_slice') 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 ## @brief This function implements an in-place stable sort
# using directly ReadyQueue methods # using directly ReadyQueue methods
# #

View File

@ -34,7 +34,6 @@ class ScriptAdapter :
self._policy = policy() self._policy = policy()
print 'ScriptAdapter for policy ', policy, ' loaded' print 'ScriptAdapter for policy ', policy, ' loaded'
## @brief Asynchronously call Policy.configure() ## @brief Asynchronously call Policy.configure()
# #
# @param self The caller object # @param self The caller object

View File

@ -36,11 +36,6 @@ class fcfs(CPUPolicy) :
def get_time_slice(self): def get_time_slice(self):
return -2 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): def sort_queue(self, queue):
cmpf = lambda a, b: \ cmpf = lambda a, b: \
a.get_arrival_time() < \ a.get_arrival_time() < \

View File

@ -27,27 +27,28 @@ class rr_priority(CPUPolicy) :
pass; pass;
def configure(self): 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): 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 # FIXME pass to a configurable amount
def get_time_slice(self): def get_time_slice(self):
return 2 return self.get_parameters().get_int("Time slice")
# FIXME incorrect, but must be implemented to allow
# loading from the policy manager
def wants(self):
return 0
def sort_queue(self, queue): def sort_queue(self, queue):
by_prio = lambda a, b: \ by_prio = lambda a, b: \
a.get_current_priority() < \ a.get_current_priority() < \
b.get_current_priority() b.get_current_priority()
by_ltime = lambda a, b: \ by_ltime = lambda a, b: \
a.get_last_acquisition() > \ a.get_last_acquisition() > \
b.get_last_acquisition() b.get_last_acquisition()
self.sort(queue,by_ltime) self.sort(queue,by_ltime)
self.sort(queue,by_prio) self.sort(queue,by_prio)

View File

@ -36,11 +36,6 @@ class sjf(CPUPolicy) :
def get_time_slice(self): def get_time_slice(self):
return -1 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): def sort_queue(self, queue):
cmpf = lambda a, b: \ cmpf = lambda a, b: \
a.get_total_cpu_time() - a.get_elapsed_time() < \ a.get_total_cpu_time() - a.get_elapsed_time() < \

View File

@ -86,6 +86,25 @@ PythonCPUPolicy::~PythonCPUPolicy()
if(_upolicy_dict) Py_DECREF(_upolicy_dict); 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 void
PythonCPUPolicy::configure() throw(UserInterruptException) PythonCPUPolicy::configure() throw(UserInterruptException)

View File

@ -76,15 +76,9 @@ namespace sgpem
*/ */
int get_time_slice() const throw(UserInterruptException); int get_time_slice() const throw(UserInterruptException);
void activate() void activate();
{
//FIXME write code for me
}
void deactivate() void deactivate();
{
//FIXME write code for me
}
private: private:
PythonCPUPolicy(const PythonCPUPolicy&); PythonCPUPolicy(const PythonCPUPolicy&);

View File

@ -165,6 +165,8 @@ namespace sgpem {
virtual unsigned int get_arrival_time() const = 0; virtual unsigned int get_arrival_time() const = 0;
virtual unsigned int get_elapsed_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_base_priority() const = 0;
virtual int get_current_priority() const = 0; virtual int get_current_priority() const = 0;
virtual unsigned int get_total_cpu_time() const = 0; virtual unsigned int get_total_cpu_time() const = 0;