//
|
//
|
// Project : High-Speed SDRAM Controller with adaptive bank management and command pipeline
|
// Project : High-Speed SDRAM Controller with adaptive bank management and command pipeline
|
//
|
//
|
// Project Nick : HSSDRC
|
// Project Nick : HSSDRC
|
//
|
//
|
// Version : 1.0-beta
|
// Version : 1.0-beta
|
//
|
//
|
// Revision : $Revision: 1.1 $
|
// Revision : $Revision: 1.1 $
|
//
|
//
|
// Date : $Date: 2008-03-06 13:54:00 $
|
// Date : $Date: 2008-03-06 13:54:00 $
|
//
|
//
|
// Workfile : hssrdc_bandwidth_monitor_class.sv
|
// Workfile : hssrdc_bandwidth_monitor_class.sv
|
//
|
//
|
// Description : bandwidth monitor measurement class
|
// Description : bandwidth monitor measurement class
|
//
|
//
|
// HSSDRC is licensed under MIT License
|
// HSSDRC is licensed under MIT License
|
//
|
//
|
// Copyright (c) 2007-2008, Denis V.Shekhalev (des00@opencores.org)
|
// Copyright (c) 2007-2008, Denis V.Shekhalev (des00@opencores.org)
|
//
|
//
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
// this software and associated documentation files (the "Software"), to deal in
|
// this software and associated documentation files (the "Software"), to deal in
|
// the Software without restriction, including without limitation the rights to
|
// the Software without restriction, including without limitation the rights to
|
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
// the Software, and to permit persons to whom the Software is furnished to do so,
|
// the Software, and to permit persons to whom the Software is furnished to do so,
|
// subject to the following conditions:
|
// subject to the following conditions:
|
//
|
//
|
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
//
|
//
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
//
|
//
|
|
|
|
|
`include "hssdrc_define.vh"
|
`include "hssdrc_define.vh"
|
`include "hssdrc_timing.vh"
|
`include "hssdrc_timing.vh"
|
`include "hssdrc_tb_sys_if.vh"
|
`include "hssdrc_tb_sys_if.vh"
|
|
|
`include "sdram_transaction_class.sv"
|
`include "sdram_transaction_class.sv"
|
`include "hssrdc_driver_cbs_class.sv"
|
`include "hssrdc_driver_cbs_class.sv"
|
|
|
|
|
`ifndef __HSSDRC_BANDWIDTH_MONITOR_CLASS__
|
`ifndef __HSSDRC_BANDWIDTH_MONITOR_CLASS__
|
|
|
`define __HSSDRC_BANDWIDTH_MONITOR_CLASS__
|
`define __HSSDRC_BANDWIDTH_MONITOR_CLASS__
|
|
|
class hssdrc_bandwidth_monitor_class extends hssrdc_driver_cbs_class;
|
class hssdrc_bandwidth_monitor_class extends hssrdc_driver_cbs_class;
|
|
|
virtual hssdrc_tb_sys_if sys_if;
|
virtual hssdrc_tb_sys_if sys_if;
|
|
|
// bandwidth measurement FSM
|
// bandwidth measurement FSM
|
enum {idle, wait_start, work} state = idle;
|
enum {idle, wait_start, work} state = idle;
|
|
|
// timestamps
|
// timestamps
|
realtime end_time;
|
realtime end_time;
|
realtime start_time;
|
realtime start_time;
|
|
|
// word transfer counters
|
// word transfer counters
|
int unsigned wr_word_num;
|
int unsigned wr_word_num;
|
int unsigned rd_word_num;
|
int unsigned rd_word_num;
|
|
|
// bandwidth measurement itself
|
// bandwidth measurement itself
|
real write_bandwidth ;
|
real write_bandwidth ;
|
real read_bandwidth ;
|
real read_bandwidth ;
|
real bandwidth ;
|
real bandwidth ;
|
|
|
real write_bandwidth_percent ;
|
real write_bandwidth_percent ;
|
real read_bandwidth_percent ;
|
real read_bandwidth_percent ;
|
real bandwidth_percent ;
|
real bandwidth_percent ;
|
|
|
// semaphore to controll access to variables
|
// semaphore to controll access to variables
|
semaphore sem;
|
semaphore sem;
|
|
|
// bandwidth measurement parameters
|
// bandwidth measurement parameters
|
real mbps_mfactor;
|
real mbps_mfactor;
|
real max_bandwidth;
|
real max_bandwidth;
|
|
|
// tb syncronization
|
// tb syncronization
|
int measured_tr_num = 0;
|
int measured_tr_num = 0;
|
event done;
|
event done;
|
|
|
function new (virtual hssdrc_tb_sys_if sys_if, ref event done);
|
function new (virtual hssdrc_tb_sys_if sys_if, ref event done);
|
sem = new (1);
|
sem = new (1);
|
|
|
this.sys_if = sys_if;
|
this.sys_if = sys_if;
|
|
|
this.done = done;
|
this.done = done;
|
endfunction
|
endfunction
|
|
|
|
|
//
|
//
|
// function to start measurement process
|
// function to start measurement process
|
//
|
//
|
|
|
task start();
|
task start();
|
|
|
sem.get (1) ;
|
sem.get (1) ;
|
|
|
// set begin
|
// set begin
|
state = wait_start;
|
state = wait_start;
|
|
|
// clear all counters
|
// clear all counters
|
end_time = 0ns;
|
end_time = 0ns;
|
start_time = 0ns;
|
start_time = 0ns;
|
|
|
wr_word_num = 0;
|
wr_word_num = 0;
|
rd_word_num = 0;
|
rd_word_num = 0;
|
|
|
measured_tr_num = 0;
|
measured_tr_num = 0;
|
|
|
sem.put (1) ;
|
sem.put (1) ;
|
endtask
|
endtask
|
|
|
//
|
//
|
// function to stop measurement process
|
// function to stop measurement process
|
//
|
//
|
|
|
task stop();
|
task stop();
|
sem.get (1);
|
sem.get (1);
|
|
|
state = idle;
|
state = idle;
|
count_bandwidth();
|
count_bandwidth();
|
|
|
sem.put (1);
|
sem.put (1);
|
|
|
endtask
|
endtask
|
|
|
//
|
//
|
// callback for command part of hssdrc_driver_class
|
// callback for command part of hssdrc_driver_class
|
//
|
//
|
|
|
task post_Command (input realtime t);
|
task post_Command (input realtime t);
|
endtask
|
endtask
|
|
|
//
|
//
|
// callback for write part of hssdrc_driver_class
|
// callback for write part of hssdrc_driver_class
|
//
|
//
|
|
|
task post_WriteData (input realtime t, sdram_transaction_class tr);
|
task post_WriteData (input realtime t, sdram_transaction_class tr);
|
int burst;
|
int burst;
|
begin
|
begin
|
|
|
burst = tr.burst + 1;
|
burst = tr.burst + 1;
|
|
|
sem.get (1);
|
sem.get (1);
|
|
|
if (state == wait_start) begin
|
if (state == wait_start) begin
|
start_time = t;
|
start_time = t;
|
state = work;
|
state = work;
|
end
|
end
|
else if (state == work) begin
|
else if (state == work) begin
|
wr_word_num += burst;
|
wr_word_num += burst;
|
end_time = t;
|
end_time = t;
|
end
|
end
|
|
|
measured_tr_num++;
|
measured_tr_num++;
|
-> done;
|
-> done;
|
|
|
sem.put (1);
|
sem.put (1);
|
end
|
end
|
endtask
|
endtask
|
|
|
//
|
//
|
// callback for read part of hssdrc_driver_class
|
// callback for read part of hssdrc_driver_class
|
//
|
//
|
|
|
task post_ReadData ( input realtime t, sdram_transaction_class tr);
|
task post_ReadData ( input realtime t, sdram_transaction_class tr);
|
int burst;
|
int burst;
|
begin
|
begin
|
|
|
burst = tr.burst + 1;
|
burst = tr.burst + 1;
|
|
|
sem.get (1);
|
sem.get (1);
|
|
|
if (state == wait_start) begin
|
if (state == wait_start) begin
|
start_time = t;
|
start_time = t;
|
state = work;
|
state = work;
|
end
|
end
|
else if (state == work) begin
|
else if (state == work) begin
|
rd_word_num += burst;
|
rd_word_num += burst;
|
end_time = t;
|
end_time = t;
|
end
|
end
|
|
|
measured_tr_num++;
|
measured_tr_num++;
|
|
|
-> done;
|
-> done;
|
|
|
sem.put (1);
|
sem.put (1);
|
end
|
end
|
endtask
|
endtask
|
|
|
//
|
//
|
// measurement count function bwth = mbps_mfactor*num/(end_time - start_time);
|
// measurement count function bwth = mbps_mfactor*num/(end_time - start_time);
|
//
|
//
|
|
|
function void count_bandwidth();
|
function void count_bandwidth();
|
realtime delta;
|
realtime delta;
|
int unsigned wrrd_word_num;
|
int unsigned wrrd_word_num;
|
begin
|
begin
|
|
|
delta = (end_time - start_time);
|
delta = (end_time - start_time);
|
|
|
wrrd_word_num = wr_word_num + rd_word_num;
|
wrrd_word_num = wr_word_num + rd_word_num;
|
|
|
write_bandwidth = (wr_word_num/delta)*mbps_mfactor;
|
write_bandwidth = (wr_word_num/delta)*mbps_mfactor;
|
read_bandwidth = (rd_word_num/delta)*mbps_mfactor;
|
read_bandwidth = (rd_word_num/delta)*mbps_mfactor;
|
bandwidth = (wrrd_word_num/delta)*mbps_mfactor;
|
bandwidth = (wrrd_word_num/delta)*mbps_mfactor;
|
|
|
write_bandwidth_percent = write_bandwidth*100.0/max_bandwidth ;
|
write_bandwidth_percent = write_bandwidth*100.0/max_bandwidth ;
|
read_bandwidth_percent = read_bandwidth *100.0/max_bandwidth ;
|
read_bandwidth_percent = read_bandwidth *100.0/max_bandwidth ;
|
bandwidth_percent = bandwidth *100.0/max_bandwidth ;
|
bandwidth_percent = bandwidth *100.0/max_bandwidth ;
|
|
|
end
|
end
|
endfunction
|
endfunction
|
|
|
//
|
//
|
// task to get multiplicatin factor for counters
|
// task to get multiplicatin factor for counters
|
//
|
//
|
|
|
task count_mbps_mfactor (int bytes_in_kilobytes) ;
|
task count_mbps_mfactor (int bytes_in_kilobytes) ;
|
realtime delta;
|
realtime delta;
|
realtime scale;
|
realtime scale;
|
begin
|
begin
|
// define current timeunit value
|
// define current timeunit value
|
delta = $realtime;
|
delta = $realtime;
|
#1;
|
#1;
|
delta = $realtime - delta;
|
delta = $realtime - delta;
|
|
|
// define time scale factor
|
// define time scale factor
|
scale = 1s/delta;
|
scale = 1s/delta;
|
|
|
// kilobytes
|
// kilobytes
|
mbps_mfactor = real'(scale)/(bytes_in_kilobytes);
|
mbps_mfactor = real'(scale)/(bytes_in_kilobytes);
|
|
|
// megabytes
|
// megabytes
|
mbps_mfactor = mbps_mfactor/(bytes_in_kilobytes);
|
mbps_mfactor = mbps_mfactor/(bytes_in_kilobytes);
|
|
|
mbps_mfactor = mbps_mfactor*pDatamBits;
|
mbps_mfactor = mbps_mfactor*pDatamBits;
|
|
|
// define max bandwwidth : 1 world per cycle period
|
// define max bandwwidth : 1 world per cycle period
|
@(sys_if.cb);
|
@(sys_if.cb);
|
delta = $realtime;
|
delta = $realtime;
|
@(sys_if.cb);
|
@(sys_if.cb);
|
delta = $realtime - delta;
|
delta = $realtime - delta;
|
|
|
max_bandwidth = (1/delta)*mbps_mfactor;
|
max_bandwidth = (1/delta)*mbps_mfactor;
|
|
|
end
|
end
|
endtask
|
endtask
|
|
|
endclass
|
endclass
|
|
|
`endif
|
`endif
|
|
|