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

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable_0_2_0_rc3/] [or1ksim/] [support/] [sched.h] - Blame information for rev 1778

Go to most recent revision | 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
#define SCHED_HEAP_SIZE 128
31 1390 nogj
#define SCHED_TIME_MAX  INT32_MAX
32 807 markom
 
33 1390 nogj
DECLARE_DEBUG_CHANNEL(sched);
34 1541 nogj
DECLARE_DEBUG_CHANNEL(sched_jobs);
35 1319 phoenix
 
36 807 markom
/* Structure for holding one job entry */
37
struct sched_entry {
38 1390 nogj
  int32_t time;          /* Clock cycles before job starts */
39
  void *param;           /* Parameter to pass to the function */
40 1365 nogj
  void (*func)(void *);  /* Function to call when time reaches 0 */
41 1390 nogj
  struct sched_entry *next;
42 807 markom
};
43
 
44
/* Heap of jobs */
45
struct scheduler_struct {
46 1390 nogj
  struct sched_entry *free_job_queue;
47
  struct sched_entry *job_queue;
48 807 markom
};
49
 
50 1390 nogj
void sched_init(void);
51
void sched_reset(void);
52 1545 nogj
void sched_next_insn(void (*func)(void *), void *dat);
53 1390 nogj
 
54 807 markom
extern struct scheduler_struct scheduler;
55
 
56 1390 nogj
static inline void sched_print_jobs(void)
57
{
58
  struct sched_entry *cur;
59
  int i;
60 807 markom
 
61 1390 nogj
  for (cur = scheduler.job_queue, i = 0; cur; cur = cur->next, i++)
62
    TRACE_(sched)("\t%i: %p $%p @ %"PRIi32"\n", i, cur->func, cur->param,
63
                  cur->time);
64 807 markom
}
65
 
66
/* Adds new job to the queue */
67 1365 nogj
static inline void sched_add(void (*job_func)(void *), void *job_param,
68 1390 nogj
                             int32_t job_time, const char *func)
69 1365 nogj
{
70 1390 nogj
  struct sched_entry *cur, *prev, *new_job;
71
  int32_t alltime;
72 1365 nogj
 
73 1541 nogj
  TRACE_(sched)("%s@%lli:SCHED_ADD(time %"PRIi32")\n", func, runtime.sim.cycles,
74
                job_time);
75
  if(TRACE_ON(sched_jobs))
76
    sched_print_jobs();
77 1365 nogj
 
78 1541 nogj
  if(TRACE_ON(sched_jobs))
79
    TRACE_(sched) ("--------\n");
80 1365 nogj
 
81 1390 nogj
  cur = scheduler.job_queue;
82
  prev = NULL;
83
  alltime = cur->time;
84
  while(cur && (alltime < job_time)) {
85
    prev = cur;
86
    cur = cur->next;
87
    if(cur)
88
      alltime += cur->time;
89 1365 nogj
  }
90
 
91 1390 nogj
  new_job = scheduler.free_job_queue;
92
  scheduler.free_job_queue = new_job->next;
93
  new_job->next = cur;
94
 
95
  new_job->func = job_func;
96
  new_job->param = job_param;
97
 
98
  if(prev) {
99
    new_job->time = job_time - (alltime - (cur ? cur->time : 0));
100
    prev->next = new_job;
101
    TRACE_(sched)("Scheduled job not going to head of queue, relative time: %"
102
                  PRIi32"\n", new_job->time);
103
  } else {
104
    scheduler.job_queue = new_job;
105 1558 nogj
    new_job->time = job_time >= 0 ? job_time : cur->time;
106 1390 nogj
#if DYNAMIC_EXECUTION
107
    /* If we are replaceing the first job in the queue, then update the
108
     * recompiler's internal cycle counter */
109
    set_sched_cycle(job_time);
110
#endif
111
    TRACE_(sched)("Setting to-go cycles to %"PRIi32" at %lli\n", job_time,
112
                  runtime.sim.cycles);
113
  }
114
 
115
  if(cur)
116
    cur->time -= new_job->time;
117
 
118 1541 nogj
  if(TRACE_ON(sched_jobs))
119
    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 1452 nogj
/* If we are not running with dynamic execution, then do_scheduler will be
161
 * inlined and this declaration will be useless (it will also fail to compile)*/
162
#if DYNAMIC_EXECUTION
163
void do_scheduler (void);
164
#endif
165
 
166 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.