我使用spike在“riscv-tools / riscv-tests / build / benchmarkmarks”中运行测试程序:
$ spike multiply.riscv
输出显示:
mcycle = 24096
minstret = 24103
为什么mcycle
小于minstret
?
剂量是否意味着尖峰可以在一个循环中运行多个指令? (我试图追踪尖峰代码,但无法找到如何计算mcycle。)
答案 0 :(得分:1)
在这种情况下,mcycle和minstret值的打印不是来自Spike,而是来自测试(基准)。有代码:
https://github.com/ucb-bar/riscv-benchmarks/blob/master/common/syscalls.c
#define NUM_COUNTERS 2
static uintptr_t counters[NUM_COUNTERS];
static char* counter_names[NUM_COUNTERS];
static int handle_stats(int enable)
{
int i = 0;
#define READ_CTR(name) do { \
while (i >= NUM_COUNTERS) ; \
uintptr_t csr = read_csr(name); \
if (!enable) { csr -= counters[i]; counter_names[i] = #name; } \
counters[i++] = csr; \
} while (0)
READ_CTR(mcycle);
READ_CTR(minstret);
#undef READ_CTR
return 0;
}
阅读mcycle& amp; minstret。现在您知道读数之间有多少代码。
在Spike mcycle&根据定义,minstret总是相等的(它们由相同的代码处理):https://github.com/riscv/riscv-isa-sim/blob/9e012462f53113dc9ed00d7fbb89aeafeb9b89e9/riscv/processor.cc#L347
case CSR_MINSTRET:
case CSR_MCYCLE:
if (xlen == 32)
state.minstret = (state.minstret >> 32 << 32) | (val & 0xffffffffU);
else
state.minstret = val;
break;
syscalls.c链接到https://github.com/ucb-bar/riscv-benchmarks/blob/master/multiply/bmark.mk的multiply.riscv二进制文件 - multiply_riscv_bin = multiply.riscv $(multiply_riscv_bin):... $(patsubst%.c,%。o,... syscalls.c ...)
syscalls.c函数中有_init
调用main
测试并打印值,记录在SYS_stats&#34;系统调用&#34;与handle_stats
。
void _init(int cid, int nc)
{
init_tls();
thread_entry(cid, nc);
// only single-threaded programs should ever get here.
int ret = main(0, 0);
char buf[NUM_COUNTERS * 32] __attribute__((aligned(64)));
char* pbuf = buf;
for (int i = 0; i < NUM_COUNTERS; i++)
if (counters[i])
pbuf += sprintf(pbuf, "%s = %d\n", counter_names[i], counters[i]);
if (pbuf != buf)
printstr(buf);
exit(ret);
}