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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_70/] [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 1452 nogj
#if DYNAMIC_EXECUTION
25
#include "sched_i386.h"
26
#endif
27
 
28 1390 nogj
#include "debug.h"
29
 
30 807 markom
/* Scheduler debug level */
31
#define SCHED_DEBUG     0
32
 
33
#define SCHED_HEAP_SIZE 128
34 1390 nogj
#define SCHED_TIME_MAX  INT32_MAX
35 807 markom
 
36 1390 nogj
DECLARE_DEBUG_CHANNEL(sched);
37 1319 phoenix
 
38 807 markom
/* Structure for holding one job entry */
39
struct sched_entry {
40 1390 nogj
  int32_t time;          /* Clock cycles before job starts */
41
  void *param;           /* Parameter to pass to the function */
42 1365 nogj
  void (*func)(void *);  /* Function to call when time reaches 0 */
43 1390 nogj
  struct sched_entry *next;
44 807 markom
};
45
 
46
/* Heap of jobs */
47
struct scheduler_struct {
48 1390 nogj
  struct sched_entry *free_job_queue;
49
  struct sched_entry *job_queue;
50 807 markom
};
51
 
52 1390 nogj
void sched_init(void);
53
void sched_reset(void);
54
 
55 807 markom
extern struct scheduler_struct scheduler;
56
 
57 1390 nogj
#if SCHED_DEBUG > 1
58
#define SCHED_PRINT_JOBS() sched_print_jobs()
59
static inline void sched_print_jobs(void)
60
{
61
  struct sched_entry *cur;
62
  int i;
63 807 markom
 
64 1390 nogj
  for (cur = scheduler.job_queue, i = 0; cur; cur = cur->next, i++)
65
    TRACE_(sched)("\t%i: %p $%p @ %"PRIi32"\n", i, cur->func, cur->param,
66
                  cur->time);
67 807 markom
}
68
#else
69
#define SCHED_PRINT_JOBS()
70
#endif
71
 
72
/* Adds new job to the queue */
73 1365 nogj
static inline void sched_add(void (*job_func)(void *), void *job_param,
74 1390 nogj
                             int32_t job_time, const char *func)
75 1365 nogj
{
76 1390 nogj
  struct sched_entry *cur, *prev, *new_job;
77
  int32_t alltime;
78 1365 nogj
 
79 1390 nogj
  if (SCHED_DEBUG > 1)
80
    TRACE_(sched)("%s@%lli:SCHED_ADD(time %"PRIi32")\n", func,
81
                  runtime.sim.cycles, job_time);
82 1365 nogj
  SCHED_PRINT_JOBS();
83
 
84 1390 nogj
  if (SCHED_DEBUG > 1) TRACE_(sched) ("--------\n");
85 1365 nogj
 
86 1390 nogj
  cur = scheduler.job_queue;
87
  prev = NULL;
88
  alltime = cur->time;
89
  while(cur && (alltime < job_time)) {
90
    prev = cur;
91
    cur = cur->next;
92
    if(cur)
93
      alltime += cur->time;
94 1365 nogj
  }
95
 
96 1390 nogj
  new_job = scheduler.free_job_queue;
97
  scheduler.free_job_queue = new_job->next;
98
  new_job->next = cur;
99
 
100
  new_job->func = job_func;
101
  new_job->param = job_param;
102
 
103
  if(prev) {
104
    new_job->time = job_time - (alltime - (cur ? cur->time : 0));
105
    prev->next = new_job;
106
    TRACE_(sched)("Scheduled job not going to head of queue, relative time: %"
107
                  PRIi32"\n", new_job->time);
108
  } else {
109
    scheduler.job_queue = new_job;
110
    new_job->time = job_time;
111
#if DYNAMIC_EXECUTION
112
    /* If we are replaceing the first job in the queue, then update the
113
     * recompiler's internal cycle counter */
114
    set_sched_cycle(job_time);
115
#endif
116
    TRACE_(sched)("Setting to-go cycles to %"PRIi32" at %lli\n", job_time,
117
                  runtime.sim.cycles);
118
  }
119
 
120
  if(cur)
121
    cur->time -= new_job->time;
122
 
123 1365 nogj
  SCHED_PRINT_JOBS();
124 807 markom
}
125
 
126 1365 nogj
#define SCHED_ADD(job_func, job_param, job_time) sched_add(job_func, job_param, job_time, __FUNCTION__)
127
 
128 1390 nogj
/* Returns a job with specified function and param, NULL if not found */
129
static inline void sched_find_remove(void (*job_func)(void *), void *dat,
130
                                     const char *func)
131
{
132
  struct sched_entry *cur;
133
  struct sched_entry *prev = NULL;
134 807 markom
 
135 1390 nogj
  TRACE_(sched)("%s@%lli:SCHED_REMOVE()\n", func, runtime.sim.cycles);
136 807 markom
 
137 1390 nogj
  for (cur = scheduler.job_queue; cur; prev = cur, cur = cur->next) {
138
    if ((cur->func == job_func) && (cur->param == dat)) {
139
      if(cur->next)
140
        cur->next->time += cur->time;
141 807 markom
 
142 1390 nogj
      if(prev) {
143
        prev->next = cur->next;
144
      } else {
145
        scheduler.job_queue = cur->next;
146
#if DYNAMIC_EXECUTION
147
        if(cur->next)
148
          set_sched_cycle(cur->next->time);
149
#endif
150
        if(cur->next)
151
          TRACE_(sched)("Setting to-go cycles to %"PRIi32" at %lli\n",
152
                        cur->next->time, runtime.sim.cycles);
153
      }
154
      cur->next = scheduler.free_job_queue;
155
      scheduler.free_job_queue = cur;
156
      break;
157
    }
158
  }
159
}
160 807 markom
 
161
/* Deletes job with specified function and param */
162 1390 nogj
#define SCHED_FIND_REMOVE(f, p) sched_find_remove(f, p, __FUNCTION__)
163 807 markom
 
164 1452 nogj
/* If we are not running with dynamic execution, then do_scheduler will be
165
 * inlined and this declaration will be useless (it will also fail to compile)*/
166
#if DYNAMIC_EXECUTION
167
void do_scheduler (void);
168
#endif
169
 
170 807 markom
#endif /* _SCHED_H_ */

powered by: WebSVN 2.1.0

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