Subversion Repositories shark

Rev

Rev 1255 | 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
 
11
/* Delay Calibration */
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);
71
    hard_task_def_usemath(ht);
72
    return &ht;
73
  }  
74
 
75
 
76
  if (current->local_scheduler == PAR_RM) {
77
    static HARD_TASK_MODEL ht;
78
 
79
    hard_task_default_model(ht);
80
    hard_task_def_mit(ht,TIMESPEC2USEC(&current->deadline));
81
    hard_task_def_wcet(ht,TIMESPEC2USEC(&current->wcet));
82
    hard_task_def_ctrl_jet(ht);
83
    hard_task_def_group(ht,current->group);
84
    hard_task_def_usemath(ht);
85
    return &ht;
86
  }  
87
 
88
  return NULL;
89
 
90
}  
91
 
92
void set_simulation_time (struct timespec *total) {
93
  struct timespec end_time;
94
 
95
  ADDTIMESPEC(&zero_time,total,&end_time);
96
  kern_event_post(&end_time,(void *)((void *)(sys_end)),NULL);
97
 
98
}
99
 
100
int calibration_func() {
101
  return kern_gettime(NULL);
102
 
103
}
104
 
105
void start_simulation() {
106
 
107
  int i;
108
  struct loader_task *l = loader_task_list;
109
  struct timespec end_time;
110
 
111
  i  = 0;
112
 
113
  kern_gettime(&zero_time);
114
 
115
  while (i < total_loader_task) {
116
 
117
    if (l->act_number > 0) {
118
      ADDTIMESPEC(&zero_time, &l->act[0], &end_time);
119
      l->act_current++;
120
      kern_event_post(&end_time,(void *)((void *)(loader_task_activate)),l);
121
    }
122
 
123
    i++;
124
    l=&loader_task_list[i];
125
 
126
  }
127
 
128
}
129
 
130
 
131
void loader_task_activate(struct loader_task *l) {
132
 
133
  struct timespec actual_time,end_time;
134
 
135
  kern_gettime(&actual_time);
136
  group_activate(l->group);
137
 
138
  if (l->act_number > l->act_current) {
139
 
140
    ADDTIMESPEC(&actual_time, &l->act[l->act_current], &end_time);
141
 
142
    l->act_current++;
143
    kern_event_post(&end_time,(void *)((void *)(loader_task_activate)),l);
144
 
145
  }
146
 
147
}