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 (10737B)


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