Subversion Repositories shark

Rev

Rev 1489 | Rev 1491 | Go to most recent revision | Details | Compare with Previous | 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
 
1490 giacomo 28
#define IPOINT(a) TRACER_LOGEVENT(FTrace_EVT_ipoint,(a),0);
29
 
1489 giacomo 30
int num_aster = 0;
31
#define ASTER_LIM       67
32
#define ASTER_MAX       90
33
 
34
TASK asteroide(void)
35
{
36
  int i = 1;
37
  int y = 0;
38
 
1490 giacomo 39
  IPOINT(1000);
1489 giacomo 40
 
41
  y = rand() % 20 + 1;
42
 
43
  while (i < ASTER_LIM) {
44
 
1490 giacomo 45
    IPOINT(1001);
1489 giacomo 46
 
47
    puts_xy(i,y,WHITE,"*");
48
 
1490 giacomo 49
    IPOINT(1002);
50
    task_testcancel();
1489 giacomo 51
    task_endcycle();
52
 
53
    puts_xy(i,y,WHITE," ");
54
    i++;
55
  }
56
 
1490 giacomo 57
  IPOINT(1003);
1489 giacomo 58
  num_aster--;
59
 
1490 giacomo 60
  IPOINT(1004);
1489 giacomo 61
  return 0;
62
 
63
}
64
 
65
DWORD taskCreated = 0;
66
 
67
TASK aster(void)
68
{
69
  PID p;
70
 
71
  HARD_TASK_MODEL m;
72
  int r;
73
 
1490 giacomo 74
  IPOINT(2000);
1489 giacomo 75
 
76
  hard_task_default_model(m);
77
  hard_task_def_wcet(m,500);
1490 giacomo 78
  hard_task_def_group(m,3);
1489 giacomo 79
 
80
  while (1) {
81
 
1490 giacomo 82
    IPOINT(2001);
1489 giacomo 83
 
84
    if (num_aster < ASTER_MAX) {
85
 
1490 giacomo 86
      IPOINT(2002);
1489 giacomo 87
 
88
      r = (rand() % 50) - 25;
89
 
90
      hard_task_def_arg(m,(void *)((rand() % 7)+1));
91
      hard_task_def_mit(m, (50+r)*1000);
92
      p = task_create("aaa",asteroide,&m,NULL);
93
      taskCreated++;
94
      task_activate(p);
95
      num_aster++;
96
    }
97
 
1490 giacomo 98
    IPOINT(2003);
99
    task_testcancel();
1489 giacomo 100
    task_endcycle();
101
 
102
  }
103
 
1490 giacomo 104
  IPOINT(2004);
1489 giacomo 105
 
106
}
107
 
108
TASK clock()
109
{
110
  int s = 0, m = 0;
111
 
1490 giacomo 112
  IPOINT(3000);
1489 giacomo 113
 
114
  while(1) {
115
 
1490 giacomo 116
    IPOINT(3001);
1489 giacomo 117
 
118
    printf_xy(70,1,WHITE,"%2d : %2d",m,s);
1490 giacomo 119
    IPOINT(3002);
1489 giacomo 120
    task_endcycle();
121
 
122
    if (++s > 59) {
123
 
1490 giacomo 124
      IPOINT(3003);
1489 giacomo 125
      s = 0;
126
      m++;
127
 
128
    }
1490 giacomo 129
    IPOINT(3004);
1489 giacomo 130
 
131
    printf_xy(70,1,WHITE,"%2d : %2d",m,s);
132
 
1490 giacomo 133
    IPOINT(3005);
1489 giacomo 134
    task_endcycle();
135
 
136
  }
1490 giacomo 137
  IPOINT(3006);
1489 giacomo 138
 
139
}
140
 
141
void instrumented_routine() {
142
 
143
  PID p1,p2;
144
  HARD_TASK_MODEL m;
145
  struct timespec t;
146
 
147
  cprintf("Start\n");
148
 
149
  clear();
150
 
151
  hard_task_default_model(m);
152
  hard_task_def_mit(m,10000);
153
  hard_task_def_wcet(m,2000);
1490 giacomo 154
  hard_task_def_group(m,2);
1489 giacomo 155
 
156
  p1 = task_create("Aster",aster,&m,NULL);
157
  if (p1 == -1) {
158
    sys_shutdown_message("Aster.C(main): Could not create task <aster> ...");
159
    sys_end();
160
  }
161
 
162
  hard_task_def_mit(m,500000);
163
  p2 = task_create("Clock",clock,&m,NULL);
164
  if (p2 == -1) {
165
    sys_shutdown_message("Aster.C(main): Could not create task <Clock> ...");
166
    sys_end();
167
  }
168
 
1490 giacomo 169
  group_activate(2);
1489 giacomo 170
 
171
  do {
172
    sys_gettime(&t);
173
  } while (t.tv_sec < 10);
174
 
175
  cprintf("Done\n");
176
 
177
}
178
 
179
int main(int argc, char **argv)
180
{
181
 
182
  int a,b,c;
183
  struct timespec start,end,diff;
184
 
185
  srand(sys_gettime(NULL));
186
 
187
  a = FTrace_chunk_create(1000000, 1000000, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);
188
  b = FTrace_chunk_create(1000000, 1000000, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_JTN);
189
  c = FTrace_chunk_create(1000000, 1000000, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);
190
 
191
  FTrace_chunk_link(a,b);
192
  FTrace_chunk_link(b,c);
193
 
194
  kern_gettime(&start);
195
  FTrace_enable();
196
 
197
  TRACER_LOGEVENT(FTrace_EVT_trace_start,0,0);
198
 
199
    instrumented_routine();
200
 
201
  TRACER_LOGEVENT(FTrace_EVT_trace_stop,0,0);  
202
 
203
  FTrace_disable();
204
  kern_gettime(&end);
205
 
206
  SUBTIMESPEC(&end,&start,&diff);
207
 
208
  printf_xy(1,21,WHITE,"Logged Time %d s %d us",(int)diff.tv_sec,(int)diff.tv_nsec/1000);
209
 
1490 giacomo 210
  group_kill(2);
211
  group_kill(3);
212
 
213
  FTrace_OSD_init_udp(1, "192.168.82.43", "192.168.82.20");
214
 
215
  FTrace_send_chunk(a, 0, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);
216
 
1489 giacomo 217
  sys_end();
218
 
219
  return 0;
220
 
221
}
222