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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_52/] [or1ksim/] [support/] [sched.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 807 markom
/* sched.h -- Abstract entities header file handling job scheduler
2
   Copyright (C) 2001 Marko Mlinar, markom@opencores.org
3 1390 nogj
   Copyright (C) 2005 György `nog' Jeney, nog@sdf.lonestar.org
4 807 markom
 
5
This file is part of OpenRISC 1000 Architectural Simulator.
6
 
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
11
 
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
GNU General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
 
21
#ifndef _SCHED_H_
22
#define _SCHED_H_
23
 
24 1390 nogj
#include "debug.h"
25
 
26 807 markom
/* Scheduler debug level */
27
#define SCHED_DEBUG     0
28
 
29
#define SCHED_HEAP_SIZE 128
30 1390 nogj
#define SCHED_TIME_MAX  INT32_MAX
31 807 markom
 
32 1390 nogj
DECLARE_DEBUG_CHANNEL(sched);
33 1319 phoenix
 
34 807 markom
/* Structure for holding one job entry */
35
struct sched_entry {
36 1390 nogj
  int32_t time;          /* Clock cycles before job starts */
37
  void *param;           /* Parameter to pass to the function */
38 1365 nogj
  void (*func)(void *);  /* Function to call when time reaches 0 */
39 1390 nogj
  struct sched_entry *next;
40 807 markom
};
41
 
42
/* Heap of jobs */
43
struct scheduler_struct {
44 1390 nogj
  struct sched_entry *free_job_queue;
45
  struct sched_entry *job_queue;
46 807 markom
};
47
 
48 1390 nogj
void sched_init(void);
49
void sched_reset(void);
50
 
51 807 markom
extern struct scheduler_struct scheduler;
52
 
53 1390 nogj
#if SCHED_DEBUG > 1
54
#define SCHED_PRINT_JOBS() sched_print_jobs()
55
static inline void sched_print_jobs(void)
56
{
57
  struct sched_entry *cur;
58
  int i;
59 807 markom
 
60 1390 nogj
  for (cur = scheduler.job_queue, i = 0; cur; cur = cur->next, i++)
61
    TRACE_(sched)("\t%i: %p $%p @ %"PRIi32"\n", i, cur->func, cur->param,
62
                  cur->time);
63 807 markom
}
64
#else
65
#define SCHED_PRINT_JOBS()
66
#endif
67
 
68
/* Adds new job to the queue */
69 1365 nogj
static inline void sched_add(void (*job_func)(void *), void *job_param,
70 1390 nogj
                             int32_t job_time, const char *func)
71 1365 nogj
{
72 1390 nogj
  struct sched_entry *cur, *prev, *new_job;
73
  int32_t alltime;
74 1365 nogj
 
75 1390 nogj
  if (SCHED_DEBUG > 1)
76
    TRACE_(sched)("%s@%lli:SCHED_ADD(time %"PRIi32")\n", func,
77
                  runtime.sim.cycles, job_time);
78 1365 nogj
  SCHED_PRINT_JOBS();
79
 
80 1390 nogj
  if (SCHED_DEBUG > 1) TRACE_(sched) ("--------\n");
81 1365 nogj
 
82 1390 nogj
  cur = scheduler.job_queue;
83
  prev = NULL;
84
  alltime = cur->time;
85
  while(cur && (alltime < job_time)) {
86
    prev = cur;
87
    cur = cur->next;
88
    if(cur)
89
      alltime += cur->time;
90 1365 nogj
  }
91
 
92 1390 nogj
  new_job = scheduler.free_job_queue;
93
  scheduler.free_job_queue = new_job->next;
94
  new_job->next = cur;
95
 
96
  new_job->func = job_func;
97
  new_job->param = job_param;
98
 
99
  if(prev) {
100
    new_job->time = job_time - (alltime - (cur ? cur->time : 0));
101
    prev->next = new_job;
102
    TRACE_(sched)("Scheduled job not going to head of queue, relative time: %"
103
                  PRIi32"\n", new_job->time);
104
  } else {
105
    scheduler.job_queue = new_job;
106
    new_job->time = job_time;
107
#if DYNAMIC_EXECUTION
108
    /* If we are replaceing the first job in the queue, then update the
109
     * recompiler's internal cycle counter */
110
    set_sched_cycle(job_time);
111
#endif
112
    TRACE_(sched)("Setting to-go cycles to %"PRIi32" at %lli\n", job_time,
113
                  runtime.sim.cycles);
114
  }
115
 
116
  if(cur)
117
    cur->time -= new_job->time;
118
 
119 1365 nogj
  SCHED_PRINT_JOBS();
120 807 markom
}
121
 
122 1365 nogj
#define SCHED_ADD(job_func, job_param, job_time) sched_add(job_func, job_param, job_time, __FUNCTION__)
123
 
124 1390 nogj
/* Returns a job with specified function and param, NULL if not found */
125
static inline void sched_find_remove(void (*job_func)(void *), void *dat,
126
                                     const char *func)
127
{
128
  struct sched_entry *cur;
129
  struct sched_entry *prev = NULL;
130 807 markom
 
131 1390 nogj
  TRACE_(sched)("%s@%lli:SCHED_REMOVE()\n", func, runtime.sim.cycles);
132 807 markom
 
133 1390 nogj
  for (cur = scheduler.job_queue; cur; prev = cur, cur = cur->next) {
134
    if ((cur->func == job_func) && (cur->param == dat)) {
135
      if(cur->next)
136
        cur->next->time += cur->time;
137 807 markom
 
138 1390 nogj
      if(prev) {
139
        prev->next = cur->next;
140
      } else {
141
        scheduler.job_queue = cur->next;
142
#if DYNAMIC_EXECUTION
143
        if(cur->next)
144
          set_sched_cycle(cur->next->time);
145
#endif
146
        if(cur->next)
147
          TRACE_(sched)("Setting to-go cycles to %"PRIi32" at %lli\n",
148
                        cur->next->time, runtime.sim.cycles);
149
      }
150
      cur->next = scheduler.free_job_queue;
151
      scheduler.free_job_queue = cur;
152
      break;
153
    }
154
  }
155
}
156 807 markom
 
157
/* Deletes job with specified function and param */
158 1390 nogj
#define SCHED_FIND_REMOVE(f, p) sched_find_remove(f, p, __FUNCTION__)
159 807 markom
 
160
#endif /* _SCHED_H_ */

powered by: WebSVN 2.1.0

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