Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1659 giacomo 1
#include "kernel/kern.h"
2
#include "demo.h"
3
 
4
extern int white, gray, red, green, blue;
5
 
6
 
7
 
8
TASK jetdummy_task(void *arg)
9
{
10
  TIME   now_dummy, last_dummy, diff_dummy, slice;
11
  struct timespec now, last, diff;
12
  int x = 0;
13
  int height;
14
 
15
  NULL_TIMESPEC(&last);
16
  last_dummy = 0;
17
  for (;;) {
18
    task_nopreempt();
19
    jet_getstat(DUMMY_PID, NULL, NULL, NULL, &now_dummy);
20
    sys_gettime(&now);
21
    task_preempt();
22
 
23
    SUBTIMESPEC(&now, &last, &diff);
24
    slice = diff.tv_sec * 1000000 + diff.tv_nsec/1000;
25
    diff_dummy = now_dummy - last_dummy;
26
 
27
    height = (int)(JET_DUMMY_HEIGHT*((float)diff_dummy)/((float)slice));
28
 
29
    TIMESPEC_ASSIGN(&last, &now);
30
    last_dummy = now_dummy;
31
 
32
 
33
 
34
    mutex_lock(&mutex);
35
    grx_line(JET_DUMMY_X+x,JET_DUMMY_Y,
36
             JET_DUMMY_X+x,JET_DUMMY_Y+height          ,BLACK);
37
    grx_line(JET_DUMMY_X+x,JET_DUMMY_Y+height,
38
             JET_DUMMY_X+x,JET_DUMMY_Y+JET_DUMMY_HEIGHT,white);
39
    grx_line(JET_DUMMY_X+(x+1)%JET_DUMMY_WIDTH,JET_DUMMY_Y,
40
             JET_DUMMY_X+(x+1)%JET_DUMMY_WIDTH,JET_DUMMY_Y+JET_DUMMY_HEIGHT,white);
41
    mutex_unlock(&mutex);
42
 
43
    x = (x+1)%JET_DUMMY_WIDTH;
44
 
45
    task_endcycle();
46
  }
47
}
48
 
49
 
50
TASK jetctrl_task(void *arg)
51
{
52
  char st[50];
53
  TIME sum, max;
54
  int n;
55
 
56
  PID i;
57
  int printed = 0;
58
 
59
  for (;;) {
60
    for (i=2, printed=0; i<MAX_PROC && printed<JET_NTASK; i++) {
61
      if (jet_getstat(i, &sum, &max, &n, NULL) != -1) {
62
        if (!n) n=1;
63
        mutex_lock(&mutex);
64
        sprintf(st,"%6d  %6d   %10s", (int)sum/n,(int)max, proc_table[i].name);
65
        grx_text(st, 354, JET_Y_NAME+16+printed*10, green, BLACK);
66
        mutex_unlock(&mutex);
67
        printed++;
68
      }
69
    }
70
    while (printed<JET_NTASK) {
71
      mutex_lock(&mutex);
72
      grx_text("                        ",
73
               354, JET_Y_NAME+16+printed*10, gray, BLACK);
74
      mutex_unlock(&mutex);
75
      printed++;
76
    }
77
    task_endcycle();
78
  }
79
}
80
 
81
TASK jetslide_task(void *arg)
82
{
83
  TIME sum, curr, max;
84
 
85
  TIME total[JET_NTASK];
86
  int slides[JET_NTASK];
87
 
88
  PID i;
89
  int printed = 0;
90
 
91
  for (;;) {
92
    // Fill the total array in a nonpreemptive section
93
    task_nopreempt();
94
    for (i=2, printed=0; i<MAX_PROC && printed<JET_NTASK; i++) {
95
      if (jet_getstat(i, &sum, NULL, NULL, &curr) != -1) {
96
        total[printed] = sum+curr;
97
        printed++;
98
      }
99
    }
100
    task_preempt();
101
 
102
    while (printed < JET_NTASK)
103
      total[printed++] = 0;
104
 
105
    // Compute the Max elapsed time
106
    max = 0;
107
    for (i=0; i<JET_NTASK; i++)
108
      if (total[i] > max) max = total[i];
109
    if (!max) max = 1;
110
 
111
    // Compute the slides width
112
    for (i=0; i<JET_NTASK; i++)
113
      slides[i] = (int)( (((float)total[i])/max) * JET_SLIDE_WIDTH);
114
 
115
    // print the data
116
    mutex_lock(&mutex);
117
    for (i=0; i<JET_NTASK; i++) {
118
      grx_box(JET_SLIDE_X,                 JET_Y_NAME+16+i*10, \
119
	      JET_SLIDE_X+slides[i],       JET_Y_NAME+23+i*10, blue);
120
      grx_box(JET_SLIDE_X+slides[i],       JET_Y_NAME+16+i*10, \
121
	      JET_SLIDE_X+JET_SLIDE_WIDTH, JET_Y_NAME+23+i*10, BLACK);
122
    }
123
 
124
    while (i<JET_NTASK) {
125
      grx_box(JET_SLIDE_X,                 JET_Y_NAME+16+i*10, \
126
              JET_SLIDE_X+JET_SLIDE_WIDTH, JET_Y_NAME+20+i*10, BLACK);
127
      i++;
128
    }
129
    mutex_unlock(&mutex);
130
    task_endcycle();
131
  }
132
}
133
 
