interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / gpu / nvidia / driver / diag.om

173 lines · 4764 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note gpu/nvidia/driver/diag.om: the memory diagnosis the driver client adds when an allocation fails.
3note Omega form of CUDApp nvrm/nvrm.c meminfo_kb, buddy_free_blocks_ge, fail_alloc_context and
4note fail_channel_no_memory (84b524ca). Parsing reuses gpu/nvidia/native/nvrm/counts.om (nc_mem, nc_buddy),
5note which must come first in the composition (it carries the om2 line); gpu/nvidia/driver/parts.txt.
6note The caller reads /proc/meminfo and /proc/buddyinfo whole and hands the bytes in; nothing here opens a file.
7note The C reads lines in 256 and 512 byte pieces and cuts its message at 255 bytes; here a line is a whole
8note line and the message is as long as it needs to be. A caller buffer too small for the message is refused
9note (drv_amsg and drv_cmsg return 2^64 - 1), never cut short. counts.om walks at most 512 bytes of one line,
10note so a longer line is refused here (false) rather than handed to it.
11
12text drv_t " for | bytes, MemFree | kB, MemAvailable | kB| after | attempts over | ms; MemFree | kB, free 2 MiB blocks |UNKNOWN|"
13const drv_line ulong 512
14const drv_none ulong 18446744073709551615
15
16note end of the line that starts at s: the index just past its newline, or len f
17fn drv_eol f view uchar * s ulong to ulong
18i = s
19while lt i len f bound 9223372036854775807
20if eq get f i 10
21ret add i 1
22end
23i = add i 1
24end
25ret i
26end
27
28note meminfo_kb: r[0] gets the kB value of the first line "KEY:", 0 when there is none or its value does not
29note parse (the C answer for an unreadable file is also 0; the caller passes empty bytes then).
30fn drv_meminfo f view uchar * key view uchar * r edit ulong 1 to bool
31st = new ulong 2 0
32put r 0 0
33s = ulong 0
34while lt s len f bound 9223372036854775807
35e = drv_eol f s
36if gt sub e s drv_line
37ret false
38end
39if ne nc_mem part f s sub e s key st 0
40put r 0 get st 1
41ret true
42end
43s = e
44end
45ret true
46end
47
48note buddy_free_blocks_ge: r[0] gets the free blocks of every order >= order summed over all zone lines.
49note The C answer for an unreadable file, ULLONG_MAX, is the caller's to give.
50fn drv_buddy f view uchar * order ulong r edit ulong 1 to bool
51st = new ulong 2 0
52put st 0 order
53s = ulong 0
54while lt s len f bound 9223372036854775807
55e = drv_eol f s
56if gt sub e s drv_line
57ret false
58end
59x = nc_buddy part f s sub e s st
60s = e
61end
62put r 0 get st 1
63ret true
64end
65
66note copy piece w of drv_t (pieces end at "|") to o at n; the new end, or drv_none when o is too small.
67note Past the last piece nothing is copied.
68fn drv_tput o edit uchar * n ulong w ulong to ulong
69if eq n drv_none
70ret n
71end
72k = ulong 0
73i = ulong 0
74while and lt k w lt i len drv_t bound 9223372036854775807
75if eq get drv_t i 124
76k = add k 1
77end
78i = add i 1
79end
80p = n
81if ge i len drv_t
82ret p
83end
84while ne get drv_t i 124 bound 9223372036854775807
85if ge p len o
86ret drv_none
87end
88put o p get drv_t i
89p = add p 1
90i = add i 1
91end
92ret p
93end
94
95note copy the bytes of b to o at n (the C "%s" of the previous error); a NUL in b ends it, as in C
96fn drv_sput o edit uchar * n ulong b view uchar * to ulong
97if eq n drv_none
98ret n
99end
100p = n
101for i ulong len b bound 9223372036854775807
102if eq get b i 0
103break
104end
105if ge p len o
106ret drv_none
107end
108put o p get b i
109p = add p 1
110end
111ret p
112end
113
114note "%llu" of v to o at n
115fn drv_nput o edit uchar * n ulong v ulong to ulong
116if eq n drv_none
117ret n
118end
119d = new uchar 20 0
120k = ulong 0
121x = v
122while true bound 20
123put d k uchar add 48 rem x 10
124k = add k 1
125x = div x 10
126if eq x 0
127break
128end
129end
130if gt add n k len o
131ret drv_none
132end
133for j ulong k bound 20
134put o add n j get d sub sub k j 1
135end
136ret add n k
137end
138
139note fail_alloc_context: "%s for %llu bytes, MemFree %llu kB, MemAvailable %llu kB" with v = size, MemFree kB,
140note MemAvailable kB. Returns the message length in o, or drv_none when o is too small.
141fn drv_amsg prev view uchar * v view ulong 3 o edit uchar * to ulong
142n = drv_sput o 0 prev
143n = drv_tput o n 0
144n = drv_nput o n get v 0
145n = drv_tput o n 1
146n = drv_nput o n get v 1
147n = drv_tput o n 2
148n = drv_nput o n get v 2
149ret drv_tput o n 3
150end
151
152note fail_channel_no_memory: "%s after %u attempts over %u ms; MemFree %llu kB, free 2 MiB blocks %s" with
153note v = attempts, delay ms (both u32), MemFree kB, free blocks of order >= 9 (drv_none prints UNKNOWN).
154note The span is (attempts - 1) * delay in 32-bit arithmetic, as the C computes it.
155fn drv_cmsg prev view uchar * v view ulong 4 o edit uchar * to ulong
156a = and get v 0 4294967295
157w = ulong 0
158if gt a 1
159w = and mul sub a 1 and get v 1 4294967295 4294967295
160end
161n = drv_sput o 0 prev
162n = drv_tput o n 4
163n = drv_nput o n a
164n = drv_tput o n 5
165n = drv_nput o n w
166n = drv_tput o n 6
167n = drv_nput o n get v 2
168n = drv_tput o n 7
169if eq get v 3 drv_none
170ret drv_tput o n 8
171end
172ret drv_nput o n get v 3
173end