Subversion Repositories shark

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

/*
 * Project: S.Ha.R.K.
 *
 * Coordinators:
 *   Giorgio Buttazzo    <giorgio@sssup.it>
 *   Paolo Gai           <pj@gandalf.sssup.it>
 *
 * Authors     :
 *   Paolo Gai           <pj@gandalf.sssup.it>
 *   (see the web pages for full authors list)
 *
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
 *
 * http://www.sssup.it
 * http://retis.sssup.it
 * http://shark.sssup.it
 */


/**
 ------------
 CVS :        $Id: static.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $

 File:        $File$
 Revision:    $Revision: 1.1.1.1 $
 Last update: $Date: 2002-09-02 09:37:48 $
 ------------
**/


/*
 * Copyright (C) 2001 Paolo Gai
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */


#include "static.h"
#include <ll/stdio.h>
#include <ll/string.h>
#include <kernel/model.h>
#include <kernel/descr.h>
#include <kernel/var.h>
#include <kernel/func.h>
#include <kernel/trace.h>

#define STATIC_printf kern_printf
//#define STATIC_printf printk

/*+ Status used in the level +*/
#define STATIC_READY         MODULE_STATUS_BASE    /*+ - Ready status        +*/
#define STATIC_IDLE          MODULE_STATUS_BASE+4  /*+ to wait the deadline  +*/

/*+ flags +*/
#define STATIC_FLAG_NORAISEEXC  2

/*+ the level redefinition for the Earliest Deadline First level +*/
typedef struct {
  level_des l;     /*+ the standard level descriptor          +*/

  QUEUE mytable;

  PID currenttask;

  struct timespec hp;
  struct timespec ref;

} STATIC_level_des;

static void STATIC_offset_activate(void *par)
{
  PID p = (PID) par;
  STATIC_level_des *lev;

  lev = (STATIC_level_des *)level_table[proc_table[p].task_level];

  lev->currenttask = p;
  event_need_reschedule();

  STATIC_printf("(o p%d t%d)", p, (int)proc_table[p].timespec_priority.tv_sec);
}

static void STATIC_activateall(STATIC_level_des *lev)
{
  PID my_table_index;
  struct timespec x;

  STATIC_printf("(A ");

  for (my_table_index = (PID)lev->mytable;
       my_table_index != NIL;
       my_table_index = proc_table[my_table_index].next) {
    ADDTIMESPEC(&lev->ref,&proc_table[my_table_index].timespec_priority,&x);
    kern_event_post(&x, STATIC_offset_activate,(void *)my_table_index);

    STATIC_printf("|p%d t%d ",
                  my_table_index,
                  (int)proc_table[my_table_index].timespec_priority.tv_sec);
  }

  STATIC_printf(")");

}

static void STATIC_hyperperiod(void *par)
{
  STATIC_level_des *lev;
  struct timespec x;

  lev = (STATIC_level_des *)level_table[(LEVEL)par];

  STATIC_printf("(hp %d)", (int)lev->ref.tv_sec);

  STATIC_activateall(lev);

  ADDTIMESPEC(&lev->ref, &lev->hp, &x);
  lev->ref = x;

  kern_event_post(&x, STATIC_hyperperiod, par);
}


static int STATIC_level_accept_task_model(LEVEL l, TASK_MODEL *m)
{
  if (m->pclass == STATIC_PCLASS || m->pclass == (STATIC_PCLASS | l))
    return 0;

  return -1;
}

static int STATIC_level_accept_guest_model(LEVEL l, TASK_MODEL *m)
{
  return -1;
}



static void STATIC_level_status(LEVEL l)
{ kern_raise(XUNVALID_TASK,exec_shadow); }

/* The scheduler only gets the first task in the queue */
static PID STATIC_level_scheduler(LEVEL l)
{
  STATIC_level_des *lev = (STATIC_level_des *)(level_table[l]);

  return lev->currenttask;
}

/* The on-line guarantee is enabled only if the appropriate flag is set... */
static int STATIC_level_guarantee(LEVEL l, bandwidth_t *freebandwidth)
{
  return 1;
}

static int STATIC_task_create(LEVEL l, PID p, TASK_MODEL *m)
{
  STATIC_level_des *lev = (STATIC_level_des *)(level_table[l]);

  /* if the STATIC_task_create is called, then the pclass must be a
     valid pclass. */


  STATIC_TASK_MODEL *h = (STATIC_TASK_MODEL *)m;

  proc_table[p].timespec_priority.tv_sec = h->offset.tv_sec;
  proc_table[p].timespec_priority.tv_nsec = h->offset.tv_nsec;
  q_timespec_insert(p,&lev->mytable);

  return 0; /* OK, also if the task cannot be guaranteed... */
}

static void STATIC_task_detach(LEVEL l, PID p)
{
}

static int STATIC_task_eligible(LEVEL l, PID p)
{
  return 0; /* if the task p is chosen, it is always eligible */
}

static void STATIC_task_dispatch(LEVEL l, PID p, int nostop)
{
}

static void STATIC_task_epilogue(LEVEL l, PID p)
{
}

static void STATIC_task_activate(LEVEL l, PID p)
{
}

static void STATIC_task_insert(LEVEL l, PID p)
{
}

static void STATIC_task_extract(LEVEL l, PID p)
{
}

static void STATIC_task_endcycle(LEVEL l, PID p)
{
  STATIC_level_des *lev = (STATIC_level_des *)(level_table[l]);

  lev->currenttask = NIL;
}

static void STATIC_task_end(LEVEL l, PID p)
{
  STATIC_level_des *lev = (STATIC_level_des *)(level_table[l]);

  lev->currenttask = NIL;

  q_extract(p,&lev->mytable);

  /* we finally put the task in the ready queue */
  proc_table[p].status = FREE;
  q_insertfirst(p,&freedesc);
}

