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

Subversion Repositories hssdrc

[/] [hssdrc/] [trunk/] [testbench/] [hssrdc_bandwidth_monitor_class.sv] - Blame information for rev 4

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 des00
//
2
// Project      : High-Speed SDRAM Controller with adaptive bank management and command pipeline
3
//
4
// Project Nick : HSSDRC
5
//
6
// Version      : 1.0-beta
7
//
8
// Revision     : $Revision: 1.1 $
9
//
10
// Date         : $Date: 2008-03-06 13:54:00 $
11
//
12
// Workfile     : hssrdc_bandwidth_monitor_class.sv
13
//
14
// Description  : bandwidth monitor measurement class
15
//
16
// HSSDRC is licensed under MIT License
17
//
18
// Copyright (c) 2007-2008, Denis V.Shekhalev (des00@opencores.org)
19
//
20
// Permission  is hereby granted, free of charge, to any person obtaining a copy of
21
// this  software  and  associated documentation files (the "Software"), to deal in
22
// the  Software  without  restriction,  including without limitation the rights to
23
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
24
// the  Software, and to permit persons to whom the Software is furnished to do so,
25
// subject to the following conditions:
26
//
27
// The  above  copyright notice and this permission notice shall be included in all
28
// copies or substantial portions of the Software.
29
//
30
// THE  SOFTWARE  IS  PROVIDED  "AS  IS",  WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
32
// FOR  A  PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
33
// COPYRIGHT  HOLDERS  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
34
// IN  AN  ACTION  OF  CONTRACT,  TORT  OR  OTHERWISE,  ARISING  FROM, OUT OF OR IN
35
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36
//
37
 
38
 
39
`include "hssdrc_define.vh"
40
`include "hssdrc_timing.vh"
41
`include "hssdrc_tb_sys_if.vh"
42
 
43
`include "sdram_transaction_class.sv"
44
`include "hssrdc_driver_cbs_class.sv"
45
 
46
 
47
`ifndef __HSSDRC_BANDWIDTH_MONITOR_CLASS__
48
 
