Assignment P3 - Testing Schedulability

Due: Friday, February 14, 2020, at the start of class

You may work alone or with a partner, but you must type up the code yourself. You may also discuss the assignment at a high level with other students. You should list any student with whom you discussed the assignment, and the manner of discussion (high-level, partner, etc.) in a readme.txt file that you include with your submission.

You should submit your assignment as a .zip file on Moodle.

Parts of this assignment:

Starter Code: .zip (most of the changes from previous assignments are cosmetic, although they include the solutions to the previous programming assignments)

Schedulability Tests

In order to perform large-scale schedulability tests, you need to be able to generate random task systems. Then, for hundreds or thousands (or more!) of these random task systems, typically for a given total system utilization value, you can test schedulability using some test (or set of tests). The fraction of schedulable task systems is reported as a data point. The final plot looks like the following. The different curves correspond to different distributions of per-task utilizations.

<image: schedulability results>

You can read this plot as follows. For a given data point, the x-value represents the total system utilization, and the y-value represents the fraction of task systems generated with that total utilization that were schedulable given some schedulability test. In this assignment, that test is the utilization-based test for RM. We want higher schedulability overall, so higher (or further right) is “better”.

Getting started

To generate the plots needed for this assignment, you will need Matplotlib. If you cannot run schedulability.py, you can use a terminal command like the following to get Matplotlib, the library needed for plotting:

pip3 install matplotlib

Note that on Windows this might require opening the terminal by right-clicking and selecting “Run as administrator”.

Problem 1: Generating a random task set

Take a look through the code in schedulability.py. **Note that the code will not run until you have completed Problem 1.

You’ll implement two functions in this assignment. The first is generateRandomTaskSet. It takes a few parameters, so first we’ll walk through them:

  • targetUtil is the utilization sum you want to have for the generated task set. As the comments state, if a task would have utilization that causes that sum to exceed targetUtil, you should cap that task’s utilization to avoid going over.
  • utilFunc is the function you should use to select the utilization for a given task. The choices are defined a little higher in the file: lightUtilFunc, mediumLightUtilFunc, mediumUtilFunc. If you aren’t too familiar with lambda functions or passing functions as parameters, just ask!
  • periodFunc is the function you should use to select the period for a given task. This is very similar to utilFunc.

    def generateRandomTaskSet(targetUtil, utilFunc, periodFunc):
    """
    Generates a random task set with total utilization targetUtil.
    
    Just returns the task set as a list of Task objects, rather than
    the proper TaskSet type.
    """
    utilSum = 0
    
    # Generate tasks until the utilization target is met
    taskSet = []
    i = 0
    while utilSum < targetUtil:
        taskId = i+1
    
        # TODO:
        # Choose the utilization for the task based on the utilization function
        # (you just need to call it - it already has its parameters figured out).
        # If the task's utilization would push it over the target, instead choose
        # its utilization to be the remaining utilization to reach the target sum.
    
        # Choose task parameters:
        # * offset
        # * period
        # * relative deadline
        # * WCET <-- choose based on utilization and period
    
        # Build the dictionary for the task parameters
        taskDict = {}
        taskDict[TaskSetJsonKeys.KEY_TASK_ID] = taskId
        taskDict[TaskSetJsonKeys.KEY_TASK_PERIOD] = period
        taskDict[TaskSetJsonKeys.KEY_TASK_WCET] = wcet
        taskDict[TaskSetJsonKeys.KEY_TASK_DEADLINE] = relativeDeadline
        taskDict[TaskSetJsonKeys.KEY_TASK_OFFSET] = offset
    
        task = Task(taskDict)
        taskSet.append(task)
    
    return taskSet

As long as the target utilization is not reached, you should generate a new task and fill in the not-yet-specified task parameters period, wcet, relativeDeadline, and offset. For this assignment, you should assume implicit-deadline tasks only. Also, the code you’re given just returns a list of Tasks as a “task set”, and you can leave it that way.

Problem 2: Testing schedulability under RM

In order to have a meaningful schedulability study, we need a schedulability test. For this assignment, you will implement the simple utilization-based RM schedulability test.

def rmSchedulabilityTest(taskSet):
    """
    Performs the simple utilization-based schedulability test for RM.

    Only checks the total utilization sum against the U_lub bound.
    Does not check per-task.
    """
    # TODO
    return False # replace with your code

This function should take in a taskSet (as a list of Task objects), and return True if and only if the total utilization does not exceed U_lub based on the number of tasks. Recall that the value of U_lub is given by for a system of tasks.

Problem 3: Interpreting the results

Once you can generate random task sets and check their schedulability, you should be able to generate plots. The default number of task sets for which to check schedulability for a given total utilization is 10 in the starter code. This doesn’t give very robust results. Once you have a graph in the general style of the one above, you should increase this number to at least 1000. (Note that any higher may get prohibitively long for your patience.)

def testSchedulability():
    random.seed(None) # seed the random library

    # Perform the schedulability tests
    utilVals, results = performTests(10) # TODO: change to a bigger number, like 1000

    # Plot the results
    plotResults(utilVals, results)

You should generate a plot similar to the one above. Then, in your readme.txt, include a description of what is going on in the plot. You should answer the following questions:

  • What do the three lines represent?
  • Why does medium drop off at such a higher utilization than the others?
  • Why does light drop off where it does?
  • Which of these lines represents the “best” schedulability, and why?

What you should submit

You should submit a single .zip file on Moodle. It should contain the following files:

  • readme.txt (collaboration statement listing collaborators and form of collaboration, as well as answers for problem 3)
  • schedulability.py (code for problems 1 and 2)
  • plot.png (the schedulablity graph you generate)

An example readme.txt file might be the following (in addition to your answers for problem 3):

For this assignment, I collaborated with:
* Colin - partner
* Therese - discussed the difference between relative and absolute deadlines

If you did not collaborate with anyone, you should say so:

For this assignment, I worked alone.