我有一个用于数据和指令缓存的VHDL设计。我想用测试平台评估它(找到未命中率等)。
所以我想知道如何创建对缓存的随机请求?以及如何使他们喜欢某种类型的地方或有一个模式(如顺序访问,但偶尔在程序中随机跳转)?
换句话说,如何制作VHDL基准来评估不同条件下的缓存设计和内存访问模式?
答案 0 :(得分:2)
要获取随机数,请使用OSVVM - Open source, VHDL verification methodology库。
要获得“有趣的模式”,您可以利用Hennesey和Patterson的经典Computer Architecture中提供的缓存访问数据来创建各种小块和大块块大小和分色的实际概率。
答案 1 :(得分:1)
考虑一下您希望看到的缓存模式的类型,您应该能够使用IEEE.MATH_REAL.uniform在测试平台中相当容易地编写它们。
以偶尔的随机跳转为例来说明顺序访问:
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.NUMERIC_STD.all;
use IEEE.MATH_REAL.all;
entity ...
architecture ...
signal cache_read : std_logic := '0';
signal cache_addr : unsigned(31 downto 0) := (others=>'0');
...
begin
sequential_and_jumps: process
variable seed1, seed2 : positive := 42;
variable rand : real;
variable loops : integer;
variable addr : integer;
begin
cache_read <= '0';
wait until reset='0' and rising_edge(clk);
-- Starting address.
addr := 0;
-- Continual repeated accesses.
loop
-- Randomly jump to a new address between 0x0 and 0x10000
-- with a chance of 10%.
uniform(seed1, seed2, rand);
if(rand < 0.1) then
uniform(seed1, seed2, rand);
addr := integer(trunc(rand * real(16#10000#)));
end if;
-- Wait 0-15 cycles prior to the cache request.
uniform(seed1, seed2, rand);
loops := integer(trunc(rand*16.0));
for i in 1 to loops loop
wait until rising_edge(clk);
end loop;
-- Randomly request 1-32 words.
uniform(seed1, seed2, rand);
loops := integer(trunc(rand*32.0)) + 1;
for i in 1 to loops loop
cache_addr <= to_unsigned(addr, cache_addr'length);
cache_read <= '1';
wait until rising_edge(clk);
cache_read <= '0';
-- Assumes word addresses.
-- For byte addresses, increment by e.g. 4 for 32-bit words.
addr := addr + 1;
end loop;
end loop;
end process;
end architecture;
其他访问模式可以通过类似方式实现。