Fix on-demand Instance/Sample removal code

This commit is contained in:
Greek 2021-01-26 20:45:59 +01:00
parent 728a6964d3
commit 8433006fb8

View File

@ -825,7 +825,8 @@ begin
-- Wait for Instance Search to finish -- Wait for Instance Search to finish
if (inst_op_done = '1') then if (inst_op_done = '1') then
sample_addr_next <= cur_sample + SMF_DISPOSED_GEN_CNT_OFFSET; sample_addr_next <= cur_sample + SMF_DISPOSED_GEN_CNT_OFFSET;
cur_inst_next <= inst_addr_base;
-- Instance Found -- Instance Found
if (inst_addr_base /= INSTANCE_MEMORY_MAX_ADDRESS) then if (inst_addr_base /= INSTANCE_MEMORY_MAX_ADDRESS) then
@ -1234,6 +1235,8 @@ begin
newest_sample_next <= empty_sample_list_head; newest_sample_next <= empty_sample_list_head;
end if; end if;
-- NOTE: added_new_instance and remove_oldest_sample are NOT mutual exclusive, but Instance Removal takes precedence.
-- New Instance was added, and Instance Memory is Full -- New Instance was added, and Instance Memory is Full
if (added_new_instance = '1' and inst_empty_head = INSTANCE_MEMORY_MAX_ADDRESS) then if (added_new_instance = '1' and inst_empty_head = INSTANCE_MEMORY_MAX_ADDRESS) then
-- Memory Operation Guard -- Memory Operation Guard
@ -1242,12 +1245,19 @@ begin
inst_opcode <= GET_FIRST_INSTANCE; inst_opcode <= GET_FIRST_INSTANCE;
inst_data_variant <= '0'; inst_data_variant <= '0';
-- NOTE: Instances are only removed in two occasions:
-- * A new instance is added, and the instance memory gets full
-- * A Sample is removed, making an instance eligible for deletion, while the
-- instance memory is full.
-- The combination of both cases allows to search and remove instances only when needed.
stage_next <= REMOVE_STALE_INSTANCE; stage_next <= REMOVE_STALE_INSTANCE;
else else
cnt_next <= cnt; -- Keep State cnt_next <= cnt; -- Keep State
end if; end if;
elsif (remove_oldest_inst_sample = '1') then elsif (remove_oldest_inst_sample = '1') then
sample_addr_next <= cur_sample + SMF_INSTANCE_ADDR_OFFSET; cur_sample <= oldest_sample;
sample_addr_next <= oldest_sample + SMF_INSTANCE_ADDR_OFFSET;
stage_next <= FIND_OLDEST_INST_SAMPLE; stage_next <= FIND_OLDEST_INST_SAMPLE;
elsif (remove_oldest_sample = '1') then elsif (remove_oldest_sample = '1') then
stage_next <= GET_OLDEST_SAMPLE_INSTANCE; stage_next <= GET_OLDEST_SAMPLE_INSTANCE;
@ -1290,19 +1300,19 @@ begin
-- Preload -- Preload
when 0 => when 0 =>
sample_ren <= '1'; sample_ren <= '1';
sample_addr_next <= cur_sample + SMF_NEXT_ADDR_OFFSET; -- Next Addr sample_addr_next <= cur_sample + SMF_NEXT_ADDR_OFFSET;
-- Instance Address -- Instance Address
when 1 => when 1 =>
sample_ren <= '1'; sample_ren <= '1';
-- Oldest Instance Sample Found -- Oldest Instance Sample Found
if (sample_read_data = inst_addr_base) then if (sample_read_data = cur_inst) then
stage_next <= REMOVE_SAMPLE; stage_next <= REMOVE_SAMPLE;
sample_addr_next <= cur_sample + SMF_PREV_ADDR_OFFSET; sample_addr_next <= cur_sample + SMF_PREV_ADDR_OFFSET;
end if; end if;
-- Next Address -- Next Address
when 2 => when 2 =>
cur_sample_next <= sample_read_data; cur_sample_next <= sample_read_data;
sample_addr_next <= sample_read_data + SMF_INSTANCE_ADDR_OFFSET; -- Instance Addr sample_addr_next <= sample_read_data + SMF_INSTANCE_ADDR_OFFSET;
cnt_next <= 0; cnt_next <= 0;
when others => when others =>
null; null;
@ -1558,8 +1568,14 @@ begin
if (inst_op_done = '1') then if (inst_op_done = '1') then
-- Iterated through all Instances -- Iterated through all Instances
if (inst_addr_base = INSTANCE_MEMORY_MAX_ADDRESS) then if (inst_addr_base = INSTANCE_MEMORY_MAX_ADDRESS) then
-- DONE if (remove_oldest_inst_sample = '1') then
stage_next <= IDLE; cur_sample <= oldest_sample;
sample_addr_next <= oldest_sample + SMF_INSTANCE_ADDR_OFFSET;
stage_next <= FIND_OLDEST_INST_SAMPLE;
else
-- DONE
stage_next <= IDLE;
end if;
else else
-- Convert Writer Bitmap to SLV -- Convert Writer Bitmap to SLV
tmp_bitmap := to_endpoint_bitmap(inst_data.writer_bitmap); tmp_bitmap := to_endpoint_bitmap(inst_data.writer_bitmap);
@ -1570,8 +1586,14 @@ begin
inst_op_start <= '1'; inst_op_start <= '1';
inst_opcode <= REMOVE_INSTANCE; inst_opcode <= REMOVE_INSTANCE;
-- DONE if (remove_oldest_inst_sample = '1') then
stage_next <= IDLE; cur_sample <= oldest_sample;
sample_addr_next <= oldest_sample + SMF_INSTANCE_ADDR_OFFSET;
stage_next <= FIND_OLDEST_INST_SAMPLE;
else
-- DONE
stage_next <= IDLE;
end if;
else else
-- Continue Search -- Continue Search
inst_op_start <= '1'; inst_op_start <= '1';