Subversion Repositories shark

Rev

Rev 1086 | Rev 1379 | Go to most recent revision | 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
 ------------
1158 pj 21
 CVS :        $Id: jetctrl.c,v 1.2 2003-05-01 19:43:17 pj Exp $
1085 pj 22
 
23
 File:        $File$
1158 pj 24
 Revision:    $Revision: 1.2 $
25
 Last update: $Date: 2003-05-01 19:43: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
    mutex_lock(&mutex);
79
    grx_line(JET_DUMMY_X+x,JET_DUMMY_Y,
80
             JET_DUMMY_X+x,JET_DUMMY_Y+height          ,black);
81
    grx_line(JET_DUMMY_X+x,JET_DUMMY_Y+height,
82
             JET_DUMMY_X+x,JET_DUMMY_Y+JET_DUMMY_HEIGHT,white);
83
    grx_line(JET_DUMMY_X+(x+1)%JET_DUMMY_WIDTH,JET_DUMMY_Y,
84
             JET_DUMMY_X+(x+1)%JET_DUMMY_WIDTH,JET_DUMMY_Y+JET_DUMMY_HEIGHT,255);
85
    mutex_unlock(&mutex);
86
 
87
    x = (x+1)%JET_DUMMY_WIDTH;
88
 
89
    task_endcycle();
90
  }
91
}
92
 
93
 
94
TASK jetctrl_task(void *arg)
95
{
96
  char st[50];
97
  TIME sum, max;
98
  int n;
99
 
100
  PID i;
101
  int printed = 0;
102
 
103
  for (;;) {
104
    for (i=2, printed=0; i<MAX_PROC && printed<JET_NTASK; i++) {
105
      if (jet_getstat(i, &sum, &max, &n, NULL) != -1) {
106
        if (!n) n=1;
107
        sprintf(st, "%6d %6d %10s", (int)sum/n, (int)max, proc_table[i].name);
108
        mutex_lock(&mutex);
109
        grx_text(st, 384, JET_Y_NAME+16+printed*8, gray, black);
110
        mutex_unlock(&mutex);
111
        printed++;
112
      }
113
    }
114
    while (printed<JET_NTASK) {
115
      mutex_lock(&mutex);
116
      grx_text("                        ",
117
               384, JET_Y_NAME+16+printed*8, gray, black);
118
      mutex_unlock(&mutex);
119
      printed++;
120
    }
121
    task_endcycle();
122
  }
123
}
124
 
125
TASK jetslide_task(void *arg)
126
{
127
  TIME sum, curr, max;
128
 
129
  TIME total[JET_NTASK];
130
  int slides[JET_NTASK];
131
 
132
  PID i;
133
  int printed = 0;
134
 
135
  for (;;) {
136
    // Fill the total array in a nonpreemptive section
137
    task_nopreempt();
138
    for (i=2, printed=0; i<MAX_PROC && printed<JET_NTASK; i++) {
139
      if (jet_getstat(i, &sum, NULL, NULL, &curr) != -1) {
140
        total[printed] = sum+curr;
141
        printed++;
142
      }
143
    }
144
    task_preempt();
145
 
146
    while (printed < JET_NTASK)
147
      total[printed++] = 0;
148
 
149
    // Compute the Max elapsed time
150
    max = 0;
151
    for (i=0; i<JET_NTASK; i++)
152
      if (total[i] > max) max = total[i];
153
    if (!max) max = 1;
154
 
155
    // Compute the slides width
156
    for (i=0; i<JET_NTASK; i++)
157
      slides[i] = (int)( (((float)total[i])/max) * JET_SLIDE_WIDTH);
158
 
159
    // print the data
160
    mutex_lock(&mutex);
161
    for (i=0; i<JET_NTASK; i++) {
162
      grx_box(JET_SLIDE_X,                 JET_Y_NAME+16+i*8,
163
              JET_SLIDE_X+slides[i],       JET_Y_NAME+23+i*8, gray);
164
      grx_box(JET_SLIDE_X+slides[i],       JET_Y_NAME+16+i*8,
165
              JET_SLIDE_X+JET_SLIDE_WIDTH, JET_Y_NAME+23+i*8, black);
166
    }
167
 
168
    while (i<JET_NTASK) {
169
      grx_box(JET_SLIDE_X,                 JET_Y_NAME+16+i*8,
170
              JET_SLIDE_X+JET_SLIDE_WIDTH, JET_Y_NAME+20+i*8, black);
171
      i++;
172
    }
173
    mutex_unlock(&mutex);
174
    task_endcycle();
175
  }
176
}
177
 
178
 
179
void scenario_jetcontrol(void)
180
{
181
  grx_text("System load"         , 384, 45, rgb16(0,0,255), black);
182
  grx_line(384,55,639,55,red);
183
 
184
  grx_text("  Mean    Max Name  Slide", 384, JET_Y_NAME, gray, black);
185
  grx_line(384,JET_Y_NAME+10,639,JET_Y_NAME+10,gray);
186
 
187
  grx_rect(JET_DUMMY_X-1,               JET_DUMMY_Y-1,
188
           JET_DUMMY_X+JET_DUMMY_WIDTH, JET_DUMMY_Y+JET_DUMMY_HEIGHT+1, gray);
189
 
190
  grx_text("100%", JET_DUMMY_X-40, JET_DUMMY_Y, gray, black);
191
  grx_text("  0%", JET_DUMMY_X-40, JET_DUMMY_Y+JET_DUMMY_HEIGHT-8, gray, black);
192
 
193
  grx_line(JET_DUMMY_X-1, JET_DUMMY_Y, JET_DUMMY_X-5, JET_DUMMY_Y, gray);
194
  grx_line(JET_DUMMY_X-1, JET_DUMMY_Y+JET_DUMMY_HEIGHT, JET_DUMMY_X-5, JET_DUMMY_Y+JET_DUMMY_HEIGHT, gray);
195
}
196
 
197
void init_jetcontrol(void)
198
{
199
    SOFT_TASK_MODEL m3, m4, m5;
200
 
201
    PID p3, p4, p5;
202
 
203
    soft_task_default_model(m3);
204
    soft_task_def_level(m3,1);
205
    soft_task_def_period(m3, PERIOD_JETCTRL);
206
    soft_task_def_met(m3, WCET_JETCTRL);
207
    soft_task_def_ctrl_jet(m3);
208
    soft_task_def_group(m3, 1);
209
    p3 = task_create("jctrl", jetctrl_task, &m3, NULL);
210
    if (p3 == -1) {
1158 pj 211
        sys_shutdown_message("Could not create task <jetctrl> errno=%d",
212
                             errno);
1085 pj 213
        sys_end();
214
    }
215
 
216
    soft_task_default_model(m4);
217
    soft_task_def_level(m4,1);
218
    soft_task_def_period(m4, PERIOD_JETDUMMY);
219
    soft_task_def_met(m4, WCET_JETDUMMY);
220
    soft_task_def_group(m4, 1);
221
    soft_task_def_usemath(m4);
222
    soft_task_def_ctrl_jet(m4);
223
    p4 = task_create("jdmy", jetdummy_task, &m4, NULL);
224
    if (p4 == -1) {
1158 pj 225
        sys_shutdown_message("Could not create task <jetdummy> errno=%d",
226
                             errno);
1085 pj 227
        sys_end();
228
    }
229
 
230
    soft_task_default_model(m5);
231
    soft_task_def_level(m5,1);
232
    soft_task_def_period(m5, PERIOD_JETSLIDE);
233
    soft_task_def_met(m5, WCET_JETSLIDE);
234
    soft_task_def_group(m5, 1);
235
    soft_task_def_usemath(m5);
236
    soft_task_def_ctrl_jet(m5);
237
    p5 = task_create("jsli", jetslide_task, &m5, NULL);
238
    if (p5 == -1) {
1158 pj 239
        sys_shutdown_message("Could not create task <jetslide> errno=%d",
240
                             errno);
1085 pj 241
        sys_end();
242
    }
243
}
244