45

I found references to hart on page 35 of the RISC-V 2.1 spec. However, I could not find a definition for hart in this document. Does hart refer to a hardware-thread or something more sinister?

Olsonist
  • 2,051
  • 1
  • 20
  • 35
daveW
  • 511
  • 1
  • 5
  • 10
  • 6
    Yes, it's "hardware thread" - see https://en.wikipedia.org/wiki/RISC-V, for example. – jasonharper Mar 09 '17 at 02:48
  • 5
    Ah yes......'hart' is elaborated in the other RiscV spec (riscv-privileged -v1.9.1). The user level spec (volume 1) could use a attribution to the privileged spec (volume II) when it comes to 'hart'. Maybe it is best to read these specs out of order - starting with volume II? Thanks. – daveW Mar 09 '17 at 21:25
  • @daveW FWIW, the manual is maintained in a github [repo](https://github.com/riscv/riscv-isa-manual), you could submit a PR or an issue! UPDATE: there's already an [issue](https://github.com/riscv/riscv-isa-manual/issues/822) lol – Rick Dec 01 '22 at 00:59

4 Answers4

45

Yes, a hart is a hardware thread.

Chris
  • 3,827
  • 22
  • 30
22

A RISC-V compatible core might support multiple RISC-V-compatible hardware threads, or harts, through multithreading.

The RISC-V Instruction Set Manual
Volume I: Unprivileged ISA Document Version 20191214-draft
Page 2

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
johan
  • 1,664
  • 2
  • 14
  • 30
12

In simple language, a hart is a RISC-V execution context that contains a full set of RISC-V architectural registers and that executes its program independently from other harts in a RISC-V system. What constitutes a "RISC-V system" depends on the software's execution environment but for standard user-level programs, it means the user-visible harts and memory (i.e., a multithreaded Unix user process). "Execute independently" means that each hart will eventually fetch and execute its next instruction in program order regardless of the activity of other harts (at least at user level).

This is closest answer I ever got after spending a lot of time to understand what 'hart' is https://groups.google.com/a/groups.riscv.org/forum/#!topic/sw-dev/QKjUDjz_vKo

RRON
  • 1,037
  • 3
  • 12
  • 32
  • Are you implying that a hart might be an illusion of the kernel, or something, and only run user-space software threads? I'm having a hard time imagining anything that could properly be called a *hardware* thread that didn't look (to kernel software) like a full CPU, so e.g. code on two separate harts could be running kernel code simultaneously. I could see having only one hart on a physical core actually handle external interrupts, although for preemptive multi-tasking you'd need every hart to be able to receive a timer interrupt or something. – Peter Cordes Jul 24 '20 at 07:20
  • Sounds to me like "hart" is just trying to capture every possible SMT and related thing (https://en.wikipedia.org/wiki/Simultaneous_multithreading), the same concept that we describe as a "logical core" on other ISAs. – Peter Cordes Jul 24 '20 at 07:21
  • @PeterCordes RISC-V defines a separate address space of 4096 for Control Status Registers address space of CSRs associated with each hart. Further, these CSRs are NOT memory mapped so it don't go through LD/STORE instead atomically read/modifiable by machine code. So hart and thread in software differs completely when you think of context switching and harts can't run simultaneously. Chapter 9 in unprivileged spec throws light on this. Its neither a conventional hardware or software thread instead a special breed. – RRON Aug 04 '20 at 01:00
  • Its just a RISC-V execution context . – RRON Aug 04 '20 at 01:17
7

From page 20 of the RISCV Spec v2.2:

We use the term hart to unambiguously and concisely describe a hardware thread as opposed to software-managed thread contexts.

Salvatore
  • 10,815
  • 4
  • 31
  • 69