49
  `define __HSSDRC_BANDWIDTH_MONITOR_CLASS__
50
 
51
  class hssdrc_bandwidth_monitor_class extends hssrdc_driver_cbs_class;
52
 
53
    virtual hssdrc_tb_sys_if sys_if;
54
 
55
    // bandwidth measurement FSM
56
    enum {idle, wait_start, work} state = idle;
57
 
58
    // timestamps
59
    realtime end_time;
60
    realtime start_time;
61
 
62
    // word transfer counters
63
    int unsigned wr_word_num;
64
    int unsigned rd_word_num;
65
 
66
    // bandwidth measurement itself
67
    real write_bandwidth ;
68
    real read_bandwidth  ;
69
    real bandwidth       ;
70
 
71
    real write_bandwidth_percent  ;
72
    real read_bandwidth_percent   ;
73
    real bandwidth_percent        ;
74
 
75
    // semaphore to controll access to variables
76
    semaphore sem;
77
 
78
    // bandwidth measurement parameters
79
    real mbps_mfactor;
80
    real max_bandwidth;
81
 
82
    //  tb syncronization
83
    int measured_tr_num = 0;
84
    event done;
85
 
86
    function new (virtual hssdrc_tb_sys_if sys_if, ref event done);
87
      sem = new (1);
88
 
89
      this.sys_if = sys_if;
90
 
91
      this.done   = done;
92
    endfunction
93
 
94
 
95
    //
96
    // function to start measurement process
97
    //
98
 
99
    task start();
100
 
101
      sem.get (1) ;
102
 
103
      // set begin
104
      state = wait_start;
105
 
106
      // clear all counters
107
      end_time    = 0ns;
108
      start_time  = 0ns;
109
 
110
      wr_word_num = 0;
111
      rd_word_num = 0;
112
 
113
      measured_tr_num = 0;
114
 
115
      sem.put (1) ;
116
    endtask
117
 
118
    //
119
    // function to stop measurement process
120
    //
121
 
122
    task stop();
123
     sem.get (1);
124
 
125
     state = idle;
126
     count_bandwidth();
127
 
128
     sem.put (1);
129
 
130
    endtask
131
 
132
    //
133
    // callback for command part of hssdrc_driver_class
134
    //
135
 
136
    task post_Command (input realtime t);
137
    endtask
138
 
139
    //
140
    // callback for write part of hssdrc_driver_class
141
    //
142
 
143
    task post_WriteData (input realtime t, sdram_transaction_class tr);
144
      int burst;
145
    begin
146
 
147
      burst = tr.burst + 1;
148
 
149
      sem.get (1);
150
 
151
      if (state == wait_start) begin
152
        start_time  = t;
153
        state       = work;
154
      end
155
      else if (state == work) begin
156
        wr_word_num += burst;
157
        end_time    = t;
158
      end
159
 
160
      measured_tr_num++;
161
      -> done;
162
 
163
      sem.put (1);
164
    end
165
    endtask
166
 
167
    //
168
    // callback for read part of hssdrc_driver_class
169
    //
170
 
171
    task post_ReadData ( input realtime t, sdram_transaction_class tr);
172
      int burst;
173
    begin
174
 
175
      burst = tr.burst + 1;
176
 
177
      sem.get (1);
178
 
179
      if (state == wait_start) begin
180
        start_time  = t;
181
        state       = work;
182
      end
183
      else if (state == work) begin
184
        rd_word_num += burst;
185
        end_time    = t;
186
      end
187
 
188
      measured_tr_num++;
189
 
190
      -> done;
191
 
192
      sem.put (1);
193
    end
194
    endtask
195
 
196
    //
197
    // measurement count function bwth = mbps_mfactor*num/(end_time - start_time);
198
    //
199
 
200
    function void count_bandwidth();
201
      realtime delta;
202
      int unsigned wrrd_word_num;
203
    begin
204
 
205
      delta = (end_time - start_time);
206
 
207
      wrrd_word_num = wr_word_num + rd_word_num;
208
 
209
      write_bandwidth =   (wr_word_num/delta)*mbps_mfactor;
210
      read_bandwidth  =   (rd_word_num/delta)*mbps_mfactor;
211
      bandwidth       = (wrrd_word_num/delta)*mbps_mfactor;
212
 
213
      write_bandwidth_percent = write_bandwidth*100.0/max_bandwidth ;
214
      read_bandwidth_percent  = read_bandwidth *100.0/max_bandwidth ;
215
      bandwidth_percent       = bandwidth      *100.0/max_bandwidth ;
216
 
217
    end
218
    endfunction
219
 
220
    //
221
    // task to get multiplicatin factor for counters
222
    //
223
 
224
    task count_mbps_mfactor (int bytes_in_kilobytes) ;
225
      realtime delta;
226
      realtime scale;
227
    begin
228
      // define current timeunit value
229
      delta = $realtime;
230
      #1;
231
      delta = $realtime - delta;
232
 
233
      // define time scale factor
234
      scale = 1s/delta;
235
 
236
      // kilobytes
237
      mbps_mfactor = real'(scale)/(bytes_in_kilobytes);
238
 
239
      // megabytes
240
      mbps_mfactor = mbps_mfactor/(bytes_in_kilobytes);
241
 
242
      mbps_mfactor = mbps_mfactor*pDatamBits;
243
 
244
      // define max bandwwidth : 1 world per cycle period
245
      @(sys_if.cb);
246
      delta = $realtime;
247
      @(sys_if.cb);
248
      delta = $realtime - delta;
249
 
250
      max_bandwidth = (1/delta)*mbps_mfactor;
251
 
252
    end
253
    endtask
254
 
255
  endclass
256
 
257
`endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.