Subversion Repositories shark

Rev

Rev 1085 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*
 *
 *
 */


#include "config.h"

#include <kernel/func.h>
#include <kernel/model.h>
#include <kernel/const.h>

#include <drivers/glib.h>

#include <stdlib.h>
#include <assert.h>

#include "mutex.h"
#include "gload.h"

#define PERIOD  250000
#define WCET      1000

#ifdef FULLCOLOR

#define BARCOLOR rgb16(255,0,0)
#define BARBG    rgb16(0,0,0)

#define TEXTCOLOR rgb16(255,255,255)
#define TEXTBG    rgb16(0,0,0)

#else

#define BARCOLOR 128
#define BARBG      0

#define TEXTCOLOR 255
#define TEXTBG    0

#endif

#define XC (32+64)
#define YC 450
#define LEN 100
#define BOR 8

extern void draw_frame(int x, int y, int dx, int dy);

/* only for NRT task */
static TASK monitorload(void *arg)
{
  int oy,y;
  PID pid=(PID)arg;
  TIME sum,old;
  int res;

  res=jet_getstat(pid,NULL,NULL,NULL,&old);
  task_endcycle();

  oy=YC+LEN-1;
  for (;;) {
    res=jet_getstat(pid,NULL,NULL,NULL,&sum);
    if (res==-1) break;
#ifndef NOGRX
    y=YC+LEN*(sum-old)/PERIOD-1;
    if (y!=oy) {
      grxlock();
      if (y<oy) grx_box(XC,y,XC+BOR-1,oy,BARCOLOR);
      else grx_box(XC,oy,XC+BOR-1,y,BARBG);
      grxunlock();
      oy=y;
    }
#else
    n++;
    if (n%4==0)
      cprintf("#%li,%i#",sum); //(1000-sum*1000/PERIOD);
#endif
    old=sum;
    task_endcycle();
  }
  return 0;
}

int gload_init(int taskpid)
{
  SOFT_TASK_MODEL model;
  PID pid;
 
  soft_task_default_model(model);        
  soft_task_def_met(model,WCET);
  soft_task_def_wcet(model,WCET);
  soft_task_def_period(model,PERIOD);
  soft_task_def_periodic(model);
  soft_task_def_arg(model,(void*)taskpid);
  /*soft_task_def_group(model,group);*/
   
  pid=task_create("load",monitorload,&model,NULL);
  if (pid==-1) return -6;

#ifndef NOGRX
  draw_frame(XC,YC,BOR,LEN);
  grxlock();
  grx_text("Load",XC-10,YC+LEN+BOR*2,TEXTCOLOR,TEXTBG);
  grx_text("100%",XC+BOR*2+1,YC-4,TEXTCOLOR,TEXTBG);
  grx_text(" 75%",XC+BOR*2+1,YC+LEN/4-4,TEXTCOLOR,TEXTBG);
  grx_text(" 50%",XC+BOR*2+1,YC+LEN/4*2-4,TEXTCOLOR,TEXTBG);
  grx_text(" 25%",XC+BOR*2+1,YC+LEN/4*3-4,TEXTCOLOR,TEXTBG);
  grx_text("  0%",XC+BOR*2+1,YC+LEN-4,TEXTCOLOR,TEXTBG);
  grxunlock();
#endif
 
  return pid;
}