opentitan icon indicating copy to clipboard operation
opentitan copied to clipboard

[edn] assertion error in arbiter

Open weicaiyang opened this issue 5 years ago • 18 comments

@mwbranstad

I found this assertion error in top-level CSR test. it violates the protocol that the req can't be dropped without ready. The req is cleared due to system clock. Not sure if we should use entropy_enable to reset the arbiter or other way to avoid the assertion error. PTAL, thanks

Screen Shot 2021-02-22 at 11 57 31 AM

weicaiyang avatar Feb 22 '21 20:02 weicaiyang

@weicaiyang can you provide test, seed, repo level, and approx time?

mwbranstad avatar Feb 22 '21 23:02 mwbranstad

@mwbranstad i think it's all kind of up to you to decide if you want to allow this kind of behavior. By default i think our arbiters require that..if you request, you cannot de-assert your request until you've been granted.

Specifically in this case, the jen is a hardware request to jitter the clock. So if the enable is not there, ast technically has no need to request for entropy anymore. I assume that's why it dropped the request.

tjaychen avatar Feb 22 '21 23:02 tjaychen

@mwbranstad

please use VCS/2020.03-SP2 to reproduce it. Please you don't have this version. Run 20 cases with different seeds, and probably some of them may have the same failure.

Here is the command

cd hw/top_earlgrey/dv; 
$REPO_PATH/util/dvsim/dvsim.py chip_sim_cfg.hjson chip_csr_rw -w -s 157854891 

approx time and error

run.log:UVM_ERROR @ 892416425 ps: (prim_arbiter_ppc.sv:168) [ASSERT FAILED] ReqStaysHighUntilGranted0_M run.log:UVM_ERROR @ 892416425 ps: (prim_arbiter_ppc.sv:171) [ASSERT FAILED] LockArbDecision_A

weicaiyang avatar Feb 22 '21 23:02 weicaiyang

In case this stability cannot be guaranteed, the assertion can be disabled: https://github.com/lowRISC/opentitan/blob/50978abe1e2fd623cfd3693a5738f421fc349c92/hw/ip/prim/rtl/prim_arbiter_tree.sv#L43-L44

msfschaffner avatar Feb 23 '21 00:02 msfschaffner

After talking to @mwbranstad , we are going to check-in with Nuvoton to see if there's a better way of handling this. There is actually more than one scenario where the request could go away (the device going to sleep is potentially another one). It would be nice instead of just dropping the request, the ast could gracefully complete the request.

Also, just looking at the waveforms, there appears to be a cdc issue. jen coming from clkmgr is on the io_div4 domain, while the edn handling the request is on the main domain. The ast logic should probably use the supplied edn clocks and resets to construct the request interface instead of directly OR-ing together (this might already be done, but just not reflected in open source).

tjaychen avatar Feb 23 '21 21:02 tjaychen

@arnonsha @Jacob-Levy

tjaychen avatar Feb 23 '21 21:02 tjaychen

Synchronizing the enables to clk_ast_es_i... is it different then the edn clock?

///////////////////////////////////////
// Entropy Reset
///////////////////////////////////////
// Entropy Logic @clk_ast_es_i clock domain
// Reset De-Assert syncronizer
logic entropy_reset_n, sync_rst_es_n, rst_es_n;

assign entropy_reset_n = (rst_ast_es_ni && clk_src_sys_en_i && clk_src_sys_jen_i);

prim_flop_2sync #(
  .Width ( 1 ),
  .ResetValue ( 1'b0 )
) rst_es_da_sync (
  .clk_i ( clk_ast_es_i ),
  .rst_ni ( entropy_reset_n ),
  .d_i ( 1'b1 ),
  .q_o ( sync_rst_es_n )
);
assign rst_es_n = sync_rst_es_n;

And edn_req/edn_ack are done as follow, using the clk_ast_es_i and the rst_es_n

///////////////////////////////////////
// Entropy FIFO
///////////////////////////////////////
//
//                            64-bit FIFO
//          32 +----------------------------------------+ 1
// edn_bus =/=>|+--------------------+ +---------------+|-/-> To LFSR
// edn_ack --->|| 32-bit prim_packer |-| 32 1-bit fifo ||---> valid (!empty)
// edn_req <---|+--------------------+ +---------------+|<--- read_entropy
//             +----------------------------------------+
//
// The FIFO level should be calculated by (32*n - bits_to_LFSR)
// A request will be issue when the 32-bit buffer is empty!
// That means, the FIFO level <= 31 (?Air? bubble cleared from the fifo)
// So, making sure the req_o is/was issued when the FIFO level < 16 will
// be true at all time.

// FIFO RDP/WRP/Level
logic [6-1:0] fifo_cnt;            // For 32 1-bit FIFO
logic [5-1:0] fifo_rdp, fifo_wrp;  // FIFO read pointer & write pointer
logic [32-1:0] fifo_data;          // 32 1-bit FIFO
logic fifo_full, fifo_empty;

logic entropy_req, entropy_ack, entropy_bit, entropy_bit_valid;
logic [6-1:0] entropy_depth_o;
logic [32-1:0] entropy_bus;

assign entropy_req_o.edn_req = entropy_req;
assign entropy_ack = entropy_rsp_i.edn_ack;
assign entropy_bus = entropy_rsp_i.edn_bus;

prim_packer_fifo #(
  .InW ( 32 ),
  .OutW ( 1 )
) u_pached_fifo (
  .clk_i ( clk_ast_es_i ),
  .rst_ni ( rst_es_n ),
  .clr_i ( 1'b0 ),                      // Not used
  .wvalid_i ( entropy_ack ),            // EDN_ACK
  .wdata_i (  entropy_bus ),            // EDN_BUS (32-bit)
  .wready_o ( entropy_req ),            // EDN_REQ
  //
  .rvalid_o ( entropy_bit_valid ),      // Entropy bit is valid
  .rdata_o ( entropy_bit ),             // Entropy bit
  .rready_i ( !fifo_full ),             // FIFO is not full
  .depth_o ( entropy_depth_o[6-1:0] )   // empty when (entropy_depth_o == `0)
);

Jacob-Levy avatar Feb 23 '21 21:02 Jacob-Levy

hmmmm using the incoming enable as a reset feels like it could be problematic to me. This means potentially your edn_req will change asynchronously (1->0) relative to the module receiving your request right?

I think back to Mark's point, he prefers to have something complete gracefully as well.

tjaychen avatar Feb 23 '21 22:02 tjaychen

The clr_i of prim_packer_fifo is synchronous clear. I can use a synchronize version of: clr_i = sync( !(clk_src_sys_en_i && clk_src_sys_jen_i)); Then the edn_req will be dropped to '0' on the 'es' clock. Will this work?

prim_flop_2sync #(
  .Width ( 1 ),
  .ResetValue ( 1'b0 )
) rst_es_da_sync (
  .clk_i ( clk_ast_es_i ),
  .rst_ni ( rst_ast_es_ni ),
  .d_i ( !(clk_src_sys_en_i && clk_src_sys_jen_i) ),
  .q_o ( entropy_clr )
);

prim_packer_fifo #(
  .InW ( 32 ),
  .OutW ( 1 )
) u_pached_fifo (
  .clk_i ( clk_ast_es_i ),
  .rst_ni ( rst_ast_es_ni ),
  .clr_i ( entropy_clr ),               // EDN Clear
  .wvalid_i ( entropy_ack ),            // EDN_ACK
  .wdata_i (  entropy_bus ),            // EDN_BUS (32-bit)
  .wready_o ( entropy_req ),            // EDN_REQ
  //
  .rvalid_o ( entropy_bit_valid ),      // Entropy bit is valid
  .rdata_o ( entropy_bit ),             // Entropy bit
  .rready_i ( !fifo_full ),             // FIFO is not full
  .depth_o ( entropy_depth_o[6-1:0] )   // empty when (entropy_depth_o == `0)
);

Jacob-Levy avatar Feb 24 '21 00:02 Jacob-Levy

that sounds good to me. But to circle back to Mark's point, I believe he still prefers a more graceful completion of the transaction, instead of suddenly taking the request away.

tjaychen avatar Feb 24 '21 00:02 tjaychen

How can I be more graceful?

  • The request is generated when the FIFO is not full and not get cleared.
  • The entropy data is not required when system clock or the jitter are not enabled.

Jacob-Levy avatar Feb 24 '21 00:02 Jacob-Levy

I think what Mark had in mind (@mwbranstad please chime in so i don't put words in your mouth) is that when jen drops (or other similar conditions), just allow the current req/ack transaction to complete, and prevent new requests from going out.

tjaychen avatar Feb 24 '21 00:02 tjaychen

Added the following Flop on the request to decouple the FIFO clear from the req/ack interface. Hope this works :)

// .wready_o ( entropy_req_wrdy ),  // EDN_REQ Write Ready

assign set_entropy_req = !entropy_ack && entropy_req_wrdy;
assign clr_entropy_req =  entropy_ack;

always_ff @( posedge clk_ast_es_i, negedge rst_ast_es_ni ) begin
  if ( !rst_ast_es_ni ) begin
    entropy_req <= 1'b0;
  end else if ( set_entropy_req ) begin
    entropy_req <= 1'b1; 
  end else if ( clr_entropy_req ) begin
    entropy_req <= 1'b0;
  end
end

Jacob-Levy avatar Feb 24 '21 09:02 Jacob-Levy

As @tjaychen was suggesting, it would be best to construct the request logic to never drop the request before the ack. If conditions are such that the entropy is not needed, then when the ack returns, the entropy can be dropped. The above circuit makes sense in general in that it is more of a small state machine doing the coordination. To potentially avoid a loop case, instead of gating the set_entropy_req with the ack, maybe use the state of the flop, or equivalent. Side note: OT verilog guidelines recommend at least a "_q" at the end of a flop name. It actually helps for readability! Thanks for addressing.

mwbranstad avatar Feb 24 '21 15:02 mwbranstad

@mwbranstad @Jacob-Levy looks like we prefer to update the EDN request. Can you guys finalize it and make a PR to fix? Thanks

weicaiyang avatar Feb 25 '21 18:02 weicaiyang

PR is on the way :)

Jacob-Levy avatar Feb 25 '21 19:02 Jacob-Levy

@Jacob-Levy did your latest merged PR already fix this? Just wanted to see if we can close this.

tjaychen avatar Mar 05 '21 04:03 tjaychen

Yes it did. I hope :)

Jacob-Levy avatar Mar 05 '21 08:03 Jacob-Levy