A proposal to enhance RISC-V HPM (Hardware Performance Monitor)
To be fair, I said the same thing a month or so ago and had the same thing pointed out to me!
toggle quoted message
Show quoted text
-Allen On Aug 21, 2020, at 10:25 AM, Bill Huffman <huffman@...> wrote:
|
|
Bill Huffman
You're right, Allen. I didn't think that one was true. Delegation bits are presumably part of the core dispatch area and not kept somewhere else. It would be different to have exceptions depend on operational performance counter registers, though. Bill On 8/20/20 9:26 PM, Allen Baum wrote:
|
|
Prvi spec v1.12 sec 3.1.12: When the CY, TM, IR, or HPMn bit in the mcounteren register is clear, attempts to read the cycle, time, instret, or hpmcountern register while executing in S-mode or U-mode will cause an illegal instruction exception. When one of these bits is set, access to the corresponding register is permitted in the next implemented privilege mode (S-mode if implemented, otherwise U-mode). On Thu, Aug 20, 2020 at 3:29 PM Allen Baum via lists.riscv.org <allen.baum=esperantotech.com@...> wrote:
|
|
Bill Huffman
The CSRs can determine what happens on a write and what is read on a read. But they cannot control whether a read or write is legal as far as I know. Bill On 8/20/20 3:28 PM, Allen Baum wrote:
|
|
Well, I'd be a little bit more specific: access can be conditioned on more than the CSR number, as the existence of Mcounteren CSR proves. But, in that case, the register bit that controls access is static, held in a CSR, not dynamic and selected by the instruction, as a GPR value would do. On Thu, Aug 20, 2020 at 12:35 PM Bill Huffman <huffman@...> wrote:
|
|
Bill Huffman
Chuanhua, The spec is set to determine writable (and required privilege) based entirely on CSR number. Anything that determined exceptions based on data or the current value of the register has been very carefully avoided. I expect that avoidance to continue. I'm not knowledgeable on the proposal. I'm just commenting on CSR instruction exceptions based on additional bits. Bill On 8/19/20 9:16 PM, Chuanhua Chang wrote:
|
|
Chuanhua Chang
Hi, Bill,
I understand your timing concern for generating an exception based on data values. However, the concern is for data values directly read out from the general registers (GPR/FPR) by the instruction itself and the exception is generated based on these values or some computations of these values, so the timing is tight between the data read out and computation of an exception (such as divide by zero). The concern is usually not for using data values (1 or 2 bits as control) in CSRs written by a previous instruction or even relaxed, by a previous instruction in a different privileged mode (i.e., relaxed in terms of the length of time between the write and the use). The current mcounteren CSR value is already used to control the generation of an exception of the read operation of the hmpcounter CSRs for S and U-mode. The timing should be similar, if we have a mcounterwen CSR and use its value to control the generation of an exception of the write operation of a counter CSR for S and U-mode. This is a general discussion. I am fine with dropping the S-mode direct counter update proposal based on its limited use case. Regards, Chuanhua |
|
Chuanhua Chang
Hi, Anup,
I am fine with dropping the proposal of letting the S-mode write HPMCOUNTER CSRs directly based on its limited use cases in debugging and analysis. Regards, Chuanhua |
|
Bill Huffman
On 8/18/20 8:19 AM, Chuanhua Chang wrote:
They're not the same idea. The PMP L bit changes the meaning of a write. Rather than becoming a read-only register, it remains read-write, but writes behave differently and do nothing. Registers with read-only numbers always take an exception on write. The idea behind this is that exceptions do not depend on data in CSR registers to avoid difficult timing/layout issues. Bill
|
|
Hi Chuanhua,
Even if we ignore the RISC-V CSR range violation in allowing writes to HPMCOUNTER CSR from S-mode, still the “bypass-sbi” DT property is not an acceptable solution.
The “bypass-sbi” DT property will make Linux PMU driver do things differently for HS-mode and VS-mode. Further, it is totally unclear how “bypass-sbi” DT property should be used in nested virtualization because here we will have virtual VS-mode (Guest OS) running on virtual HS-mode (Guest Hypervisor) which in-turn runs on real HS-mode (Host Hypervisor). For a clean nested virtualization, both HS-mode (Hypervisor) and VS-mode (Guest) should write HPMCOUNTER CSR in the same way.
Further, the “bypass-sbi” DT property cannot be used for existing RISC-V platforms (SiFive Unleashed, Microchip PolarFire, etc) because existing HARDWARE don’t have proposed “write-enable” bit in HPMEVENT CSR. This means Linux PMU driver will again have to do things differently for existing RISC-V platforms.
I think if we want to allow S-mode direct writes to HPMCOUNTER CSRs along with clean nested virtualization then it is better to add separate HS-mode and VS-mode CSRs. Although, I am still wondering why we should allow S-mode direct writes to HPMCOUNTER CSRs considering Linux perf tools are only used for debugging and analysis.
Regards, Anup
From: tech-privileged@... <tech-privileged@...>
On Behalf Of Chuanhua Chang
Sent: 18 August 2020 20:49 To: tech-privileged@... Subject: Re: [RISC-V] [tech-privileged] A proposal to enhance RISC-V HPM (Hardware Performance Monitor)
Hi, Anup, |
|
Chuanhua Chang
Hi, Anup,
Regarding the aspect of a "read-only" CSR, in the RISC-V PMP design, a control bit "L" in the pmpcfg CSR, once set, will change the corresponding read/write pmpaddr CSR to a "read-only" CSR. So fundamentally, I do not see any reason why a control bit cannot change a "read-only" CSR to a "read/write" CSR. It should be similar to the above case in terms of implementation complexity. And regarding the aspect of a "user" CSR, I also do not see any reason why a higher privileged mode such as S-mode cannot write to a user register, once the write permission is allowed by M-mode. Regards, Chuanhua |
|
Hi Chuanhua,
The fact that “write-enable” bit in HPMEVENT CSR makes corresponding HPMCOUNTER as writeable violates the RISC-V CSR numbering scheme of RISC-V privilege spec because it allows S-mode writing to a CSR from “User-read-only” range.
Regards, Anup
From: tech-privileged@... <tech-privileged@...>
On Behalf Of Chuanhua Chang
Sent: 18 August 2020 15:35 To: tech-privileged@... Subject: Re: [RISC-V] [tech-privileged] A proposal to enhance RISC-V HPM (Hardware Performance Monitor)
The idea of adding write enable bit without adding extra CSR in the read/write register range is that the setting of the write enable bit will change the read-only CSR to a read/write CSR. |
|
Hi Alan,
Like mentioned previously, having different mechanism for HS-mode and VS-mode to write HPMCOUNTER CSR is not acceptable. The “bypass-sbi” DT property only means that Linux PMU driver is now aware whether it is running natively or running inside Guest/VM. This is totally hacky and won’t be acceptable.
Regards, Anup
From: tech-privileged@... <tech-privileged@...>
On Behalf Of alankao
Sent: 18 August 2020 15:17 To: tech-privileged@... Subject: Re: [RISC-V] [tech-privileged] A proposal to enhance RISC-V HPM (Hardware Performance Monitor)
Hi Anup, |
|
Chuanhua Chang
The idea of adding write enable bit without adding extra CSR in the read/write register range is that the setting of the write enable bit will change the read-only CSR to a read/write CSR.
Chuanhua |
|
Hi Anup,
We did the experiment based on our own settings and not yet consider the SBI extension proposal. Please consider the approach in #278 with one additional condition: Any platform that supports configurations more than M-S-U should not provide a PMU with "bypass-sbi" attribute, like QEMU virt. Neither VS- nor HS- usage will be affected by this bit. Then, you ask, what about emulating a platform that aims to only runs on M-S-U machines? Well, the one who ports the platform to QEMU/other simulators should put some warning message when the attempt to write happens, rather than implement the whole save-restore just for the PMU status. We don't need to add many CSRs. Just one bit in hpmevent*. Regards, Alan |
|
Hi Alan,
Thanks for the data points. The proposed SBI_PMU_COUNTER_CONFIG_MATCHING will helps us minimize SBI calls for configuring HPMEVENT CSR. I am not sure if you have considered latest SBI PMU extension proposal for benchmarking.
My question in-context of Hypervisors is still unanswered. The existing HPMCOUNTER CSRs are in read-only CSR range. We will need separate CSR range from S-mode Read-Write CSRs. Further, we will also need separate CSRs from HS-mode to save-restore VS-mode HPMCOUNTER CSRs states.
A more general question is that is it worth to add so many CSRs and add increase overhead for Hypervisors just to make HPMCOUNTER writeable form HS-mode and VS-mode. We should also consider the fact the Linux perf will be mostly used for debugging and analysis.
Regards, Anup
From: tech-privileged@... <tech-privileged@...>
On Behalf Of alankao
Sent: 18 August 2020 14:12 To: tech-privileged@... Subject: Re: [RISC-V] [tech-privileged] A proposal to enhance RISC-V HPM (Hardware Performance Monitor)
Hi Anup,
Fair enough. Of course, your conclusion is totally correct: "we CAN EASILY set the HPM* ...," but the real question here is in point 1: Are counter updates really that in-frequent so? So far, nobody provided any convincing pieces of evidence. Yet, I would like to share our findings from an out-of-the-box experiment.
The system for testing is a 4.17-based Linux branch which contains andes_pmu patch, running on our A27 design on FPGA. The testing command was
time perf record -e cache-references ./whestone
where "cache-references" is an andes_pmu cache event and the target program is a normal whestone executable. We tested three different settings,
Baseline: all HPM CSRs are written in S-mode using plain csr_write. SBI1: HPM counter CSRs are written with SBI calls. |
|
Hi Anup,
Fair enough. Of course, your conclusion is totally correct: "we CAN EASILY set the HPM* ...," but the real question here is in point 1: Are counter updates really that in-frequent so? So far, nobody provided any convincing pieces of evidence. Yet, I would like to share our findings from an out-of-the-box experiment.
The system for testing is a 4.17-based Linux branch which contains andes_pmu patch, running on our A27 design on FPGA. The testing command was
time perf record -e cache-references ./whestone
where "cache-references" is an andes_pmu cache event and the target program is a normal whestone executable. We tested three different settings,
Baseline: all HPM CSRs are written in S-mode using plain csr_write. SBI1: HPM counter CSRs are written with SBI calls. |
|
Jonathan Behrens <behrensj@...>
I'd also strongly argue for there only being a single configuration for both virtualized and non-virtualized systems. The fewer different cases that software has to handle, the better for everyone. This is especially true for smaller projects like research/teaching operating systems, which don't have the resources of something like the Linux kernel. There is a long history of paravirtualization (virtualization where the guest kernel knows it is in a VM), but that is generally only done in cases where the original interface was poorly designed, or for exposing features that don't make sense on actual hardware. I don't think it should be used here. Jonathan
|
|
Hi Alan,
My statement “Allowing S-mode to write HPMCOUNTER CSR is good but won’t benefit much.” is because:
Regards, Anup
From: tech-privileged@... <tech-privileged@...>
On Behalf Of alankao
Sent: 05 August 2020 14:11 To: tech-privileged@... Subject: Re: [RISC-V] [tech-privileged] A proposal to enhance RISC-V HPM (Hardware Performance Monitor)
Hi Anup,
> The “bypass-sbi” DT property will break QEMU virt machine
No, it won’t. Why should QEMU virt machine’s PMU follow this flag? The platform can totally choose not to support the attribute of its PMU.
Of course, I know the SBI route works. If you don’t see the benefit, based on what did you say the feature is good? Your words were “Allowing S-mode to write HPMCOUNTER CSR is good but won’t benefit much.” So the issue here is if it will benefit much or marginally. Writing from S-mode can skip the whole M-mode part every time the kernel wants to write CSRs. Isn't that obvious?
Also, you didn't comment on my final part yet.
Thanks, Alan |
|
Hi Anup,
> The “bypass-sbi” DT property will break QEMU virt machine
No, it won’t. Why should QEMU virt machine’s PMU follow this flag? The platform can totally choose not to support the attribute of its PMU.
Of course, I know the SBI route works. If you don’t see the benefit, based on what did you say the feature is good? Your words were “Allowing S-mode to write HPMCOUNTER CSR is good but won’t benefit much.” So the issue here is if it will benefit much or marginally. Writing from S-mode can skip the whole M-mode part every time the kernel wants to write CSRs. Isn't that obvious?
Also, you didn't comment on my final part yet.
Thanks, Alan |
|