Skip to content

Hart enumeration algorithm (Sec 3.3) is impractical and conflicts with hart state definitions (Sec 3.4) #1176

@dokunira

Description

@dokunira

I would like to propose a discussion on the hart enumeration algorithm in Section 3.3 "Selecting Harts". The current mandatory (must) algorithm appears to be impractical and based on a premise that conflicts with other parts of the specification.

The specification currently requires debuggers to stop scanning for harts as soon as they find one that is nonexistent:

"...a debugger must ... selects each hart starting from 0 until either anynonexistent in dmstatus is 1, or the highest index... is reached."

This requirement creates several significant problems:

1. The Algorithm Conflicts with Real-World Practice

This algorithm assumes the debugger has zero knowledge of the target. In reality, debuggers (or their users) almost always know the target's configuration (i.e., NUM_HARTS) beforehand. This information is typically provided via a debugger configuration script (e.g., an OpenOCD .cfg file). A mandatory scan is unnecessary when the hart count is already known.

2. Redundancy with confstrptr

The confstrptr mechanism (Section 3.14.9) is provided for configuration discovery. If this is available, the "scan-until-nonexistent" algorithm is completely redundant.

3. Contradictory Definitions for "Holes" (Section 3.4)

The definitions in Section 3.4 "Hart DM States" are contradictory regarding permanently disabled harts ("holes"):

  • nonexistent is defined as "if they will never be part of this hardware platform". This perfectly describes a "hole".
  • However, the spec also states that "holes... must show up as unavailable".
  • This forces implementations to use the semantically incorrect unavailable status (which implies the hart "might... become available") for something that is truly nonexistent.

4. The Algorithm Prevents Flexible Implementations

Because of the mandatory "Stop-at-Nonexistent" rule, implementations cannot use the more logical nonexistent status for "holes". If an implementation did report a "hole" (e.g., hart 2) as nonexistent, a spec-compliant debugger would incorrectly stop its scan and fail to find existing harts at higher indices (e.g., hart 3).

Proposal:

The specification should be updated to align with real-world use and logical definitions.

  1. Allow nonexistent Harts as "Holes": Implementations should be allowed to have existing harts at indices above a nonexistent hart.
  2. Change the Enumeration Algorithm (Section 3.3):
    • Remove the "Stop-at-Nonexistent" Rule. The algorithm should not require debuggers to stop at the first nonexistent hart.
    • The primary method for enumeration should be reading confstrptr (Sec 3.14.9) or using user-provided configuration (which is the common case).
    • The full scan (up to the maximum HARTSELLEN) should be only a fallback, and nonexistent should not halt it.
  3. Clarify Definitions (Section 3.4):
    • nonexistent should be defined as any hart that is permanently disabled (including "holes").
    • unavailable should be defined only as any hart that might genuinely become available later (e.g., powered down, in reset).

This approach provides a more logical definition of hart states, aligns with realistic debugging practices, and gives implementers the flexibility needed for modern hardware (like binned devices).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions