FPGA開発日記

カテゴリ別記事インデックス https://msyksphinz.github.io/github_pages , English Version https://fpgadevdiary.hatenadiary.com/

RISC-V OoOコアであるBOOMのChicken Bitを使うための試行

RISC-VのOut-of-orderedコアであるBOOMの詳細を少し調べていたのだが、Chicken Bitというのがある。 どうもアウトオブオーダ実行を止めることができる機能らしい。

と思ったら、あれ?違うかな。完全にPipelineをクリアしながら進めるのか。じゃあInOrderよりもかなり遅くなるな。

Chicken Bits
------------

BOOM supports a chicken-bit to delay all instructions from issue until the
pipeline clears. This effectively turns BOOM into a unpipelined in-order
core. The chicken bit is controlled by the third bit of the CSR at ``0x7c1``.
Writing this CSR with `csrwi 0x7c1, 0x8` will turn off all out-of-orderiness
in the core. High-performance can be re-enabled with `csrwi 0x7c1, 0x0`.
/**
  * Defines custom BOOM CSRs
  */
class BoomCustomCSRs(implicit p: Parameters) extends freechips.rocketchip.tile.CustomCSRs
  with HasBoomCoreParameters {
  override def chickenCSR = {
    val params = tileParams.core.asInstanceOf[BoomCoreParams]
    val mask = BigInt(
      tileParams.dcache.get.clockGate.toInt << 0 |
      params.clockGate.toInt << 1 |
      params.clockGate.toInt << 2 |
      1 << 3 // Disable OOO when this bit is high
    )
    val init = BigInt(
      tileParams.dcache.get.clockGate.toInt << 0 |
      params.clockGate.toInt << 1 |
      params.clockGate.toInt << 2 |
      0 << 3 // Enable OOO at init
    )
    Some(CustomCSR(chickenCSRId, mask, Some(init)))
  }
  def disableOOO = getOrElse(chickenCSR, _.value(3), true.B)
}

Chicken Bitは0x7c1に設定されている。これをベンチマークでの評価に活用してみたい。

テストベンチに以下のような機能を用意する。

diff --git a/common/common.h b/common/common.h
index cacfe37..865c850 100644
--- a/common/common.h
+++ b/common/common.h
@@ -104,3 +104,20 @@ void init_array_one_2d(double **ar, int n, int m) {
     for (int j = 0; j < m; ++j)
       ar[i][j] = 1;
 }
+
+void boom_disable_ooo ()
+{
+  // 0x7c1 is chicken bit
+  asm volatile ("csrsi 0x7c1, 3");
+}

これを搭載してChipyard上のBOOMを実行してみた。

0 0x000000000001131a sb      a1, 1(a4)
0 0x000000000001131e sb      a1, 0(a4)
0 0x0000000000011322 ret
3 0x0000000080000004 csrrw   sp, mscratch, sp x 2 0x000000008000fec0
3 0x0000000080000008 beqz    sp, pc + 432
3 0x000000008000000c sd      a0, 80(sp)
3 0x0000000080000010 sd      a1, 88(sp)
3 0x0000000080000014 csrr    a1, mcause x11 0x0000000000000002
3 0x0000000080000018 bgez    a1, pc + 132
3 0x000000008000009c sd      ra, 8(sp)
3 0x00000000800000a0 sd      gp, 24(sp)
3 0x00000000800000a4 sd      tp, 32(sp)
3 0x00000000800000a8 sd      t0, 40(sp)
3 0x00000000800000ac auipc   t0, 0xc x 5 0x000000008000c0ac
3 0x00000000800000b0 sd      t1, 48(sp)
3 0x00000000800000b4 slli    t1, a1, 3 x 6 0x0000000000000010
3 0x00000000800000b8 sd      t2, 56(sp)

うーん、例外が発生したっぽい?