start filling in
[libreriscv.git] / isa_conflict_resolution.mdwn
1 # Resolving ISA conflicts and providing a pain-free RISC-V Standards Upgrade Path
2
3 In a lengthy thread that ironically was full of conflict indicative
4 of the future direction in which RISC-V will go if left unresolved,
5 multiple Custom Extensions were noted to be permitted free rein to
6 introduce global binary-encoding conflict with no means of resolution
7 described or endorsed by the RISC-V Standard: a practice that has known
8 disastrous and irreversible consequences for any architecture that
9 permits such practices (1).
10
11 Much later on in the discussion it was realised that there is also no way
12 within the current RISC-V Specification to transition to improved versions
13 of the standard, regardless of whether the fixes are absolutely critical
14 show-stoppers or whether they are just keeping the standard up-to-date (2).
15
16 With no transition path there is guaranteed to be tension and conflict
17 within the RISC-V Community over whether revisions should be made:
18 should existing legacy designs be prioritised, mutually-exclusively over
19 future designs (and what happens during the transition period is absolute
20 chaos, with the compiler toolchain, software ecosystem and ultimately
21 the end-users bearing the full brunt of the impact). If several
22 overlapping revisions are required that have not yet transitioned out
23 of use (which could take well over two decades to occur) the situation
24 becomes disastrous for the credibility of the entire RISC-V ecosystem.
25
26 It was also pointed out that Compliance is an extremely important factor
27 to take into consideration, and that Custom Extensions (as being optional)
28 effectively and quite reasonably fall entirely outside of the scope of
29 Compliance Testing. At this point in the discussion however it was not
30 yet noted the stark problem that the *mandatory* RISC-V Specification
31 also faces, by virtue of there being no transitional way to bring in
32 show-stopping critical alterations.
33
34 To put this into perspective, just taking into account hardware costs
35 alone: with production mask charges for 28nm being around USD $1.5m,
36 engineering development costs and licensing of RTLs for peripherals
37 being of a similar magnitude, no manufacturer is going to back away
38 from selling a "flawed" or "legacy" product (whether it complies with
39 the RISC-V Specification or not) without a bitter fight.
40
41 It was also pointed out that there will be significant software tool
42 maintenance costs for manufacturers, meaning that the probability will
43 be extremely high that they will refuse to shoulder such costs, and
44 will publish and continue to publish (and use) hopelessly out-of-date
45 unpatched tools. This practice is well-known to result in security
46 flaws going unpatched, with one of many immediate undesirable consequences
47 being that product in extremely large volume gets discarded into landfill.
48
49 All and any of the issues that were discussed, and all of those that
50 were not, can be avoided by providing a hardware-level runtime-enabled
51 forwards and backwards compatible transition path between *all* parts
52 (mandatory or not) of current and future revisions of the RISC-V ISA
53 Standard.
54
55 The rest of the discussion - indicative as it was of the stark mutually
56 exclusive gap being faced by the RISC-V ISA Standard given that it does
57 not cope with the problem - was an effort by two groups in two clear
58 camps: one that wanted things to remain as they are, and another that
59 made efforts to point out that the consequences of not taking action
60 are clearly extreme and irreversible (which, unfortunately, given the
61 severity, some of the first group were unable to believe, despite there
62 being clear historical precedent for the same mistake being made in
63 other architectures).
64
65 However after a significant amount of time, certain clear requirements came
66 out of the discussion:
67
68 * Any proposal must be a minimal change with minimal (or zero) impact
69 * Any proposal should place no restriction on existing or future
70 ISA encoding space
71 * Any proposal should take into account that there are existing implementors
72 of the (yet to be finalised but still "partly frozen") Standard who may
73 resist, for financial investment reasons, efforts to make any change
74 (at all) that could cost them immediate short-term profits.
75
76 Several proposals were put forward (and some are still under discussion)
77
78 * "Do nothing": problem is not severe: no action needed.
79 * "Do nothing": problem is out-of-scope for RISC-V Foundation.
80 * "Do nothing": problem complicates Compliance Testing (and is out of scope)
81 * "MISA": the MISA CSR enables and disables extensions already: use that
82 * "MISA-like": a new CSR which switches in and out new encodings
83 (without destroying state)
84 * "mvendorid/marchid WARL": switching the entire "identity" of a machine
85 * "ioctl-like": a OO proposal based around the linux kernel "ioctl" system.
86
87 Each of these will be discussed below in their own sections.
88
89 # Do nothing (no problem exists)
90
91 TBD (basically not an option).
92
93 There were several solutions offered that fell into this category.
94 A few of them are listed in the introduction; more are listed below,
95 and it was exhaustively (and exhaustingly) established that none of
96 them are workable.
97
98 Initially it was pointed out that Fabless Semiconductor companies could
99 simply license multiple Custom Extensions and a suitable RISC-V core, and
100 modify them accordingly. The Fabless Semi Company would be responsible
101 for paying the NREs on re-developing the test vectors (as the extension
102 licensers would be extremely unlikely to do that without payment), and
103 given that said Companies have an "integration" job to do, it would
104 be reasonable to expect them to have such additional costs as well.
105
106 The costs of this approach were outlined and discussed as being
107 disproportionate and extreme compared to the actual likely cost of
108 licensing the Custom Extensions in the first place. Additionally it
109 was pointed out that not only hardware NREs would be involved but
110 custom software tools (compilers and more) would also be required
111 (and maintained separately, on the basis that upstream would not
112 accept them except under extreme pressure, and then only with
113 prejudice).
114
115 All similar schemes involving customisation of the custom extensions
116 were likewise rejected, but not before the customisation process was
117 mistakenly conflated with tne *normal* integration process of developing
118 a custom processor (Bus Architectures, Cache layouts, peripheral layouts).
119
120 The most compelling hardware-related reason (excluding the severe impact on
121 the software ecosystem) for rejecting the customisation-of-customisation
122 approach was the case where Extensions were using an instruction encoding
123 space (48-bit, 64-bit) *greater* than that which the chosen core could
124 cope with (32-bit, 48-bit).
125
126 Overall, none of the options presented were feasible, and, in addition,
127 even if they were followed through, still would result in the failure
128 of the RISC-V ecosystem due to global conflicting ISA binary-encoding
129 meanings (POWERPC's Altivec / SPE nightmare).
130
131 # Do nothing (out of scope)
132
133 TBD (basically, may not be RV Foundation's "scope", still results in
134 problem, so not an option)
135
136 This was one of the first arguments presented: The RISC-V Foundation
137 considers Custom Extensions to be "out of scope"; that "it's not their
138 problem, therefore there isn't a problem".
139
140 The logical errors in this argument were quickly enumerated: namely
141 that the RISC-V Foundation is not in control of the use-cases, such
142 that binary-encoding is a hundred percent guaranteed to occur, and
143 a hundred percent guaranteed to occur in *commodity* hardware where
144 Debian, Fedora, SUSE and other distros will be hardest hit by the
145 resultant chaos, and that will just be the more "visible" aspect of
146 the underlying problem.
147
148 # Do nothing (Compliance too complex, therefore out of scope)
149
150 TBD (basically, may not be RV Foundation's "scope", still results in
151 problem, so not an option)
152
153 Two interestingly diametrically-opposed equally valid arguments exist here:
154
155 * Whilst Compliance testing of Custom Extensions is definitely legitimately
156 out of scope, Compliance testing of simultaneous legacy (old revisions of
157 ISA Standards) and current (new revisions of ISA Standard) definitely
158 is not. Efforts to reduce *Compliance Testing* complexity is therefore
159 "Compliance Tail Wagging Standard Dog".
160 * Beyond a certain threshold, complexity of Compliance Testing is so
161 burdensome that it risks outright rejection of the entire Standard.
162
163 Meeting these two diametrically-opposed perspectives requires that the
164 solution be very, very simple.
165
166 # MISA
167
168 TBD, basically MISA not suitable
169
170 MISA permits extensions to be disabled by masking out the relevant bit.
171 Hypothetically it could be used to disable one extension, then enable
172 another that happens to use the same binary encoding.
173
174 *However*:
175
176 * MISA Extension disabling is permitted (optionally) to **destroy**
177 the state information. Thus it is totally unsuitable for cases
178 where instructions from different Custom extensions are needed in
179 quick succession.
180 * MISA was only designed to cover Standard Extensions.
181 * There is nothing to prevent multiple Extensions being enabled
182 that wish to simultaneously interpret the same binary encoding.
183
184 Overall, whilst the MISA concept is a step in the right direction it's
185 a hundred percent unsuitable for solving the problem.
186
187 # MISA-like
188
189 TBD, basically same as mvend/march WARL except needs an extra CSR where
190 mv/ma doesn't.
191
192 # mvendorid/marchid WARL
193
194 TBD paraphrase and clarify
195
196 > In an earlier part of the thread someone kindly pointed out that MISA
197 > already switches out entire sets of instructions [which interacts at the
198 > "decode" phase]. However it was noted after a few days of investigating
199 > that particular lead that:
200 >
201 > * MISA Extension disabling is permitted (optionally) to DESTROY the state
202 > information (which means that it *has* to be re-initialised just to be
203 > safe... mistake in the standard, there), and * MISA was only designed
204 > to cover Standard Extensions.
205 >
206 > So the practice of switching extensions in and out - and the resultant
207 > "disablement" and "enablement" at the *instruction decode phase* is
208 > *already* a hard requirement as part of conforming with the present
209 > RISC-V Specification.
210 >
211 > Around the same MISA discussion, someone else also kindly pointed out
212 > that one solution to the heavyweight nature of the switching would
213 > be to deliberately introduce a pipeline stall whilst the switching is
214 > occurring: I can see the sense in that approach, even if I don't know the
215 > full details of what each implementor might choose to do. They may even
216 > choose two, or three, or N pipeline stalls: it really doesn't matter,
217 > as it's an implementors' choice (and problem to solve).
218 >
219 > So yes it's pretty heavy-duty... and also already required.
220 >
221 > For the case where "legacy" variants of the RISC-V Standard are
222 > backwards-forwards-compatibly supported over a 10-20 year period
223 > in Industrial and Military/Goverment-procurement scenarios (so that
224 > the impossible-to-achieve pressure is off to get the spec ABSOLUTELY
225 > correct, RIGHT now), nobody would expect a seriously heavy-duty amount
226 > of instruction-by-instruction switching: it'd be used pretty much once
227 > and only once at boot-up (or once in a Hypervisor Virtual Machine client)
228 > and that's it.
229 >
230 > I can however foresee instances where implementors would actually
231 > genuinely want a bank of operations to be carried out using one extension,
232 > followed immediately by another bank from a (conflicting binary-encoding)
233 > extension, in an inner loop: Software-defined MPEG / MP4 decode to call
234 > DCT block decode Custom Extension followed immediately by Custom Video
235 > Processing Extension followed immediately by Custom DSP Processing
236 > Extension to do YUV-to-RGB conversion for example is something that
237 > is clearly desirable. Solving that one would be entiiirely their
238 > problem... and the RISC-V Specification really really should give them
239 > the space to do that in a clear-cut unambiguous way.
240
241 # ioctl-like
242
243 TBD - [[ioctl]] for full details, summary kept here
244
245 # Discussion and analysis
246
247 TBD
248
249 # Conclusion
250
251 TBD
252
253 # Conversation Exerpts
254
255 The following conversation exerpts are taken from the ISA-dev discussion
256
257 ## (1) Albert Calahan on SPE / Altiven conflict in POWERPC
258
259 > Yes. Well, it should be blocked via legal means. Incompatibility is
260 > a disaster for an architecture.
261 >
262 > The viability of PowerPC was badly damaged when SPE was
263 > introduced. This was a vector instruction set that was incompatible
264 > with the AltiVec instruction set. Software vendors had to choose,
265 > and typically the choice was "neither". Nobody wants to put in the
266 > effort when there is uncertainty and a market fragmented into
267 > small bits.
268 > Note how Intel did not screw up. When SSE was added, MMX remained.
269 > Software vendors could trust that instructions would be supported.
270 > Both MMX and SSE remain today, in all shipping processors. With very
271 > few exceptions, Intel does not ship chips with missing functionality.
272 > There is a unified software ecosystem.
273 >
274 > This goes beyond the instruction set. MMU functionality also matters.
275 > You can add stuff, but then it must be implemented in every future CPU.
276 > You can not take stuff away without harming the architecture.
277
278 ## (2) Luke Kenneth Casson Leighton on Standards backwards-compatibility
279
280 > For the case where "legacy" variants of the RISC-V Standard are
281 > backwards-forwards-compatibly supported over a 10-20 year period in
282 > Industrial and Military/Goverment-procurement scenarios (so that the
283 > impossible-to-achieve pressure is off to get the spec ABSOLUTELY
284 > correct, RIGHT now), nobody would expect a seriously heavy-duty amount
285 > of instruction-by-instruction switching: it'd be used pretty much once
286 > and only once at boot-up (or once in a Hypervisor Virtual Machine
287 > client) and that's it.
288
289 ## (3) Allen Baum on Standards Compliance
290
291 > Putting my compliance chair hat on: One point that was made quite
292 > clear to me is that compliance will only test that an implementation
293 > correctly implements the portions of the spec that are mandatory, and
294 > the portions of the spec that are optional and the implementor claims
295 > it is implementing. It will test nothing in the custom extension space,
296 > and doesn't monitor or care what is in that space.
297