Update 2019 RISC-V talk.
[riscv-talks.git] / 2019-redhat / 2019-riscv-talk.txt
1 RISC-V ("Risc Five") is an open source Instruction Set Architecture
2 (ISA).  Today I will explain what that means and talk about what we
3 have done to port Fedora and upstream projects to RISC-V.
4
5 1. Background - What is RISC-V?
6 ----------------------------------------------------------------------
7
8 First we ask: What is an Instruction Set Architecture (ISA)?  ISAs are
9 the lowest level at which software talks to the machine.  An ISA
10 consists of:
11
12  - machine code that runs on a CPU
13  - a wide-ranging description of many other aspects of the hardware
14    (Intel's ISA document is over 2000 pages long)
15
16 Today, ISAs are mainly owned by companies.  Intel owns the x86
17 architecture used in the majority of servers and laptops.  ARM owns
18 the ARM architecture used in the majority of phones and tablets.  IBM
19 owns two architectures (s/390 and POWER).  And there are others but
20 those are the major ones today.
21
22 Can you make your own x86-compatible chip?
23
24 No.  Companies protect ISAs aggressively with patents, copyrights and
25 trade secrets.  Intel and AMD cross-license patents and prevent anyone
26 else from developing x86 chips.
27
28 [SLIDE: ARM]
29
30 ARM operates slightly differently: their architecture is also heavily
31 defended with patents, but anyone can come along and license that
32 architecture to make their own chips, but they will pay millions up
33 front plus a few dollars for each chip they sell.
34
35 [SLIDE: RISC-V LOGO AND FOUNDATION MEMBERS]
36
37 RISC-V is different: RISC-V is an attempt to create a modern ISA which
38 is *not* covered by patents, and has a liberal open source license
39 (BSD).  There are no up front costs or per unit license fees.  The
40 only real limitation is use of the RISC-V Trade Mark which requires a
41 fairly modest fee, and doesn't prevent you from making chips as long
42 as you don't use the Trade Mark.
43
44 RISC-V is run by the RISC-V Foundation (https://riscv.org/) of which
45 IBM is a member (but not Red Hat, yet).  There are hundreds of
46 companies who are members of the Foundation.
47
48 [SLIDE: RISC-V CODE]
49
50 Let's have a look at some RISC-V machine code.
51
52 * Most instructions are 32 bits (4 bytes) long.
53 * Compressed instructions are 16 bits.
54 * Some instructions can be longer than 32 bits.
55 * Decoding instruction boundaries is easy, even if you can't or
56   don't fully parse them.
57
58 [SLIDE: RISC-V REGISTERS]
59
60 * 32 general purpose registers
61 * 32 floating point registers (extension)
62 * Zero register
63 * Always little-endian
64 * Influenced by MIPS architecture
65 * Proven to be patent-free
66
67 The architecture is "boring"!  It doesn't contain any surprise
68 features.  It's is meant to be as independent as possible of the
69 micro-architecture.  It's simple to decode, simple to implement (at
70 least if you don't care about performance), and simple to emulate.
71 There are no weird features like register windows or branch delay
72 slots.
73
74 [SLIDE: RISC-V EXTENSIONS]
75
76 RISC-V is designed to be extensible.  The base architectures are:
77
78  * RV32I = 32 bit, integer arithmetic, basic instructions like compare, jump etc
79  * RV32E = 32 bit embedded variant, 16 registers, not yet standardized
80  * RV64I = 64 bit + integers
81  * RV128I = 128 bit + integers (not yet standardized)
82
83 Normally you will add a few extensions.  The common ones are:
84
85  * I = base + integer (this is not an extension, it's required)
86  * M = integer multiplication and division
87  * A = atomic operations
88  * F = floating point
89  * D = double-precision floating point
90  * C = compressed instructions
91  * G = IMAFD
92
93 Fedora and Debian are targetting RV64GC
94
95 There are other extensions too.  The notable ones are:
96
97  * B = bit manipulation
98  * J = JIT features
99  * V = vectorization
100
101 [SLIDE: RISC-V SPECIFICATIONS]
102
103 There are two important documents:
104
105  * "User spec" (RISC-V ISM Vol 1) version 2.2 / 20190608
106    236 pages
107    Covers what userspace code needs to know:
108    User instructions, Memory ordering, Calling conventions, etc.
109
110  * "Priv spec" (RISC-V ISM Vol 2) version 1.10 / 20190608
111    109 pages
112    Covers what the kernel needs to know:
113    Priv instructions, Page tables,
114    Machine Status Registers, Interrupts, Timers, etc.
115
116 These documents are freely downloadable and distributed under a
117 Creative Commons license.
118
119 [SLIDE: RISC-V OPEN SOURCE IMPLEMENTATIONS]
120
121 At least 7 open source implementations:
122
123  * Rocket chip: Simple in-order processor
124  * BOOM and BOOMv2: OOO Superscalar processor
125  * PicoRV32
126  * Two Western Digital processors
127  * Two educational implementations that I won't talk about today
128
129 Rocket is the most widely used.  It is written in Chisel which is a
130 Scala-based metalanguage that generates Verilog.  PicoRV32 is a lot of
131 fun too: It's written in Verilog and can be programmed on to a very
132 cheap (under $40) FPGA.  Great for tinkering.
133
134 [SLIDE: OTHER PARTS OF THE ECOSYSTEM]
135
136 As well as the CPU core, there are also open source implementations
137 of:
138
139  * L1 and L2 Cache hierarchy and coherence
140  * ChipLink/TileLink: Communicate between sockets and with peripherals
141  * Interrupt controllers
142  * Ethernet PHYs
143  * Serial ports
144  * DDR DRAM controller
145
146 So you can (sort of) create your own computer.
147
148 There are still many missing bits:
149
150  * High-performance DDR
151  * High-performance ethernet
152  * SATA
153  * BMC management
154  * Standard boot environment (although this is coming together)
155
156 There are three emulators:
157
158  * QEMU has supported RV64GC since around 2017.
159  * Spike is the RISC-V Foundation's cycle-accurate simulator
160  * Fabrice Bellard's emulator
161
162 There are ports of the major tools:
163
164  * Linux (of course!) since around 2018
165  * binutils since 2017
166  * GCC since 2016
167  * glibc since 2018
168
169
170
171 2. RISC-V and Fedora, Debian and upstream communities
172 ----------------------------------------------------------------------
173
174 I did the first bootstrap of Fedora in September 2016.
175
176 Bootstrapping Fedora is complicated: I started off with an x86-64 disk
177 image which could run rpmbuild.  I then removed all of the x86-64
178 binaries and libraries.  I replaced them with cross-compiled RISC-V
179 binaries and libraries.  About 60 packages had to be cross-compiled
180 and hundreds of binaries were built.
181
182 After several weeks of work I ended up with a disk image which was
183 bootable under QEMU emulation, which could run rpmbuild.  This was
184 called the "stage 3" disk image.
185
186 The stage 3 disk image allowed me to (very slowly) build RPMs
187 natively.  After many more weeks of work I had built enough RPMs by
188 hand so that I could create a disk image from just RPMs.  This was
189 called the "stage 4" disk image.
190
191 Using the stage 4 disk image we were then able to rebuild most of
192 Fedora, successively building newer and newer disk images.
193
194 Git repo: https://github.com/rwmjones/fedora-riscv-bootstrap
195
196 Initially we had a custom autobuilder which went through the whole of
197 Fedora blindly attempting to rebuild each package.  We spent many
198 months fixing Fedora packages, fixing upstream programs, and manually
199 breaking dependency chains.
200
201 [SLIDE: SECOND AND THIRD BOOTSTRAPS]
202
203 Because of changes that kept breaking glibc backwards compatibility,
204 we knew that the first bootstrap wouldn't be the last one.  In fact we
205 ended up doing two more bootstraps.  The second was a practice one to
206 produce a "script" for bootstrapping Fedora.  The third one was done
207 in February 2018 after glibc was released with a permanently stable
208 ABI.  The third one should be the last one and is the basis for all
209 current work.
210
211 [SLIDE: KOJI]
212
213 Nowadays we have a normal Koji builder which shadows Fedora 29, 30 and
214 Rawhide.
215
216 [SLIDE: FEDORA RISC-V]
217
218 You can grab Fedora for RISC-V and run it either on the real hardware
219 or under QEMU on your laptop.
220
221 [I will show a demo of Fedora RISC-V, showing that it looks very much
222 like Fedora on any other architecture]
223
224 [SLIDE: DEBIAN]
225
226 While we were working on Fedora, we were also working closely with the
227 Debian and upstream communities.  Patches and techniques are shared
228 with upstream and with Debian.
229
230 To get involved with Fedora RISC-V please join us on Freenode:
231
232  #fedora-riscv
233
234
235
236 3. Companies making RISC-V hardware
237 ----------------------------------------------------------------------
238
239 Initial RISC-V implementations were small-run silicon or FPGAs.  It
240 wasn't until 2018 that we started to see companies producing RISC-V
241 processors and boards.  It seems that most companies at the moment are
242 looking at the embedded space, and are doing this in order to save on
243 ARM licensing fees.  It's still very early days.
244
245 Note that embedded processors (RV32) will *not* run Fedora or Debian,
246 and some won't even run Linux.
247
248 [SLIDE: SIFIVE]
249
250 The RISC-V single board computer you can buy today is made by SiFive,
251 and it's called the *HiFive Unleashed*.  I have two of these, and we
252 have 4 or 5 in total across Red Hat.
253
254 This uses the Rocket chip design, with 4 cores.  It's mostly open
255 source.  SiFive also have a 32 bit embedded single board computer.
256
257 [SLIDE: OTHERS]
258
259  * SHAKTI
260  * Andes N25 and NX25
261  * Kendryte
262  * Codasip
263  * Syntacore
264  * Nvidia
265  * Western Digital
266  * lowRISC
267  * PULPino
268  * Esperanto
269  * Adapteva
270
271
272
273 4. RISC-V on the Server
274 ----------------------------------------------------------------------
275
276 [This section will be a more free-form discussion about servers and
277 whether RISC-V will ever capture any significant share of the
278 marketplace.  Here I just outline topics for discussion.]
279
280 * What is a server?  What is the difference between a server and a
281   laptop?  What specialized components go into a server?
282
283     - NUMA and interrupt routing
284     - headless remote management and BMC
285     - very high speed network interfaces, RDMA
286     - separation of storage from compute, SANs, iSCSI, FC
287     - GPGPU, TPU, custom hardware
288     - hardware offload and accelerators
289     - virtualization, NFV, SR-IOV, ...
290     - fencing
291
292 * How is server hardware deployed?  Single servers versus datacenters.
293
294 * How is server software provisioned?
295
296     - mass provisioning of nodes (eg. with Ironic)
297     - orchestration and configuration management
298
299 * Single kernel image works everywhere.
300
301 * Standard boot method.
302
303 * Hardware discovery.
304
305 * Reliability
306
307     - distributed computing, fast fail-over, containers, etc.
308     - mainframe-style redundancy