Skip to content
Browse files

Add a separate queue for events in the current cycle

  • Loading branch information...
1 parent 66d6e92 commit 114c1d80c1a14553c1202b0682e8c6d8f60d6872 @nickg committed Apr 11, 2012
Showing with 70 additions and 11 deletions.
  1. +46 −8 src/rt/rtkern.c
  2. +24 −3 test/regress/case3.vhd
View
54 src/rt/rtkern.c
@@ -110,10 +110,17 @@ struct loaded {
struct loaded *next;
};
+struct run_queue {
+ struct event **queue;
+ size_t wr, rd;
+ size_t alloc;
+};
+
static struct rt_proc *procs = NULL;
static struct rt_proc *active_proc = NULL;
static struct sens_list *resume = NULL;
static struct loaded *loaded = NULL;
+static struct run_queue run_queue;
static heap_t eventq_heap = NULL;
static size_t n_procs = 0;
@@ -773,6 +780,34 @@ static void rt_update_driver(struct signal *s, int source)
assert(w_now != NULL);
}
+static void rt_push_run_queue(struct event *e)
+{
+ if (unlikely(run_queue.wr == run_queue.alloc)) {
+ if (run_queue.alloc == 0) {
+ run_queue.alloc = 128;
+ run_queue.queue = xmalloc(sizeof(struct event *) * run_queue.alloc);
+ }
+ else {
+ run_queue.alloc *= 2;
+ run_queue.queue = realloc(run_queue.queue,
+ sizeof(struct event *) * run_queue.alloc);
+ }
+ }
+
+ run_queue.queue[(run_queue.wr)++] = e;
+}
+
+static struct event *rt_pop_run_queue(void)
+{
+ if (run_queue.wr == run_queue.rd) {
+ run_queue.wr = 0;
+ run_queue.rd = 0;
+ return NULL;
+ }
+ else
+ return run_queue.queue[(run_queue.rd)++];
+}
+
static void rt_cycle(void)
{
// Simulation cycle is described in LRM 93 section 12.6.4
@@ -795,8 +830,18 @@ static void rt_cycle(void)
#endif
for (;;) {
- struct event *event = heap_extract_min(eventq_heap);
+ rt_push_run_queue(heap_extract_min(eventq_heap));
+ if (heap_size(eventq_heap) == 0)
+ break;
+
+ peek = heap_min(eventq_heap);
+ if (peek->when > now || peek->iteration != iteration)
+ break;
+ }
+
+ struct event *event;
+ while ((event = rt_pop_run_queue())) {
switch (event->kind) {
case E_PROCESS:
rt_run(event->wake_proc, false /* reset */);
@@ -808,13 +853,6 @@ static void rt_cycle(void)
}
rt_free(event_stack, event);
-
- if (heap_size(eventq_heap) == 0)
- break;
-
- peek = heap_min(eventq_heap);
- if (peek->when > now || peek->iteration != iteration)
- break;
}
if (unlikely(now == 0 && iteration == 0))
View
27 test/regress/case3.vhd
@@ -2,11 +2,29 @@ entity case3 is
end entity;
architecture test of case3 is
- signal x : bit_vector(3 downto 0);
- signal y : integer;
+ signal x : bit_vector(3 downto 0);
+ signal y, z, q : integer;
begin
- decode: with x select y <=
+ decode_y: with x select y <=
+ 0 when X"0",
+ 1 when X"1",
+ 2 when X"2",
+ 3 when X"3",
+ 4 when X"4",
+ 5 when X"5",
+ 6 when X"6",
+ 7 when X"7",
+ 8 when X"8",
+ 9 when X"9",
+ 10 when X"a",
+ 11 when X"b",
+ 12 when X"c",
+ 13 when X"d",
+ 14 when X"e",
+ 15 when X"f";
+
+ decode_z: with x(3 downto 0) select z <=
0 when X"0",
1 when X"1",
2 when X"2",
@@ -28,12 +46,15 @@ begin
begin
wait for 0 ns;
assert y = 0;
+ assert z = 0;
x <= X"4";
wait for 1 ns;
assert y = 4;
+ assert y = 4;
x <= X"f";
wait for 1 ns;
assert y = 15;
+ assert z = 15;
wait;
end process;

0 comments on commit 114c1d8

Please sign in to comment.
Something went wrong with that request. Please try again.