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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel-0-3-0-rc3/] [or1ksim/] [support/] [sched.c] - Diff between revs 1748 and 1751

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 1748 Rev 1751
Line 37... Line 37...
#include "sched.h"
#include "sched.h"
#include "debug.h"
#include "debug.h"
#include "sim-config.h"
#include "sim-config.h"
 
 
 
 
DEFAULT_DEBUG_CHANNEL(sched);
 
DECLARE_DEBUG_CHANNEL(sched_jobs);
DECLARE_DEBUG_CHANNEL(sched_jobs);
 
 
#define SCHED_HEAP_SIZE 128
#define SCHED_HEAP_SIZE 128
#define SCHED_TIME_MAX  INT32_MAX
#define SCHED_TIME_MAX  INT32_MAX
 
 
Line 112... Line 111...
 
 
    tmp->func (tmp->param);
    tmp->func (tmp->param);
  } while(scheduler.job_queue->time <= 0);
  } while(scheduler.job_queue->time <= 0);
}
}
 
 
static void sched_print_jobs(void)
 
{
 
  struct sched_entry *cur;
 
  int i;
 
 
 
  for (cur = scheduler.job_queue, i = 0; cur; cur = cur->next, i++)
 
    TRACE("\t%i: %p $%p @ %"PRIi32"\n", i, cur->func, cur->param, cur->time);
 
}
 
 
 
/* Adds new job to the queue */
/* Adds new job to the queue */
void sched_add(void (*job_func)(void *), void *job_param, int32_t job_time,
void sched_add(void (*job_func)(void *), void *job_param, int32_t job_time,
               const char *func)
               const char *func)
{
{
  struct sched_entry *cur, *prev, *new_job;
  struct sched_entry *cur, *prev, *new_job;
  int32_t alltime;
  int32_t alltime;
 
 
  TRACE("%s@%lli:SCHED_ADD(time %"PRIi32")\n", func, runtime.sim.cycles,
 
        job_time);
 
  if(TRACE_ON(sched_jobs)) {
 
    sched_print_jobs();
 
    TRACE("--------\n");
 
  }
 
 
 
  cur = scheduler.job_queue;
  cur = scheduler.job_queue;
  prev = NULL;
  prev = NULL;
  alltime = cur->time;
  alltime = cur->time;
  while(cur && (alltime < job_time)) {
  while(cur && (alltime < job_time)) {
    prev = cur;
    prev = cur;
Line 155... Line 138...
  new_job->param = job_param;
  new_job->param = job_param;
 
 
  if(prev) {
  if(prev) {
    new_job->time = job_time - (alltime - (cur ? cur->time : 0));
    new_job->time = job_time - (alltime - (cur ? cur->time : 0));
    prev->next = new_job;
    prev->next = new_job;
    TRACE("Scheduled job not going to head of queue, relative time: %"
 
          PRIi32"\n", new_job->time);
 
  } else {
  } else {
    scheduler.job_queue = new_job;
    scheduler.job_queue = new_job;
    new_job->time = job_time >= 0 ? job_time : cur->time;
    new_job->time = job_time >= 0 ? job_time : cur->time;
    TRACE("Setting to-go cycles to %"PRIi32" at %lli\n", job_time,
 
          runtime.sim.cycles);
 
  }
  }
 
 
  if(cur)
  if(cur)
    cur->time -= new_job->time;
    cur->time -= new_job->time;
 
 
  if(TRACE_ON(sched_jobs))
 
    sched_print_jobs();
 
}
}
 
 
/* Returns a job with specified function and param, NULL if not found */
/* Returns a job with specified function and param, NULL if not found */
void sched_find_remove(void (*job_func)(void *), void *dat, const char *func)
void sched_find_remove(void (*job_func)(void *), void *dat)
{
{
  struct sched_entry *cur;
  struct sched_entry *cur;
  struct sched_entry *prev = NULL;
  struct sched_entry *prev = NULL;
 
 
  TRACE("%s@%lli:SCHED_REMOVE()\n", func, runtime.sim.cycles);
 
 
 
  for (cur = scheduler.job_queue; cur; prev = cur, cur = cur->next) {
  for (cur = scheduler.job_queue; cur; prev = cur, cur = cur->next) {
    if ((cur->func == job_func) && (cur->param == dat)) {
    if ((cur->func == job_func) && (cur->param == dat)) {
      if(cur->next)
      if(cur->next)
        cur->next->time += cur->time;
        cur->next->time += cur->time;
 
 

powered by: WebSVN 2.1.0

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