OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_70/] [or1ksim/] [support/] [sched.c] - Diff between revs 1466 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 1466 Rev 1765
/* sched.c -- Abstract entities, handling job scheduling
/* sched.c -- Abstract entities, handling job scheduling
   Copyright (C) 2001 Marko Mlinar, markom@opencores.org
   Copyright (C) 2001 Marko Mlinar, markom@opencores.org
 
 
This file is part of OpenRISC 1000 Architectural Simulator.
This file is part of OpenRISC 1000 Architectural Simulator.
 
 
This program is free software; you can redistribute it and/or modify
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
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
(at your option) any later version.
 
 
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
GNU General Public License for more details.
 
 
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
 
/* Abstract memory and routines that go with this. I need to
/* Abstract memory and routines that go with this. I need to
add all sorts of other abstract entities. Currently we have
add all sorts of other abstract entities. Currently we have
only memory. */
only memory. */
 
 
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <ctype.h>
#include <ctype.h>
#include <string.h>
#include <string.h>
#include <limits.h>
#include <limits.h>
 
 
#include "config.h"
#include "config.h"
 
 
#ifdef HAVE_INTTYPES_H
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#include <inttypes.h>
#endif
#endif
 
 
#include "port.h"
#include "port.h"
#include "arch.h"
#include "arch.h"
#include "sim-config.h"
#include "sim-config.h"
#include "config.h"
#include "config.h"
#include "sched.h"
#include "sched.h"
 
 
struct scheduler_struct scheduler;
struct scheduler_struct scheduler;
 
 
/* Dummy function, representing a guard, which protects heap from
/* Dummy function, representing a guard, which protects heap from
   emptying */
   emptying */
void sched_guard (void *dat)
void sched_guard (void *dat)
{
{
  if(scheduler.job_queue)
  if(scheduler.job_queue)
    SCHED_ADD(sched_guard, dat, SCHED_TIME_MAX);
    SCHED_ADD(sched_guard, dat, SCHED_TIME_MAX);
  else {
  else {
    scheduler.job_queue = scheduler.free_job_queue;
    scheduler.job_queue = scheduler.free_job_queue;
    scheduler.free_job_queue = scheduler.free_job_queue->next;
    scheduler.free_job_queue = scheduler.free_job_queue->next;
    scheduler.job_queue->next = NULL;
    scheduler.job_queue->next = NULL;
    scheduler.job_queue->func = sched_guard;
    scheduler.job_queue->func = sched_guard;
    scheduler.job_queue->time = SCHED_TIME_MAX;
    scheduler.job_queue->time = SCHED_TIME_MAX;
#if DYNAMIC_EXECUTION
#if DYNAMIC_EXECUTION
    set_sched_cycle(SCHED_TIME_MAX);
    set_sched_cycle(SCHED_TIME_MAX);
#endif
#endif
  }
  }
}
}
 
 
void sched_reset(void)
void sched_reset(void)
{
{
  struct sched_entry *cur, *next;
  struct sched_entry *cur, *next;
 
 
  for(cur = scheduler.job_queue; cur; cur = next) {
  for(cur = scheduler.job_queue; cur; cur = next) {
    next = cur->next;
    next = cur->next;
    cur->next = scheduler.free_job_queue;
    cur->next = scheduler.free_job_queue;
    scheduler.free_job_queue = cur;
    scheduler.free_job_queue = cur;
  }
  }
  scheduler.job_queue = NULL;
  scheduler.job_queue = NULL;
  sched_guard(NULL);
  sched_guard(NULL);
}
}
 
 
void sched_init(void)
void sched_init(void)
{
{
  int i;
  int i;
  struct sched_entry *new;
  struct sched_entry *new;
 
 
  scheduler.free_job_queue = NULL;
  scheduler.free_job_queue = NULL;
 
 
  for(i = 0; i < SCHED_HEAP_SIZE; i++) {
  for(i = 0; i < SCHED_HEAP_SIZE; i++) {
    if(!(new = malloc(sizeof(struct sched_entry)))) {
    if(!(new = malloc(sizeof(struct sched_entry)))) {
      fprintf(stderr, "Out-of-memory while allocateing scheduler queue\n");
      fprintf(stderr, "Out-of-memory while allocateing scheduler queue\n");
      exit(1);
      exit(1);
    }
    }
    new->next = scheduler.free_job_queue;
    new->next = scheduler.free_job_queue;
    scheduler.free_job_queue = new;
    scheduler.free_job_queue = new;
  }
  }
  scheduler.job_queue = NULL;
  scheduler.job_queue = NULL;
  sched_guard(NULL);
  sched_guard(NULL);
}
}
#warning Scheduler should continue from previous cycles not current ones
#warning Scheduler should continue from previous cycles not current ones
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.