Subversion Repositories shark

Rev

Rev 2 | Blame | Compare with Previous | 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: endcycle.c,v 1.1.1.1 2002-03-29 14:12:51 pj Exp $

 File:        $File$
 Revision:    $Revision: 1.1.1.1 $
 Last update: $Date: 2002-03-29 14:12:51 $
 ------------

 Kernel module registration and miscellaneous functions

 This file contains:

 task_endcycle

**/


/*
 * Copyright (C) 2000 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 <stdarg.h>
#include <ll/ll.h>
#include <ll/stdlib.h>
#include <ll/stdio.h>
#include <ll/string.h>
#include <kernel/config.h>
#include <kernel/model.h>
#include <kernel/const.h>
#include <sys/types.h>
#include <kernel/types.h>
#include <kernel/descr.h>
#include <errno.h>
#include <kernel/var.h>
#include <kernel/func.h>
#include <kernel/trace.h>


/*+
  Suspend the executing periodic task till the next period

  The executing task will be now placed into the right queue...
  normally, it goes also in the idle state if it is periodic or
  in the sleep state if it is aperiodic.

  I.e., if the task is an hard-periodic task & we are calling the
  task_endcycle, then it cannot be over the deadline because the
  timer should detect this; anyway it could be finishing just on
  the deadline! In this case, we must place it into a ready queue
+*/

void task_endcycle(void)
{
  LEVEL l;            /* for readableness only */
  TIME tx;            /* a dummy TIME for timespec operations */
  struct timespec ty; /* a dummy timespec for timespec operations */

  proc_table[exec_shadow].context = kern_context_save();

  /* SAME AS SCHEDULER... manage the capacity event and the load_info */
  ll_gettime(TIME_EXACT, &schedule_time);
  SUBTIMESPEC(&schedule_time, &cap_lasttime, &ty);
  tx = TIMESPEC2USEC(&ty);
  proc_table[exec_shadow].avail_time -= tx;
  jet_update_slice(tx);
  if (cap_timer != NIL) {
    event_delete(cap_timer);
    cap_timer = NIL;
  }

  l = proc_table[exec_shadow].task_level;
  level_table[l]->task_endcycle(l,exec_shadow);

  /* Update the Jet data... */
  jet_update_endcycle();

  /* tracer stuff */
  trc_logevent(TRC_ENDCYCLE,&exec_shadow);

  exec = exec_shadow = -1;
  scheduler();
  kern_context_load(proc_table[exec_shadow].context);
}