Subversion Repositories shark

Rev

Rev 1381 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1085 pj 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
 *   Paolo Gai           <pj@gandalf.sssup.it>
10
 *   (see the web pages for full authors list)
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
 ------------
1550 pj 21
 CVS :        $Id: jetctrl.c,v 1.5 2005-01-08 14:35:17 pj Exp $
1085 pj 22
 
23
 File:        $File$
1550 pj 24
 Revision:    $Revision: 1.5 $
25
 Last update: $Date: 2005-01-08 14:35:17 $
1085 pj 26
 ------------
27
**/
28
 
29
/*
30
 * Copyright (C) 2000 Paolo Gai
31
 *
32
 * This program is free software; you can redistribute it and/or modify
33
 * it under the terms of the GNU General Public License as published by
34
 * the Free Software Foundation; either version 2 of the License, or
35
 * (at your option) any later version.
36
 *
37
 * This program is distributed in the hope that it will be useful,
38
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
40
 * GNU General Public License for more details.
41
 *
42
 * You should have received a copy of the GNU General Public License
43
 * along with this program; if not, write to the Free Software
44
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
45
 *
46
 */
47
 
48
 
49
// JetControl
50
 
51
#include "demo.h"
52
#include "kernel/func.h"
53
 
54
TASK jetdummy_task(void *arg)
55
{
56
  TIME   now_dummy, last_dummy, diff_dummy, slice;
57
  struct timespec now, last, diff;
58
  int x = 0;
59
  int height;
60
 
61
  NULL_TIMESPEC(&last);
62
  last_dummy = 0;
63
  for (;;) {
64
    task_nopreempt();
65
    jet_getstat(DUMMY_PID, NULL, NULL, NULL, &now_dummy);
66
    sys_gettime(&now);
67
    task_preempt();
68
 
69
    SUBTIMESPEC(&now, &last, &diff);
70
    slice = diff.tv_sec * 1000000 + diff.tv_nsec/1000;
71
    diff_dummy = now_dummy - last_dummy;
72
 
73
    height = (int)(JET_DUMMY_HEIGHT*((float)diff_dummy)/((float)slice));
74
 
75
    TIMESPEC_ASSIGN(&last, &now);
76
    last_dummy = now_dummy;
77
 
78
    grx_line(JET_DUMMY_X+x,JET_DUMMY_Y,
79
             JET_DUMMY_X+x,JET_DUMMY_Y+height          ,black);
80
    grx_line(JET_DUMMY_X+x,JET_DUMMY_Y+height,
81
             JET_DUMMY_X+x,JET_DUMMY_Y+JET_DUMMY_HEIGHT,white);
82
    grx_line(JET_DUMMY_X+(x+1)%JET_DUMMY_WIDTH,JET_DUMMY_Y,
83
             JET_DUMMY_X+(x+1)%JET_DUMMY_WIDTH,JET_DUMMY_Y+JET_DUMMY_HEIGHT,255);
84
 
85
    x = (x+1)%JET_DUMMY_WIDTH;
86
 
87
    task_endcycle();
88
  }
89
}
90
 
91
 
92
TASK jetctrl_task(void *arg)
93
{
94
  char st[50];
95
  TIME sum, max;
96
  int n;
97
 
98
  PID i;
99
  int printed = 0;
100
 
101
  for (;;) {
102
    for (i=2, printed=0; i<MAX_PROC && printed<JET_NTASK; i++) {
103
      if (jet_getstat(i, &sum, &max, &n, NULL) != -1) {
104
        if (!n) n=1;
105
        sprintf(st, "%6d %6d %10s", (int)sum/n, (int)max, proc_table[i].name);
106
        grx_text(st, 384, JET_Y_NAME+16+printed*8, gray, black);
107
        printed++;
108
      }
109
    }
110
    while (printed<JET_NTASK) {
111
      grx_text("                        ",
112
               384, JET_Y_NAME+16+printed*8, gray, black);
113
      printed++;
114
    }
115
    task_endcycle();
116
  }
117
}
118
 
