Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1627 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     :
1644 anton 9
 *   Giacomo Guidi       <giacomo@gandalf.sssup.it>
10
 *   Anton Cervin
1627 giacomo 11
 *
12
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
13
 *
14
 * http://www.sssup.it
15
 * http://retis.sssup.it
16
 * http://shark.sssup.it
17
 */
18
 
19
/*
20
 * This program is free software; you can redistribute it and/or modify
21
 * it under the terms of the GNU General Public License as published by
22
 * the Free Software Foundation; either version 2 of the License, or
23
 * (at your option) any later version.
24
 *
25
 * This program is distributed in the hope that it will be useful,
26
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
 * GNU General Public License for more details.
29
 *
30
 * You should have received a copy of the GNU General Public License
31
 * along with this program; if not, write to the Free Software
32
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
33
 */
34
 
35
#include "kernel/kern.h"
1643 anton 36
#include "time.h"
1631 anton 37
#include "modules/elastic.h"
1639 anton 38
#include <drivers/shark_keyb26.h>
1627 giacomo 39
 
1643 anton 40
 
1639 anton 41
#define MAX_TASKS 7
1631 anton 42
 
1639 anton 43
 
1643 anton 44
/* A task that scrolls a number (the task number) across the screen */
1639 anton 45
 
1627 giacomo 46
TASK elastic_test(void *arg) {
47
 
1639 anton 48
  int y = (int)arg;
1643 anton 49
  int x = 0;  
1629 anton 50
 
1639 anton 51
  char str[2];
1643 anton 52
  str[0] = '0' + y + 1;
1639 anton 53
  str[1] = '\0';
54
 
1627 giacomo 55
  while(1) {
1639 anton 56
    puts_xy(x,y,LIGHTGRAY," ");
57
    x = (x + 1) % 80;
58
    puts_xy(x,y,LIGHTGRAY,str);
59
    task_testcancel();
1627 giacomo 60
    task_endcycle();
61
  }
62
}
63
 
1643 anton 64
/* A simple keyboard string input routine */
1639 anton 65
 
1643 anton 66
void myinput(char *query, char *buf, int len) {
1639 anton 67
  BYTE c;
68
  int n = 0;
69
 
1643 anton 70
  cprintf(query);
71
 
1639 anton 72
  do {
73
    c = keyb_getch(NON_BLOCK);
1643 anton 74
    if (c == '\r') break;
75
    if (c == '\b') {
1639 anton 76
      if (n > 0) {
1643 anton 77
        cprintf("%c", '\b');
1639 anton 78
        n--;
79
      }
1642 anton 80
    } else if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z')) {
1639 anton 81
      cprintf("%c", c);
82
      buf[n++] = c;
83
    }
84
  } while (n < len);
85
 
86
  buf[n] = '\0';
87
  cprintf("\n");
88
}
89
 
1643 anton 90
/* The main program */
1639 anton 91
 