static void STATIC_task_sleep(LEVEL l, PID p)
{ kern_raise(XUNVALID_TASK,exec_shadow); }

static void STATIC_task_delay(LEVEL l, PID p, TIME usdelay)
{ kern_raise(XUNVALID_TASK,exec_shadow); }

/* Guest Functions
   These functions manages a JOB_TASK_MODEL, that is used to put
   a guest task in the STATIC ready queue. */


static int STATIC_guest_create(LEVEL l, PID p, TASK_MODEL *m)
{ kern_raise(XUNVALID_GUEST,exec_shadow); return 0; }

static void STATIC_guest_detach(LEVEL l, PID p)
{ kern_raise(XUNVALID_GUEST,exec_shadow); }

static void STATIC_guest_dispatch(LEVEL l, PID p, int nostop)
{ kern_raise(XUNVALID_GUEST,exec_shadow); }

static void STATIC_guest_epilogue(LEVEL l, PID p)
{ kern_raise(XUNVALID_GUEST,exec_shadow); }

static void STATIC_guest_activate(LEVEL l, PID p)
{ kern_raise(XUNVALID_GUEST,exec_shadow); }

static void STATIC_guest_insert(LEVEL l, PID p)
{ kern_raise(XUNVALID_GUEST,exec_shadow); }

static void STATIC_guest_extract(LEVEL l, PID p)
{ kern_raise(XUNVALID_GUEST,exec_shadow); }

static void STATIC_guest_endcycle(LEVEL l, PID p)
{ kern_raise(XUNVALID_GUEST,exec_shadow); }

static void STATIC_guest_end(LEVEL l, PID p)
{ kern_raise(XUNVALID_GUEST,exec_shadow); }

static void STATIC_guest_sleep(LEVEL l, PID p)
{ kern_raise(XUNVALID_GUEST,exec_shadow); }

static void STATIC_guest_delay(LEVEL l, PID p, TIME usdelay)
{ kern_raise(XUNVALID_GUEST,exec_shadow); }

/* Registration functions */

/*+ Registration function:
    int flags                 the init flags ... see STATIC.h +*/

void STATIC_register_level()
{
  LEVEL l;            /* the level that we register */
  STATIC_level_des *lev;  /* for readableness only */

  printk("STATIC_register_level\n");

  /* request an entry in the level_table */
  l = level_alloc_descriptor();

  printk("    alloco descrittore %d %d\n",l,(int)sizeof(STATIC_level_des));

  /* alloc the space needed for the STATIC_level_des */
  lev = (STATIC_level_des *)kern_alloc(sizeof(STATIC_level_des));

  printk("    lev=%d\n",(int)lev);

  /* update the level_table with the new entry */
  level_table[l] = (level_des *)lev;

  /* fill the standard descriptor */
  strncpy(lev->l.level_name,  STATIC_LEVELNAME, MAX_LEVELNAME);
  lev->l.level_code               = STATIC_LEVEL_CODE;
  lev->l.level_version            = STATIC_LEVEL_VERSION;

  lev->l.level_accept_task_model  = STATIC_level_accept_task_model;
  lev->l.level_accept_guest_model = STATIC_level_accept_guest_model;
  lev->l.level_status             = STATIC_level_status;
  lev->l.level_scheduler          = STATIC_level_scheduler;

  lev->l.level_guarantee        = NULL;

  lev->l.task_create              = STATIC_task_create;
  lev->l.task_detach              = STATIC_task_detach;
  lev->l.task_eligible            = STATIC_task_eligible;
  lev->l.task_dispatch            = STATIC_task_dispatch;
  lev->l.task_epilogue            = STATIC_task_epilogue;
  lev->l.task_activate            = STATIC_task_activate;
  lev->l.task_insert              = STATIC_task_insert;
  lev->l.task_extract             = STATIC_task_extract;
  lev->l.task_endcycle            = STATIC_task_endcycle;
  lev->l.task_end                 = STATIC_task_end;
  lev->l.task_sleep               = STATIC_task_sleep;
  lev->l.task_delay               = STATIC_task_delay;

  lev->l.guest_create             = STATIC_guest_create;
  lev->l.guest_detach             = STATIC_guest_detach;
  lev->l.guest_dispatch           = STATIC_guest_dispatch;
  lev->l.guest_epilogue           = STATIC_guest_epilogue;
  lev->l.guest_activate           = STATIC_guest_activate;
  lev->l.guest_insert             = STATIC_guest_insert;
  lev->l.guest_extract            = STATIC_guest_extract;
  lev->l.guest_endcycle           = STATIC_guest_endcycle;
  lev->l.guest_end                = STATIC_guest_end;
  lev->l.guest_sleep              = STATIC_guest_sleep;
  lev->l.guest_delay              = STATIC_guest_delay;

  /* fill the STATIC descriptor part */

  lev->mytable = NIL;
  lev->currenttask = NIL;

  NULL_TIMESPEC(&lev->hp);
  NULL_TIMESPEC(&lev->ref);
}

void STATIC_start(LEVEL l, struct timespec *h, struct timespec *o)
{
  STATIC_level_des *lev = (STATIC_level_des *)(level_table[l]);
  struct timespec x;

  kern_cli();
  ll_gettime(TIME_EXACT, &x);
  lev->hp = *h;

  ADDTIMESPEC(&x,o,&lev->ref);
  STATIC_printf("(ST: ref:%d.%d x:%d.%d)\n",
                (int)lev->ref.tv_sec, (int)lev->ref.tv_nsec,
                (int)x.tv_sec, (int)x.tv_nsec);

  kern_event_post(&x, STATIC_hyperperiod,(void *)l);

  kern_sti();
}