Rev 1245 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1246 | giacomo | 1 | /* FSF Loader |
2 | * |
||
3 | * Load and run a specific set of tasks/contracts |
||
4 | * |
||
5 | * This is the system indipendent part |
||
6 | * |
||
7 | * Giacomo Guidi <giacomo@gandalf.sssup.it> |
||
8 | * Michael Timarchi <trimarchi@gandalf.sssup.it> |
||
9 | * |
||
10 | */ |
||
1232 | giacomo | 11 | |
1246 | giacomo | 12 | #include <kernel/kern.h> //Shark dependent header, it's used only for TASK_OUTPUT debug |
1232 | giacomo | 13 | |
1246 | giacomo | 14 | #include "fsf_contract.h" //Framework main header |
15 | #include "func.h" //Generic function definitions |
||
16 | |||
17 | /* Activate task output debug */ |
||
1232 | giacomo | 18 | #define TASK_OUTPUT |
19 | |||
1246 | giacomo | 20 | int cal_cycles = 0; //Calibration const, it converts usec in cycles |
21 | struct timespec zero_time; //Zero time of the simulation |
||
22 | extern struct loader_task loader_task_list[]; //Loader task array |
||
23 | extern int total_loader_task; //Loader task number |
||
1232 | giacomo | 24 | |
1246 | giacomo | 25 | /* OS: Oneshot Task: |
26 | begin |
||
27 | - execution |
||
28 | end |
||
29 | */ |
||
1239 | giacomo | 30 | void *oneshot_task(void *arg) |
1232 | giacomo | 31 | { |
32 | long long i,exec_cycles = 0; |
||
1234 | giacomo | 33 | struct loader_task *l = (struct loader_task *)(arg); |
1232 | giacomo | 34 | char tmp[20]; |
35 | |||
1236 | giacomo | 36 | #ifdef TASK_OUTPUT |
1246 | giacomo | 37 | sprintf(tmp,"[ONESHOT]"); |
1236 | giacomo | 38 | printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task() / 5 + 5, GREEN, tmp); |
39 | #endif |
||
1232 | giacomo | 40 | |
1246 | giacomo | 41 | exec_cycles = (long long)(TIMESPEC2USEC(&l->exec[l->act_current-1])) * CALIBRATION_DELTA / cal_cycles; |
1232 | giacomo | 42 | |
1245 | giacomo | 43 | for (i=0;i<exec_cycles;i++) |
44 | __asm__ __volatile__ ("xorl %%eax,%%eax\n\t" |
||
45 | "cpuid\n\t" |
||
46 | :::"eax","ebx","ecx","edx"); |
||
1232 | giacomo | 47 | |
1239 | giacomo | 48 | return NULL; |
49 | |||
50 | } |
||
51 | |||
1246 | giacomo | 52 | /* CT: Cyclical Task: |
53 | begin |
||
54 | while (1) { |
||
55 | - execution |
||
56 | - end_cycle |
||
57 | } |
||
58 | end (never end) |
||
59 | */ |
||
60 | void *periodic_task(void *arg) |
||
1239 | giacomo | 61 | { |
62 | long long i,exec_cycles = 0; |
||
63 | int act = 0; |
||
64 | struct loader_task *l = (struct loader_task *)(arg); |
||
65 | char tmp[20]; |
||
66 | |||
67 | while(1) { |
||
68 | |||
69 | #ifdef TASK_OUTPUT |
||
1246 | giacomo | 70 | sprintf(tmp,"C[%06d]",act); |
1239 | giacomo | 71 | printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task() / 5 + 5, GREEN, tmp); |
72 | #endif |
||
1235 | giacomo | 73 | |
1246 | giacomo | 74 | exec_cycles = (long long)(TIMESPEC2USEC(&l->exec[l->act_current-1])) * CALIBRATION_DELTA / cal_cycles; |
1239 | giacomo | 75 | |
1245 | giacomo | 76 | for (i=0;i<exec_cycles;i++) |
77 | __asm__ __volatile__ ("xorl %%eax,%%eax\n\t" |
||
78 | "cpuid\n\t" |
||
79 | :::"eax","ebx","ecx","edx"); |
||
1239 | giacomo | 80 | |
81 | generic_task_endcycle(); |
||
82 | |||
83 | act++; |
||
84 | |||
1246 | giacomo | 85 | } |
86 | |||
1232 | giacomo | 87 | return NULL; |
88 | |||
89 | } |
||
90 | |||
1246 | giacomo | 91 | /* BT: Background Task: |
92 | begin |
||
93 | while (1) { |
||
94 | - execution |
||
95 | } |
||
96 | end (never end) |
||
97 | */ |
||
98 | void *back_task(void *arg) |
||
1239 | giacomo | 99 | { |
100 | long long i,exec_cycles = 0; |
||
101 | int act = 0; |
||
102 | struct loader_task *l = (struct loader_task *)(arg); |
||
103 | char tmp[20]; |
||
104 | |||
105 | while(1) { |
||
106 | |||
107 | #ifdef TASK_OUTPUT |
||
1246 | giacomo | 108 | sprintf(tmp,"B[%06d]",act); |
1239 | giacomo | 109 | printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task() / 5 + 5, GREEN, tmp); |
110 | #endif |
||
111 | |||
1246 | giacomo | 112 | exec_cycles = (long long)(TIMESPEC2USEC(&l->exec[l->act_current-1])) * CALIBRATION_DELTA / cal_cycles; |
1239 | giacomo | 113 | |
1245 | giacomo | 114 | for (i=0;i<exec_cycles;i++) |
115 | __asm__ __volatile__ ("xorl %%eax,%%eax\n\t" |
||
116 | "cpuid\n\t" |
||
117 | :::"eax","ebx","ecx","edx"); |
||
1239 | giacomo | 118 | |
119 | act++; |
||
120 | |||
121 | } |
||
122 | return NULL; |
||
123 | |||
124 | } |
||
125 | |||
1232 | giacomo | 126 | /* Task create */ |
1239 | giacomo | 127 | /* this function create the task struct in memory */ |
1234 | giacomo | 128 | void loader_task_create() |
1232 | giacomo | 129 | { |
130 | |||
1234 | giacomo | 131 | struct loader_task *current = loader_task_list; |
1241 | giacomo | 132 | int i=0, k=0; |
1232 | giacomo | 133 | |
1241 | giacomo | 134 | while (k <total_loader_task) { |
1232 | giacomo | 135 | k++; |
1243 | giacomo | 136 | |
1232 | giacomo | 137 | for (i=0; i < current->number; i++) { |
1239 | giacomo | 138 | |
1232 | giacomo | 139 | pthread_t j; |
1243 | giacomo | 140 | int err = 0; |
1242 | giacomo | 141 | |
1239 | giacomo | 142 | switch(current->task_type) { |
143 | case PAR_TASK_OS: |
||
1245 | giacomo | 144 | err = generic_create_thread(generic_get_server_from_contract(current->contract),&j,NULL, |
145 | oneshot_task,(void *)current,generic_get_task_model(current)); |
||
1239 | giacomo | 146 | break; |
147 | case PAR_TASK_BT: |
||
1245 | giacomo | 148 | err = generic_create_thread(generic_get_server_from_contract(current->contract),&j,NULL, |
149 | back_task,(void *)current,generic_get_task_model(current)); |
||
1239 | giacomo | 150 | break; |
151 | case PAR_TASK_CT: |
||
1245 | giacomo | 152 | err = generic_create_thread(generic_get_server_from_contract(current->contract),&j,NULL, |
153 | periodic_task,(void *)current,generic_get_task_model(current)); |
||
1239 | giacomo | 154 | break; |
155 | } |
||
1232 | giacomo | 156 | if (err) { |
1246 | giacomo | 157 | printf("Error fsf task creating\n"); |
158 | generic_end_simulation(); |
||
1232 | giacomo | 159 | } |
160 | |||
161 | } |
||
162 | |||
1234 | giacomo | 163 | current = &loader_task_list[k]; |
164 | |||
1232 | giacomo | 165 | } |
166 | |||
1246 | giacomo | 167 | printf("Created %d loader tasks\n",k); |
1234 | giacomo | 168 | |
1232 | giacomo | 169 | |
170 | } |
||
171 | |||
1246 | giacomo | 172 | /* Main Function */ |
1239 | giacomo | 173 | int start_environment() |
1232 | giacomo | 174 | { |
175 | |||
1234 | giacomo | 176 | struct timespec total = {20,0}; |
1233 | giacomo | 177 | |
1232 | giacomo | 178 | generic_calibrate_cycle(); |
1234 | giacomo | 179 | |
1232 | giacomo | 180 | generic_fsfinit(); |
181 | |||
1234 | giacomo | 182 | loader_task_create(); |
1232 | giacomo | 183 | |
1243 | giacomo | 184 | generic_start_simulation(); |
185 | |||
1233 | giacomo | 186 | generic_set_simulation_time(&total); |
1232 | giacomo | 187 | |
188 | return 0; |
||
189 | |||
190 | } |