134
 
135
void scenario_jetcontrol(void)
136
{     mutex_lock(&mutex);
137
  grx_rect(10,JET_DUMMY_Y-30, JET_DUMMY_X+600,JET_DUMMY_Y+70,red);
138
 
139
  grx_text("System load" , JET_DUMMY_X+36  ,JET_DUMMY_Y-16 , green, BLACK);
140
 
141
  grx_text("   Mean    Max     Name        Slide",354 ,JET_Y_NAME, green,BLACK);
142
 
143
  grx_rect(JET_DUMMY_X-1, JET_DUMMY_Y-1, JET_DUMMY_X+JET_DUMMY_WIDTH, JET_DUMMY_Y+JET_DUMMY_HEIGHT+1, gray);
144
 
145
  grx_text("100%", JET_DUMMY_X-40, JET_DUMMY_Y, green, BLACK);
146
  grx_text("  0%", JET_DUMMY_X-40, JET_DUMMY_Y+JET_DUMMY_HEIGHT-8,green,BLACK);
147
 
148
  grx_line(JET_DUMMY_X-1, JET_DUMMY_Y, JET_DUMMY_X-5, JET_DUMMY_Y, gray);
149
  grx_line(JET_DUMMY_X-1, JET_DUMMY_Y+JET_DUMMY_HEIGHT, JET_DUMMY_X-5, JET_DUMMY_Y+JET_DUMMY_HEIGHT, gray);
150
     mutex_unlock(&mutex);
151
}
152
 
153
 
154
void init_jetcontrol(void)
155
{
156
    SOFT_TASK_MODEL m3, m4, m5;
157
 
158
    PID p3, p4, p5;
159
 
160
    soft_task_default_model(m3);
161
    soft_task_def_level(m3,1);
162
    soft_task_def_period(m3, PERIOD_JETCTRL);
163
    soft_task_def_met(m3, WCET_JETCTRL);
164
    soft_task_def_ctrl_jet(m3);
165
    soft_task_def_group(m3, 1);
166
    p3 = task_create("jctrl", jetctrl_task, &m3, NULL);
167
    if (p3 == -1) {
168
        grx_close();
169
	perror("FFTPlay: Could not create task <jetctrl>\n");
170
        ll_abort(54);
171
	sys_end();
172
    }
173
 
174
    soft_task_default_model(m4);
175
    soft_task_def_level(m4,1);
176
    soft_task_def_period(m4, PERIOD_JETDUMMY);
177
    soft_task_def_met(m4, WCET_JETDUMMY);
178
    soft_task_def_group(m4, 1);
179
    soft_task_def_usemath(m4);
180
    soft_task_def_ctrl_jet(m4);
181
    p4 = task_create("jdmy", jetdummy_task, &m4, NULL);
182
    if (p4 == -1) {
183
        grx_close();
184
	perror("FFTPlay: Could not create task <jetdummy>\n");
185
        ll_abort(54);
186
	sys_end();
187
    }
188
 
189
    soft_task_default_model(m5);
190
    soft_task_def_level(m5,1);
191
    soft_task_def_period(m5, PERIOD_JETSLIDE);
192
    soft_task_def_met(m5, WCET_JETSLIDE);
193
    soft_task_def_group(m5, 1);
194
    soft_task_def_usemath(m5);
195
    soft_task_def_ctrl_jet(m5);
196
    p5 = task_create("jsli", jetslide_task, &m5, NULL);
197
    if (p5 == -1) {
198
        grx_close();
199
	perror("FFTPlay: Could not create task <jetslide>\n");
200
        ll_abort(54);
201
	sys_end();
202
    }
203
}
204
 
205