FPGA開発日記

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

サイクルベースシミュレータSniperについて調査する (サイクル情報の出力方法)

Sniperのトレースファイルを触っているのだが、いくつかやり方が分かってきた。

サイクルトーレスは一部しか出すことができず、もっと広範囲にトレースを出したい場合はソースコードを改変する必要がありそうだ。

  • config/base.cfg
[loop_tracer]
enabled = true
base_address = 800024ce # Start address in hex (without 0x)
iter_start = 1
iter_count = 36
  • ./common/performance_model/instruction_tracers/loop_tracer.cc
void
LoopTracer::traceInstruction(const DynamicMicroOp *uop, uop_times_t *times)
/* 途中省略 */
if (m_active)
   {
      std::pair<IntPtr, UInt8> opid(address, m_instr_uop);
      if (m_instructions.count(opid) == 0)
      {
         m_instructions[opid] = Instr(inst, m_instr_uop);
         m_disas_max = std::max(m_disas_max, (uint64_t)inst->getDisassembly().length());
      }
      m_instructions[opid].issued[m_iter_current - m_iter_start] = cycle_issue;

      m_cycle_min = std::min(m_cycle_min, cycle_issue);
      m_cycle_max = std::max(m_cycle_max, cycle_issue);

      ++m_instr_uop;
      if (uop->getMicroOp()->isLast())
      {
         ++m_iter_instr;
         m_instr_uop = 0;
      }

      // Record only up to 100 instructions
      if (m_iter_instr > 100)
         m_active = false;
   }

あとは、命令トレースのアセンブリ命令が正しく出てこないので多少ソースコードを修正する必要がある。これを解析するのに結構時間をとってしまった。

diff --git a/common/trace_frontend/trace_thread.cc b/common/trace_frontend/trace_thread.cc
index 60449f3..bbc7610 100644
--- a/common/trace_frontend/trace_thread.cc
+++ b/common/trace_frontend/trace_thread.cc
@@ -408,10 +408,8 @@ Instruction* TraceThread::decode(Sift::Instruction &inst)
    instruction->setAddress(va2pa(inst.sinst->addr));
    instruction->setSize(inst.sinst->size);
    instruction->setAtomic(dec_inst.is_atomic());
-   char disassembly[64];
-   dec_inst.disassembly_to_str();
-   instruction->setDisassembly(disassembly);
-   //printf("%s\n", instruction->getDisassembly().c_str());
+   instruction->setDisassembly(dec_inst.disassembly_to_str().c_str());
+   printf("%s\n", instruction->getDisassembly().c_str());

こうすると、最終的に以下のような感じて命令トレースが表れ始める。ただし、1000サイクルまで出し、折り返して表示できない。このへんはもうちょっと見やすさを改善したいところだなあ。

[SNIPER] Disabling performance models
[SNIPER] Leaving ROI after 1.26 seconds
[SNIPER] Simulated 0.2M instructions, 0.2M cycles, 1.17 IPC
[SNIPER] Simulation speed 172.7 KIPS (172.7 KIPS / target core - 5791.9ns/instr)
[SNIPER] Setting instrumentation mode to FAST_FORWARD
                                             0                   10                  20                  30                  40                  50                  60                  70                  80                  >
                                             0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 >
[80000000] mv          ra, zero       (0)    0                                                                                                                                                                                   >
[80000004] mv          sp, zero       (0)    0                                                                                                                                                                                   >
[80000008] mv          gp, zero       (0)    0                                                                                                                                                                                   >
[8000000c] mv          tp, zero       (0)      0                                                                                                                                                                                 >
[80000010] mv          t0, zero       (0)      0                                                                                                                                                                                 >
[80000014] mv          t1, zero       (0)      0                                                                                                                                                                                 >
[80000018] mv          t2, zero       (0)        0                                                                                                                                                                               >
[8000001c] mv          s0, zero       (0)        0                                                                                                                                                                               >
[80000020] mv          s1, zero       (0)        0                                                                                                                                                                               >
[80000024] mv          a0, zero       (0)          0                                                                                                                                                                             >
[80000028] mv          a1, zero       (0)          0                                                                                                                                                                             >
[8000002c] mv          a2, zero       (0)          0                                                                                                                                                                             >
[80000030] mv          a3, zero       (0)            0                                                                                                                                                                           >
[80000034] mv          a4, zero       (0)            0                                                                                                                                                                           >
[80000038] mv          a5, zero       (0)            0                                                                                                                                                                           >
[8000003c] mv          a6, zero       (0)              0                                                                                                                                                                         >
[80000040] mv          a7, zero       (0)                                                                                                                                                                                        >
[80000044] mv          s2, zero       (0)                                                                                                                                                                                        >
[80000048] mv          s3, zero       (0)                                                                                                                                                                                        >
[8000004c] mv          s4, zero       (0)                                                                                                                                                                                        >
[80000050] mv          s5, zero       (0)                                                                                                                                                                                        >
[80000054] mv          s6, zero       (0)                                                                                                                                                                                        >
[80000058] mv          s7, zero       (0)                                                                                                                                                                                        >
[8000005c] mv          s8, zero       (0)                                                                                                                                                                                        >
[80000060] mv          s9, zero       (0)                                                                                                                                                                                        >
[80000064] mv          s10, zero      (0)                                                                                                                                                                                        >
[80000068] mv          s11, zero      (0)                                                                                                                                                                                        >
[8000006c] mv          t3, zero       (0)                                                                                                                                                                                        >
[80000070] mv          t4, zero       (0)                                                                                                                                                                                        >
[80000074] mv          t5, zero       (0)                                                                                                                                                                                        >
[80000078] mv          t6, zero       (0)                                                                                                                                                                                        >
[8000007c] lui         t0, 122880     (0)                                                                                                                                                                                        >