Project

General

Profile

Download (6.6 KB) Statistics
| Branch: | Tag: | Revision:
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_srvr-b.vhd,v 1.2 2001-10-26 16:29:36 paw Exp $
23
-- $Revision: 1.2 $
24
--
25
-- ---------------------------------------------------------------------
26

    
27
library math;
28

    
29
architecture behavior of server is
30

    
31
begin
32

    
33
  service : process is
34

    
35
                      variable served_token : token_type;
36
                    variable release_time : time;
37
                    variable number_of_tokens_served : natural := 0;
38
                    variable service_time : natural;  -- in time_unit
39
                    variable sum_of_service_times : real := 0.0;  -- in time_unit
40
                    variable sum_of_squares_of_service_times : real := 0.0;  --in time_unit**2
41

    
42
                    variable random_info : random_info_record;
43
                    variable random_number : real;
44

    
45
                    use std.textio.all;
46
                    file info_file : text;
47
                    variable L : line;
48

    
49
                    use math.math_real.sqrt;
50

    
51
                    procedure write_summary is
52
                      variable measured_mean_service_time : real
53
                        := sum_of_service_times / real(number_of_tokens_served);
54
                      variable measured_std_dev_of_service_times : real
55
                        := sqrt ( ( sum_of_squares_of_service_times
56
                                    - sum_of_service_times**2 / real(number_of_tokens_served) )
57
                                  / real( number_of_tokens_served - 1 ) );
58
                    begin
59
                      write(L, string'("Summary information for server "));
60
                      write(L, name);
61
                      write(L, string'(" up to time "));
62
                      write(L, now, unit => time_unit);
63
                      writeline(info_file, L);
64
                      write(L, string'("  Service distribution: "));
65
                      write(L, distribution_type'image(distribution));
66
                      write(L, string'(" with mean service time of "));
67
                      write(L, mean_service_time, unit => time_unit);
68
                      writeline(info_file, L);
69
                      write(L, string'("  Number of tokens served = "));
70
                      write(L, natural(number_of_tokens_served));
71
                      writeline(info_file, L);
72
                      write(L, string'("  Mean service time = "));
73
                      write(L, measured_mean_service_time * time_unit, unit => time_unit);
74
                      writeline(info_file, L);
75
                      write(L, string'("  Standard deviation of service times = "));
76
                      write(L, measured_std_dev_of_service_times * time_unit, unit => time_unit);
77
                      writeline(info_file, L);
78
                      write(L, string'("  Utilization = "));
79
                      write(L, sum_of_service_times / real(now / time_unit), digits => 4);
80
                      writeline(info_file, L);
81
                      writeline(info_file, L);
82
                    end procedure write_summary;
83

    
84
                    procedure write_trace_service is
85
                    begin
86
                      write(L, string'("Server "));
87
                      write(L, name);
88
                      write(L, string'(": at "));
89
                      write(L, now, unit => time_unit);
90
                      write(L, string'(" served "));
91
                      write(L, in_arc.token, time_unit);
92
                      writeline(info_file, L);
93
                    end procedure write_trace_service;
94

    
95
                    procedure write_trace_release is
96
                    begin
97
                      write(L, string'("Server "));
98
                      write(L, name);
99
                      write(L, string'(": at "));
100
                      write(L, now, unit => time_unit);
101
                      write(L, string'(" released "));
102
                      write(L, served_token, time_unit);
103
                      writeline(info_file, L);
104
                    end procedure write_trace_release;
105

    
106
  begin
107
    file_open(info_file, info_file_name, write_mode);
108

    
109
    case distribution is
110
      when fixed =>
111
        init_fixed(random_info, real(mean_service_time / time_unit));
112
      when uniform =>
113
        init_uniform( random_info,
114
                      lower_bound => 0.0,
115
                      upper_bound => 2.0 * real(mean_service_time / time_unit),
116
                      seed => seed );
117
      when exponential =>
118
        init_exponential( random_info,
119
                          mean => real(mean_service_time / time_unit),
120
                          seed => seed );
121
    end case;
122

    
123
    in_ready <= true;
124
    loop
125
      wait on info_detail'transaction, in_arc;
126
      if info_detail'active and info_detail = summary then
127
        write_summary;
128
      end if;
129
      if in_arc'event then
130
	in_ready <= false;
131
        if info_detail = trace then
132
          write_trace_service;
133
        end if;
134
        served_token := in_arc.token;
135
        generate_random(random_info, random_number);
136
        service_time :=  natural(random_number);
137
        release_time := service_time * time_unit + now;
138
        loop
139
          wait on info_detail'transaction for release_time - now;
140
          if info_detail'active and info_detail = summary then
141
            write_summary;
142
          end if;
143
          exit when release_time = now;
144
        end loop;
145
	in_ready <= true;
146
	out_arc <= arc_type'( transaction => not out_arc.transaction'driving_value,
147
			      token => served_token );
148
        number_of_tokens_served := number_of_tokens_served + 1;
149
        sum_of_service_times := sum_of_service_times + real(service_time);
150
        sum_of_squares_of_service_times := sum_of_squares_of_service_times
151
                                           + real(service_time) ** 2;
152
        if info_detail = trace then
153
          write_trace_release;
154
        end if;
155
      end if;
156
    end loop;
157
  end process service;
158

    
159
end architecture behavior;
(151-151/171)