Esempio n. 1
0
def test():
    #    priorities = [2, 1, 6]

    failed = False
    for priorities in itertools.permutations([1, 2, 3]):
        if not _run_test(schedulers.SPPScheduler(), priorities):
            failed = True

    assert not failed
Esempio n. 2
0
def profiling_test():

    options.init_pycpa()

    # generate an new system
    s = model.System()

    # add two resources (CPUs) to the system
    # and register the static priority preemptive scheduler
    r1 = s.bind_resource(model.Resource("R1", schedulers.SPPScheduler()))
    r2 = s.bind_resource(model.Resource("R2", schedulers.SPPScheduler()))

    # create and bind tasks to r1
    t11 = r1.bind_task(
        model.Task("T11", wcet=10, bcet=5, scheduling_parameter=1))
    t12 = r1.bind_task(
        model.Task("T12", wcet=3, bcet=1, scheduling_parameter=2))

    # create and bind tasks to r2
    t21 = r2.bind_task(
        model.Task("T21", wcet=2, bcet=2, scheduling_parameter=1))
    t22 = r2.bind_task(
        model.Task("T22", wcet=9, bcet=4, scheduling_parameter=2))

    # specify precedence constraints: T11 -> T21; T12-> T22
    t11.link_dependent_task(t21)
    t12.link_dependent_task(t22)

    # register a periodic with jitter event model for T11 and T12
    t11.in_event_model = model.PJdEventModel(P=30, J=5)
    t12.in_event_model = model.PJdEventModel(P=15, J=6)

    filename = "profiling_example.prof"
    prof = hotshot.Profile(filename)
    prof.runcall(analysis.analyze_system, s)
    prof.close()

    stats = hotshot.stats.load(filename)
    stats.strip_dirs()
    stats.sort_stats('time', 'calls')
    stats.print_stats(20)
Esempio n. 3
0
def gantt_test():
    # initialyze pycpa. (e.g. read command line switches and set up default options)
    options.init_pycpa()

    # generate an new system
    s = model.System()

    # instantiate a resource
    r1 = s.bind_resource(model.Resource("R1", schedulers.SPPScheduler()))

    # create and bind tasks to r1
    t11 = r1.bind_task(
        model.Task("T11", wcet=5, bcet=5, scheduling_parameter=1))
    t12 = r1.bind_task(
        model.Task("T12", wcet=9, bcet=1, scheduling_parameter=2))

    # connect communicating tasks: T11 -> T12
    t11.link_dependent_task(t12)

    # register a PJd event model
    t11.in_event_model = model.PJdEventModel(P=30, J=60)

    # perform the analysis
    print("Performing analysis")
    results = analysis.analyze_system(s)

    # print the worst case response times (WCRTs)
    print("Result:")
    for r in sorted(s.resources, key=str):
        for t in sorted(r.tasks, key=str):
            print("%s: wcrt=%d" % (t.name, results[t].wcrt))

    simmodel = simulation.ResourceModel(r1)
    simmodel.runModel(task=t12,
                      scheduler=simulation.SimSPP(name="SPP", sim=simmodel))

    # plot
    hp_tasks = list()
    for t in sorted(r1.tasks, key=str):
        if t.scheduling_parameter <= t12.scheduling_parameter:
            hp_tasks.append(t)

    plot.plot_gantt(hp_tasks,
                    results,
                    height=2. / 3,
                    bar_linewidth=2,
                    min_dist_arrows=1,
                    arrow_head_width=1,
                    task=t12,
                    show=options.get_opt('show'),
                    file_name='gantt.pdf')
Esempio n. 4
0
def simple_test():
    # initialyze pycpa. (e.g. read command line switches and set up default options)
    options.init_pycpa()

    # generate an new system
    s = model.System()

    # instantiate a resource
    r1 = s.bind_resource(model.Resource("R1", schedulers.SPPScheduler()))

    # create and bind tasks to r1
    t11 = r1.bind_task(
        model.Task("T11", wcet=5, bcet=5, scheduling_parameter=1))
    t12 = r1.bind_task(
        model.Task("T12", wcet=9, bcet=1, scheduling_parameter=2))

    # connect communicating tasks: T11 -> T12
    t11.link_dependent_task(t12)

    # register a PJd event model
    t11.in_event_model = model.PJdEventModel(P=30, J=60)

    # create a path
    p1 = model.Path("P1", [t11, t12])

    # add constraints to task t11
    s.constraints.add_backlog_constraint(t11, 5)

    # add constraints to task t12
    s.constraints.add_wcrt_constraint(t12, 90)

    try:
        # plot the system graph to visualize the architecture
        g = graph.graph_system(s, 'simple_graph.pdf')
    except Exception:
        # gracefully pass for machines without matplotlib
        pass

    # perform the analysis
    print("Performing analysis")
    results = analysis.analyze_system(s)

    # print the worst case response times (WCRTs)
    print("Result:")
    for r in sorted(s.resources, key=str):
        for t in sorted(r.tasks, key=str):
            print("%s: wcrt=%d" % (t.name, results[t].wcrt))

    bcl, wcl = path_analysis.end_to_end_latency(p1, results, 2)
    print "bcl: %d, wcl: %d" % (bcl, wcl)
