Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

a review of v0.1 focusing on VMs and forward compatibility #2

Open
sorear opened this issue Jun 3, 2023 · 5 comments
Open

a review of v0.1 focusing on VMs and forward compatibility #2

sorear opened this issue Jun 3, 2023 · 5 comments

Comments

@sorear
Copy link

sorear commented Jun 3, 2023

  1. "CTR" is likely to be confused with "counter" in the abbreviations of various CSRs. I suppose it's too late to use "CXR" or something else?

  2. We need clear guidance about whether bits of mctrcontrol which are not defined in the current specification should be set to 0 or 1 by software. The forward compatibility requirements are presently inconsistent between hypothetical new control transfer types (which are 1 to ignore) and hypothetical new modes (0 to ignore). Current examples of unused portions of multi-function bitfield registers are either WPRI (mstatus, hstatus, menvcfg, mseccfg, fcsr) or have ad-hoc reserved rules (effectively WLRL); WARL seems inappropriate in either case.

  3. SEN has the function of a mstateen bit and should be required to be 0 at reset for the reasons described in the Smstateen specification.

  4. VSTE is the only control bit not allocated an index in mctrcontrol. If it had one, M-mode code would not need to reference vsctrcontrol for emulation or context swaps.

  5. We don't need names for VS or VU in sctrcontrol since they are also available in vsctrcontrol. Bits [4:3] in both CSRs can be defined as read-only zero, saving two of the three fake-virtualization bits.

  6. sctrcontrol.VSEN should always exist as a writable field, regardless of the H extension, as part of the minimal support required to emulate the H-extension using M-mode primitives. Alternatively, VSEN can be moved to a CSR accessible only in HS-mode (a new hctrcontrol, or vsctrcontrol, assuming in the latter case that the new bit is hidden when it is accessed as sctrcontrol in VS-mode).

  7. I think that the current handling of DEPTH in vsctrcontrol and sctrcontrol is fine, since it can be configured in a privilege mode iff filtering can be configured in that privilege mode.

  8. Clarify accessibility of vsctrcontrol. Since it contains the only name of VSTE, it must be accessible for higher modes even if access to the CTR unit is disabled or mediated by VSEN=0. I think the correct check is prv = M OR (prv = HS AND mctrcontrol.SEN).

  9. We should specify the behavior of attempting to access entry registers using vsireg. (Always illegal instruction?)

  10. WPRI should only apply to the undefined portions of the Entry Registers, not the whole registers.

  11. Why are ctrsource.V and ctrtarget.MISP in address fields when we have a perfectly good ctrdata?

  12. Is there a difference between TYPE 0 or 4 (Undefined) and 7 (Reserved)?

  13. It could be a little clearer (in the ctrdata and mctrcontrol definitions) that the numeric values and precise definitions of the control transfer types are from "4.1D Instruction Trace Interface requirements" and "Table 4.4: Instruction Type (itype) encoding" in the E-trace spec, although the names are slightly different. In particular, there is no indication in this draft of which registers are used to distinguish calls, returns, and jumps.

  14. If one of ctrtarget and ctrdata.CC is going to be optional, only one of them can be inferred from ctrsource in most dynamical cases.

  15. Clarify that unsupported fields will read as zero in newly added entries; the text as written implies that fields could be picked up from an unrelated entry.

  16. "Target Mode > Source Mode" column header is unclear, suggest explicit column headers.

  17. Are the filtering bits in mctrcontrol honored when RASEMU=1?

  18. A single trap can service multiple interrupts (e.g. using a loop on mtopi). At what point do we consider "a LCOFI is taken"? Would it be more appropriate for the freeze to occur at some point after the LCOFI becomes pending?

  19. If an ebreak instruction is executed with dcsr.ebreakx=1 and Debug Mode is entered, is this considered a "breakpoint exception" for the purposes of BPFRZ?

  20. "Writing all 1s to the Entry Registers at entry 0" is not permissible because the Entry Registers are defined as WPRI, and therefore software may only change the defined portions. "Writing 1s to all defined fields of the Entry Registers at entry 0"?

  21. Discovering xctrcontrol features by writing all 1s is similarly problematic if future fields have effects when written. Write all 1s to defined fields of xctrcontrol?

@bcstrongx
Copy link
Collaborator

bcstrongx commented Jun 5, 2023 via email

@sorear
Copy link
Author

sorear commented Jul 14, 2023

status in 0.1.2:

  1. not worth persuing
  2. resolved in 0.1.2, everything is WPRI
  3. resolved in 0.1.2, SEN consolidated with mstateen
  4. misunderstanding
  5. resolved in 0.1.2, bits removed
  6. resolved in 0.1.2, VSEN is part of hstateen0 which traps in VS-mode or with M-mode virt
  7. not an issue
  8. hstateen0 affects state accessibility depending on the accessing mode, not the affected mode, so this is no longer ambiguous in 0.1.2.
  9. 0.1.2 is somewhat clearer
  10. seems to be clear in 0.1.2.
  11. moved to proposals
  12. resolved
  13. resolved
  14. moved to proposals
  15. still an issue
  16. resolved
  17. resolved
  18. proposing clarification
  19. proposing clarification
  20. resolved
  21. resolved

