1
|
|
2
|
-- Copyright (C) 1996 Morgan Kaufmann Publishers, Inc
|
3
|
|
4
|
-- This file is part of VESTs (Vhdl tESTs).
|
5
|
|
6
|
-- VESTs is free software; you can redistribute it and/or modify it
|
7
|
-- under the terms of the GNU General Public License as published by the
|
8
|
-- Free Software Foundation; either version 2 of the License, or (at
|
9
|
-- your option) any later version.
|
10
|
|
11
|
-- VESTs is distributed in the hope that it will be useful, but WITHOUT
|
12
|
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
13
|
-- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
14
|
-- for more details.
|
15
|
|
16
|
-- You should have received a copy of the GNU General Public License
|
17
|
-- along with VESTs; if not, write to the Free Software Foundation,
|
18
|
-- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
|
20
|
-- ---------------------------------------------------------------------
|
21
|
--
|
22
|
-- $Id: ch_19_queue-b.vhd,v 1.3 2001-10-26 16:29:36 paw Exp $
|
23
|
-- $Revision: 1.3 $
|
24
|
--
|
25
|
-- ---------------------------------------------------------------------
|
26
|
|
27
|
library math;
|
28
|
|
29
|
architecture behavior of queue is
|
30
|
|
31
|
begin
|
32
|
|
33
|
queue_manager : process is
|
34
|
|
35
|
use qsim.queue_types.all, qsim.waiting_token_fifo_adt.all;
|
36
|
|
37
|
variable waiting_token, head_token : waiting_token_type;
|
38
|
variable waiting_token_fifo : fifo_type := new_fifo;
|
39
|
variable out_token_in_transit : boolean := false;
|
40
|
variable number_of_tokens_released : natural := 0;
|
41
|
variable current_queue_size : natural := 0;
|
42
|
variable maximum_queue_size : natural := 0;
|
43
|
variable waiting_time : natural; -- in time_unit
|
44
|
variable sum_of_waiting_times : real := 0.0; -- in time_unit
|
45
|
variable sum_of_squares_of_waiting_times : real := 0.0; --in time_unit**2
|
46
|
|
47
|
use std.textio.all;
|
48
|
file info_file : text;
|
49
|
variable L : line;
|
50
|
|
51
|
use math.math_real.sqrt;
|
52
|
|
53
|
procedure write_summary is
|
54
|
variable mean_waiting_time : real
|
55
|
:= sum_of_waiting_times / real(number_of_tokens_released);
|
56
|
variable std_dev_of_waiting_times : real
|
57
|
:= sqrt ( ( sum_of_squares_of_waiting_times
|
58
|
- sum_of_waiting_times**2 / real(number_of_tokens_released) )
|
59
|
/ real( number_of_tokens_released - 1 ) );
|
60
|
begin
|
61
|
write(L, string'("Summary information for queue "));
|
62
|
write(L, name);
|
63
|
write(L, string'(" up to time "));
|
64
|
write(L, now, unit => time_unit);
|
65
|
writeline(info_file, L);
|
66
|
write(L, string'(" Number of tokens currently waiting = "));
|
67
|
write(L, natural(current_queue_size));
|
68
|
writeline(info_file, L);
|
69
|
write(L, string'(" Number of tokens released = "));
|
70
|
write(L, natural(number_of_tokens_released));
|
71
|
writeline(info_file, L);
|
72
|
write(L, string'(" Maximum queue size = "));
|
73
|
write(L, natural(maximum_queue_size));
|
74
|
writeline(info_file, L);
|
75
|
write(L, string'(" Mean waiting time = "));
|
76
|
write(L, mean_waiting_time * time_unit, unit => time_unit);
|
77
|
writeline(info_file, L);
|
78
|
write(L, string'(" Standard deviation of waiting times = "));
|
79
|
write(L, std_dev_of_waiting_times * time_unit, unit => time_unit);
|
80
|
writeline(info_file, L);
|
81
|
writeline(info_file, L);
|
82
|
end procedure write_summary;
|
83
|
|
84
|
procedure write_trace_enqueue is
|
85
|
begin
|
86
|
write(L, string'("Queue "));
|
87
|
write(L, name);
|
88
|
write(L, string'(": at "));
|
89
|
write(L, now, unit => time_unit);
|
90
|
write(L, string'(" enqueued "));
|
91
|
write(L, waiting_token.token, time_unit);
|
92
|
writeline(info_file, L);
|
93
|
end procedure write_trace_enqueue;
|
94
|
|
95
|
procedure write_trace_dequeue is
|
96
|
begin
|
97
|
write(L, string'("Queue "));
|
98
|
write(L, name);
|
99
|
write(L, string'(": at "));
|
100
|
write(L, now, unit => time_unit);
|
101
|
write(L, string'(" dequeued "));
|
102
|
write(L, head_token.token, time_unit);
|
103
|
writeline(info_file, L);
|
104
|
end procedure write_trace_dequeue;
|
105
|
|
106
|
begin
|
107
|
file_open(info_file, info_file_name, write_mode);
|
108
|
loop
|
109
|
wait on info_detail'transaction, in_arc, out_ready;
|
110
|
if info_detail'active and info_detail = summary then
|
111
|
write_summary;
|
112
|
end if;
|
113
|
if in_arc'event then
|
114
|
waiting_token := waiting_token_type'( token => in_arc.token,
|
115
|
time_when_enqueued => now );
|
116
|
insert(waiting_token_fifo, waiting_token);
|
117
|
current_queue_size := current_queue_size + 1;
|
118
|
if current_queue_size > maximum_queue_size then
|
119
|
maximum_queue_size := current_queue_size;
|
120
|
end if;
|
121
|
if info_detail = trace then
|
122
|
write_trace_enqueue;
|
123
|
end if;
|
124
|
end if;
|
125
|
if out_ready and current_queue_size > 0 and not out_token_in_transit then
|
126
|
remove(waiting_token_fifo, head_token);
|
127
|
current_queue_size := current_queue_size - 1;
|
128
|
out_arc <= arc_type'( transaction => not out_arc.transaction'driving_value,
|
129
|
token => head_token.token );
|
130
|
out_token_in_transit := true;
|
131
|
number_of_tokens_released := number_of_tokens_released + 1;
|
132
|
waiting_time := (now - head_token.time_when_enqueued) / time_unit;
|
133
|
sum_of_waiting_times := sum_of_waiting_times + real(waiting_time);
|
134
|
sum_of_squares_of_waiting_times := sum_of_squares_of_waiting_times
|
135
|
+ real(waiting_time) ** 2;
|
136
|
if info_detail = trace then
|
137
|
write_trace_dequeue;
|
138
|
end if;
|
139
|
end if;
|
140
|
if out_token_in_transit and not out_ready then
|
141
|
out_token_in_transit := false;
|
142
|
end if;
|
143
|
end loop;
|
144
|
end process queue_manager;
|
145
|
|
146
|
end architecture behavior;
|