riscv / riscv-isa-manual

RISC-V Instruction Set Manual
https://riscv.org/
Creative Commons Attribution 4.0 International
3.57k stars 617 forks source link

`mhartid` wording re. hart ID zero confusing/incorrect? #1446

Open TommyMurphyTM1234 opened 3 months ago

TommyMurphyTM1234 commented 3 months ago

The latest release of the privilged spec:

has this (emhpasis is mine):

3.1.5. Hart ID (mhartid) Register

The mhartid CSR is an MXLEN-bit read-only register containing the integer ID of the hardware thread running the code. This register must be readable in any implementation. Hart IDs might not necessarily be numbered contiguously in a multiprocessor system, but at least one hart must have a hart ID of zero. Hart IDs must be unique within the execution environment.

Is "at least one hart must have a hart ID of zero" actually correct? Can more than one hart have an ID of zero? Or is it the case that exactly one hart must have an ID of zero?

pdonahue-ventana commented 3 months ago

The next sentence says "Hart IDs must be unique within the execution environment" which means that more than one hart cannot have an ID of zero.

TommyMurphyTM1234 commented 3 months ago

Thanks @pdonahue-ventana.

The next sentence says "Hart IDs must be unique within the execution environment" which means that more than one hart cannot have an ID of zero.

Yes - I know - that's why I think that "at least one hart must have a hart ID of zero" is unnecessarily confusing and should actually be "exactly one hart must have a hart ID of zero". Why have one sentence specify a looser constraint only for the next sentence to further tighten it up when it can be stated more clearly, concisely and correctly in the first place/sentence?

Also - I wasn't sure if "in a multiprocessor subsystem" and "within the execution environment" were different contexts that mayhe had different constraints in this respect.

The wording seems unnecessarily confusing in my opinion.

pdonahue-ventana commented 3 months ago

I had mentally swapped the original text and your proposed text. I assume that the key lies in the fact that a multiprocessor system may have more than one execution environment, but I'll let others (who know more) address that.

steven-bellock commented 1 week ago

Also, is this conditional on multiprocessor systems? Or, if there is a single processor / hart, must its hartid be exactly 0?

TommyMurphyTM1234 commented 1 week ago

if there is a single processor / hart, must its hartid be exactly 0?

I think that this is the case given the above wording. But, as I've said, I think that the wording could be more clearly prescriptive in order to eliminate the need to infer any of the details.

Yes - I know - that's why I think that "at least one hart must have a hart ID of zero" is unnecessarily confusing and should actually be "exactly one hart must have a hart ID of zero". Why have one sentence specify a looser constraint only for the next sentence to further tighten it up when it can be stated more clearly, concisely and correctly in the first place/sentence?