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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [or1ksim/] [support/] [sched.h] - Diff between revs 1319 and 1365

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

Rev 1319 Rev 1365
Line 28... Line 28...
 
 
 
 
/* Structure for holding one job entry */
/* Structure for holding one job entry */
struct sched_entry {
struct sched_entry {
  long long time;     /* Clock cycles before job starts */
  long long time;     /* Clock cycles before job starts */
  int  param;         /* Parameter to pass to the function */
  void *param;        /* Parameter to pass to the function */
  void (*func)(int);  /* Function to call when time reaches 0 */
  void (*func)(void *);  /* Function to call when time reaches 0 */
};
};
 
 
/* Heap of jobs */
/* Heap of jobs */
struct scheduler_struct {
struct scheduler_struct {
  int size;
  int size;
Line 42... Line 42...
 
 
extern struct scheduler_struct scheduler;
extern struct scheduler_struct scheduler;
 
 
/* Dummy function, representing a guard, which protects heap from
/* Dummy function, representing a guard, which protects heap from
   emptying */
   emptying */
extern void sched_guard (int i);
extern void sched_guard (void *);
 
 
/* Init scheduler -- clear the heap */
/* Init scheduler -- clear the heap */
#define SCHED_INIT() {\
#define SCHED_INIT() {\
        scheduler.heap[1].func = sched_guard;\
        scheduler.heap[1].func = sched_guard;\
        scheduler.heap[1].time = SCHED_TIME_MAX;\
        scheduler.heap[1].time = SCHED_TIME_MAX;\
Line 62... Line 62...
#else
#else
#define SCHED_PRINT_JOBS()
#define SCHED_PRINT_JOBS()
#endif
#endif
 
 
/* Adds new job to the queue */
/* Adds new job to the queue */
#define SCHED_ADD(job_func, job_param, job_time) {\
static inline void sched_add(void (*job_func)(void *), void *job_param,
        int ___i;\
                             long long job_time, const char *func)
        if (SCHED_DEBUG > 0) PRINTF ("%s@%i:SCHED_ADD(func %p, param %i, time %i)\n", __FUNCTION__, runtime.sim.cycles, (job_func), (job_param), (job_time));\
{
        SCHED_PRINT_JOBS();\
  int i;
 
 
 
  if (SCHED_DEBUG > 0)
 
    PRINTF ("%s@%lli:SCHED_ADD(func %p, param %p, time %lli)\n", func,
 
            runtime.sim.cycles, job_func, job_param, job_time);
 
  SCHED_PRINT_JOBS();
 
 
        if (SCHED_DEBUG > 1) PRINTF ("--------\n");\
        if (SCHED_DEBUG > 1) PRINTF ("--------\n");\
        ___i = scheduler.size++;\
 
        while (___i > 1 && scheduler.heap[___i / 2].time > (job_time)) scheduler.heap[___i] = scheduler.heap[___i /= 2];\
  i = scheduler.size++;
        scheduler.heap[___i].func = (job_func);\
  while (i > 1 && scheduler.heap[i / 2].time > job_time) {
        scheduler.heap[___i].param = (job_param);\
    scheduler.heap[i] = scheduler.heap[i / 2];
        scheduler.heap[___i].time = (job_time);\
    i /= 2;
        SCHED_PRINT_JOBS();\
 
}
}
 
 
 
  scheduler.heap[i].func = job_func;
 
  scheduler.heap[i].param = job_param;
 
  scheduler.heap[i].time = job_time;
 
  SCHED_PRINT_JOBS();
 
}
 
 
 
#define SCHED_ADD(job_func, job_param, job_time) sched_add(job_func, job_param, job_time, __FUNCTION__)
 
 
/* Removes an item from the heap */
/* Removes an item from the heap */
#define SCHED_REMOVE_ITEM(index) {\
#define SCHED_REMOVE_ITEM(index) {\
        struct sched_entry *tmp;\
        struct sched_entry *tmp;\
        int ___i = (index), ___j;\
        int ___i = (index), ___j;\
        if (SCHED_DEBUG > 0) PRINTF ("%s@%i:SCHED_REMOVE%i(time %li)\n", __FUNCTION__, runtime.sim.cycles, (index), scheduler.heap[___i].time); \
        if (SCHED_DEBUG > 0) PRINTF ("%s@%i:SCHED_REMOVE%i(time %li)\n", __FUNCTION__, runtime.sim.cycles, (index), scheduler.heap[___i].time); \

powered by: WebSVN 2.1.0

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