Subversion Repositories shark

Rev

Rev 1490 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1489 giacomo 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Giacomo Guidi       <giacomo@gandalf.sssup.it>
10
 *
11
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
12
 *
13
 * http://www.sssup.it
14
 * http://retis.sssup.it
15
 * http://shark.sssup.it
16
 */
17
 
18
/* The tracer instrumentation ideas come from the York PWCET analisys tool
19
 *     
20
 *      Real-Time System Group
21
 *      University of York
22
 *
23
 */
24
 
25
#include <kernel/kern.h>
26
#include <tracer.h>
27
 
28
int num_aster = 0;
29
#define ASTER_LIM       67
30
#define ASTER_MAX       90
31
 
32
TASK asteroide(void)
33
{
34
  int i = 1;
35
  int y = 0;
36
 
37
  FAST_TRACER_LOGEVENT(FTrace_EVT_ipoint,1000,0);
38
 
39
  y = rand() % 20 + 1;
40
 
41
  while (i < ASTER_LIM) {
42
 
43
    FAST_TRACER_LOGEVENT(FTrace_EVT_ipoint,1001,0);
44
 
45
    puts_xy(i,y,WHITE,"*");
46
 
47
    FAST_TRACER_LOGEVENT(FTrace_EVT_ipoint,1002,0);
48
    task_endcycle();
49
 
50
    puts_xy(i,y,WHITE," ");
51
    i++;
52
  }
53
 
54
  FAST_TRACER_LOGEVENT(FTrace_EVT_ipoint,1003,0);
55
  num_aster--;
56
 
57
  FAST_TRACER_LOGEVENT(FTrace_EVT_ipoint,1004,0);
58
  return 0;
59
 
60
}
61
 
62
DWORD taskCreated = 0;
63
 
64
TASK aster(void)
65
{
66
  PID p;
67
 
68
  HARD_TASK_MODEL m;
69
  int r;
70
 
71
  FAST_TRACER_LOGEVENT(FTrace_EVT_ipoint,2000,0);
72
 
73
  hard_task_default_model(m);
74
  hard_task_def_wcet(m,500);
75
 
76
  while (1) {
77
 
78
    FAST_TRACER_LOGEVENT(FTrace_EVT_ipoint,2001,0);
79
 
80
    if (num_aster < ASTER_MAX) {
81
 
82
      FAST_TRACER_LOGEVENT(FTrace_EVT_ipoint,2002,0);
83
 
84
      r = (rand() % 50) - 25;
85
 
86
      hard_task_def_arg(m,(void *)((rand() % 7)+1));
87
      hard_task_def_mit(m, (50+r)*1000);
88
      p = task_create("aaa",asteroide,&m,NULL);
89
      taskCreated++;
90
      task_activate(p);
91
      num_aster++;
92
    }
93
 
94
    FAST_TRACER_LOGEVENT(FTrace_EVT_ipoint,2003,0);
95
    task_endcycle();
96
 
97
  }
98
 
99
  FAST_TRACER_LOGEVENT(FTrace_EVT_ipoint,2004,0);
100
 
101
}
102
 
103
TASK clock()
104
{
105
  int s = 0, m = 0;
106
 
107
  FAST_TRACER_LOGEVENT(FTrace_EVT_ipoint,3000,0);
108
 
109
  while(1) {
110
 
111
    FAST_TRACER_LOGEVENT(FTrace_EVT_ipoint,3001,0);
112
 
113
    printf_xy(70,1,WHITE,"%2d : %2d",m,s);
114
    FAST_TRACER_LOGEVENT(FTrace_EVT_ipoint,3002,0);
115
    task_endcycle();
116
 
117
    if (++s > 59) {
118
 
119
      FAST_TRACER_LOGEVENT(FTrace_EVT_ipoint,3003,0);
120
      s = 0;
121
      m++;
122
 
123
    }
124
    FAST_TRACER_LOGEVENT(FTrace_EVT_ipoint,3004,0);
125
 
126
    printf_xy(70,1,WHITE,"%2d : %2d",m,s);
127
 
128
    FAST_TRACER_LOGEVENT(FTrace_EVT_ipoint,3005,0);
129
    task_endcycle();
130
 
131
  }
132
  FAST_TRACER_LOGEVENT(FTrace_EVT_ipoint,3006,0);
133
 
134
}
135
 
136
void instrumented_routine() {
137
 
138
  PID p1,p2;
139
  HARD_TASK_MODEL m;
140
  struct timespec t;
141
 
142
  cprintf("Start\n");
143
 
144
  clear();
145
 
146
  hard_task_default_model(m);
147
  hard_task_def_mit(m,10000);
148
  hard_task_def_wcet(m,2000);
149
  hard_task_def_group(m,1);
150
 
151
  p1 = task_create("Aster",aster,&m,NULL);
152
  if (p1 == -1) {
153
    sys_shutdown_message("Aster.C(main): Could not create task <aster> ...");
154
    sys_end();
155
  }
156
 
157
  hard_task_def_mit(m,500000);
158
  p2 = task_create("Clock",clock,&m,NULL);
159
  if (p2 == -1) {
160
    sys_shutdown_message("Aster.C(main): Could not create task <Clock> ...");
161
    sys_end();
162
  }
163
 
164
  group_activate(1);
165
 
166
  do {
167
    sys_gettime(&t);
168
  } while (t.tv_sec < 10);
169
 
170
  cprintf("Done\n");
171
 
172
}
173
 
174
int main(int argc, char **argv)
175
{
176
 
177
  int a,b,c;
178
  struct timespec start,end,diff;
179
 
180
  srand(sys_gettime(NULL));
181
 
182
  a = FTrace_chunk_create(1000000, 1000000, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);
183
  b = FTrace_chunk_create(1000000, 1000000, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_JTN);
184
  c = FTrace_chunk_create(1000000, 1000000, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);
185
 
186
  FTrace_chunk_link(a,b);
187
  FTrace_chunk_link(b,c);
188
 
189
  kern_gettime(&start);
190
  FTrace_enable();
191
 
192
  TRACER_LOGEVENT(FTrace_EVT_trace_start,0,0);
193
 
194
    instrumented_routine();
195
 
196
  TRACER_LOGEVENT(FTrace_EVT_trace_stop,0,0);  
197
 
198
  FTrace_disable();
199
  kern_gettime(&end);
200
 
201
  SUBTIMESPEC(&end,&start,&diff);
202
 
203
  printf_xy(1,21,WHITE,"Logged Time %d s %d us",(int)diff.tv_sec,(int)diff.tv_nsec/1000);
204
 
205
  sys_end();
206
 
207
  return 0;
208
 
209
}
210