URL
https://opencores.org/ocsvn/or1k/or1k/trunk
Subversion Repositories or1k
Compare Revisions
- This comparison shows the changes necessary to convert path
/
- from Rev 1687 to Rev 1688
- ↔ Reverse comparison
Rev 1687 → Rev 1688
/trunk/or1ksim/toplevel.c
67,7 → 67,10
#include "trace.h" |
#include "cuc.h" |
#include "tick.h" |
#include "debug.h" |
|
DECLARE_DEBUG_CHANNEL(sched); |
|
const char *or1ksim_ver = "0.2.0"; |
|
inline void debug(int level, const char *format, ...) |
/trunk/or1ksim/support/sched.c
38,7 → 38,14
#include "sim-config.h" |
#include "config.h" |
#include "sched.h" |
#include "debug.h" |
|
DEFAULT_DEBUG_CHANNEL(sched); |
DECLARE_DEBUG_CHANNEL(sched_jobs); |
|
#define SCHED_HEAP_SIZE 128 |
#define SCHED_TIME_MAX INT32_MAX |
|
/* FIXME: Scheduler should continue from previous cycles not current ones */ |
|
struct scheduler_struct scheduler; |
90,6 → 97,89
sched_guard(NULL); |
} |
|
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 */ |
void sched_add(void (*job_func)(void *), void *job_param, int32_t job_time, |
const char *func) |
{ |
struct sched_entry *cur, *prev, *new_job; |
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; |
prev = NULL; |
alltime = cur->time; |
while(cur && (alltime < job_time)) { |
prev = cur; |
cur = cur->next; |
if(cur) |
alltime += cur->time; |
} |
|
new_job = scheduler.free_job_queue; |
scheduler.free_job_queue = new_job->next; |
new_job->next = cur; |
|
new_job->func = job_func; |
new_job->param = job_param; |
|
if(prev) { |
new_job->time = job_time - (alltime - (cur ? cur->time : 0)); |
prev->next = new_job; |
TRACE("Scheduled job not going to head of queue, relative time: %" |
PRIi32"\n", new_job->time); |
} else { |
scheduler.job_queue = new_job; |
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) |
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 */ |
void sched_find_remove(void (*job_func)(void *), void *dat, const char *func) |
{ |
struct sched_entry *cur; |
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) { |
if ((cur->func == job_func) && (cur->param == dat)) { |
if(cur->next) |
cur->next->time += cur->time; |
|
if(prev) |
prev->next = cur->next; |
else |
scheduler.job_queue = cur->next; |
cur->next = scheduler.free_job_queue; |
scheduler.free_job_queue = cur; |
break; |
} |
} |
} |
|
/* Schedules the next job so that it will run after the next instruction */ |
void sched_next_insn(void (*func)(void *), void *dat) |
{ |
/trunk/or1ksim/support/sched.h
21,14 → 21,15
#ifndef _SCHED_H_ |
#define _SCHED_H_ |
|
#include "debug.h" |
void sched_init(void); |
void sched_reset(void); |
void sched_next_insn(void (*func)(void *), void *dat); |
void sched_find_remove(void (*job_func)(void *), void *dat, const char *func); |
void sched_add(void (*job_func)(void *), void *job_param, int32_t job_time, |
const char *func); |
#define SCHED_ADD(job_func, job_param, job_time) sched_add(job_func, job_param, job_time, #job_func) |
#define SCHED_FIND_REMOVE(f, p) sched_find_remove(f, p, __FUNCTION__) |
|
#define SCHED_HEAP_SIZE 128 |
#define SCHED_TIME_MAX INT32_MAX |
|
DECLARE_DEBUG_CHANNEL(sched); |
DECLARE_DEBUG_CHANNEL(sched_jobs); |
|
/* Structure for holding one job entry */ |
struct sched_entry { |
int32_t time; /* Clock cycles before job starts */ |
43,107 → 44,9
struct sched_entry *job_queue; |
}; |
|
void sched_init(void); |
void sched_reset(void); |
void sched_next_insn(void (*func)(void *), void *dat); |
|
extern struct scheduler_struct scheduler; |
|
static inline void sched_print_jobs(void) |
{ |
struct sched_entry *cur; |
int i; |
|
for (cur = scheduler.job_queue, i = 0; cur; cur = cur->next, i++) |
TRACE_(sched)("\t%i: %p $%p @ %"PRIi32"\n", i, cur->func, cur->param, |
cur->time); |
} |
|
/* Adds new job to the queue */ |
static inline void sched_add(void (*job_func)(void *), void *job_param, |
int32_t job_time, const char *func) |
{ |
struct sched_entry *cur, *prev, *new_job; |
int32_t alltime; |
|
TRACE_(sched)("%s@%lli:SCHED_ADD(time %"PRIi32")\n", func, runtime.sim.cycles, |
job_time); |
if(TRACE_ON(sched_jobs)) |
sched_print_jobs(); |
|
if(TRACE_ON(sched_jobs)) |
TRACE_(sched) ("--------\n"); |
|
cur = scheduler.job_queue; |
prev = NULL; |
alltime = cur->time; |
while(cur && (alltime < job_time)) { |
prev = cur; |
cur = cur->next; |
if(cur) |
alltime += cur->time; |
} |
|
new_job = scheduler.free_job_queue; |
scheduler.free_job_queue = new_job->next; |
new_job->next = cur; |
|
new_job->func = job_func; |
new_job->param = job_param; |
|
if(prev) { |
new_job->time = job_time - (alltime - (cur ? cur->time : 0)); |
prev->next = new_job; |
TRACE_(sched)("Scheduled job not going to head of queue, relative time: %" |
PRIi32"\n", new_job->time); |
} else { |
scheduler.job_queue = new_job; |
new_job->time = job_time >= 0 ? job_time : cur->time; |
TRACE_(sched)("Setting to-go cycles to %"PRIi32" at %lli\n", job_time, |
runtime.sim.cycles); |
} |
|
if(cur) |
cur->time -= new_job->time; |
|
if(TRACE_ON(sched_jobs)) |
sched_print_jobs(); |
} |
|
#define SCHED_ADD(job_func, job_param, job_time) sched_add(job_func, job_param, job_time, __FUNCTION__) |
|
/* Returns a job with specified function and param, NULL if not found */ |
static inline void sched_find_remove(void (*job_func)(void *), void *dat, |
const char *func) |
{ |
struct sched_entry *cur; |
struct sched_entry *prev = NULL; |
|
TRACE_(sched)("%s@%lli:SCHED_REMOVE()\n", func, runtime.sim.cycles); |
|
for (cur = scheduler.job_queue; cur; prev = cur, cur = cur->next) { |
if ((cur->func == job_func) && (cur->param == dat)) { |
if(cur->next) |
cur->next->time += cur->time; |
|
if(prev) { |
prev->next = cur->next; |
} else { |
scheduler.job_queue = cur->next; |
if(cur->next) |
TRACE_(sched)("Setting to-go cycles to %"PRIi32" at %lli\n", |
cur->next->time, runtime.sim.cycles); |
} |
cur->next = scheduler.free_job_queue; |
scheduler.free_job_queue = cur; |
break; |
} |
} |
} |
|
/* Deletes job with specified function and param */ |
#define SCHED_FIND_REMOVE(f, p) sched_find_remove(f, p, __FUNCTION__) |
|
/* If we are not running with dynamic execution, then do_scheduler will be |
* inlined and this declaration will be useless (it will also fail to compile)*/ |
#if DYNAMIC_EXECUTION |