Esempio n. 5
0
def sampling_test(wclat_results):

    options.init_pycpa()

    # generate an new system
    s = model.System()

    # add two resources to the system
    # register two schedulers
    r1 = s.bind_resource(model.Resource("R1", schedulers.SPPScheduler()))

    # add a task
    t11 = r1.bind_task(model.Task(name="T11", wcet=3, bcet=1, scheduling_parameter=1))
    # register input event model
    t11.in_event_model = model.PJdEventModel(P=30, J=15)

    # add three more tasks, these will be triggered by other tasks
    t12 = r1.bind_task(model.Task(name="T12", wcet=3, bcet=2, scheduling_parameter=2))

    # add a sampling junction
    j1 = s.bind_junction(model.Junction(name="J1", strategy=junctions.SampledInput()))
    j1.strategy.set_trigger_event_model(model.PJdEventModel(P=50, J=0))

    # register a task chain as a stream: t11->j1->t12
    s1 = s.bind_path(model.Path("S1", [t11, j1, t12]))

    # graph the system
    graph.graph_system(s, "sampling_example.pdf")

    # analyze the system
    print("Performing analysis")
    results = analysis.analyze_system(s)

    # print the results
    print("Result:")
    for r in sorted(s.resources, key=str):
        print "load on resource %s: %0.2f" % (r.name, r.load())
        for t in sorted(r.tasks, key=str):
            print "  task %s - wcrt: %d" % (t.name, results[t].wcrt)

    # calculate the latency for the first 10 events
    for n in range(1, 11):
        best_case_latency, worst_case_latency = path_analysis.end_to_end_latency(s1, results, n)
        print("stream S1 e2e latency. best case: %d, worst case: %d" % (best_case_latency, worst_case_latency))
        assert(worst_case_latency == wclat_results[n-1])
Esempio n. 6
0
def time_bases_test(auto=True):
    # print the welcome message
    options.init_pycpa()
    # generate an new system
    s = model.System()

    # add two resources (CPUs) to the system
    # and register the static priority preemptive scheduler
    r1 = s.bind_resource(
        model.Resource("R1", schedulers.SPPScheduler(), frequency=333333333))
    r2 = s.bind_resource(
        model.Resource("R2", schedulers.SPPScheduler(), frequency=100000000))

    # get a common time-base
    common_time_base = util.ns

    if auto == True:
        common_time_base = util.calculate_base_time(
            [r.frequency for r in s.resources])

    print "Basetime is %d Hz" % common_time_base

    # create and bind tasks to r1. Here the timing is specified in absolute time (i.e. 10 ms)
    t11 = r1.bind_task(
        model.Task("T11",
                   wcet=util.time_to_time(10, util.ms, common_time_base,
                                          'ceil'),
                   bcet=util.time_to_time(5, util.ms, common_time_base,
                                          'floor'),
                   scheduling_parameter=1))
    t12 = r1.bind_task(
        model.Task("T12",
                   wcet=util.time_to_time(3, util.ms, common_time_base,
                                          'ceil'),
                   bcet=util.time_to_time(1, util.ms, common_time_base,
                                          'floor'),
                   scheduling_parameter=2))

    # create and bind tasks to r2. Here the timing is specified in cycle time (i.e. 10000 cycles)
    t21 = r2.bind_task(
        model.Task("T21",
                   wcet=util.cycles_to_time(200000, r2.frequency,
                                            common_time_base, 'ceil'),
                   bcet=util.cycles_to_time(200000, r2.frequency,
                                            common_time_base, 'floor'),
                   scheduling_parameter=1))
    t22 = r2.bind_task(
        model.Task("T22",
                   wcet=util.cycles_to_time(900000, r2.frequency,
                                            common_time_base, 'ceil'),
                   bcet=util.cycles_to_time(400000, r2.frequency,
                                            common_time_base, 'floor'),
                   scheduling_parameter=2))

    # specify precedence constraints: T11 -> T21; T12-> T22
    t11.link_dependent_task(t21)
    t12.link_dependent_task(t22)

    # register a periodic with jitter event model for T11 and T12
    t11.in_event_model = model.PJdEventModel(
        P=util.time_to_time(30, util.ms, common_time_base, 'floor'),
        J=util.time_to_time(5, util.ms, common_time_base, 'ceil'))
    t12.in_event_model = model.PJdEventModel(
        P=util.time_to_time(15, util.ms, common_time_base, 'floor'),
        J=util.time_to_time(6, util.ms, common_time_base, 'ceil'))

    # perform the analysis
    print("Performing analysis")
    task_results = analysis.analyze_system(s)

    # print the worst case response times (WCRTs)
    print("Result:")
    for r in sorted(s.resources, key=str):
        for t in sorted(r.tasks, key=str):
            wcrt_ms = util.time_to_time(task_results[t].wcrt, common_time_base,
                                        util.ms, 'ceil')
            print("%s: wcrt=%d ms" % (t.name, wcrt_ms))