Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1085 pj 1
/*
2
 *
3
 *
4
 */
5
 
6
#include "config.h"
7
 
8
#include <kernel/func.h>
9
#include <kernel/model.h>
10
#include <kernel/const.h>
11
 
12
#include <drivers/glib.h>
13
 
14
#include <stdlib.h>
15
#include <assert.h>
16
 
17
#include "mutex.h"
18
#include "gload.h"
19
 
20
#define PERIOD  250000
21
#define WCET      1000
22
 
23
#ifdef FULLCOLOR
24
 
25
#define BARCOLOR rgb16(255,0,0)
26
#define BARBG    rgb16(0,0,0)
27
 
28
#define TEXTCOLOR rgb16(255,255,255)
29
#define TEXTBG    rgb16(0,0,0)
30
 
31
#else
32
 
33
#define BARCOLOR 128
34
#define BARBG      0
35
 
36
#define TEXTCOLOR 255
37
#define TEXTBG    0
38
 
39
#endif
40
 
41
#define XC (32+64)
42
#define YC 450
43
#define LEN 100
44
#define BOR 8
45
 
46
extern void draw_frame(int x, int y, int dx, int dy);
47
 
48
/* only for NRT task */
49
static TASK monitorload(void *arg)
50
{
51
  int oy,y;
52
  PID pid=(PID)arg;
53
  TIME sum,old;
54
  int res;
55
 
56
  res=jet_getstat(pid,NULL,NULL,NULL,&old);
57
  task_endcycle();
58
 
59
  oy=YC+LEN-1;
60
  for (;;) {
61
    res=jet_getstat(pid,NULL,NULL,NULL,&sum);
62
    if (res==-1) break;
63
#ifndef NOGRX
64
    y=YC+LEN*(sum-old)/PERIOD-1;
65
    if (y!=oy) {
66
      grxlock();
67
      if (y<oy) grx_box(XC,y,XC+BOR-1,oy,BARCOLOR);
68
      else grx_box(XC,oy,XC+BOR-1,y,BARBG);
69
      grxunlock();
70
      oy=y;
71
    }
72
#else
73
    n++;
74
    if (n%4==0)
75
      cprintf("#%li,%i#",sum); //(1000-sum*1000/PERIOD);
76
#endif
77
    old=sum;
78
    task_endcycle();
79
  }
80
  return 0;
81
}
82
 
83
int gload_init(int taskpid)
84
{
85
  SOFT_TASK_MODEL model;
86
  PID pid;
87
 
88
  soft_task_default_model(model);        
89
  soft_task_def_met(model,WCET);
90
  soft_task_def_wcet(model,WCET);
91
  soft_task_def_period(model,PERIOD);
92
  soft_task_def_periodic(model);
93
  soft_task_def_arg(model,(void*)taskpid);
94
  /*soft_task_def_group(model,group);*/
95
 
96
  pid=task_create("load",monitorload,&model,NULL);
97
  if (pid==-1) return -6;
98
 
99
#ifndef NOGRX
100
  draw_frame(XC,YC,BOR,LEN);
101
  grxlock();
102
  grx_text("Load",XC-10,YC+LEN+BOR*2,TEXTCOLOR,TEXTBG);
103
  grx_text("100%",XC+BOR*2+1,YC-4,TEXTCOLOR,TEXTBG);
104
  grx_text(" 75%",XC+BOR*2+1,YC+LEN/4-4,TEXTCOLOR,TEXTBG);
105
  grx_text(" 50%",XC+BOR*2+1,YC+LEN/4*2-4,TEXTCOLOR,TEXTBG);
106
  grx_text(" 25%",XC+BOR*2+1,YC+LEN/4*3-4,TEXTCOLOR,TEXTBG);
107
  grx_text("  0%",XC+BOR*2+1,YC+LEN-4,TEXTCOLOR,TEXTBG);
108
  grxunlock();
109
#endif
110
 
111
  return pid;
112
}
113