new and continuing issues:

  1. Smstateen requires extensions to document what types of implicit accesses are allowed at lower privilege levels. We must document that control transfers are recorded (affecting CTR state), using the current mctrcontrol and vsctrcontrol, regardless of whether explicit access to CTRs is allowed at the current privilege level.
  2. "Privilege mode transitions" does not address the issue of whether traps and trap returns between VS-mode and V=0 modes use the transfer type filtering bits from the new mode's ctrcontrol or the old mode's ctrcontrol. Freeze likewise does not address whether the new or old mode's BPFRZ or LCOFIFRZ is used.
  3. We document the effects of accessing mireg* in M-mode, sireg* in HS-mode, and vsireg* (via sireg*) in VS-mode. Access to the vsireg* or mireg* in VS-mode, or mireg* in M-mode, is forbidden by the rules in Smcsrind. We do not clearly state that using vsireg* to access CTR entries in HS-mode has exactly the same effect as using sireg*.
  4. "Behavior" should specify that when a new record is created, all implemented fields are written with values for the new record. The current text of "will update at least" does not make clear that the set of fields with valid values is consistent and the same as the set of fields determined by the discovery procedure.
  5. Defining ctrsource.PC and ctrtarget.PC fields as being XLEN wide is problematic for profiling workloads which mix RV64 and RV32; when control transfers into RV32, XLEN becomes 32, and the entry bits are truncated to 32 bits (CSR Width Modulation) before being re-zero-extended on entry to RV64. Proposing that the width of PC fields in entry registers is the current or maximum supported MXLEN, they are truncated on reads, and zero extended on implicit writes. Do RV32 writes to sireg* preserve the upper bits of ctr*?
  6. We have a CSR number listed for xctrcontrol but not xctrcontrolh.
  7. The semantics of WRAP seem not very useful for determining when stitching is possible, since you cannot distinguish "recorded one value, wrapped around" from "recorded many values, overwrote entire entry file". Propose a 2 bit field encoding -1, 0, +1, sticky overflow.
  8. The statement about read-modify-writes to xctrstatus should only apply to multi-instruction sequences. A control transfer is an architectural event corresponding to an instruction and therefore cannot occur in the middle of a single csrrs/csrrc/csrrw instruction.

proposed clarifications:

  1. Breakpoint exception refers only to architectural traps with a cause of "breakpoint exception" as defined in the privileged spec, regardless of source (ebreak, c.ebreak, Sdtrig); it does not include entry into Debug Mode, even in cores where this is implemented as an exception.
  2. LCOFI interrupt refers only to architectural traps directly caused by a local counter overflow interrupt. If a local counter overflow interrupt is recognized without a trap, for instance by reading mip, FROZEN is not automatically set.

proposals:

  1. VM migrations are extremely rare events compared to profile samples, and profile samples are expected to occasionally be lost anyway, so rather than writable DEPTH I would like to suggest a model where DEPTH is not software writable at any mode but allowed to spontaneously change as viewed by modes lower than M. The visible effect of a DEPTH change must be specified in a way that allows software to identify potentially lost events; I propose to redefine nonexistent CTR entries as ctrsource.PC=1, ctrsource.V=everything else=0, and specify that all CTR entries keep their values through a sequence of DEPTH changes unless they become nonexistent or temporarily nonexistent, in which case they change to PC=1 V=0.
  2. Requiring WRPTR to always be 8 bits would simplify the handing of DEPTH changes and wrapping detection.
  3. We could avoid a number of edge cases in the privilege mode change and freeze definitions if all fields in vsctrcontrol other than VS, VU, and VSTE were made read-write aliases of the identically named fields in mctrcontrol.
  4. WPRI is normally used for fields that contain, or might contain in the future, control fields, where writing garbage to them will cause the hart to behave in unpredictable ways. The entry registers shouldn't behave like that - writing anything to them should have no effect other than to cause a value to be read back in the future - so it might make more sense to make them WARL as a whole.
  5. This year marks 20 years since the first sale of x86_64 processors. Custom extensions that allow IALIGN=8 will happen with or without RVI's blessing, all we can do is not make them needlessly painful by using pc[0] for other purposes without a better reason than "it's free real estate". I am unsure that allowing implementations to not decode ctrdata counts as a better reason.
  6. PGO uses both ctrsource and ctrtarget on x86_64 but I'd like to do tests on a ctrsource-only PGO pipeline. I suspect it will be nearly indistinguishable from the case with both.

@bcstrongx
Copy link
Collaborator

bcstrongx commented Jul 24, 2023 via email

@sorear
Copy link
Author

sorear commented Jul 25, 2023 via email

@bcstrongx
Copy link
Collaborator

bcstrongx commented Aug 2, 2023 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants