logo

drewdevault.com

[mirror] blog and personal website of Drew DeVault git clone https://hacktivis.me/git/mirror/drewdevault.com.git

2022-01-15-The-RISC-V-experience.md (10740B)


  1. ---
  2. title: The RISC-V experience
  3. date: 2022-01-15
  4. outputs: [html, gemtext]
  5. ---
  6. I'm writing to you from a Sway session on Alpine Linux, which is to say from a
  7. setup quite similar to the one I usually write blog posts on, save for one
  8. important factor: a RISC-V CPU.
  9. I'll state upfront that what I'm using is not a very practical system. What I'm
  10. going to describe is all of the impractical hacks and workarounds I have used to
  11. build a "useful" RISC-V system on which I can mostly conduct my usual work. It
  12. has been an interesting exercise, and it bodes well for the future of RISC-V,
  13. but for all practical purposes the promise of RISC-V still lives in tomorrow,
  14. not today.
  15. In [December of 2018], I wrote an article about the process of bootstrapping
  16. Alpine Linux for RISC-V on the HiFive Unleashed board. This board was
  17. essentially a crappy SoC built around a RISC-V CPU: a microSD slot, GPIO pins,
  18. an ethernet port, a little bit of RAM, and the CPU itself, in a custom
  19. form-factor.[^expansion] Today I'm writing this on the HiFive Unmatched, which
  20. is a big step up: it's a Mini-ITX form factor (that is, it fits in a
  21. standardized PC case) with 16G of RAM, and the ethernet, microSD, and GPIO ports
  22. are complemented with a very useful set of additional I/O via two M.2 slots, a
  23. PCIe slot, and a USB 3 controller, plus an SPI flash chip. I have an NVMe drive
  24. with my root filesystem on it and an AMD Radeon Pro WX 2100 GPU installed. In
  25. form, it essentially functions like a standard PC workstation.
  26. [^expansion]: Plus an expansion slot which was ultimately entirely useless.
  27. [December of 2018]: https://drewdevault.com/2018/12/20/Porting-Alpine-Linux-to-RISC-V.html
  28. I have been gradually working on bringing this system up to the standards that I
  29. expect from a useful PC, namely that it can run upstream Alpine Linux with
  30. minimal fuss. This was not really possible on the previous SiFive hardware, but
  31. I have got pretty close on this machine. I had to go to some lengths to get
  32. u-Boot to provide a working UEFI environment,[^uefi] and I had to patch grub as
  33. well, but the result is that I can write a standard Alpine ISO to a USB stick,
  34. then boot it and install Alpine onto an NVMe normally, which then boots itself
  35. with UEFI with no further fiddling. I interact with it through three means: the
  36. on-board UART via a micro-USB cable (necessary to interact with u-Boot, grub, or
  37. the early Linux environment), or ethernet (once sshd is up), or with keyboard,
  38. mouse, and displays connected to the GPU.
  39. [^uefi]: I have u-Boot installed on a microSD card which the firmware boots to,
  40. which then runs grub, which runs Linux. I could theoretically install u-Boot
  41. to the SPI Flash and then I would not have to use a microSD card for this
  42. process, but my initial attempts were not met with success and I didn't debug
  43. it any further. I think other people have managed to get it working, though,
  44. and someone is working on making Alpine handle this for you. In future
  45. hardware from SiFive I hope that they will install a working u-Boot UEFI
  46. environment on the SPI before shipping so that you can just install standard
  47. ISOs from a flash drive like you would with any other PC.
  48. Another of the standards I expect is that everything runs with upstream free
  49. software, perhaps with a few patches, but not from a downstream or proprietary
  50. tree. I'm pleased to report that I am running an unpatched mainline Linux
  51. 5.15.13 build. I am running mainline u-Boot with one patch to correct the name
  52. of a device tree node to match a change in Linux upstream. I have a patched grub
  53. build, but the relevant patches have been proposed for grub upstream. I have a
  54. spattering of patches applied to a small handful of userspace programs and
  55. libraries, but all of them only call for one or two patches applied to the
  56. upstream trees. Overall, this is quite good for something this bleeding edge
  57. — my Pinephone build is worse.
  58. I have enclosed the system in a mini-ITX case and set it down on top of my usual
  59. x86_64 workstation, then moved a few of my peripherals and displays over to it
  60. to use it as my workstation for the day.[^workstation] I was able to
  61. successfully set up almost all of my standard workstation loadout on it, with
  62. some notable exceptions. Firefox is the most painful omission —
  63. bootstrapping Rust is an utter nightmare[^bootstrap] and no one has managed to
  64. do it for Alpine Linux riscv64 yet (despite many attempts and lots of hours
  65. wasted), so anything which depends on it does not work. librsvg is problematic
  66. for the same reason; I had to patch a number of things to be configured without
  67. it. For web browsing I am using [visurf], which is based on Netsurf, and which
  68. works for many of the lightweight websites that I generally prefer to use, but
  69. not for most others. For instance, I was unable to address an issue that was
  70. raised on GitLab today because I cannot render GitLab properly on this browser.
  71. SourceHut mostly works, of course, but it's not exactly pleasant — I still
  72. haven't found time to improve the SourceHut UI for NetSurf.
  73. <a href="https://l.sr.ht/jJWl.jpg">
  74. <img src="https://l.sr.ht/jJWl.jpg" alt="A picture of two computers stacked on on top of the other." style="max-width: 70%" />
  75. </a>
  76. <div class="text-center"><small>The lower computer is my typical x86_64
  77. workstation, and the upper computer is the RISC-V machine. The USB ports on the
  78. side are not connected to the board, so I pulled a USB extension cord around
  79. from the back. This is mainly useful for rapid iteration when working on a
  80. RISC-V kernel that a colleague has been developing using our new programming
  81. language. I can probably get netboot working later, but this works for
  82. now.</small></div>
  83. [^workstation]: I use this machine fairly often for RISC-V testing, particularly
  84. for the new programming language I'm working on, but I usually just SSH into
  85. it instead of connecting my displays and peripherals to it directly.
  86. [^bootstrap]: Incidentally, my new language can be fully bootstrapped on this
  87. machine in 272 seconds, including building and running the test suite. For
  88. comparison, it takes about 10 seconds on my x86_64 workstation. Building LLVM
  89. on this machine, let alone Rust, takes upwards of 12+ hours. You can
  90. cross-compile it, but this is difficult and it still takes *ages*, and it's so
  91. complicated and brittle that you're going to waste a huge amount of time
  92. troubleshooting between every attempt.
  93. [visurf]: https://sr.ht/~sircmpwn/visurf
  94. Complicating things is the fact that my ordinary workstation uses two 4K
  95. displays. For example, my terminal emulator of choice is [foot], but it uses CPU
  96. rendering and the 4K window is noticeably sluggish. Alacritty, which renders on
  97. the GPU, would probably fare better &mdash; but Rust spoils this again. I
  98. settled for [st], which has acceptable performance (perhaps in no small part
  99. thanks to being upscaled from 1080p on this setup). visurf also renders on the
  100. CPU and is annoyingly slow; as a workaround I have taken to resizing the window
  101. to be much smaller while actively navigating and then scaling it back up to full
  102. size to read the final page.
  103. [foot]: https://codeberg.org/dnkl/foot
  104. [st]: https://st.suckless.org/
  105. CPU-bound programs can be a struggle. However, this system has a consumer
  106. workstation GPU plugged into its PCIe slot. Any time I can get the GPU to pick
  107. up the slack, it works surprisingly effectively. For example, I watched Dune
  108. (2021) today in 4K on this machine &mdash; buttery smooth, stunningly beautiful
  109. 4K playback &mdash; a feat that my Pinebook Pro couldn't dream of. The GPU has a
  110. hardware HEVC decoder, and mpv and Sway can use dmabufs such that the GPU
  111. decodes and displays each frame without it ever having to touch the CPU, and
  112. meanwhile the NVMe is fast enough to feed it data at a suitable bandwidth. A
  113. carefully configured obs-studio is also able to record my 4K display at 30 FPS
  114. and encode it on the GPU with VAAPI with no lag, something that I can't even do
  115. on-CPU on x86_64 very reliably. The board does not provide onboard audio, but
  116. being an audiophile I have a USB DAC available that works just fine.
  117. I was able to play Armagetron Advanced at 120+ FPS in 4K, but that's not exactly
  118. a demanding game. I also played SuperTuxKart, a more demanding game, at 1080p
  119. with all of the settings maxed out at a stable 30 FPS. I cannot test any
  120. commercial games, since I'm reasonably certain that there are no proprietary
  121. games that distribute a riscv64 build for Linux. If Ethan Lee is reading this,
  122. please get in touch so that we can work together on testing out a Celeste build.
  123. My ordinary workday needs are mostly met on this system. For communication, my
  124. mail setup with aerc and postfix works just fine, and my normal Weechat setup
  125. works great for IRC.[^discord] Much like any other day, I reviewed a few patches
  126. and spent some time working on a shell I've been writing in our new programming
  127. language. The new language is quite performant, so no issues there. I think if I
  128. had to work on SourceHut today, it might be less pleasant to work with Python
  129. and Go, or to work on the web UI without a performant web browser. Naturally,
  130. browsing Geminispace with gmnlm works great.
  131. [^discord]: There's not a snowball's chance in hell of using Discord or Slack on this system, for the record.
  132. So, where does this leave us? I have unusually conservative demands of my
  133. computers. Even on high-end, top-of-the-line systems, I run a very lightweight
  134. environment, and that's the way I like it. Even so, my modest demands stress the
  135. limits of this machine. If I relied more on a web browser, or on more GUI
  136. applications, or used a heavier desktop environment, or heavier programming
  137. environments, I would not be able to be productive on this system. Tomorrow, I
  138. expect to return to my x86_64 machine as my daily workstation and continue to
  139. use this machine as I have before, for RISC-V development and testing over
  140. serial and SSH. There are few use-cases for which this hardware, given its
  141. limitations, is adequate.
  142. Even so, this is a very interesting system. The ability to incorporate more
  143. powerful components like DDR4 RAM, PCIe GPUs, NVMe storage, and so on, can make
  144. up for the slow CPU in many applications. Though many use-cases for this system
  145. must be explained under strict caveats, one use-case it certainly offers is a
  146. remarkably useful system with which to advance the development of the RISC-V
  147. FOSS ecosystem. I'm using it to work on Alpine Linux, on kernel hacking
  148. projects, compiler development, and more, on a CPU that is designed in adherence
  149. to an open ISA standard and runs on open source firmware. This is a fascinating
  150. product that promises great things for the future of RISC-V as a platform.