Subversion Repositories shark

Rev

Rev 1262 | Rev 1266 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1254 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
 */
11
 
12
#include "fsf_contract.h" //Framework main header
13
#include "calibrate.h"
14
#include "func.h" //Generic function definitions
1255 giacomo 15
#include "lconst.h"
1254 giacomo 16
 
17
/* Activate task output debug */
18
#define TASK_OUTPUT
19
 
1255 giacomo 20
int cal_cycles = CALIBRATION_RESULT; //Calibration const, it converts usec to cycles
1254 giacomo 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
24
 
25
/* OS: Oneshot Task:
26
   begin
27
    - execution
28
   end
29
*/
30
void *oneshot_task(void *arg)
31
{
32
  long long i,exec_cycles = 0;
33
  struct loader_task *l = (struct loader_task *)(arg);
1262 giacomo 34
  #ifdef TASK_OUTPUT
35
    #ifdef OS_SHARK
36
      char tmp[20];
37
    #endif
38
  #endif
1254 giacomo 39
 
1264 giacomo 40
  start_oneshot_task();
41
 
42
  /* to avoid problem if the task start inside the create function */
1254 giacomo 43
  if (l->act_current == 0) l->act_current = 1;                                                                                                                            
44
  #ifdef TASK_OUTPUT
1262 giacomo 45
    #ifdef OS_SHARK
46
      sprintf(tmp,"[ONESHOT]");
47
      printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task()  / 5 + 5, GREEN, tmp);
48
    #endif
1254 giacomo 49
  #endif
50
 
51
  exec_cycles = (long long)(TIMESPEC2USEC(&l->exec[l->act_current-1])) * CALIBRATION_DELTA / cal_cycles;
52
 
53
  /* Execution delay */
54
  for (i=0;i<exec_cycles;i++)
55
    __asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
56
                          "cpuid\n\t"
57
                          :::"eax","ebx","ecx","edx");
58
 
1264 giacomo 59
  end_oneshot_task();
60
 
1254 giacomo 61
  return NULL;
62
 
63
}
64
 
65
/* CT: Cyclical Task:
66
   begin
67
     while (1) {
68
       - execution
69
       - end_cycle
70
     }
71
   end (never end)
72
*/
73
void *periodic_task(void *arg)
74
{
75
  long long i,exec_cycles = 0;
76
  int act = 0;
77
  struct loader_task *l = (struct loader_task *)(arg);
78
 
1262 giacomo 79
  #ifdef TASK_OUTPUT
80
    #ifdef OS_SHARK
81
      char tmp[20];
82
    #endif
83
  #endif
84
 
1264 giacomo 85
  start_periodic_task();
86
 
1254 giacomo 87
  if (l->act_current == 0) l->act_current = 1;
88
 
89
  while(1) {
90
 
1264 giacomo 91
    start_job_periodic_task();
92
 
1254 giacomo 93
    #ifdef TASK_OUTPUT
1262 giacomo 94
      #ifdef OS_SHARK
95
        sprintf(tmp,"C[%06d]",act);
96
        printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task()  / 5 + 5, GREEN, tmp);
97
      #endif
1254 giacomo 98
    #endif
99
 
100
    exec_cycles = (long long)(TIMESPEC2USEC(&l->exec[l->act_current-1])) * CALIBRATION_DELTA / cal_cycles;
101
 
102
    /* Execution delay */  
103
    for (i=0;i<exec_cycles;i++)
104
    __asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
105
                          "cpuid\n\t"
106
                          :::"eax","ebx","ecx","edx");
107
 
1264 giacomo 108
    end_job_periodic_task();
109
 
1254 giacomo 110
    generic_task_endcycle();
111
 
112
    act++;
113
 
114
  }  
1264 giacomo 115
 
116
  end_periodic_task();
1254 giacomo 117
 
118
  return NULL;
119
 
120
}
121
 
122
/* BT: Background Task:
123
   begin
124
     while (1) {
125
       - execution
126
     }
127
   end (never end)
128
*/
129
void *back_task(void *arg)
130
{
131
  long long i,exec_cycles = 0;
132
  int act = 0;
133
  struct loader_task *l = (struct loader_task *)(arg);
1262 giacomo 134
  #ifdef TASK_OUTPUT
135
    #ifdef OS_SHARK
136
      char tmp[20];
137
    #endif
138
  #endif
1254 giacomo 139
 
1264 giacomo 140
  start_back_task();
141
 
1254 giacomo 142
  if (l->act_current == 0) l->act_current = 1;
143
 
144
  while(1) {
145
 
1264 giacomo 146
    start_job_back_task();
147
 
1254 giacomo 148
    #ifdef TASK_OUTPUT
1262 giacomo 149
      #ifdef OS_SHARK
150
        sprintf(tmp,"B[%06d]",act);
151
        printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task()  / 5 + 5, GREEN, tmp);
152
      #endif
1254 giacomo 153
    #endif
154
 
155
    exec_cycles = (long long)(TIMESPEC2USEC(&l->exec[l->act_current-1])) * CALIBRATION_DELTA / cal_cycles;
156
 
157
    /* Execution delay */
158
    for (i=0;i<exec_cycles;i++)
159
    __asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
160
                          "cpuid\n\t"
161
                          :::"eax","ebx","ecx","edx");
162
 
1264 giacomo 163
    end_job_back_task();
164
 
1254 giacomo 165
    act++;
166
 
1264 giacomo 167
  }
168
 
169
  end_back_task();
170
 
1254 giacomo 171
  return NULL;
172
 
173
}
174
 
175
/* Task create */
176
/* this function create the task struct in memory */
177
void loader_task_create()
178
{
179
 
180
  struct loader_task *current = loader_task_list;
181
  int i=0, k=0;
182
 
183
  while (k <total_loader_task) {
184
    k++;
185
 
186
    for (i=0; i < current->number; i++) {
187
 
188
      pthread_t j;
189
      int err = 0;
190
 
191
      switch(current->task_type)  {
192
      case PAR_TASK_OS:
193
        err = generic_create_thread(generic_get_server_from_contract(current->contract),&j,NULL,
194
              oneshot_task,(void *)current,generic_get_task_model(current));
195
        break;
196
      case PAR_TASK_BT:
197
        err = generic_create_thread(generic_get_server_from_contract(current->contract),&j,NULL,
198
              back_task,(void *)current,generic_get_task_model(current));
199
        break;
200
      case PAR_TASK_CT:
201
        err = generic_create_thread(generic_get_server_from_contract(current->contract),&j,NULL,
202
              periodic_task,(void *)current,generic_get_task_model(current));
203
        break;
204
      }
205
      if (err) {
206
        printf("Error fsf task creating\n");
207
        generic_end_simulation();
208
      }
209
 
210
    }
211
 
212
    current = &loader_task_list[k];
213
 
214
  }
215
 
216
  printf("Created %d loader tasks\n",k);
217
 
218
 
219
}
220
 
221
/* Main Function */
222
int start_environment()
223
{
224
 
225
  extern struct timespec total_time;
226
 
227
  /* Calibrate the exec time */  
228
  generic_calibrate_cycle();
229
 
230
  /* Create the servers usign defined contracts */
231
  generic_fsfinit();
232
 
233
  /* Create the tasks */
234
  loader_task_create();
235
 
236
  /* Start the simulation */
237
  generic_start_simulation();
238
 
239
  /* Set the simulation end time */
240
  generic_set_simulation_time(&total_time);
241
 
242
  return 0;
243
 
244
}