SchedDeadline


Setup


In [3]:
from trappy.stats.Topology import Topology
from bart.sched.SchedMultiAssert import SchedMultiAssert
from bart.sched.SchedAssert import SchedAssert
import trappy
import os
import operator
import json

#Define a CPU Topology (for multi-cluster systems)
BIG = [1, 2]
LITTLE = [0, 3, 4, 5]
CLUSTERS = [BIG, LITTLE]
topology = Topology(clusters=CLUSTERS)

BASE_PATH = "/Users/kapileshwarsingh/AnalysisRawData/LPC/sched_deadline/"

THRESHOLD = 10.0
def between_threshold(a, b):
    return abs(((a - b) * 100.0) / b) < THRESHOLD

Periodic Yield

The thread periodic_yeild is woken up at 30ms intervals where it calls sched_yield and relinquishes its time-slice. The expectation is that the task will have a duty cycle < 1% and a period of 30ms.

There are two threads, and the rank=1 conveys that the condition is true for one of the threads with the name "periodic_yeild"


In [10]:
TRACE_FILE = os.path.join(BASE_PATH, "yield")
ftrace = trappy.FTrace(TRACE_FILE, "cpuhog")

# Assert Period
s = SchedMultiAssert(ftrace, topology, execnames="periodic_yield")
if s.assertPeriod(30, between_threshold, rank=1):
    print "PASS: Period"
    print json.dumps(s.getPeriod(), indent=3)

print ""
    
# Assert DutyCycle    
if s.assertDutyCycle(1, operator.lt, window=(0,4), rank=2):
    print "PASS: DutyCycle"
    print json.dumps(s.getDutyCycle(window=(0,4)), indent=3)


PASS: Period
{
   "1844": {
      "period": 1.0085000000401578, 
      "task_name": "periodic_yield"
   }, 
   "1845": {
      "period": 29.822017857142669, 
      "task_name": "periodic_yield"
   }
}

PASS: DutyCycle
{
   "1844": {
      "task_name": "periodic_yield", 
      "dutycycle": 0.074749999998857675
   }, 
   "1845": {
      "task_name": "periodic_yield", 
      "dutycycle": 0.03862499999343072
   }
}

CPU Hog

The reservation of a CPU hogging task is set to 10ms for every 100ms. The assertion ensures a duty cycle of 10%


In [11]:
TRACE_FILE = os.path.join(BASE_PATH, "cpuhog")
ftrace = trappy.FTrace(TRACE_FILE, "cpuhog")
s = SchedMultiAssert(ftrace, topology, execnames="cpuhog")
s.plot().view()

# Assert DutyCycle
if s.assertDutyCycle(10, between_threshold, window=(0, 5), rank=1):
    print "PASS: DutyCycle"
    print json.dumps(s.getDutyCycle(window=(0, 5)), indent=3)


PASS: DutyCycle
{
   "1852": {
      "task_name": "cpuhog", 
      "dutycycle": 10.050119999991693
   }
}

Changing Reservations

A CPU hogging task has reservations set in the increasing order starting from 10% followed by a 2s period of normal execution


In [4]:
TRACE_FILE = os.path.join(BASE_PATH, "cancel_dl_timer")
ftrace = trappy.FTrace(TRACE_FILE, "cpuhog")
s = SchedAssert(ftrace, topology, execname="cpuhog")
s.plot().view()

NUM_PHASES = 10
PHASE_DURATION = 2
start = s.getStartTime()
DUTY_CYCLE_FACTOR = 10


for phase in range(NUM_PHASES + 1):
    window = (start + (phase * PHASE_DURATION),
              start + ((phase + 1) * PHASE_DURATION))
    
    if phase % 2 == 0:
        DUTY_CYCLE = (phase + 2) * DUTY_CYCLE_FACTOR / 2
    else:
        DUTY_CYCLE = 100


    print "WINDOW -> [{:.2f}, {:.2f}]".format(window[0],
                                            window[1])
    
    
    
    if s.assertDutyCycle(DUTY_CYCLE, between_threshold, window=window):
        print "PASS: Expected={} Actual={:.2f} THRESHOLD={}".format(DUTY_CYCLE,
                                                                s.getDutyCycle(window=window),
                                                                THRESHOLD)
    else:
        print "FAIL: Expected={} Actual={:.2f} THRESHOLD={}".format(DUTY_CYCLE,
                                                                s.getDutyCycle(window=window),
                                                                THRESHOLD)
    
    print ""


WINDOW -> [0.00, 2.00]
PASS: Expected=10 Actual=10.38 THRESHOLD=10.0

WINDOW -> [2.00, 4.00]
PASS: Expected=100 Actual=99.60 THRESHOLD=10.0

WINDOW -> [4.00, 6.00]
PASS: Expected=20 Actual=21.06 THRESHOLD=10.0

WINDOW -> [6.00, 8.00]
PASS: Expected=100 Actual=95.69 THRESHOLD=10.0

WINDOW -> [8.00, 10.00]
PASS: Expected=30 Actual=31.78 THRESHOLD=10.0

WINDOW -> [10.00, 12.00]
PASS: Expected=100 Actual=98.23 THRESHOLD=10.0

WINDOW -> [12.00, 14.00]
PASS: Expected=40 Actual=40.74 THRESHOLD=10.0

WINDOW -> [14.00, 16.00]
PASS: Expected=100 Actual=97.58 THRESHOLD=10.0

WINDOW -> [16.00, 18.00]
PASS: Expected=50 Actual=52.51 THRESHOLD=10.0

WINDOW -> [18.00, 20.00]
PASS: Expected=100 Actual=96.38 THRESHOLD=10.0

WINDOW -> [20.00, 22.00]
PASS: Expected=60 Actual=60.71 THRESHOLD=10.0