Initial draft of 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 5 open source implementations:
122
123  * Rocket chip: Simple in-order processor
124  * BOOM and BOOMv2: OOO Superscalar processor
125  * PicoRV32
126  * Two educational implementations that I won't talk about today
127
128 Rocket is the most widely used.  It is written in Chisel which is a
129 Scala-based metalanguage that generates Verilog.  PicoRV32 is a lot of
130 fun too: It's written in Verilog and can be programmed on to a very
131 cheap (under $40) FPGA.
132
133 [SLIDE: OTHER PARTS OF THE ECOSYSTEM]
134
135 As well as the CPU core, there are also open source implementations
136 of:
137
138  * L1 and L2 Cache hierarchy and coherence
139  * ChipLink/TileLink: Communicate between sockets and with peripherals
140  * Interrupt controllers
141  * Ethernet PHYs
142  * Serial ports
143  * DDR DRAM controller
144
145 So you can (sort of) create your own computer.
146
147 There are still many missing bits:
148
149  * High-performance DDR
150  * High-performance ethernet
151  * SATA
152  * BMC management
153  * Standard boot environment (although this is coming together)
154
155 There are two emulators:
156
157  * QEMU has supported RV64GC since around 2017.
158  * Spike is the RISC-V Foundation's cycle-accurate simulator
159
160 There are ports of the major tools:
161
162  * Linux (of course!) since around 2018
163  * binutils since 2017
164  * GCC since 2016
165  * glibc since 2018
166
167
168
169 2. RISC-V and Fedora, Debian and upstream communities
170 ----------------------------------------------------------------------
171
172 I did the first bootstrap of Fedora in September 2016.
173
174 Bootstrapping Fedora is complicated: I started off with an x86-64 disk
175 image which could run rpmbuild.  I then removed all of the x86-64
176 binaries and libraries.  I replaced them with cross-compiled RISC-V
177 binaries and libraries.  About 60 packages had to be cross-compiled
178 and hundreds of binaries were built.
179
180 After several weeks of work I ended up with a disk image which was
181 bootable under QEMU emulation, which could run rpmbuild.  This was
182 called the "stage 3" disk image.
183
184 The stage 3 disk image allowed me to (very slowly) build RPMs
185 natively.  After many more weeks of work I had built enough RPMs by
186 hand so that I could create a disk image from just RPMs.  This was
187 called the "stage 4" disk image.
188
189 Using the stage 4 disk image we were then able to rebuild most of
190 Fedora, successively building newer and newer disk images.
191
192 Git repo: https://github.com/rwmjones/fedora-riscv-bootstrap
193
194 Initially we had a custom autobuilder which went through the whole of
195 Fedora blindly attempting to rebuild each package.  We spent many
196 months fixing Fedora packages, fixing upstream programs, and manually
197 breaking dependency chains.
198
199 [SLIDE: SECOND AND THIRD BOOTSTRAPS]
200
201 Because of changes that kept breaking glibc backwards compatibility,
202 we knew that the first bootstrap wouldn't be the last one.  In fact we
203 ended up doing two more bootstraps.  The second was a practice one to
204 produce a "script" for bootstrapping Fedora.  The third one was done
205 in February 2018 after glibc was released with a permanently stable
206 ABI.  The third one should be the last one and is the basis for all
207 current work.
208
209 [SLIDE: KOJI]
210
211 Nowadays with have a normal Koji builder which shadows Fedora 29, 30
212 and Rawhide.
213
214 [SLIDE: FEDORA RISC-V]
215
216 You can grab Fedora for RISC-V and run it either on the real hardware
217 or under QEMU on your laptop.
218
219 [I will show a demo of Fedora RISC-V, showing that it looks very much
220 like Fedora on any other architecture]
221
222 [SLIDE: DEBIAN]
223
224 While we were working on Fedora, we were also working closely with the
225 Debian and upstream communities.  Changes and tips are shared with
226 upstream and with Debian.
227
228
229
230 3. Companies making RISC-V hardware
231 ----------------------------------------------------------------------
232
233
234
235
236
237
238
239
240 4. RISC-V on the Server
241 ----------------------------------------------------------------------
242
243
244
245