Ejemplo n.º 1
0
def spp_test():
    # init pycpa and trigger command line parsing
    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)

    # plot the system graph to visualize the architecture
    g = graph.graph_system(s, 'spp_graph.pdf', dotout='spp_graph.dot')

    # 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):
            print("%s: wcrt=%d" % (t.name, task_results[t].wcrt))
            print("    b_wcrt=%s" % (task_results[t].b_wcrt_str()))

    expected_wcrt = dict()
    expected_wcrt[t11] = 10
    expected_wcrt[t12] = 13
    expected_wcrt[t21] = 2
    expected_wcrt[t22] = 19

    for t in expected_wcrt.keys():
        assert (expected_wcrt[t] == task_results[t].wcrt)
Ejemplo n.º 2
0
def constraints_example():

    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)

    p1 = model.Path("myPath", [t11, t21])
    s.bind_path(p1)

    # deliberately overconstrain the system
    s.constraints.add_path_constraint(p1, 5, n=2)
    s.constraints.add_wcrt_constraint(t11, 1)
    s.constraints.add_load_constraint(r1, 0.5)
    s.constraints.add_backlog_constraint(t11, 1)

    # 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):
            print("%s: wcrt=%d" % (t.name, task_results[t].wcrt))
Ejemplo n.º 3
0
    def xmlrpc_assign_pjd_event_model(self, task_id, period, jitter, min_dist):
        """ Create an eventmodel and assign it to task.

        :param task_id: ID of the task
        :type task_id: string
        :param period: Period (in unit time)
        :type period: integer
        :param jitter: Jitter (in unit time)
        :type jitter: integer
        :param min_dist: Minimum distance between events (in unit time)
        :type min_dist: integer
        :returns: 0

        """
        task = self._obj_from_id(task_id, model.Task)
        em = None
        try:
            em = model.PJdEventModel(int(period), int(jitter), int(min_dist))
        except ValueError:
            raise xmlrpc.Fault(INVALID_EVENT_MODEL_DESC,
                               "invalid event model parametrization")
        task.in_event_model = em

        # casting to int in debug output so that it matches what our code
        # actually does to the input
        logger.debug("{}assign_pjd_event_model({}, {}, {}, {})".format(
            self.debug_prefix, task_id, int(period), int(jitter),
            int(min_dist)))
        return 0
Ejemplo n.º 4
0
def e2e_test(expected_wclat):
    options.init_pycpa()

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

    # add a resource to the system
    # register round robin scheduler
    r1 = s.bind_resource(model.Resource("R1",
                                        schedulers.RoundRobinScheduler()))

    # map two tasks to
    t11 = r1.bind_task(model.Task("T11", wcet=1, bcet=1))
    t12 = r1.bind_task(model.Task("T12", wcet=2, bcet=1))

    # register precedence constraint
    t11.link_dependent_task(t12)

    t11.in_event_model = model.PJdEventModel(P=4, J=3)

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

    # perform a system analysis
    print("analyzing")
    task_results = analysis.analyze_system(s)

    # 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, task_results, n)
        print("stream S1 e2e latency. best case: %d, worst case: %d" %
              (best_case_latency, worst_case_latency))
        assert (worst_case_latency == expected_wclat[n - 1])
Ejemplo n.º 5
0
def test_spp():
    # 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)

    # perform the analysis
    task_results = analysis.analyze_system(s)

    # print the worst case response times (WCRTs)
    busy_times_t11 = [0, 10]
    busy_times_t12 = [0, 13, 16]
    busy_times_t21 = [0, 2]
    busy_times_t22 = [0, 11, 20, 31, 40]

    assert task_results[t11].busy_times == busy_times_t11
    assert task_results[t12].busy_times == busy_times_t12
    assert task_results[t21].busy_times == busy_times_t21
    assert task_results[t22].busy_times == busy_times_t22

    assert task_results[t11].wcrt == 10
    assert task_results[t12].wcrt == 13
    assert task_results[t21].wcrt == 2
    assert task_results[t22].wcrt == 19
Ejemplo n.º 6
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])
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
 def test_eta_to_delta_min(self):
     # create some standard event model
     em_a = model.PJdEventModel(P=10, J=99)
     em_b = model.EventModel()
     em_b.deltamin_func = model.EventModel.delta_min_from_eta_plus(
         em_a.eta_plus)
     em_b.deltaplus_func = model.EventModel.delta_plus_from_eta_min(
         em_a.eta_min)
     seq = range(0, 100, 1)
     self.assertEqual([em_b.delta_min(n) for n in seq],
                      [em_a.delta_min(n) for n in seq])
     self.assertEqual([em_b.delta_plus(n) for n in seq],
                      [em_a.delta_plus(n) for n in seq])
Ejemplo n.º 9
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')
Ejemplo n.º 10
0
class TestArrivalCurveSteps(unittest.TestCase):
    models = [
        model.PJdEventModel(P=20, J=5, dmin=1),
        model.PJdEventModel(P=100, J=400, dmin=2),
        model.PJdEventModel(P=20, J=30, dmin=20),
        model.CTEventModel(c=5, T=10),
        model.CTEventModel(c=5, T=5, dmin=3)
    ]

    def bruteforce_model_test(self, m):
        "Check that the bruteforce arrive_curve_steps predicts the first 100 steps of the arrival curve correctly"
        steps = list(
            itertools.islice(ros.arrival_curve_steps(m, optimized=False), 100))
        eta = [m.eta_plus(i) for i in range(steps[-1] + 1)]

        self.assertIn(0, steps)
        for i in range(1, len(eta)):
            if i in steps:
                self.assertNotEqual(eta[i - 1], eta[i])
            else:
                self.assertEqual(eta[i - 1], eta[i])

    def specialized_model_test(self, m):
        specialized = itertools.islice(ros.arrival_curve_steps(m), 100)
        forced = itertools.islice(ros.arrival_curve_steps(m, optimized=False),
                                  100)
        for s, f in zip(specialized, forced):
            self.assertEqual(s, f)

    def test_bruteforce(self):
        for m in self.models:
            with self.subTest(m=m):
                self.bruteforce_model_test(m)

    def test_specialization(self):
        for m in self.models:
            with self.subTest(m=m):
                self.specialized_model_test(m)
Ejemplo n.º 11
0
def tdma_test():

    options.init_pycpa()

    s = model.System()
    r1 = s.bind_resource(model.Resource("R1", schedulers.TDMAScheduler()))
    r2 = s.bind_resource(model.Resource("R2", schedulers.TDMAScheduler()))

    # scheduling_parameter denotes the slotsize
    t11 = r1.bind_task(
        model.Task("T11", wcet=10, bcet=5, scheduling_parameter=2))
    t12 = r1.bind_task(
        model.Task("T12", wcet=3, bcet=1, scheduling_parameter=2))

    t21 = r2.bind_task(
        model.Task("T21", wcet=2, bcet=2, scheduling_parameter=2))
    t22 = r2.bind_task(
        model.Task("T22", wcet=3, bcet=3, scheduling_parameter=2))

    t11.link_dependent_task(t21)
    t12.link_dependent_task(t22)

    t11.in_event_model = model.PJdEventModel()
    t11.in_event_model.set_PJd(30, 5)

    t12.in_event_model = model.PJdEventModel()
    t12.in_event_model.set_PJd(15, 6)

    g = graph.graph_system(s, 'tdma_graph.pdf')

    print("Performing analysis")
    results = analysis.analyze_system(s)

    print("Result:")
    for r in sorted(s.resources, key=str):
        for t in sorted(r.tasks, key=str):
            print str(t), " - ", results[t].wcrt
            print "    ", results[t].b_wcrt_str()
