Subversion Repositories shark

Rev

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

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