Commit a12909b5 authored by Pablo Andreu's avatar Pablo Andreu
Browse files

Improved leaky bucket algorithm randomizer

- Now is more fair and works as expected
- Removed useless xor operation on randomization
parent 4710cf6d
......@@ -57,7 +57,7 @@
wire [DATA_WIDTH-1:0] quotaResetPeriodRandomized;
reg [DATA_WIDTH-1:0] quotaResetPeriodRandomizedRegistered = 32'b0;
reg [DATA_WIDTH-1:0] quotaResetPeriodRandomizedRegistered[N_CORES-1:0] = '{default:0};
wire [DATA_WIDTH-1:0] outputRNG;
wire [DATA_WIDTH-1:0] quotaResetPeriodScaled;
wire [DATA_WIDTH-1:0] outputRNGMask;
......@@ -70,7 +70,7 @@
assign outputRNGMask[z] = quotaResetPeriodScaled[z] | outputRNGMask[z+1];
end
assign quotaResetPeriodRandomized = quotaResetPeriodScaled ^ (outputRNG & outputRNGMask);
assign quotaResetPeriodRandomized = outputRNG & outputRNGMask;
LFSR #(
.NUM_BITS(DATA_WIDTH)
......@@ -84,18 +84,22 @@
.o_LFSR_Done()
);
reg[31:0] cycleCounter = 0;
integer i;
reg[31:0] cycleCounter[N_CORES-1:0] = '{default:0};
always @(posedge clk_i, negedge rstn_i) begin : CycleCounter
if(!rstn_i)
cycleCounter <= 0;
else if(enableLeakyBucket && enable_i) begin
if(cycleCounter < quotaResetPeriodRandomizedRegistered) begin
cycleCounter <= cycleCounter+1;
if(!rstn_i) begin
for(i=0; i < N_CORES; i++)begin
cycleCounter[i] <= 0;
end
end else if(enableLeakyBucket && enable_i) begin
for(i=0; i < N_CORES; i++) begin
if((interruption_quota_o[i] == 1) && cycleCounter[i] < quotaResetPeriodRandomizedRegistered[i]) begin
cycleCounter[i] <= cycleCounter[i]+1;
end else begin
quotaResetPeriodRandomizedRegistered <= quotaResetPeriodRandomized;
cycleCounter <= 0;
end
quotaResetPeriodRandomizedRegistered[i] <= quotaResetPeriodRandomized;
cycleCounter[i] <= 0;
end
end
end
end
......@@ -126,7 +130,6 @@
Generate one mechanism to monitor the quota for each of the cores in the
SOC,
----------*/
integer i;
integer j;
// generate begin : GeneratedQuotaMonitor
always @(posedge clk_i, negedge rstn_i) begin: AsyncReset
......@@ -226,7 +229,7 @@
quota_int[i] <= quota_i[i];
//Enable && !update:Replace quota_int with quota_int minus
// consumed quota (ccc_quota)
end else if (enable_i && !update_quota_i[i] && !(enableLeakyBucket && (cycleCounter == quotaResetPeriodRandomizedRegistered))) begin
end else if (enable_i && !update_quota_i[i] && !(enableLeakyBucket && (cycleCounter[i] == quotaResetPeriodRandomizedRegistered[i]))) begin
for (j=0; j<CORE_EVENTS; j=j+1) begin
//underflow detection. Padding needed for
// prevent width mismatch
......@@ -239,7 +242,7 @@
end
//Enable && update: Update values quota_int with quota_i and
// substract ccc_quota
end else if(enable_i && (update_quota_i[i] || (enableLeakyBucket && (cycleCounter == quotaResetPeriodRandomizedRegistered))))begin
end else if(enable_i && (update_quota_i[i] || (enableLeakyBucket && (cycleCounter[i] == quotaResetPeriodRandomizedRegistered[i]))))begin
for (j=0; j<CORE_EVENTS; j=j+1) begin
//underflow detection. Padding needed for
// prevent width mismatch
......@@ -326,7 +329,7 @@
for(x=0; x<N_CORES; x=x+1) begin: InterruptionQuotaHold
always @(posedge clk_i) begin
if(rstn_i == 1'b0 | (enableLeakyBucket & (cycleCounter == quotaResetPeriodRandomizedRegistered))) begin
if(rstn_i == 1'b0 | (enableLeakyBucket & (cycleCounter[x] == quotaResetPeriodRandomizedRegistered[x]))) begin
interruption_quota_q[x] <= '0;
end else begin
interruption_quota_q[x] <= interruption_quota_d[x] | interruption_quota_q[x];
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment