interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / tests / nvml / host.om

942 lines · 19671 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note CUDA++ NVML host tier in Omega: the checks of tests/nvml/nvml_test.c, one for one and in the
3note same order, run against native/nvml (nvml_step, nvml_errstr) and the RM fake
4note tests/nvml/rmfake.om, with no foreign code. tests/nvml/gate.om composes this program as
5note native/nvml/nvml.om query.om step.om errstr.om, tests/nvml/rmfake.om, then this file, and
6note compiles it with the pinned seeded omc.
7note
8note hv_run is the call protocol of native/nvml/api.om (generated as compat/nvml/libnvidia-ml.c):
9note stage the op and arguments, alternate nvml_step with the one action it requests,
10note bound the copies, map the status. hv_ioctl, hv_open and hv_close are the test transport of
11note tests/nvml/transport.c (fault S included). Pointers of the C test become flags and slots:
12note a device handle is 0 (NULL), 1+index (issued by hv_handle) or 1000 (a foreign pointer); a
13note scalar out-pointer is 1+slot in HvV (0 is NULL); the caller's output buffer is HvO.
14note One difference from the C caller: a trap inside a unit ends this program with the trap
15note status (101..114) instead of reading as NVML_ERROR_UNKNOWN; either way the tier fails.
16note usage: host ERRSTR_ORACLE.tsv; prints CUDAPP-NVML HOST PASS (N checks), exit 0, or
17note CUDAPP-NVML HOST FAIL (F of N checks), exit 1; a usage error exits 2.
18
19global HvA ulong 8
20global HvG ulong 4
21global HvO uchar 6144
22global HvV ulong 4
23global HvH ulong 4
24global HvC ulong 4
25global HvF ulong 4
26global HvR ulong 1
27global HvT uchar 2048
28global HvTs uchar 32
29
30text HvNm "NVIDIA GB10"
31text HvU0 "GPU-fb8e53f0-3207-e89b-d02f-acdfe2695b59"
32text HvU1 "GPU-fb8e53f0-3207-e89b-d02f-acdfe2695b5a"
33text HvUnk "Unknown Error"
34text HvFl "oadPA902cGnESgthvzxmwyerZXklpbijf"
35text HvFi "94944U000000000000000000000000000"
36text HvFc "000000112222234445556666667777770"
37text HvFr "000000003FUUUUUU333U34UUUU30U00U0"
38text HvFail "FAIL check "
39text HvNL "\n"
40text HvPass "CUDAPP-NVML HOST PASS ("
41text HvBad "CUDAPP-NVML HOST FAIL ("
42text HvOf " of "
43text HvChk " checks)\n"
44text HvUse "usage: host ERRSTR_ORACLE.tsv\n"
45
46const HvMAX ulong 18446744073709551615
47const HvNA32 ulong 4294967295
48const HvFOR ulong 1000
49
50note Decimal digits of v to fd.
51fn hv_num fd int v ulong to void
52rev = new uchar 32 0
53out = new uchar 32 0
54x = v
55n = ulong 0
56while true bound 32
57put rev n uchar add rem x 10 48
58n = add n 1
59x = div x 10
60if eq x 0
61break
62end
63end
64for i ulong n
65put out i get rev sub sub n 1 i
66end
67w = write fd out 0 n
68end
69
70fn hv_ck ok bool to void
71put HvC 0 add get HvC 0 1
72if not ok
73put HvC 1 add get HvC 1 1
74w = write 1 HvFail 0 len HvFail
75hv_num 1 get HvC 0
76w = write 1 HvNL 0 1
77end
78end
79
80fn hv_rc got ulong wt ulong to void
81hv_ck eq got wt
82end
83
84note The caller's output buffer: fill, little-endian reads and writes.
85fn hv_fill v ulong n ulong to void
86for i ulong n
87put HvO i uchar v
88end
89end
90
91fn hv_o32 at ulong to ulong
92r = ulong 0
93for i ulong 4
94r = or r shl ulong get HvO add at i mul 8 i
95end
96ret r
97end
98
99fn hv_o64 at ulong to ulong
100r = ulong 0
101for i ulong 8
102r = or r shl ulong get HvO add at i mul 8 i
103end
104ret r
105end
106
107fn hv_p32 at ulong v ulong to void
108for i ulong 4
109put HvO add at i uchar and shr v mul 8 i 255
110end
111end
112
113note strcmp(HvO, text) == 0 for the three expected strings.
114fn hv_isnm to bool
115n = len HvNm
116for i ulong n
117if ne get HvO i get HvNm i
118ret false
119end
120end
121ret eq get HvO n 0
122end
123
124fn hv_isu0 to bool
125n = len HvU0
126for i ulong n
127if ne get HvO i get HvU0 i
128ret false
129end
130end
131ret eq get HvO n 0
132end
133
134fn hv_isu1 to bool
135n = len HvU1
136for i ulong n
137if ne get HvO i get HvU1 i
138ret false
139end
140end
141ret eq get HvO n 0
142end
143
144note fake_reset of tests/nvml/transport.c.
145fn hv_reset st edit ulong 64 c ulong to void
146for i ulong 64
147put st i 0
148end
149put st 5 c
150put HvC 2 0
151end
152
153note One fake step; a trap or refusal counts as a violation and reads as transport status 1.
154fn hv_fstep st edit ulong 64 h edit uchar HN p edit uchar PN to ulong
155r = nvml_fake st h p
156if ne r 0
157put HvC 2 add get HvC 2 1
158put st 13 add get st 13 1
159ret 1
160end
161put HvR 0 get st 6
162ret 0
163end
164
165note Copy the header and parameter spans between the step buffer and the fake (in when tofk).
166fn hv_xfer b edit uchar BN h edit uchar HN p edit uchar PN hl ulong pl ulong tofk bool to void
167for i ulong hl
168if tofk
169put h i get b i
170else
171put b i get h i
172end
173end
174for j ulong pl
175if tofk
176put p j get b add PO j
177else
178put b add PO j get p j
179end
180end
181end
182
183note omega2_nvrm_ioctl over the fake: copy the request in, one step, copy the reply back.
184fn hv_ioctl s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong
185hl = get s 11
186pl = get s 12
187if or gt hl HN gt pl PN
188ret 32
189end
190if and and eq get st 5 83 eq get s 10 42 ge hl 12
191if eq g32 b 8 545259792
192ret 1
193end
194end
195hv_xfer b h p hl pl true
196put st 0 1
197put st 1 get s 9
198put st 2 get s 10
199put st 3 hl
200put st 4 pl
201r = hv_fstep st h p
202hv_xfer b h p hl pl false
203ret r
204end
205
206fn hv_open s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong
207n = get s 13
208if or eq n 0 gt n PN
209ret 32
210end
211for i ulong n
212put p i get b add PO i
213end
214put st 0 2
215put st 7 n
216ret hv_fstep st h p
217end
218
219fn hv_close s edit ulong SN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong
220put st 0 3
221put st 1 get s 9
222ret hv_fstep st h p
223end
224
225note nvml_act: perform the requested action; false is a malformed request.
226fn hv_act s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to bool
227k = get s 8
228put HvR 0 0
229if eq k 1
230if gt get s 11 PO
231ret false
232end
233if gt get s 12 sub OO PO
234ret false
235end
236put s 15 hv_ioctl s b st h p
237put s 14 get HvR 0
238ret true
239end
240if eq k 2
241if eq get s 13 0
242ret false
243end
244if gt get s 13 sub OO PO
245ret false
246end
247put s 15 hv_open s b st h p
248put s 14 get HvR 0
249ret true
250end
251if eq k 3
252put s 15 hv_close s st h p
253put s 14 get HvR 0
254ret true
255end
256ret false
257end
258
259note The step reported done: bound the copies like nvml_run, copy out, map the status.
260fn hv_fin s edit ulong SN b edit uchar BN to ulong
261k = get s 7
262sp = get HvA 7
263if or gt k get HvA 5 and ne k 0 eq get HvA 6 0
264ret 999
265end
266if ne get s 27 0
267if or eq sp 0 gt get s 5 HvNA32
268ret 999
269end
270end
271for i ulong k
272put HvO i get b add OO i
273end
274if ne get s 27 0
275put HvV sub sp 1 get s 5
276end
277v = get s 6
278if or le v 30 eq v 999
279ret v
280end
281ret 999
282end
283
284note nvml_run: HvA holds op, four arguments, the output capacity, the output-pointer flag and
285note the scalar slot (1+index into HvV, 0 for NULL). Returns the nvmlReturn_t value.
286fn hv_run s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong
287rc = ulong 999
288for i ulong 5
289put s i get HvA i
290end
291put s 22 0
292for n ulong 4096
293if ne nvml_step s b 0
294break
295end
296if eq get s 8 0
297rc = hv_fin s b
298break
299end
300if not hv_act s b st h p
301break
302end
303end
304put s 22 0
305ret rc
306end
307
308fn hv_stage op ulong a1 ulong a2 ulong a3 ulong a4 ulong to void
309put HvA 0 op
310put HvA 1 a1
311put HvA 2 a2
312put HvA 3 a3
313put HvA 4 a4
314end
315
316fn hv_io cap ulong outok ulong sp ulong to void
317put HvA 5 cap
318put HvA 6 outok
319put HvA 7 sp
320end
321
322note API call arguments: hv_g sets HvG 0..2 before each entry point below.
323fn hv_g a ulong b ulong c ulong to void
324put HvG 0 a
325put HvG 1 b
326put HvG 2 c
327end
328
329fn hv_nz v ulong to ulong
330if ne v 0
331ret 1
332end
333ret 0
334end
335
336note nvml_index: the index of a handle hv_handle issued, or UINT64_MAX.
337fn hv_idx d ulong to ulong
338if and ge d 1 le d 8
339ret sub d 1
340end
341ret HvMAX
342end
343
344fn hv_init s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong
345hv_stage 1 0 0 0 0
346hv_io 0 0 0
347ret hv_run s b st h p
348end
349
350fn hv_shut s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong
351hv_stage 2 0 0 0 0
352hv_io 0 0 0
353ret hv_run s b st h p
354end
355
356note count: G0 the scalar slot.
357fn hv_count s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong
358sp = get HvG 0
359hv_stage 3 0 hv_nz sp 0 0
360hv_io 0 0 sp
361ret hv_run s b st h p
362end
363
364note handle: G0 the index, G1 the handle slot (1+index into HvH, 0 for NULL).
365fn hv_handle s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong
366hs = get HvG 1
367put HvV 3 0
368hv_stage 4 get HvG 0 hv_nz hs 0 0
369hv_io 0 0 4
370rc = hv_run s b st h p
371if eq rc 0
372i = get HvV 3
373if ge i 8
374ret 999
375end
376put HvH sub hs 1 add i 1
377end
378ret rc
379end
380
381note name and uuid: G0 the device, G1 the buffer flag, G2 the length.
382fn hv_name s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong
383hv_stage 5 hv_idx get HvG 0 get HvG 1 get HvG 2 0
384hv_io get HvG 2 get HvG 1 0
385ret hv_run s b st h p
386end
387
388fn hv_uuid s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong
389hv_stage 6 hv_idx get HvG 0 get HvG 1 get HvG 2 0
390hv_io get HvG 2 get HvG 1 0
391ret hv_run s b st h p
392end
393
394note temperature: G0 the device, G1 the sensor, G2 the scalar slot.
395fn hv_temp s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong
396sp = get HvG 2
397hv_stage 7 hv_idx get HvG 0 hv_nz sp get HvG 1 0
398hv_io 0 0 sp
399ret hv_run s b st h p
400end
401
402note memory (24 bytes) and utilization (8 bytes): G0 the device, G1 the output flag.
403fn hv_mem s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong
404hv_stage 8 hv_idx get HvG 0 get HvG 1 0 0
405hv_io 24 get HvG 1 0
406ret hv_run s b st h p
407end
408
409fn hv_util s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong
410hv_stage 9 hv_idx get HvG 0 get HvG 1 0 0
411hv_io 8 get HvG 1 0
412ret hv_run s b st h p
413end
414
415note processes: G0 the device, G1 the count slot, G2 the infos flag; capacity is 24 per entry.
416fn hv_procs s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong
417sp = get HvG 1
418wc = ulong 0
419if ne sp 0
420wc = get HvV sub sp 1
421end
422hv_stage 10 hv_idx get HvG 0 hv_nz sp wc get HvG 2
423hv_io mul wc 24 get HvG 2 sp
424ret hv_run s b st h p
425end
426
427note nvmlErrorString: the slot of the cached text, or 32 for the static "Unknown Error".
428fn hv_errstr code ulong to ulong
429o = new uchar 64 0
430r = nvml_errstr code o
431n = and r 255
432sl = and shr r 8 255
433if and lt n 64 lt sl 32
434if eq get HvTs sl 0
435for i ulong 64
436put HvT add mul sl 64 i get o i
437end
438put HvT add mul sl 64 n 0
439put HvTs sl 1
440end
441ret sl
442end
443ret 32
444end
445
446note strcmp(nvmlErrorString(code), line[wo..wo+wn)) == 0.
447fn hv_streq sl ulong w edit uchar 65536 wo ulong wn ulong to bool
448if eq sl 32
449if ne wn len HvUnk
450ret false
451end
452for i ulong wn
453if ne get HvUnk i get w add wo i
454ret false
455end
456end
457ret true
458end
459if ge wn 64
460ret false
461end
462for i ulong wn
463if ne get HvT add mul sl 64 i get w add wo i
464ret false
465end
466end
467ret eq get HvT add mul sl 64 wn 0
468end
469
470note strtoll(line, NULL, 10) over fb[at..lim), then (nvmlReturn_t)(int)(unsigned) as the shell
471note widens it: the low 32 bits, sign-extended.
472fn hv_strtoll fb edit uchar 65536 at ulong lim ulong to ulong
473i = at
474while lt i lim bound 999999
475if and ne get fb i 32 ne get fb i 9
476break
477end
478i = add i 1
479end
480minus = false
481if lt i lim
482if eq get fb i 45
483minus = true
484i = add i 1
485else
486if eq get fb i 43
487i = add i 1
488end
489end
490end
491mag = ulong 0
492while lt i lim bound 999999
493if or lt get fb i 48 gt get fb i 57
494break
495end
496mag = add mul mag 10 ulong sub get fb i 48
497i = add i 1
498end
499if minus
500mag = sub 0 mag
501end
502mag = and mag HvNA32
503if ge mag 2147483648
504mag = or mag 18446744069414584320
505end
506ret mag
507end
508
509note One oracle line fb[ls..ln): false when it has no tab, else its check.
510fn hv_row fb edit uchar 65536 ls ulong ln ulong to bool
511tab = ls
512while lt tab ln bound 999999
513if eq get fb tab 9
514break
515end
516tab = add tab 1
517end
518if ge tab ln
519ret false
520end
521sl = hv_errstr hv_strtoll fb ls tab
522hv_ck hv_streq sl fb add tab 1 sub sub ln tab 1
523ret true
524end
525
526fn hv_rows fb edit uchar 65536 used ulong to ulong
527rows = ulong 0
528ls = ulong 0
529while lt ls used bound 999999
530ln = ls
531while lt ln used bound 999999
532if eq get fb ln 10
533break
534end
535ln = add ln 1
536end
537if hv_row fb ls ln
538rows = add rows 1
539end
540ls = add ln 1
541end
542ret rows
543end
544
545note errstrings: every row of the oracle, then the row count and pointer stability.
546fn hv_errs ap edit uchar 4096 an ulong to void
547fb = new uchar 65536 0
548fd = fopen ap 0 an 0 0
549hv_ck ge fd 0
550if lt fd 0
551ret
552end
553used = ulong 0
554while lt used 65536 bound 999999
555k = read int fd fb used sub 65536 used
556if le k 0
557break
558end
559used = add used ulong k
560end
561c = fclose int fd
562hv_ck eq hv_rows fb used 37
563hv_ck eq hv_errstr 0 hv_errstr 0
564hv_ck eq hv_errstr 31 hv_errstr 999
565end
566
567note Output checks over HvO (and HvV), kept out of the callers' registers.
568fn hv_memok to bool
569if ne hv_o64 0 131072000000
570ret false
571end
572if ne hv_o64 8 102400000000
573ret false
574end
575ret eq hv_o64 16 28672000000
576end
577
578fn hv_utilok to bool
579if ne hv_o32 0 42
580ret false
581end
582ret eq hv_o32 4 13
583end
584
585fn hv_pok at ulong pid ulong used ulong to bool
586if ne hv_o32 at pid
587ret false
588end
589ret eq hv_o64 add at 8 used
590end
591
592note Both entries report no GPU or compute instance.
593fn hv_naok to bool
594if ne hv_o32 16 HvNA32
595ret false
596end
597if ne hv_o32 20 HvNA32
598ret false
599end
600if ne hv_o32 40 HvNA32
601ret false
602end
603ret eq hv_o32 44 HvNA32
604end
605
606note Fault b: entry i is pid 1000+i using (1000+i)*65536 bytes.
607fn hv_bok to bool
608nb = ulong 0
609for i ulong 250
610o = mul i 24
611if ne hv_o32 o add 1000 i
612nb = add nb 1
613else
614if ne hv_o64 add o 8 mul add 1000 i 65536
615nb = add nb 1
616end
617end
618end
619ret eq nb 0
620end
621
622note Fault i: the second entry's memory is NVML_VALUE_NOT_AVAILABLE.
623fn hv_iok to bool
624if ne get HvV 0 2
625ret false
626end
627if ne hv_o64 8 351272960
628ret false
629end
630if ne hv_o32 24 4242
631ret false
632end
633ret eq hv_o64 32 HvMAX
634end
635
636note Every fd closed, every RM object freed, no request outside the RM contract.
637fn hv_clean st edit ulong 64 to void
638hv_ck eq get st 14 0
639hv_ck eq get st 15 0
640hv_ck eq get st 16 0
641hv_ck eq get st 8 get st 9
642hv_ck eq get st 13 0
643end
644
645fn hv_healthy s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to void
646put HvV 0 77
647put HvV 1 0
648put HvH 0 0
649put HvH 1 0
650hv_reset st 0
651hv_g 1 0 0
652hv_rc hv_count s b st h p 1
653hv_g 0 1 0
654hv_rc hv_handle s b st h p 1
655hv_rc hv_shut s b st h p 1
656hv_ck eq get st 8 0
657hv_rc hv_init s b st h p 0
658hv_g 1 0 0
659hv_rc hv_count s b st h p 0
660hv_ck eq get HvV 0 1
661hv_g 0 0 0
662hv_rc hv_count s b st h p 2
663hv_g 0 1 0
664hv_rc hv_handle s b st h p 0
665hv_ck ne get HvH 0 0
666hv_g 1 2 0
667hv_rc hv_handle s b st h p 2
668hv_g 0 0 0
669hv_rc hv_handle s b st h p 2
670d = get HvH 0
671hv_fill 120 128
672hv_g d 1 96
673hv_rc hv_name s b st h p 0
674hv_ck hv_isnm
675hv_g d 1 11
676hv_rc hv_name s b st h p 7
677hv_fill 120 128
678hv_g d 1 12
679hv_rc hv_name s b st h p 0
680hv_ck hv_isnm
681hv_g 0 1 64
682hv_rc hv_name s b st h p 2
683hv_g HvFOR 1 64
684hv_rc hv_name s b st h p 2
685hv_g d 0 64
686hv_rc hv_name s b st h p 2
687hv_fill 120 128
688hv_g d 1 96
689hv_rc hv_uuid s b st h p 0
690hv_ck hv_isu0
691hv_g d 1 40
692hv_rc hv_uuid s b st h p 7
693hv_fill 120 128
694hv_g d 1 41
695hv_rc hv_uuid s b st h p 0
696hv_ck hv_isu0
697hv_g d 0 80
698hv_rc hv_uuid s b st h p 2
699hv_g d 0 2
700hv_rc hv_temp s b st h p 0
701hv_ck eq get HvV 1 40
702hv_g d 1 2
703hv_rc hv_temp s b st h p 2
704hv_g d 0 0
705hv_rc hv_temp s b st h p 2
706hv_fill 165 24
707hv_g d 1 0
708hv_rc hv_mem s b st h p 0
709hv_ck hv_memok
710hv_g d 0 0
711hv_rc hv_mem s b st h p 2
712hv_p32 0 77
713hv_p32 4 77
714hv_g d 1 0
715hv_rc hv_util s b st h p 0
716hv_ck hv_utilok
717hv_g d 0 0
718hv_rc hv_util s b st h p 2
719put HvV 0 0
720hv_g d 1 0
721hv_rc hv_procs s b st h p 7
722hv_ck eq get HvV 0 2
723put HvV 0 1
724hv_g d 1 1
725hv_rc hv_procs s b st h p 7
726hv_ck eq get HvV 0 2
727put HvV 0 2
728hv_g d 1 0
729hv_rc hv_procs s b st h p 2
730hv_g d 0 1
731hv_rc hv_procs s b st h p 2
732hv_fill 0 120
733put HvV 0 5
734hv_g d 1 1
735hv_rc hv_procs s b st h p 0
736hv_ck eq get HvV 0 2
737hv_ck hv_pok 0 68451 351272960
738hv_ck hv_pok 24 4242 278003712
739hv_ck hv_naok
740hv_ck eq hv_o32 48 0
741hv_rc hv_shut s b st h p 0
742hv_g 1 0 0
743hv_rc hv_count s b st h p 1
744hv_g d 1 64
745hv_rc hv_name s b st h p 1
746hv_rc hv_shut s b st h p 1
747hv_clean st
748end
749
750note nvmlInit/nvmlShutdown keep a reference count; only the last shutdown tears down.
751fn hv_refcount s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to void
752put HvV 0 0
753hv_reset st 0
754hv_rc hv_init s b st h p 0
755opens = get st 8
756hv_ck eq opens 2
757hv_rc hv_init s b st h p 0
758hv_ck eq get st 8 opens
759hv_rc hv_shut s b st h p 0
760hv_g 1 0 0
761hv_rc hv_count s b st h p 0
762hv_ck eq get st 9 0
763hv_rc hv_shut s b st h p 0
764hv_g 1 0 0
765hv_rc hv_count s b st h p 1
766hv_clean st
767hv_rc hv_init s b st h p 0
768hv_rc hv_shut s b st h p 0
769hv_clean st
770end
771
772note A fault-table return code: a digit, F for GPU_IS_LOST (15) or U for UNKNOWN (999).
773fn hv_code c uchar to ulong
774if eq c 85
775ret 999
776end
777if eq c 70
778ret 15
779end
780ret ulong sub c 48
781end
782
783note Fault COUNT: the device count, then (fault 0 aside) both handles, their UUIDs and sensors.
784fn hv_cnt s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to void
785hv_g 1 0 0
786hv_rc hv_count s b st h p get HvF 3
787if eq get HvF 0 48
788hv_ck eq get HvV 0 0
789hv_g 0 1 0
790hv_rc hv_handle s b st h p 2
791ret
792end
793hv_ck eq get HvV 0 2
794put HvH 2 0
795put HvH 1 0
796hv_g 0 3 0
797hv_rc hv_handle s b st h p 0
798hv_g 1 2 0
799hv_rc hv_handle s b st h p 0
800hv_ck ne get HvH 2 get HvH 1
801hv_g get HvH 1 1 96
802hv_rc hv_uuid s b st h p 0
803hv_ck hv_isu1
804hv_g get HvH 2 1 96
805hv_rc hv_uuid s b st h p 0
806hv_ck hv_isu0
807hv_g get HvH 1 0 2
808hv_rc hv_temp s b st h p 0
809hv_ck eq get HvV 1 41
810hv_g 2 1 0
811hv_rc hv_handle s b st h p 2
812end
813
814note Fault PROCS: the process list and the letter's extra checks.
815fn hv_pcall s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to void
816letter = get HvF 0
817put HvV 0 256
818hv_fill 0 6144
819hv_g get HvH 0 1 1
820hv_rc hv_procs s b st h p get HvF 3
821if eq letter 108
822hv_ck eq get HvV 0 0
823end
824if eq letter 98
825hv_ck eq get HvV 0 250
826hv_ck hv_bok
827put HvV 0 249
828hv_g get HvH 0 1 1
829hv_rc hv_procs s b st h p 7
830hv_ck eq get HvV 0 250
831end
832if eq letter 105
833hv_ck hv_iok
834end
835end
836
837note The faulted call of kinds NAME..UTIL, which must return the table's code.
838fn hv_call s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to void
839kind = get HvF 2
840d = get HvH 0
841if eq kind 2
842hv_g d 1 96
843hv_rc hv_name s b st h p get HvF 3
844end
845if eq kind 3
846hv_g d 1 96
847hv_rc hv_uuid s b st h p get HvF 3
848end
849if eq kind 4
850hv_g d 0 2
851hv_rc hv_temp s b st h p get HvF 3
852end
853if eq kind 5
854hv_g d 1 0
855hv_rc hv_mem s b st h p get HvF 3
856end
857if eq kind 6
858hv_g d 1 0
859hv_rc hv_util s b st h p get HvF 3
860end
861end
862
863note one(): row f of the fault table; HvF holds its letter, init code, call kind and call code.
864fn hv_one s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN f ulong to void
865put HvF 0 ulong get HvFl f
866put HvF 1 hv_code get HvFi f
867put HvF 2 ulong sub get HvFc f 48
868put HvF 3 hv_code get HvFr f
869put HvV 0 0
870put HvV 1 0
871put HvH 0 0
872hv_reset st get HvF 0
873r = hv_init s b st h p
874hv_ck eq r get HvF 1
875if ne r 0
876hv_g 1 0 0
877hv_rc hv_count s b st h p 1
878hv_clean st
879ret
880end
881kind = get HvF 2
882if ne kind 1
883hv_g 0 1 0
884hv_rc hv_handle s b st h p 0
885end
886if eq kind 1
887hv_cnt s b st h p
888end
889hv_call s b st h p
890if eq kind 7
891hv_pcall s b st h p
892end
893if eq get HvF 0 102
894hv_rc hv_shut s b st h p 999
895hv_g 1 0 0
896hv_rc hv_count s b st h p 1
897hv_ck eq get st 14 0
898hv_ck eq get st 13 0
899ret
900end
901hv_rc hv_shut s b st h p 0
902hv_clean st
903end
904
905fn main to int
906c = argcnt
907if ne c 2
908w = write 2 HvUse 0 len HvUse
909ret 2
910end
911s = new ulong SN 0
912b = new uchar BN 0
913st = new ulong 64 0
914h = new uchar HN 0
915p = new uchar PN 0
916ap = new uchar 4096 0
917an = argread 1 ap 0 4096
918if lt an 0
919hv_ck false
920else
921hv_errs ap ulong an
922end
923hv_healthy s b st h p
924hv_refcount s b st h p
925for f ulong 33
926hv_one s b st h p f
927end
928hv_healthy s b st h p
929hv_ck eq get HvC 2 0
930if ne get HvC 1 0
931w = write 1 HvBad 0 len HvBad
932hv_num 1 get HvC 1
933w = write 1 HvOf 0 len HvOf
934hv_num 1 get HvC 0
935w = write 1 HvChk 0 len HvChk
936ret 1
937end
938w = write 1 HvPass 0 len HvPass
939hv_num 1 get HvC 0
940w = write 1 HvChk 0 len HvChk
941ret 0
942end