- 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:
parent
addad6aa26
commit
72e562e803
|
@ -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
|
||||
|
@ -92,26 +93,6 @@ class CPUPolicy:
|
|||
# @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
|
||||
#
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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() < \
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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() < \
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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&);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue