Main modules

simso.core module

The core module include all the classes needed for the simulation.

Scheduler

class Scheduler(sim, scheduler_info, **kwargs)

The implementation of a scheduler is done by subclassing this abstract class.

The scheduling events are modeled by method calls which take as arguments the jobs and the processors.

The following methods should be redefined in order to interact with the simulation:

  • init() Called when the simulation is ready. The scheduler logic should be initialized here.
  • on_activate() Called upon a job activation.
  • on_terminated() Called when a job is terminated.
  • schedule() Take the scheduling decision. This method should not be called directly. A call to the resched method is required.

By default, the scheduler can only run on a single processor at the same simulation time. It is also possible to override this behavior by overriding the get_lock() and release_lock() methods.

Args:

Attributes:

  • sim: Model instance. Useful to get current time with sim.now_ms() (in ms) or sim.now() (in cycles).
  • processors: List of processors handled by this scheduler.
  • task_list: List of tasks handled by this scheduler.

Methods:

add_processor(cpu)

Add a processor to the list of processors handled by this scheduler.

Args:
add_task(task)

Add a task to the list of tasks handled by this scheduler.

Args:
  • task: The task to add.
get_lock()

Implement a lock mechanism. Override it to remove the lock or change its behavior.

init()

This method is called when the system is ready to run. This method should be used in lieu of the __init__ method. This method is guaranteed to be called when the simulation starts, after the tasks are instantiated

on_activate(job)

This method is called upon a job activation.

Args:
  • job: The activated job.
on_terminated(job)

This method is called when a job finish (termination or abortion).

Args:
  • job: The job that terminates .
release_lock()

Release the lock. Goes in pair with get_lock().

schedule(cpu)

The schedule method must be redefined by the simulated scheduler. It takes as argument the cpu on which the scheduler runs.

Args:
  • cpu: The processor on which the scheduler runs.

Returns a decision or a list of decisions. A decision is a couple (job, cpu).

class SchedulerInfo(clas='', overhead=0, overhead_activate=0, overhead_terminate=0, fields=None)

SchedulerInfo groups the data that characterize a Scheduler (such as the scheduling overhead) and do the dynamic loading of the scheduler.

Args:
  • name: Name of the scheduler.
  • cls: Class associated to this scheduler.
  • overhead: Overhead associated to a scheduling decision.

Methods:

get_cls()

Get the class of this scheduler.

instantiate(model)

Instantiate the Scheduler class.

Args:
  • model: The Model object that is passed to the constructor.

Task

class ATask(sim, task_info)

Non-periodic Task process. Inherits from GenericTask. The job is created by another task.

Args:

  • sim: Model instance.
  • task_info: A TaskInfo representing the Task.
class GenericTask(sim, task_info)

Abstract class for Tasks. ATask and PTask inherits from this class.

These classes simulate the behavior of the simulated task. It controls the release of the jobs and is able to abort the jobs that exceed their deadline.

The majority of the task_info attributes are available through this class too. A set of metrics such as the number of preemptions and migrations are available for analysis.

Args:

  • sim: Model instance.
  • task_info: A TaskInfo representing the Task.
create_job(pred=None)

Create a new job from this task. This should probably not be used directly by a scheduler.

data

Extra data to characterize the task. Only used by the scheduler.

deadline

Deadline in milliseconds.

followed_by

Task that is activated by the end of a job from this task.

identifier

Identifier of the task.

jobs

List of the jobs.

monitor

The monitor for this Task. Similar to a log mechanism (see Monitor in SimPy doc).

period

Period of the task.

wcet

Worst-Case Execution Time in milliseconds.

class PTask(sim, task_info)

Periodic Task process. Inherits from GenericTask. The jobs are created periodically.

Args:

  • sim: Model instance.
  • task_info: A TaskInfo representing the Task.
class SporadicTask(sim, task_info)

Sporadic Task process. Inherits from GenericTask. The jobs are created using a list of activation dates.

Args:

  • sim: Model instance.
  • task_info: A TaskInfo representing the Task.
Task(sim, task_info)

Task factory. Return and instantiate the correct class according to the task_info.

class TaskInfo(name, identifier, task_type, abort_on_miss, period, activation_date, n_instr, mix, stack_file, wcet, acet, et_stddev, deadline, base_cpi, followed_by, list_activation_dates, preemption_cost, data)

TaskInfo is mainly a container class grouping the data that characterize a Task. A list of TaskInfo objects are passed to the Model so that Task instances can be created.

csdp

Accumulated Stack Distance Profile. Used by the cache models instead of the Stack Distance Profile for optimization matters.

set_stack_file(stack_file, cur_dir)

Set the stack distance profile.

stack_file

Stack distance profile input file.

Job

class Job(task, name, pred, monitor, etm, sim)

The Job class simulate the behavior of a real Job. This should only be instantiated by a Task.

Args:
  • task: The parent task.
  • name: The name for this job.
  • pred: If the task is not periodic, pred is the job that released this one.
  • monitor: A monitor is an object that log in time.
  • etm: The execution time model.
  • sim: Model instance.
abort()

Abort this job. Warning, this is currently only used by the Task when the job exceeds its deadline. It has not be tested from outside, such as from the scheduler.

aborted

True if the job has been aborted.

Return type:bool
absolute_deadline

Absolute deadline in milliseconds for this job. This is the activation date + the relative deadline.

activation_date

Activation date in milliseconds for this job.

actual_computation_time

Computation time in ms as if the processor speed was 1.0 during the whole execution.

actual_computation_time_cycles

Computation time as if the processor speed was 1.0 during the whole execution.

computation_time

Time spent executing the job in ms.

computation_time_cycles

Time spent executing the job.

cpu

The processor on which the job is attached. Equivalent to self.task.cpu.

data

The extra data specified for the task. Equivalent to self.task.data.

deadline

Relative deadline in milliseconds. Equivalent to self.task.deadline.

end_date

Date (in ms) when this job finished its execution.

exceeded_deadline

True if the end_date is greater than the deadline or if the job was aborted.

is_active()

Return True if the job is still active.

is_running()

Return True if the job is currently running on a processor. Equivalent to self.cpu.running == self.

Return type:bool
laxity

Dynamic laxity of the job in ms.

period

Period in milliseconds. Equivalent to self.task.period.

ret

Remaining execution time in ms.

start_date

Date (in ms) when this job started executing (different than the activation).

task

The task for this job.

wcet

Worst-Case Execution Time in milliseconds. Equivalent to self.task.wcet.

Model

class Model(configuration, callback=None)

Main class for the simulation. It instantiate the various components required by the simulation and run it.

Args:
  • callback: A callback can be specified. This function will be called to report the advance of the simulation (useful for a progression bar).
  • configuration: The configuration of the simulation.

Methods:

cycles_per_ms

Number of cycles per milliseconds. A cycle is the internal unit used by SimSo. However, the tasks are defined using milliseconds.

duration

Duration of the simulation.

etm

Execution Time Model

logs

All the logs from the Logger.

processors

List of all the processors.

run_model()

Execute the simulation.

task_list

List of all the tasks.

Processor

class Processor(model, proc_info)

A processor is responsible of deciding whether the simulated processor should execute a job or execute the scheduler. There is one instance of Processor per simulated processor. Those are responsible to call the scheduler methods.

When a scheduler needs to take a scheduling decision, it must invoke the resched() method. This is typically done in the on_activate, on_terminated or in a timer handler.

internal_id

A unique, internal, id.

is_running()

Return True if a job is currently running on that processor.

resched()

Add a resched event to the list of events to handle.

running

The job currently running on that processor. None if no job is currently running on the processor.

Timer

class Timer(sim, function, args, delay, one_shot=True, prior=False, cpu=None, in_ms=True, overhead=0)

Allow to declare a timer. A timer is a mechanism that allows to call a function after a certain amount of time, periodically or single shot.

A Timer can be used with or without specifying a processor. If a processor is specified, when the timer fire, if a job was running on the processor, it is temporarly interrupted. This is more realistic, even if for the moment there is no overhead associated to this action. A scheduler using a timer should define on which processor the callback will execute.

The delay is expressed in milliseconds by default but it can also be given in cycles.

Args:
  • sim: The model object.
  • function: Callback function, called when the delay expires.
  • args: Arguments passed to the callback function.
  • delay: Time to wait before calling the function.
  • one_shot: True if the timer should execute only once.
  • prior: If true, for the same date, the simulation should start by handling the timer (should probably not be True).
  • cpu: On which processor the function is virtually executing.
  • in_ms: True if the delay is expressed in millisecond. In cycles otherwise.

Methods:

start()

Start the timer.

stop()

Stop the timer.

Logger

class Logger(sim)

Simple logger. Every message is logged with its date.

Args:
log(msg, kernel=False)

Log the message msg.

Args:
  • msg: The message to log.
  • kernel: Allows to make a distinction between a message from the core of the simulation or from the scheduler.
logs

The logs, a SimPy Monitor object.

results

class JobR(date, job)

Add a set of metrics to a job. Such metrics include: preemption count, migration count, response time, etc.

class ProcessorR

Add information about a processor such as the number of CxtSave and CxtLoad and their total overhead.

class Results(model)

This class embeds and analyzes all the results from the simulation. This allows to retrieve the usual metrics.

The Results instance object contains the following attributes:
  • tasks: a dictionary of TaskR where the key is the original Task.
  • scheduler: a SchedulerR instance.
  • processors: a dictionary of ProcessorR where the key is the original Processor.

.

calc_load()

Yield a tuple (proc, load, overhead) for each processor.

get_observation_window()

Get the observation window.

observation_window

Get the observation window.

set_observation_window(window)

Set the observation window. The events that occurs outside of the observation window are discarded.

tasks_event()

Generator of the tasks events sorted by their date.

class SchedulerR

Add information about the scheduler such as the number of scheduling events and their total overhead.

class TaskR(task, delta_preemption=100)

Add a set of metrics to a task. These metrics include: task_migrations, abortion count, etc.

The attribute jobs contains a list of JobR, sorted by activation date.

simso.configuration module

Configuration

class Configuration(filename=None)

The configuration class store all the details about a system. An instance of this class will be passed to the constructor of the Model class.

Args:
  • filename A file can be used to initialize the configuration.
add_processor(name, identifier, cs_overhead=0, cl_overhead=0, migration_overhead=0, speed=1.0)

Helper method to create a ProcInfo and add it to the list of processors.

add_task(name, identifier, task_type='Periodic', abort_on_miss=True, period=10, activation_date=0, n_instr=0, mix=0.5, stack_file='', wcet=0, acet=0, et_stddev=0, deadline=10, base_cpi=1.0, followed_by=None, list_activation_dates=[], preemption_cost=0, data=None)

Helper method to create a TaskInfo and add it to the list of tasks.

check_all()

Check the correctness of the configuration (without simulating it).

get_hyperperiod()

Compute and return the hyperperiod of the tasks.

proc_info_list

List of processors (ProcInfo objects).

save(simulation_file=None)

Save the current configuration in a file. If no file is given as argument, the previous file used to write or read the configuration is used again.

scheduler_info

SchedulerInfo object.

task_info_list

List of tasks (TaskInfo objects).

simso.generator module

Tools for generating task sets.

StaffordRandFixedSum(n, u, nsets)

Copyright 2010 Paul Emberson, Roger Stafford, Robert Davis. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice,

    this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice,

    this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS’’ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of Paul Emberson, Roger Stafford or Robert Davis.

Includes Python implementation of Roger Stafford’s randfixedsum implementation http://www.mathworks.com/matlabcentral/fileexchange/9700 Adapted specifically for the purpose of taskset generation with fixed total utilisation value

Please contact paule@rapitasystems.com or robdavis@cs.york.ac.uk if you have any questions regarding this software.

gen_kato_utilizations(nsets, umin, umax, target_util)

Kato et al. tasksets generator.

Args:
  • nsets: Number of tasksets to generate.
  • umin: Minimum task utilization.
  • umax: Maximum task utilization.
  • target_util:
gen_periods_discrete(n, nsets, periods)

Generate a matrix of (nsets x n) random periods chosen randomly in the list of periods.

Args:
  • n: The number of tasks in a task set.
  • nsets: Number of sets to generate.
  • periods: A list of available periods.
gen_periods_loguniform(n, nsets, min_, max_, round_to_int=False)

Generate a list of nsets sets containing each n random periods using a loguniform distribution.

Args:
  • n: The number of tasks in a task set.
  • nsets: Number of sets to generate.
  • min_: Period min.
  • max_: Period max.
gen_periods_uniform(n, nsets, min_, max_, round_to_int=False)

Generate a list of nsets sets containing each n random periods using a uniform distribution.

Args:
  • n: The number of tasks in a task set.
  • nsets: Number of sets to generate.
  • min_: Period min.
  • max_: Period max.
gen_randfixedsum(nsets, u, n)

Stafford’s RandFixedSum algorithm implementated in Python.

Based on the Python implementation given by Paul Emberson, Roger Stafford, and Robert Davis. Available under the Simplified BSD License.

Args:
  • n: The number of tasks in a task set.
  • u: Total utilization of the task set.
  • nsets: Number of sets to generate.
gen_ripoll(nsets, compute, deadline, period, target_util)

Ripoll et al. tasksets generator.

Args:
  • nsets: Number of tasksets to generate.
  • compute: Maximum computation time of a task.
  • deadline: Maximum slack time.
  • period: Maximum delay after the deadline.
  • target_util: Total utilization to reach.
gen_tasksets(utilizations, periods)

Take a list of task utilization sets and a list of task period sets and return a list of couples (c, p) sets. The computation times are truncated at a precision of 10^-10 to avoid floating point precision errors.

Args:
  • utilization: The list of task utilization sets. For example:

    [[0.3, 0.4, 0.8], [0.1, 0.9, 0.5]]
    
  • periods: The list of task period sets. For examples:

    [[100, 50, 1000], [200, 500, 10]]
    
Returns:

For the above example, it returns:

[[(30.0, 100), (20.0, 50), (800.0, 1000)],
 [(20.0, 200), (450.0, 500), (5.0, 10)]]
gen_uunifastdiscard(nsets, u, n)

The UUniFast algorithm was proposed by Bini for generating task utilizations on uniprocessor architectures.

The UUniFast-Discard algorithm extends it to multiprocessor by discarding task sets containing any utilization that exceeds 1.

This algorithm is easy and widely used. However, it suffers from very long computation times when n is close to u. Stafford’s algorithm is faster.

Args:
  • n: The number of tasks in a task set.
  • u: Total utilization of the task set.
  • nsets: Number of sets to generate.

Returns nsets of n task utilizations.

simso.utils module

PartitionedScheduler

class PartitionedScheduler(sim, scheduler_info, **kwargs)

The PartitionedScheduler class provide facilities to create a new Partitioned Scheduler. Only the packing phase is not done and should be overriden.

Args:

  • sim: Model instance.
  • scheduler_info: A SchedulerInfo representing the scheduler.

Attributes:

  • sim: Model instance. Useful to get current time with sim.now_ms() (in ms) or sim.now() (in cycles).
  • processors: List of processors handled by this scheduler.
  • task_list: List of tasks handled by this scheduler.

Methods:

init(scheduler_info, packer=None)
Args:
  • scheduler_info: A SchedulerInfo object. One scheduler from this SchedulerInfo will be instantiated for each processor.
best_fit(scheduler, task_list=None)

Best-Fit heuristic. Put the tasks somewhere it fits but with the least spare place.

decreasing_best_fit(scheduler)

Best-Fit with tasks inversely sorted by their u_i.

decreasing_first_fit(scheduler)

First-Fit with tasks inversely sorted by their u_i.

decreasing_next_fit(scheduler)

Next-Fit with tasks inversely sorted by their u_i.

decreasing_worst_fit(scheduler)

Worst-Fit with tasks inversely sorted by their u_i.

first_fit(scheduler, task_list=None)

First-Fit heuristic. Put each task on the first processor with enough space.

next_fit(scheduler, task_list=None)

Next-Fit heuristic. Put each task on the next processor with enough space.

worst_fit(scheduler, task_list=None)

Worst-Fit heuristic. Put the tasks somewhere it fits with the largest spare place.