Subversion Repositories shark

Rev

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

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