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

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable_0_2_0_rc1/] [or1ksim/] [support/] [sched.h] - Blame information for rev 1541

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
 
53 807 markom
extern struct scheduler_struct scheduler;
54
 
55 1390 nogj
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
 
65
/* Adds new job to the queue */
66 1365 nogj
static inline void sched_add(void (*job_func)(void *), void *job_param,
67 1390 nogj
                             int32_t job_time, const char *func)
68 1365 nogj
{
69 1390 nogj
  struct sched_entry *cur, *prev, *new_job;
70
  int32_t alltime;
71 1365 nogj
 
72 1541 nogj
  TRACE_(sched)("%s@%lli:SCHED_ADD(time %"PRIi32")\n", func, runtime.sim.cycles,
73
                job_time);
74
  if(TRACE_ON(sched_jobs))
75
    sched_print_jobs();
76 1365 nogj
 
77 1541 nogj
  if(TRACE_ON(sched_jobs))
78
    TRACE_(sched) ("--------\n");
79 1365 nogj
 
80 1390 nogj
  cur = scheduler.job_queue;
81
  prev = NULL;
82
  alltime = cur->time;
83
  while(cur && (alltime < job_time)) {
84
    prev = cur;
85
    cur = cur->next;
86
    if(cur)
87
      alltime += cur->time;
88 1365 nogj
  }
89
 
90 1390 nogj
  new_job = scheduler.free_job_queue;
91
  scheduler.free_job_queue = new_job->next;
92
  new_job->next = cur;
93
 
94
  new_job->func = job_func;
95
  new_job->param = job_param;
96
 
97
  if(prev) {
98
    new_job->time = job_time - (alltime - (cur ? cur->time : 0));
99
    prev->next = new_job;
100
    TRACE_(sched)("Scheduled job not going to head of queue, relative time: %"
101
                  PRIi32"\n", new_job->time);
102
  } else {
103
    scheduler.job_queue = new_job;
104
    new_job->time = job_time;
105
#if DYNAMIC_EXECUTION
106
    /* If we are replaceing the first job in the queue, then update the
107
     * recompiler's internal cycle counter */
108
    set_sched_cycle(job_time);
109
#endif
110
    TRACE_(sched)("Setting to-go cycles to %"PRIi32" at %lli\n", job_time,
111
                  runtime.sim.cycles);
112
  }
113
 
114
  if(cur)
115
    cur->time -= new_job->time;
116
 
117 1541 nogj
  if(TRACE_ON(sched_jobs))
118
    sched_print_jobs();
119 807 markom
}
120
 
121 1365 nogj
#define SCHED_ADD(job_func, job_param, job_time) sched_add(job_func, job_param, job_time, __FUNCTION__)
122
 
123 1390 nogj
/* Returns a job with specified function and param, NULL if not found */
124
static inline void sched_find_remove(void (*job_func)(void *), void *dat,
125
                                     const char *func)
126
{
127
  struct sched_entry *cur;
128
  struct sched_entry *prev = NULL;
129 807 markom
 
130 1390 nogj
  TRACE_(sched)("%s@%lli:SCHED_REMOVE()\n", func, runtime.sim.cycles);
131 807 markom
 
132 1390 nogj
  for (cur = scheduler.job_queue; cur; prev = cur, cur = cur->next) {
133
    if ((cur->func == job_func) && (cur->param == dat)) {
134
      if(cur->next)
135
        cur->next->time += cur->time;
136 807 markom
 
137 1390 nogj
      if(prev) {
138
        prev->next = cur->next;
139
      } else {
140
        scheduler.job_queue = cur->next;
141
#if DYNAMIC_EXECUTION
142
        if(cur->next)
143
          set_sched_cycle(cur->next->time);
144
#endif
145
        if(cur->next)
146
          TRACE_(sched)("Setting to-go cycles to %"PRIi32" at %lli\n",
147
                        cur->next->time, runtime.sim.cycles);
148
      }
149
      cur->next = scheduler.free_job_queue;
150
      scheduler.free_job_queue = cur;
151
      break;
152
    }
153
  }
154
}
155 807 markom
 
156
/* Deletes job with specified function and param */
157 1390 nogj
#define SCHED_FIND_REMOVE(f, p) sched_find_remove(f, p, __FUNCTION__)
158 807 markom
 
159 1452 nogj
/* If we are not running with dynamic execution, then do_scheduler will be
160
 * inlined and this declaration will be useless (it will also fail to compile)*/
161
#if DYNAMIC_EXECUTION
162
void do_scheduler (void);
163
#endif
164
 
165 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.