Rev 1244 | 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[]; |
1245 | giacomo | 6 | extern struct loader_contract loader_contract_list[]; |
1242 | giacomo | 7 | extern int total_loader_task; |
1245 | giacomo | 8 | extern int total_loader_contract; |
1233 | giacomo | 9 | |
1232 | giacomo | 10 | /* Delay Calibration */ |
11 | int calibrate_cycle() |
||
12 | { |
||
13 | long long i; |
||
14 | struct timespec start,end,diff; |
||
15 | |||
16 | kern_cli(); |
||
17 | kern_gettime(&start); |
||
1245 | giacomo | 18 | for (i=0;i<CALIBRATION_DELTA;i++) |
19 | __asm__ __volatile__ ("xorl %%eax,%%eax\n\t" |
||
20 | "cpuid\n\t" |
||
21 | :::"eax","ebx","ecx","edx"); |
||
1232 | giacomo | 22 | kern_gettime(&end); |
23 | kern_sti(); |
||
24 | |||
25 | SUBTIMESPEC(&end,&start,&diff); |
||
26 | cal_cycles = TIMESPEC2USEC(&diff); |
||
27 | cprintf("Calibration usec/[%d cycles] = %d\n",CALIBRATION_DELTA,cal_cycles); |
||
28 | |||
29 | return 0; |
||
30 | |||
31 | } |
||
32 | |||
1245 | giacomo | 33 | int get_server_from_contract(int contract) |
34 | { |
||
35 | |||
36 | int i; |
||
37 | |||
38 | for(i=0;i<total_loader_contract;i++) |
||
39 | if (loader_contract_list[i].number == contract) |
||
40 | return loader_contract_list[i].server; |
||
41 | |||
42 | return -1; |
||
43 | |||
44 | } |
||
45 | |||
1233 | giacomo | 46 | void *get_task_model(struct loader_task *current) { |
1239 | giacomo | 47 | if (current->local_scheduler == PAR_POSIX) { |
1232 | giacomo | 48 | static NRT_TASK_MODEL nrt; |
49 | |||
50 | nrt_task_default_model(nrt); |
||
51 | nrt_task_def_save_arrivals(nrt); |
||
52 | nrt_task_def_ctrl_jet(nrt); |
||
1242 | giacomo | 53 | nrt_task_def_group(nrt,current->group); |
1232 | giacomo | 54 | nrt_task_def_usemath(nrt); |
55 | |||
56 | return &nrt; |
||
57 | |||
58 | } |
||
59 | |||
1239 | giacomo | 60 | if (current->local_scheduler == PAR_EDF) { |
1232 | giacomo | 61 | static HARD_TASK_MODEL ht; |
62 | |||
63 | hard_task_default_model(ht); |
||
64 | hard_task_def_ctrl_jet(ht); |
||
65 | hard_task_def_mit(ht,TIMESPEC2USEC(¤t->deadline)); |
||
66 | hard_task_def_wcet(ht,TIMESPEC2USEC(¤t->wcet)); |
||
1242 | giacomo | 67 | hard_task_def_group(ht,current->group); |
1232 | giacomo | 68 | hard_task_def_usemath(ht); |
69 | return &ht; |
||
70 | } |
||
71 | |||
72 | |||
1239 | giacomo | 73 | if (current->local_scheduler == PAR_RM) { |
1232 | giacomo | 74 | static HARD_TASK_MODEL ht; |
75 | |||
76 | hard_task_default_model(ht); |
||
77 | hard_task_def_mit(ht,TIMESPEC2USEC(¤t->deadline)); |
||
78 | hard_task_def_wcet(ht,TIMESPEC2USEC(¤t->wcet)); |
||
79 | hard_task_def_ctrl_jet(ht); |
||
1242 | giacomo | 80 | hard_task_def_group(ht,current->group); |
1232 | giacomo | 81 | hard_task_def_usemath(ht); |
82 | return &ht; |
||
83 | } |
||
1234 | giacomo | 84 | |
85 | return NULL; |
||
1232 | giacomo | 86 | |
87 | } |
||
88 | |||
89 | void set_simulation_time (struct timespec *total) { |
||
90 | struct timespec end_time; |
||
91 | |||
92 | ADDTIMESPEC(&zero_time,total,&end_time); |
||
93 | kern_event_post(&end_time,(void *)((void *)(sys_end)),NULL); |
||
94 | |||
95 | } |
||
96 | |||
1239 | giacomo | 97 | int calibration_func() { |
98 | return kern_gettime(NULL); |
||
99 | |||
100 | } |
||
101 | |||
102 | void start_simulation() { |
||
103 | |||
1242 | giacomo | 104 | int i; |
1243 | giacomo | 105 | struct loader_task *l = loader_task_list; |
1232 | giacomo | 106 | struct timespec end_time; |
1239 | giacomo | 107 | |
108 | i = 0; |
||
1243 | giacomo | 109 | |
110 | kern_gettime(&zero_time); |
||
1239 | giacomo | 111 | |
1242 | giacomo | 112 | while (i < total_loader_task) { |
1243 | giacomo | 113 | |
114 | if (l->act_number > 0) { |
||
1239 | giacomo | 115 | ADDTIMESPEC(&zero_time, &l->act[0], &end_time); |
116 | l->act_current++; |
||
1243 | giacomo | 117 | kern_event_post(&end_time,(void *)((void *)(loader_task_activate)),l); |
1239 | giacomo | 118 | } |
119 | |||
1243 | giacomo | 120 | i++; |
1244 | giacomo | 121 | l=&loader_task_list[i]; |
1243 | giacomo | 122 | |
1239 | giacomo | 123 | } |
124 | |||
1232 | giacomo | 125 | } |
1233 | giacomo | 126 | |
127 | |||
1239 | giacomo | 128 | void loader_task_activate(struct loader_task *l) { |
129 | |||
130 | struct timespec actual_time,end_time; |
||
131 | |||
132 | kern_gettime(&actual_time); |
||
133 | group_activate(l->group); |
||
134 | |||
135 | if (l->act_number > l->act_current) { |
||
136 | |||
137 | ADDTIMESPEC(&actual_time, &l->act[l->act_current], &end_time); |
||
138 | |||
139 | l->act_current++; |
||
1243 | giacomo | 140 | kern_event_post(&end_time,(void *)((void *)(loader_task_activate)),l); |
1239 | giacomo | 141 | |
142 | } |
||
143 | |||
1233 | giacomo | 144 | } |