Semiconductor Front-End Design: 100 Knocks (3) Round-Robin Arbiter

Semiconductor Front-End Design 100 Knocks, problem 3.

This time we build a Round-Robin Arbiter that selects exactly one out of multiple requesters. With simple fixed priority, a low-priority requester may never be granted, which is starvation. So we keep the requester granted last as state and change the next priority order dynamically.

First, let's consider a fixed 3-requester design.

The Problem

Build a 3-input Round-Robin Arbiter like the following.

module rr_arbiter (
    input  logic       i_clk,
    input  logic       i_rst_n,

    input  logic [2:0] i_req,
    output logic [2:0] o_grant
);

i_req[N] == 1 means Requester N is requesting the resource. o_grant is one-hot, and multiple bits must never be set at the same time.

In Round-Robin, the search starts from the requester after the one granted last time. For example, if Requester 0 was granted last time, the next priority order is 1 -> 2 -> 0. If it was Requester 2, the order is 0 -> 1 -> 2.

When all requesters keep issuing requests, grants must be given in order: 0 -> 1 -> 2 -> 0 -> ....

Thinking About the Internal State

This time, I decided to hold "which requester was granted last time" as a one-hot value.

logic [2:0] r_last_prio;

For example, r_last_prio = 3'b001 means Requester 0 was granted last. In this case, the next search order is 1 -> 2 -> 0.

r_last_prio = 3'b010 gives 2 -> 0 -> 1, and r_last_prio = 3'b100 gives 0 -> 1 -> 2.

Since the number of requesters is fixed at 3, we first write everything out explicitly with a case statement.

How to Decide the Grant

For example, if Requester 0 was granted last time, we check Requester 1 first.

case (r_last_prio)
3'b001: begin
    if (i_req[1]) begin
        o_grant = 3'b010;
    end else if (i_req[2]) begin
        o_grant = 3'b100;
    end else if (i_req[0]) begin
        o_grant = 3'b001;
    end
end

Because it is an if / else if chain, even if multiple requests are asserted at once, only the first match is granted. Therefore o_grant never becomes multi-hot.

The other states are written in the same way.

3'b010:
    2 -> 0 -> 1

3'b100:
    0 -> 1 -> 2

With only 3 requesters, writing them all out is the easiest to understand.

Updating the Priority State

We save the requester that was actually granted as the reference for the next time.

w_last_prio_next = r_last_prio;

This is the default, and only when a grant occurs, we perform an update equivalent to

w_last_prio_next = o_grant;

When there is no request at all, we set o_grant=0 and leave r_last_prio unchanged. If the priority were rotated on a cycle with no request, the Round-Robin reference would shift.

For that reason, the combinational logic sets default values at the beginning.

always_comb begin
    o_grant          = 3'b000;
    w_last_prio_next = r_last_prio;

    ...
end

If you forget this default assignment, o_grant is not assigned when i_req=0, which causes an unintended latch or X.

Watch Out for the Reset Value

Here r_last_prio holds not "the requester to give top priority next" but "the requester granted last time".

Therefore, if we want Requester 0 to have top priority right after reset, we need the search order to be

0 -> 1 -> 2

To get that, at reset we should pretend that "Requester 2 was granted last time".

r_last_prio <= 3'b100;

At first I had set this to 3'b001, but that means "Requester 0 was granted last time", so the first priority order after reset became 1 -> 2 -> 0.

If you are not clear about what the state means, it is easy to end up with an initial value that is off by one like this.

RTL

The final structure looks like this.

module rr_arbiter (
    input  logic       i_clk,
    input  logic       i_rst_n,

    input  logic [2:0] i_req,
    output logic [2:0] o_grant
);

logic [2:0] r_last_prio;
logic [2:0] w_last_prio_next;

always_comb begin
    o_grant          = 3'b000;
    w_last_prio_next = r_last_prio;

    case (r_last_prio)

        // Last grant = Requester 0
        // Next priority = 1 -> 2 -> 0
        3'b001: begin
            if (i_req[1]) begin
                o_grant          = 3'b010;
                w_last_prio_next = 3'b010;
            end else if (i_req[2]) begin
                o_grant          = 3'b100;
                w_last_prio_next = 3'b100;
            end else if (i_req[0]) begin
                o_grant          = 3'b001;
                w_last_prio_next = 3'b001;
            end
        end

        // Last grant = Requester 1
        // Next priority = 2 -> 0 -> 1
        3'b010: begin
            if (i_req[2]) begin
                o_grant          = 3'b100;
                w_last_prio_next = 3'b100;
            end else if (i_req[0]) begin
                o_grant          = 3'b001;
                w_last_prio_next = 3'b001;
            end else if (i_req[1]) begin
                o_grant          = 3'b010;
                w_last_prio_next = 3'b010;
            end
        end

        // Last grant = Requester 2
        // Next priority = 0 -> 1 -> 2
        3'b100: begin
            if (i_req[0]) begin
                o_grant          = 3'b001;
                w_last_prio_next = 3'b001;
            end else if (i_req[1]) begin
                o_grant          = 3'b010;
                w_last_prio_next = 3'b010;
            end else if (i_req[2]) begin
                o_grant          = 3'b100;
                w_last_prio_next = 3'b100;
            end
        end

        default: begin
            o_grant          = 3'b000;
            w_last_prio_next = 3'b100;
        end

    endcase
end

always_ff @(posedge i_clk or negedge i_rst_n) begin
    if (!i_rst_n) begin
        r_last_prio <= 3'b100;
    end else begin
        r_last_prio <= w_last_prio_next;
    end
end

endmodule

For a fixed 3 requesters, this is clear enough.


This is an English translation of the original Japanese post: 半導体フロントエンド設計100本ノック (3) Round-Robin Arbiter