Rev 1242 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1233 | giacomo | 1 | #include "func.h" |
1232 | giacomo | 2 | |
1239 | giacomo | 3 | extern int cal_cycles; |
4 | extern struct timespec zero_time; |
||
1243 | giacomo | 5 | extern struct loader_task loader_task_list[]; |
1242 | giacomo | 6 | extern int total_loader_task; |
1233 | giacomo | 7 | |
1232 | giacomo | 8 | /* Delay Calibration */ |
9 | int calibrate_cycle() |
||
10 | { |
||
11 | long long i; |
||
12 | struct timespec start,end,diff; |
||
13 | |||
14 | kern_cli(); |
||
15 | kern_gettime(&start); |
||
16 | for (i=0;i<CALIBRATION_DELTA;i++) kern_gettime(NULL); |
||
17 | kern_gettime(&end); |
||
18 | kern_sti(); |
||
19 | |||
20 | SUBTIMESPEC(&end,&start,&diff); |
||
21 | cal_cycles = TIMESPEC2USEC(&diff); |
||
22 | cprintf("Calibration usec/[%d cycles] = %d\n",CALIBRATION_DELTA,cal_cycles); |
||
23 | |||
24 | return 0; |
||
25 | |||
26 | } |
||
27 | |||
1233 | giacomo | 28 | void *get_task_model(struct loader_task *current) { |
1239 | giacomo | 29 | if (current->local_scheduler == PAR_POSIX) { |
1232 | giacomo | 30 | static NRT_TASK_MODEL nrt; |
31 | |||
32 | nrt_task_default_model(nrt); |
||
33 | nrt_task_def_save_arrivals(nrt); |
||
34 | nrt_task_def_ctrl_jet(nrt); |
||
1242 | giacomo | 35 | nrt_task_def_group(nrt,current->group); |
1232 | giacomo | 36 | nrt_task_def_usemath(nrt); |
37 | |||
38 | return &nrt; |
||
39 | |||
40 | } |
||
41 | |||
1239 | giacomo | 42 | if (current->local_scheduler == PAR_EDF) { |
1232 | giacomo | 43 | static HARD_TASK_MODEL ht; |
44 | |||
45 | hard_task_default_model(ht); |
||
46 | hard_task_def_ctrl_jet(ht); |
||
47 | hard_task_def_mit(ht,TIMESPEC2USEC(¤t->deadline)); |
||
48 | hard_task_def_wcet(ht,TIMESPEC2USEC(¤t->wcet)); |
||
1242 | giacomo | 49 | hard_task_def_group(ht,current->group); |
1232 | giacomo | 50 | hard_task_def_usemath(ht); |
51 | return &ht; |
||
52 | } |
||
53 | |||
54 | |||
1239 | giacomo | 55 | if (current->local_scheduler == PAR_RM) { |
1232 | giacomo | 56 | static HARD_TASK_MODEL ht; |
57 | |||
58 | hard_task_default_model(ht); |
||
59 | hard_task_def_mit(ht,TIMESPEC2USEC(¤t->deadline)); |
||
60 | hard_task_def_wcet(ht,TIMESPEC2USEC(¤t->wcet)); |
||
61 | hard_task_def_ctrl_jet(ht); |
||
1242 | giacomo | 62 | hard_task_def_group(ht,current->group); |
1232 | giacomo | 63 | hard_task_def_usemath(ht); |
64 | return &ht; |
||
65 | } |
||
1234 | giacomo | 66 | |
67 | return NULL; |
||
1232 | giacomo | 68 | |
69 | } |
||
70 | |||
71 | void set_simulation_time (struct timespec *total) { |
||
72 | struct timespec end_time; |
||
73 | |||
74 | ADDTIMESPEC(&zero_time,total,&end_time); |
||
75 | kern_event_post(&end_time,(void *)((void *)(sys_end)),NULL); |
||
76 | |||
77 | } |
||
78 | |||
1239 | giacomo | 79 | int calibration_func() { |
80 | return kern_gettime(NULL); |
||
81 | |||
82 | } |
||
83 | |||
84 | void start_simulation() { |
||
85 | |||
1242 | giacomo | 86 | int i; |
1243 | giacomo | 87 | struct loader_task *l = loader_task_list; |
1232 | giacomo | 88 | struct timespec end_time; |
1239 | giacomo | 89 | |
90 | i = 0; |
||
1243 | giacomo | 91 | |
92 | kern_gettime(&zero_time); |
||
1239 | giacomo | 93 | |
1242 | giacomo | 94 | while (i < total_loader_task) { |
1243 | giacomo | 95 | |
96 | if (l->act_number > 0) { |
||
1239 | giacomo | 97 | ADDTIMESPEC(&zero_time, &l->act[0], &end_time); |
98 | l->act_current++; |
||
1243 | giacomo | 99 | kern_event_post(&end_time,(void *)((void *)(loader_task_activate)),l); |
1239 | giacomo | 100 | l=&loader_task_list[i]; |
101 | } |
||
102 | |||
1243 | giacomo | 103 | i++; |
104 | |||
1239 | giacomo | 105 | } |
106 | |||
1232 | giacomo | 107 | } |
1233 | giacomo | 108 | |
109 | |||
1239 | giacomo | 110 | void loader_task_activate(struct loader_task *l) { |
111 | |||
112 | struct timespec actual_time,end_time; |
||
113 | |||
114 | kern_gettime(&actual_time); |
||
115 | group_activate(l->group); |
||
116 | |||
117 | if (l->act_number > l->act_current) { |
||
118 | |||
119 | ADDTIMESPEC(&actual_time, &l->act[l->act_current], &end_time); |
||
120 | |||
121 | l->act_current++; |
||
1243 | giacomo | 122 | kern_event_post(&end_time,(void *)((void *)(loader_task_activate)),l); |
1239 | giacomo | 123 | |
124 | } |
||
125 | |||
1233 | giacomo | 126 | } |