1627 giacomo 92
int main(int argc, char **argv)
93
{
1639 anton 94
  ELASTIC_TASK_MODEL e;
95
  PID el_pid;
1642 anton 96
  PID pidvec[MAX_TASKS];
1639 anton 97
  int quit = 0;
98
  char buf[80];
99
  int y;
100
  int Tmin, Tmax, C, E, T, nbr, i;
1644 anton 101
  double U, Umax;
1627 giacomo 102
 
1643 anton 103
  for (i=0; i<MAX_TASKS; i++) pidvec[i] = NIL;
1639 anton 104
  clear();
1627 giacomo 105
 
1643 anton 106
  /* Create predefined task 1 */
107
  elastic_task_default_model(e);
108
  elastic_task_def_period(e, 50000, 200000);
109
  elastic_task_def_wcet(e, 25000);
110
  elastic_task_def_param(e, 5, PERIOD_SCALING);
111
  elastic_task_def_arg(e, (void *)0);
112
  el_pid = task_create("Elastic",elastic_test,&e,NULL);
113
  if (el_pid == NIL) {
114
    cprintf("ELASTIC_public_create failed!\n");
115
  } else {
116
    pidvec[0] = el_pid;
117
    task_activate(el_pid);
118
  }
119
 
120
  /* Create predefined task 2 */
121
  elastic_task_default_model(e);
122
  elastic_task_def_period(e, 100000, 150000);
123
  elastic_task_def_wcet(e, 40000);
124
  elastic_task_def_param(e, 10, PERIOD_SCALING);
125
  elastic_task_def_arg(e, (void *)1);
126
  el_pid = task_create("Elastic",elastic_test,&e,NULL);
127
  if (el_pid == NIL) {
128
    cprintf("ELASTIC_public_create failed!\n");
129
  } else {
130
    pidvec[1] = el_pid;
131
    task_activate(el_pid);
132
  }
133
 
1639 anton 134
  do {
1631 anton 135
 
1644 anton 136
    /* Print task table */
1639 anton 137
    for (y = 7; y <=15; y++) {
138
      puts_xy(0,y,LIGHTGRAY,"                                                                                ");
139
    }
140
    place(0,7);
1627 giacomo 141
 
1639 anton 142
    U = 0.0;
1644 anton 143
    Umax = 0.0;
1639 anton 144
    cprintf("Nbr  Tmin  Tmax    C     E     T  \n");
145
    for (i=0; i<MAX_TASKS; i++) {
146
      if (pidvec[i] != NIL) {
1644 anton 147
        Tmin = ELASTIC_get_Tmin(pidvec[i]);
148
        Tmax = ELASTIC_get_Tmax(pidvec[i]);
149
        C = ELASTIC_get_C(pidvec[i]);
1639 anton 150
        E = ELASTIC_get_E(pidvec[i]);
1644 anton 151
        T = ELASTIC_get_period(pidvec[i]);
1639 anton 152
        U += (double)C/(double)T;
1644 anton 153
        Umax += (double)C/(double)Tmin;
154
        cprintf(" %1d   %4d  %4d  %4d  %4d  %4d\n", i+1, Tmin/1000, Tmax/1000, C/1000, E, T/1000);
1639 anton 155
      }
156
    }
1644 anton 157
    cprintf("Maximum utilization: %5.3f   Actual utilization: %5.3f\n", Umax, U);
1631 anton 158
 
1639 anton 159
    puts_xy(0,16,LIGHTGRAY,"                                                                                ");
160
    place(0,16);
1627 giacomo 161
 
1643 anton 162
    myinput("(q)uit, (c)reate, (k)ill, force (p)eriod, change (e)lasticity? ", buf, 10);
1639 anton 163
    for (y = 17; y <=24; y++) {
164
      puts_xy(0,y,LIGHTGRAY,"                                                                                ");
165
    }
1631 anton 166
 
1639 anton 167
    switch (buf[0]) {
1643 anton 168
 
169
      /* Quit */
1639 anton 170
    case 'q':
171
      quit = 1;
172
      break;
1643 anton 173
 
174
      /* Create task */
1639 anton 175
    case 'c':
1643 anton 176
      cprintf("Create task");
1639 anton 177
      for (i=0; i<MAX_TASKS; i++) {
178
        if (pidvec[i] == NIL) break;
179
      }
180
      if (i == MAX_TASKS) {
1643 anton 181
        cprintf("\nNo more task slots available!\n");
1639 anton 182
        break;
1643 anton 183
      } else {
184
        cprintf(" %d\n", i+1);
1639 anton 185
      }
186
      myinput("Tmin (ms): ", buf, 10);
187
      Tmin = 1000*atoi(buf);
188
      myinput("Tmax (ms): ", buf, 10);
189
      Tmax = 1000*atoi(buf);
190
      myinput("C (ms): ", buf, 10);
191
      C = 1000*atoi(buf);
192
      myinput("E: ", buf, 10);
193
      E = atoi(buf);
194
      elastic_task_default_model(e);
195
      elastic_task_def_period(e, Tmin, Tmax);
196
      elastic_task_def_wcet(e, C);
197
      elastic_task_def_param(e, E, PERIOD_SCALING);
198
      elastic_task_def_arg(e, (void *)i);
199
      el_pid = task_create("Elastic",elastic_test,&e,NULL);
200
      if (el_pid == NIL) {
1643 anton 201
        cprintf("ELASTIC_public_create failed!\n");
1639 anton 202
      } else {
203
        pidvec[i] = el_pid;
204
        task_activate(el_pid);
205
      }
206
      break;
1643 anton 207
 
208
      /* Force period */
1642 anton 209
    case 'p':
1639 anton 210
      myinput("Force period\nTask nbr: ", buf, 10);
211
      nbr = atoi(buf);
1643 anton 212
      if (nbr < 1 || nbr > MAX_TASKS) {
1639 anton 213
        cprintf("Invalid task number!\n");
214
        break;
215
      }
1643 anton 216
      el_pid = pidvec[nbr-1];
1639 anton 217
      if (el_pid == NIL) {
1643 anton 218
        cprintf("Task does not exist!\n");
1639 anton 219
        break;
220
      }
221
      myinput("T (ms): ", buf, 10);
222
      T = 1000*atoi(buf);
1642 anton 223
      if (ELASTIC_set_period(el_pid, T) == -1) {
224
        cprintf("ELASTIC_set_period failed!\n");
225
      }
1639 anton 226
      break;
1643 anton 227
 
228
      /* Kill task */
1642 anton 229
    case 'k':
230
      myinput("Kill task\nTask nbr: ", buf, 10);
1639 anton 231
      nbr = atoi(buf);
1643 anton 232
      if (nbr < 1 || nbr > MAX_TASKS) {
1639 anton 233
        cprintf("Invalid task number!\n");
234
        break;
235
      }
1643 anton 236
      el_pid = pidvec[nbr-1];
1639 anton 237
      if (el_pid == NIL) {
1643 anton 238
        cprintf("Task does not exist!\n");
1639 anton 239
        break;
240
      }
241
      task_kill(el_pid);
1643 anton 242
      pidvec[nbr-1] = NIL;
243
      usleep(500000);  // wait half a second before redrawing the task table!!!
244
      /* also erase task number */
245
      puts_xy(0,nbr-1,LIGHTGRAY,"                                                                                ");
1639 anton 246
      break;
1643 anton 247
 
248
      /* Set elasticity */
1642 anton 249
    case 'e':
250
      myinput("Set elasticity\nTask nbr: ", buf, 10);
251
      nbr = atoi(buf);
1643 anton 252
      if (nbr < 1 || nbr > MAX_TASKS) {
1642 anton 253
        cprintf("Invalid task number!\n");
254
        break;
255
      }
1643 anton 256
      el_pid = pidvec[nbr-1];
1642 anton 257
      if (el_pid == NIL) {
1643 anton 258
        cprintf("Task does not exist!\n");
1642 anton 259
        break;
260
      }
261
      myinput("E: ", buf, 10);
262
      E = atoi(buf);
263
      if (ELASTIC_set_E(el_pid, E) == -1) {
264
        cprintf("ELASTIC_set_E failed!\n");
265
      }
266
      break;
1643 anton 267
 
1639 anton 268
    default:
269
      cprintf("Unknown command\n");
270
      break;
271
    }
1631 anton 272
 
1639 anton 273
  } while (!quit);
1631 anton 274
 
1650 pj 275
  exit(1);
1628 giacomo 276
 
1627 giacomo 277
  return 0;
278
 
279
}