119
TASK jetslide_task(void *arg)
120
{
121
  TIME sum, curr, max;
122
 
123
  TIME total[JET_NTASK];
124
  int slides[JET_NTASK];
125
 
126
  PID i;
127
  int printed = 0;
128
 
129
  for (;;) {
130
    // Fill the total array in a nonpreemptive section
131
    task_nopreempt();
132
    for (i=2, printed=0; i<MAX_PROC && printed<JET_NTASK; i++) {
133
      if (jet_getstat(i, &sum, NULL, NULL, &curr) != -1) {
134
        total[printed] = sum+curr;
135
        printed++;
136
      }
137
    }
138
    task_preempt();
139
 
140
    while (printed < JET_NTASK)
141
      total[printed++] = 0;
142
 
143
    // Compute the Max elapsed time
144
    max = 0;
145
    for (i=0; i<JET_NTASK; i++)
146
      if (total[i] > max) max = total[i];
147
    if (!max) max = 1;
148
 
149
    // Compute the slides width
150
    for (i=0; i<JET_NTASK; i++)
151
      slides[i] = (int)( (((float)total[i])/max) * JET_SLIDE_WIDTH);
152
 
153
    // print the data
154
    for (i=0; i<JET_NTASK; i++) {
155
      grx_box(JET_SLIDE_X,                 JET_Y_NAME+16+i*8,
156
              JET_SLIDE_X+slides[i],       JET_Y_NAME+23+i*8, gray);
157
      grx_box(JET_SLIDE_X+slides[i],       JET_Y_NAME+16+i*8,
158
              JET_SLIDE_X+JET_SLIDE_WIDTH, JET_Y_NAME+23+i*8, black);
159
    }
160
 
161
    while (i<JET_NTASK) {
162
      grx_box(JET_SLIDE_X,                 JET_Y_NAME+16+i*8,
163
              JET_SLIDE_X+JET_SLIDE_WIDTH, JET_Y_NAME+20+i*8, black);
164
      i++;
165
    }
166
    task_endcycle();
167
  }
168
}
169
 
170
 
171
void scenario_jetcontrol(void)
172
{
173
  grx_text("System load"         , 384, 45, rgb16(0,0,255), black);
174
  grx_line(384,55,639,55,red);
175
 
176
  grx_text("  Mean    Max Name  Slide", 384, JET_Y_NAME, gray, black);
177
  grx_line(384,JET_Y_NAME+10,639,JET_Y_NAME+10,gray);
178
 
179
  grx_rect(JET_DUMMY_X-1,               JET_DUMMY_Y-1,
180
           JET_DUMMY_X+JET_DUMMY_WIDTH, JET_DUMMY_Y+JET_DUMMY_HEIGHT+1, gray);
181
 
182
  grx_text("100%", JET_DUMMY_X-40, JET_DUMMY_Y, gray, black);
183
  grx_text("  0%", JET_DUMMY_X-40, JET_DUMMY_Y+JET_DUMMY_HEIGHT-8, gray, black);
184
 
185
  grx_line(JET_DUMMY_X-1, JET_DUMMY_Y, JET_DUMMY_X-5, JET_DUMMY_Y, gray);
186
  grx_line(JET_DUMMY_X-1, JET_DUMMY_Y+JET_DUMMY_HEIGHT, JET_DUMMY_X-5, JET_DUMMY_Y+JET_DUMMY_HEIGHT, gray);
187
}
188
 
189
void init_jetcontrol(void)
190
{
191
    SOFT_TASK_MODEL m3, m4, m5;
192
 
193
    PID p3, p4, p5;
194
 
195
    soft_task_default_model(m3);
1379 giacomo 196
    soft_task_def_level(m3,2);
1085 pj 197
    soft_task_def_period(m3, PERIOD_JETCTRL);
198
    soft_task_def_met(m3, WCET_JETCTRL);
199
    soft_task_def_ctrl_jet(m3);
200
    soft_task_def_group(m3, 1);
201
    p3 = task_create("jctrl", jetctrl_task, &m3, NULL);
202
    if (p3 == -1) {
1158 pj 203
        sys_shutdown_message("Could not create task <jetctrl> errno=%d",
204
                             errno);
1550 pj 205
        exit(1);
1085 pj 206
    }
207
 
208
    soft_task_default_model(m4);
1379 giacomo 209
    soft_task_def_level(m4,2);
1085 pj 210
    soft_task_def_period(m4, PERIOD_JETDUMMY);
211
    soft_task_def_met(m4, WCET_JETDUMMY);
212
    soft_task_def_group(m4, 1);
213
    soft_task_def_usemath(m4);
214
    soft_task_def_ctrl_jet(m4);
215
    p4 = task_create("jdmy", jetdummy_task, &m4, NULL);
216
    if (p4 == -1) {
1158 pj 217
        sys_shutdown_message("Could not create task <jetdummy> errno=%d",
218
                             errno);
1550 pj 219
        exit(1);
1085 pj 220
    }
221
 
222
    soft_task_default_model(m5);
1379 giacomo 223
    soft_task_def_level(m5,2);
1085 pj 224
    soft_task_def_period(m5, PERIOD_JETSLIDE);
225
    soft_task_def_met(m5, WCET_JETSLIDE);
226
    soft_task_def_group(m5, 1);
227
    soft_task_def_usemath(m5);
228
    soft_task_def_ctrl_jet(m5);
229
    p5 = task_create("jsli", jetslide_task, &m5, NULL);
230
    if (p5 == -1) {
1158 pj 231
        sys_shutdown_message("Could not create task <jetslide> errno=%d",
232
                             errno);
1550 pj 233
        exit(1);
1085 pj 234
    }
235
}
236