今天没意外的话,会是 Supporting PMUs on RISC-V platforms
的最後一篇,会整理一下,perf
使用情境、RISC-V
架构上的限制、Andes
提出的解决方案、以及目前社群上提出的解决方案!
perf 是一个 profiling 的工具,可分为两种模式,perf stat
、perf record
:
perf stat
:直接测量一个程序 (process) 执行,事件发生 (e.g. context switch、cycle) 的次数。
perf record
:取样 (sampling) 模式,基本有 2 种取样方式,第一种在一个程序执行过程,事件每发生 x 次,纪录一次;第二种,每秒取样 x 次,下面以第一种取样方式为例;
perf record
;perf stat
最基本的功能是可以实作出来的,大致上,在程序开始执行时,读一次 mcycle
,结束时,再读一次,计算,整个程序所耗费的 cycle 数就计算出来了;perf record
不同,就如同前两天所提到的:
将计数器设定成某个适当的值
这件事就无法达成;kernel mode
下的某特定事件发生次数)若要支援 perf record
,那麽至少以上提到的这些限制,全部都需要有方法能够处理。
在当时 Alan (笔者的团长兼组长) 就有提出相关的解决方案,以解决上面提到的限制。
就结论来说是新增 6 个 m mode 的暂存器:
mcounterinen(Machine Counter Interrupt Enable)
、mcounterovf(Machine Counter Overflow)
mcounterwen (Machine Counter-Write-Enable)
mcountermask_[m|s|u] (Machine Counter Mask for M-/S-/U-mode)
这篇提案是目前 Andes 在 RISC-V 平台上支援 perf 的方案,并提出到社群上与大家讨论。
(印象中是社群中第一个提出 HPM 相关解决方案的!XD)
提出方案後,社群讨论的状况很是踊跃,而且也有不少不同的厂家 (vendor) 正在准备相关的提案,後来由 Ventana: Greg Favor 提出的提案成为社群青睐的解决方案。
mhpmevent
的第 63 位元,并且连 H extension
都考虑到了,并在 interrupt 相关的暂存器上新增栏位 (mie/mip/sie/sip
的第 13 位元)bit [63] OF - Overflow status and interrupt disable bit that is set when counter overflows
63 位元的 OF 同时代表 overflow interrupt enable/disable 的状态,
和是否有 overflow 发生:
当 overflow 发生时,OF 会被设置成 1;
而当 overflow interrupt 发生时,会去检查 OF。
若这时候 OF 是 0,代表 interrupt 是 enable 的状态,
所以会产生 interrupt 并同时把 OF 设成 1;
若这时候 OF 是 1,代表 interrupt 是 disable 的状态,
所以不会产生 interrupt。
mhpmevent
的 58-62 位元,来限制各个 mode 下,计数器该不该运作bit [62] MINH - If set, then counting of events in M-mode is inhibited
bit [61] SINH - If set, then counting of events in S/HS-mode is inhibited
bit [60] UINH - If set, then counting of events in U-mode is inhibited
bit [59] VSINH - If set, then counting of events in VS-mode is inhibited
bit [58] VUINH - If set, then counting of events in VU-mode is inhibited
Although one such feature worth highlighting is having a WrEn bit in mhpmevent that allows lower privilege modes that can read the associated hpmcounter CSR (based on the *counteren CSRs) to also be able to write it. In essence enabling direct S/VS-mode and U/VU-mode write access instead of always requiring OpenSBI calls up to M-mode. But this feature has had some contention, involves some details to properly support virtualization, and requires allocating a second set of "User-Read-Write" hpmcounter CSR numbers (since the current hpmcounter CSRs are "User-Read-Only"). If there is a broad upwelling of support and justification for this feature, and some party willing to put together a complete spec (including virtualization support), then this could be another fast-track extension.
scountovf(Supervisor Count Overflow)
暂存器
mhpmcounter
的第 63 位元,用来快速辨认是哪一个 event 的计数器溢位了这是目前这个新扩充指令集(sscof)的简介,而目前 Linux kernel 和 QEMU 都有相关的 patch 正在被 review
Supporting PMUs on RISC-V platforms
这系列就到这里告一个段落啦!感谢各位观看,我们明天休息一下,接下来应该就是 Cache and TLB Flushing Under Linux
的文件系列罗!
<<: [常见的自然语言处理技术] Bag-of-Words Model:简单直观的统计语言模型
大型数字 ( 图形数字 ) 教学原文参考:大型数字 ( 图形数字 ) 如果要在 Scratch 3 ...
上线之後才是开始。 第一坑 开发和部署环境不一致 如果一开始开发和部署没有「乔好」环境的话,那上线的...
#Docker Install 安装下载相关套件 sudo apt-get update sudo ...
前言 这个演讲蛮general的,也适合任何leader来看看。如果你觉得team里面的人都不太爱...
本篇大纲:Generator、Component、Layout 截至目前,我们已经学会 D3 如何...