Ejemplo n.º 12
0
    def __init__(self, num_reservations, period=Hz(12.5), **kwargs):
        super().__init__(num_reservations,
                         name='move_base.time-driven{}'.format(num_reservations), **kwargs)

        # Prioritize the timers from source to destination. We want the source tasks to run first, so
        # the data can flow through the entire path in a single period.
        # We prioritize the local planner higher than the global planner components
        callbacks_ = [
            Callback('sensor2mem', CBType.SUBSCRIBER, 0, wcet=wcets['sensor2mem']),
            Callback('goal2mem', CBType.SUBSCRIBER, 0, wcet=wcets['sensor2mem']),
            Callback('local_costmap', CBType.TIMER, 4, wcet=wcets['local_costmap']),
            Callback('global_costmap', CBType.TIMER, 1, wcet=wcets['global_costmap']),
            Callback('local_planner', CBType.TIMER, 3, wcet=wcets['local_planner']),
            Callback('global_planner', CBType.TIMER, 5, wcet=wcets['global_planner']),
            Callback('pose_estimator', CBType.TIMER, 2, wcet=wcets['pose_estimator'])]

        self.register_callbacks(callbacks_)

        self.link(['/scan', '/tF', '/odom'], 'sensor2mem')
        self.link('/goal', 'goal2mem')
        self.link('local_planner', '/cmd_vel')
        self.callbacks['local_costmap'].in_event_model = model.PJdEventModel(P=period, J=0)
        self.callbacks['local_planner'].in_event_model = model.PJdEventModel(P=period, J=0)
        self.callbacks['pose_estimator'].in_event_model = model.PJdEventModel(P=period, J=0)
        self.callbacks['global_costmap'].in_event_model = model.PJdEventModel(P=period, J=0)
        self.callbacks['global_planner'].in_event_model = model.PJdEventModel(P=Hz(1), J=0)

        if num_reservations == 1:
            self.res_bind(self.reservations[0], callbacks_)
        elif num_reservations == 2:
            self.res_bind(self.reservations[0],
                          ['local_costmap', 'local_planner', 'pose_estimator', 'sensor2mem'])
            self.res_bind(self.reservations[1],
                          ['global_costmap', 'global_planner', 'goal2mem'])
        else:
            raise ValueError("Unsupported reservation count: %s", num_reservations)

        assert all([cb.resource for cb in self.callbacks.values()])
Ejemplo n.º 13
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)
Ejemplo n.º 14
0
 def test_delta_min_PJd(self):
     delta_reference = [
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 11, 21, 31, 41, 51, 61, 71, 81,
         91, 101, 111, 121, 131, 141, 151, 161, 171, 181, 191, 201, 211,
         221, 231, 241, 251, 261, 271, 281, 291, 301, 311, 321, 331, 341,
         351, 361, 371, 381, 391, 401, 411, 421, 431, 441, 451, 461, 471,
         481, 491, 501, 511, 521, 531, 541, 551, 561, 571, 581, 591, 601,
         611, 621, 631, 641, 651, 661, 671, 681, 691, 701, 711, 721, 731,
         741, 751, 761, 771, 781, 791, 801, 811, 821, 831, 841, 851, 861,
         871, 881
     ]
     em = model.PJdEventModel(P=10, J=99)
     self.assertEqual(delta_reference,
                      [em.delta_min(n) for n in range(0, 100, 1)])
Ejemplo n.º 15
0
def _run_test(scheduler, priorities):
    # 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", scheduler))

    # create and bind tasks to r1
    t11 = r1.bind_task(
        model.Task("T11", wcet=10, bcet=1, scheduling_parameter=priorities[0]))
    t21 = r1.bind_task(
        model.Task("T21", wcet=2, bcet=2, scheduling_parameter=priorities[1]))
    t31 = r1.bind_task(
        model.Task("T31", wcet=4, bcet=2, scheduling_parameter=priorities[2]))

    # specify precedence constraints: T11 -> T21 -> T31
    t11.link_dependent_task(t21)
    t21.link_dependent_task(t31)

    # register a periodic with jitter event model for T11
    t11.in_event_model = model.PJdEventModel(P=20, J=5)

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

    failed = False
    for t in r1.tasks:
        for n in range(1, 11):
            if t.in_event_model.delta_min(n) != t.in_event_model.deltamin_func(
                    n):
                failed = True
                print("%s: cached EM of != uncached EM" % (t.name))
                print("delta_min(%d) = %d != %d" %
                      (n, t.in_event_model.delta_min(n),
                       t.in_event_model.deltamin_func(n)))
                print("for priorities = %s" % str(priorities))
                break

    return not failed
Ejemplo n.º 16
0
    def __init__(self, num_reservations, **kwargs):
        super().__init__(num_reservations,
                         name='move_base.driver-event.{}'.format(num_reservations), **kwargs)
        # Since there is only one timer, the priorities don't matter. We just keep them different
        callbacks_ = [
            Callback('sensor2mem', CBType.SUBSCRIBER, 0, wcet=wcets['sensor2mem']),
            Callback('local_costmap', CBType.SUBSCRIBER, 4, wcet=wcets['local_costmap']),
            Callback('global_costmap', CBType.SUBSCRIBER, 5, wcet=wcets['global_costmap']),
            Callback('local_planner', CBType.SUBSCRIBER, 6, wcet=wcets['local_planner']),
            Callback('global_planner_goalset', CBType.SUBSCRIBER, 7, wcet=wcets['global_planner']),
            Callback('global_planner_timed', CBType.TIMER, 8, wcet=wcets['global_planner']),
            Callback('pose_estimator', CBType.SUBSCRIBER, 10, wcet=wcets['pose_estimator'])]

        self.register_callbacks(callbacks_)

        self.callbacks['global_planner_timed'].in_event_model = model.PJdEventModel(P=Hz(1), J=0)

        link = self.link
        link(['/scan', '/tF'], 'sensor2mem')
        link('pose_estimator', ['local_costmap', 'global_costmap'])
        link('local_costmap', 'local_planner')
        link('local_planner', '/cmd_vel')
        link('/odom', 'pose_estimator')
        link('/goal', 'global_planner_goalset')

        if num_reservations == 1:
            self.res_bind(self.reservations[0], callbacks_)
        elif num_reservations == 2:
            self.res_bind(self.reservations[0],
                          ['local_costmap', 'local_planner', 'pose_estimator', 'sensor2mem'])
            self.res_bind(self.reservations[1],
                          ['global_costmap', 'global_planner_timed', 'global_planner_goalset'])
        else:
            raise ValueError(
                "Unsupported reservation count: %s", num_reservations)

        assert all([cb.resource for cb in self.callbacks.values()])
Ejemplo n.º 17
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))
Ejemplo n.º 18
0
try:
    import matplotlib
    matplotlib.use('Agg')
except ImportError:
    print "matplotlib not available"
    exit(0)

from pycpa import model
from pycpa import plot

# only type 1 fonts
matplotlib.rcParams['ps.useafm'] = True
matplotlib.rcParams['pdf.use14corefonts'] = True
matplotlib.rcParams['text.usetex'] = True

P = 30
J = 60  # 5
d = 0  # 1
em = model.PJdEventModel(P=P, J=J, dmin=d)

print "delta_min(0) =", em.delta_min(0)
print "eta_plus(0) =", em.eta_plus(0)
print "eta_plus(eps) =", em.eta_plus(1e-12)

plot.plot_event_model(em,
                      7,
                      separate_plots=False,
                      file_format='pdf',
                      file_prefix='event-model-',
                      ticks_at_steps=True)
Ejemplo n.º 19
0
 def jittered_models(J):
     return {'/scan': model.PJdEventModel(P=Hz(12.5), J=J),
             '/tF': model.PJdEventModel(P=Hz(12.5), J=J),
             '/odom': model.PJdEventModel(P=Hz(12.5), J=J)}
Ejemplo n.º 20
0

class PBurstModel (model.PJdEventModel):
    def __init__(self, P, burstlen, dmin, name='min', **kwargs):
        J = burstlen * P
        super().__init__(P, J, dmin, name=name, **kwargs)


wcets = {'local_costmap': mseconds(5),
         'global_costmap': mseconds(10),
         'local_planner': mseconds(18),
         'global_planner': mseconds(200),
         'goal_setter': min_jitter,
         'pose_estimator': mseconds(6),
         'sensor2mem': min_jitter}
input_topics = [('/scan', model.PJdEventModel(P=Hz(12.5), J=min_jitter)),
                ('/tF', model.PJdEventModel(P=Hz(12.5), J=min_jitter)),
                ('/odom', model.PJdEventModel(P=Hz(12.5), J=min_jitter)),
                ('/goal', PBurstModel(P=Hz(0.1), burstlen=0, dmin=mseconds(100)))]


class MoveBase(model.System):
    """The common parts of the move_base system model"""
    # Global dictionary of callback names -> callbacks
    callbacks = dict()
    reservations = []

    def __init__(self, num_reservations, *args, override_model={}, **kwargs):
        super().__init__(*args, **kwargs)
        for name, events in input_topics:
            if name in override_model: