@threadedstack/wmd-web 0.1.21 → 0.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/RELEASE.json +24 -9
- package/guest/arm64/vm.wasm +0 -0
- package/package.json +3 -3
- package/src/boot.js +1 -0
- package/src/host/chan-services.js +42 -4
- package/src/host/chan.js +99 -9
- package/wmdpack.wasm +0 -0
package/RELEASE.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wmd-web",
|
|
3
3
|
"version": "0.5.1",
|
|
4
|
-
"commit": "
|
|
4
|
+
"commit": "09d452477b96bc9c01ac408e2257c43e039c1023",
|
|
5
5
|
"previous": null,
|
|
6
6
|
"decisions": [
|
|
7
7
|
"D-388",
|
|
@@ -56,15 +56,18 @@
|
|
|
56
56
|
"D-550",
|
|
57
57
|
"D-551",
|
|
58
58
|
"D-552",
|
|
59
|
-
"D-554"
|
|
59
|
+
"D-554",
|
|
60
|
+
"D-563",
|
|
61
|
+
"D-566",
|
|
62
|
+
"D-567"
|
|
60
63
|
],
|
|
61
|
-
"vmSources": "
|
|
64
|
+
"vmSources": "04717ca15314d9d8abe6d5c9b343becf82ac0b22",
|
|
62
65
|
"guest": {
|
|
63
66
|
"arch": "arm64",
|
|
64
67
|
"files": {
|
|
65
68
|
"vm.wasm": {
|
|
66
|
-
"sha256": "
|
|
67
|
-
"bytes":
|
|
69
|
+
"sha256": "4292c9a5981dda7215acd66ee6023cacd4bd502b379b469ef9a3bb606eb1309d",
|
|
70
|
+
"bytes": 1564377
|
|
68
71
|
},
|
|
69
72
|
"Image": {
|
|
70
73
|
"sha256": "6952a8d4f1bafec9c3e3b17e2c4af20ab5de8a7086956d087979804be2a01353",
|
|
@@ -89,11 +92,11 @@
|
|
|
89
92
|
"guest/arm64/Image": "6952a8d4f1bafec9c3e3b17e2c4af20ab5de8a7086956d087979804be2a01353",
|
|
90
93
|
"guest/arm64/Image-4k": "47a1dcf06bcd1cc31fb4f02adbd1e035bc9e9a243fe57f3efd71b4a287581de2",
|
|
91
94
|
"guest/arm64/initramfs.cpio.gz": "efa6eb2338cb01d87eeebce8035ed7a26b00edcfc3b9db963b38272715d2ee9d",
|
|
92
|
-
"guest/arm64/vm.wasm": "
|
|
95
|
+
"guest/arm64/vm.wasm": "4292c9a5981dda7215acd66ee6023cacd4bd502b379b469ef9a3bb606eb1309d",
|
|
93
96
|
"package.json": "7d43c05047d0a3ea56b4a7709f48a60de32e15c3bdf328d55435c46637981b40",
|
|
94
97
|
"src/base.js": "982f8e46dbb727ec542a494ebdb884ccd19a31ff4e091425b2d1fc01b0d4754a",
|
|
95
98
|
"src/blob.js": "bb2a2f0d87ce236280a7be2f246c926010dfe07f649c27da5e70d8eb5eaf7061",
|
|
96
|
-
"src/boot.js": "
|
|
99
|
+
"src/boot.js": "8330c1045553ed0fbc4a446ae1cd736f0386a93e421eef9d30573af1d8664d7f",
|
|
97
100
|
"src/build/builder.js": "0d5355c8570b0ecedce25602ff7f60c49b7daaed669426328f05f52e26048213",
|
|
98
101
|
"src/build/context.js": "d38097c61dbdadc4d41290c010425a4422f499aba473fa2b83f2a5c41e543571",
|
|
99
102
|
"src/build/dockerfile.js": "5957fe3d4ac8ff8b312f980ee04bd1d98ad4373a61f9a33e02f1ff1108b6ea53",
|
|
@@ -118,8 +121,8 @@
|
|
|
118
121
|
"src/host/base-io.js": "cdd049875dce9f1417f28b27efa2c6f494cbe2a49851249150d0c1ec871a8b59",
|
|
119
122
|
"src/host/boot-events.js": "a6567c889fa1e95ad7e917107a2593f03d14cc921827616368b3417de96faad2",
|
|
120
123
|
"src/host/chan-service.js": "f131746c6c03167b5968dfd430d797c4717c7c332563de475e62c6ed84acecbe",
|
|
121
|
-
"src/host/chan-services.js": "
|
|
122
|
-
"src/host/chan.js": "
|
|
124
|
+
"src/host/chan-services.js": "0031a73e3d7f6f0761477916c1888e86124a0fcf3337d3f24f68c069f261e177",
|
|
125
|
+
"src/host/chan.js": "bb9e76890b0efeee7cfbd8481b9fb4620b3b184459d96d62ff68ddcdc8a46f83",
|
|
123
126
|
"src/host/ckpt-file.js": "da7938fa640a062e77bdfb59caad5b3b1fcbf6150e3220de3be23f253f4c4497",
|
|
124
127
|
"src/host/ckpt-io.js": "3fbe74f0254c597f10d088c85e8ba72725502d86ae4dd8c6d2bf0821a93c873f",
|
|
125
128
|
"src/host/ckpt-point.js": "42bc16b3f754de3cd4e39f37a0feca2ffd8b4231cd72ec32bd6e1ea734c3c8c7",
|
|
@@ -170,5 +173,17 @@
|
|
|
170
173
|
"src/registry/ref.js": "24038e0fbcb6ac143cb8e8f7b9fac4dd0803d0891961786dc88dba01a4402e7b",
|
|
171
174
|
"src/registry/wasi-mem.js": "a7f684343010892460db27ee8c1e38e47e797c93dc4ebe4c30185dca6ca56ee2",
|
|
172
175
|
"src/worker.js": "c654be359e741d5b1fde1be05f8909968d4e00d1fca61be169e60ea691daa662"
|
|
176
|
+
},
|
|
177
|
+
"builder": {
|
|
178
|
+
"arm64": {
|
|
179
|
+
"file": "wmd-web-0.5.1-builder-arm64.tar",
|
|
180
|
+
"sha256": "905d0735a2fb7aa12f00bb21f50e82651d1f65db0aa030aa38ab4033047072ee",
|
|
181
|
+
"bytes": 107119104
|
|
182
|
+
},
|
|
183
|
+
"amd64": {
|
|
184
|
+
"file": "wmd-web-0.5.1-builder-amd64.tar",
|
|
185
|
+
"sha256": "be2199d5eb05d1bcc2814999749de17d4e4ce206726f31fe8a495cf602fd3ccd",
|
|
186
|
+
"bytes": 113018368
|
|
187
|
+
}
|
|
173
188
|
}
|
|
174
189
|
}
|
package/guest/arm64/vm.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threadedstack/wmd-web",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.22",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"homepage": "https://github.com/threadedstack/wmd-releases",
|
|
6
6
|
"repository": {
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
},
|
|
10
10
|
"description": "Browser host for wmd's guest vm.wasm (Web Workers + shared memory + WASI preview1)",
|
|
11
11
|
"wmd": {
|
|
12
|
-
"tag": "v0.1.
|
|
13
|
-
"commit": "
|
|
12
|
+
"tag": "v0.1.22",
|
|
13
|
+
"commit": "09d452477b96bc9c01ac408e2257c43e039c1023",
|
|
14
14
|
"web": "0.5.1"
|
|
15
15
|
},
|
|
16
16
|
"type": "module",
|
package/src/boot.js
CHANGED
|
@@ -1006,6 +1006,7 @@ export async function bootWmd(o) {
|
|
|
1006
1006
|
ports: chanSvcs.map(s => ({ port: s.port, kind: s.kind })),
|
|
1007
1007
|
nslots: o.channels.nslots ?? 8,
|
|
1008
1008
|
ringBytes: o.channels.ringBytes ?? 1 << 20,
|
|
1009
|
+
count9p: !!o.channels.count9p, // X16: 9P counts by type and layer class (chanStats().p9Count); off by default
|
|
1009
1010
|
})
|
|
1010
1011
|
memTook += absMs() - tc
|
|
1011
1012
|
// W56: on an in-page switch the guest gets its address there (the DHCP lease) and a port for its peers;
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
// blocks.
|
|
29
29
|
|
|
30
30
|
import {
|
|
31
|
-
CHAN_CONSOLE, CHAN_CONTROL, CHAN_NET, CHAN_P9, CONSOLE_IN_LIMIT, G2H, H2G, H_CIN_TAKEN, H_CLOSES, H_GONE,
|
|
32
|
-
RTT_BUCKETS, S_GEN, S_PORT, S_STATE, ST_CLOSING, ST_FREE, ST_OPEN, chanPorts, chanView, histSummary,
|
|
33
|
-
ringAvail, ringKick, ringRead, ringSpace, ringWrite, rttBucket, stageNote,
|
|
31
|
+
CHAN_CONSOLE, CHAN_CONTROL, CHAN_NET, CHAN_P9, CONSOLE_IN_LIMIT, G2H, H2G, H_CIN_TAKEN, H_CLOSES, H_GONE, H_P9COUNT, KIND_NAMES, P9C_LOWER,
|
|
32
|
+
P9C_NONE, P9C_UPPER, R_GONE, R_SHUT, RTT_BUCKETS, S_GEN, S_PORT, S_STATE, ST_CLOSING, ST_FREE, ST_OPEN, chanPorts, chanView, histSummary,
|
|
33
|
+
p9cServed, ringAvail, ringKick, ringRead, ringSpace, ringWrite, rttBucket, stageNote,
|
|
34
34
|
} from './chan.js'
|
|
35
35
|
import { NinePServer } from '../fs/9p/server.js'
|
|
36
36
|
import { adoptServer, dumpService, loadService } from '../fs/svc-snapshot.js'
|
|
@@ -59,6 +59,40 @@ export function crc32(bytes, crc = 0) {
|
|
|
59
59
|
return ~c >>> 0
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
const u32at = (b, o) => (b[o] | (b[o + 1] << 8) | (b[o + 2] << 16) | (b[o + 3] << 24)) >>> 0
|
|
63
|
+
const TVERSION = 100
|
|
64
|
+
const TAUTH = 102
|
|
65
|
+
const TFLUSH = 108
|
|
66
|
+
const TWALK = 110
|
|
67
|
+
const RWALK = 111
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* X16: which layer a request touched. The file the request names (its fid, at offset 7), looked up in the
|
|
71
|
+
* server's fid table: a lower inode nothing has changed (a pack entry's number is a Number) is P9C_LOWER; one made or
|
|
72
|
+
* changed in the writable layer is P9C_UPPER. A walk is told by the file it reached (newfid) when it reached one,
|
|
73
|
+
* else by the directory it started from. A directory that got a new name counts as changed (the inode's `upper`),
|
|
74
|
+
* so a listing of it (Treaddir) is UPPER even when most of its names are lower: reads of such directories are
|
|
75
|
+
* a lower bound for P9C_LOWER. `before` is the class taken before the request ran (a Tclunk drops its fid).
|
|
76
|
+
*/
|
|
77
|
+
export function p9Class(server, frame, reply, before) {
|
|
78
|
+
const type = frame[4]
|
|
79
|
+
if (type === TWALK && reply && reply[4] === RWALK && frame.length >= 15) {
|
|
80
|
+
const nf = server.fids.get(u32at(frame, 11))
|
|
81
|
+
if (nf) return nodeClass(nf.node)
|
|
82
|
+
}
|
|
83
|
+
return before
|
|
84
|
+
}
|
|
85
|
+
export function p9ClassBefore(server, frame) {
|
|
86
|
+
const type = frame[4]
|
|
87
|
+
if (type === TVERSION || type === TAUTH || type === TFLUSH || frame.length < 11) return P9C_NONE
|
|
88
|
+
const f = server.fids.get(u32at(frame, 7))
|
|
89
|
+
return f ? nodeClass(f.node) : P9C_NONE
|
|
90
|
+
}
|
|
91
|
+
function nodeClass(n) {
|
|
92
|
+
if (!n) return P9C_NONE
|
|
93
|
+
return n.upper || typeof n.lino !== 'number' ? P9C_UPPER : P9C_LOWER
|
|
94
|
+
}
|
|
95
|
+
|
|
62
96
|
/** A queue of byte chunks written into a ring as room appears. */
|
|
63
97
|
class OutQueue {
|
|
64
98
|
constructor() {
|
|
@@ -138,9 +172,13 @@ class P9Session {
|
|
|
138
172
|
const tag = frame[5] | (frame[6] << 8)
|
|
139
173
|
const ts = v.tagTimes[tag]
|
|
140
174
|
if (ts > 0) stageNote(v.pickup, (performance.timeOrigin + performance.now() - ts) * 1000)
|
|
175
|
+
const count = v.i32[H_P9COUNT]
|
|
176
|
+
const before = count ? p9ClassBefore(this.server, frame) : 0
|
|
141
177
|
const t0 = performance.now()
|
|
142
178
|
const reply = this.server.handle(frame)
|
|
143
|
-
|
|
179
|
+
const took = (performance.now() - t0) * 1000
|
|
180
|
+
this.host.noteP9(frame[4], took)
|
|
181
|
+
if (count) p9cServed(v, tag, frame[4] & 127, p9Class(this.server, frame, reply, before), took)
|
|
144
182
|
sess.out.push(reply)
|
|
145
183
|
v.replyTimes[tag] = performance.timeOrigin + performance.now() // flushed right after this frame's data()
|
|
146
184
|
}
|
package/src/host/chan.js
CHANGED
|
@@ -69,6 +69,7 @@ export const H_REFUSED = 8
|
|
|
69
69
|
export const H_CLOSES = 9
|
|
70
70
|
const H_PIPE_RING = 10 // bytes of the page pipe ring
|
|
71
71
|
export const H_CIN_TAKEN = 11 // console input bytes the service has put into a guest ring (or dropped), mod 2^32
|
|
72
|
+
export const H_P9COUNT = 12 // X16: 1 = count 9P requests by type and layer class (createChanBlock count9p); 0 (the default) = off
|
|
72
73
|
export const H_PORTS = 16 // MAX_PORTS x [port, kind]
|
|
73
74
|
export const MAX_PORTS = 16
|
|
74
75
|
const HDR_INTS = 64
|
|
@@ -151,8 +152,77 @@ export function stageNote(st, us) {
|
|
|
151
152
|
st.f64[1] += 1
|
|
152
153
|
if (us > st.f64[2]) st.f64[2] = us
|
|
153
154
|
}
|
|
155
|
+
// X16: the guest side of the 9P counts. p9cSent runs in chan_send of a T-message (any vCPU thread), p9cDone when the
|
|
156
|
+
// pump thread has read the whole R-message. In flight = sent and not yet answered; the busy time is the time with at
|
|
157
|
+
// least one request in flight (the periods are closed with an atomic count, so two threads can race at an edge by
|
|
158
|
+
// a few microseconds: a diagnostic, not a clock).
|
|
159
|
+
export function p9cSent(v, tag, type, nowMs) {
|
|
160
|
+
const c = v.p9c
|
|
161
|
+
c.tagType[tag] = type
|
|
162
|
+
c.tagClass[tag] = P9C_NONE
|
|
163
|
+
const was = Atomics.add(c.inflight, 0, 1)
|
|
164
|
+
if (was === 0) c.f[P9C_BUSY_START] = nowMs
|
|
165
|
+
if (was + 1 > c.inflight[1]) c.inflight[1] = was + 1
|
|
166
|
+
}
|
|
167
|
+
export function p9cDone(v, tag, us, replyBytes, nowMs) {
|
|
168
|
+
const c = v.p9c
|
|
169
|
+
const i = c.tagType[tag] * P9C_CLASSES + c.tagClass[tag]
|
|
170
|
+
Atomics.add(c.n, i, 1)
|
|
171
|
+
c.f[i] += us
|
|
172
|
+
c.f[P9C_CELLS + i] += replyBytes
|
|
173
|
+
const was = Atomics.sub(c.inflight, 0, 1)
|
|
174
|
+
if (was === 1) {
|
|
175
|
+
c.f[P9C_BUSY_MS] += nowMs - c.f[P9C_BUSY_START]
|
|
176
|
+
c.f[P9C_BUSY_N] += 1
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/** The service Worker: the class of the file request `tag` touched, and the time the server took to answer it. */
|
|
180
|
+
export function p9cServed(v, tag, type, cls, us) {
|
|
181
|
+
const c = v.p9c
|
|
182
|
+
c.tagClass[tag] = cls
|
|
183
|
+
c.f[2 * P9C_CELLS + type * P9C_CLASSES + cls] += us
|
|
184
|
+
}
|
|
185
|
+
/** A snapshot for the page: every type seen, by class, plus the busy time up to now. */
|
|
186
|
+
export function p9cSummary(v, nowMs) {
|
|
187
|
+
const c = v.p9c
|
|
188
|
+
const byType = {}
|
|
189
|
+
for (let t = 0; t < P9C_TYPES; t++) {
|
|
190
|
+
for (let k = 0; k < P9C_CLASSES; k++) {
|
|
191
|
+
const i = t * P9C_CLASSES + k
|
|
192
|
+
const n = Atomics.load(c.n, i)
|
|
193
|
+
if (!n) continue
|
|
194
|
+
const name = P9_TYPE_NAMES[t] || `type${t}`
|
|
195
|
+
byType[name] ??= {}
|
|
196
|
+
byType[name][P9C_CLASS_NAMES[k]] = { n, rttUs: Math.round(c.f[i]), replyBytes: c.f[P9C_CELLS + i], serviceUs: Math.round(c.f[2 * P9C_CELLS + i]) }
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
let busyMs = c.f[P9C_BUSY_MS]
|
|
200
|
+
if (Atomics.load(c.inflight, 0) > 0 && c.f[P9C_BUSY_START] > 0) busyMs += nowMs - c.f[P9C_BUSY_START]
|
|
201
|
+
return { byType, inFlight: Atomics.load(c.inflight, 0), maxInFlight: c.inflight[1], busyMs: Math.round(busyMs * 10) / 10, busyPeriods: c.f[P9C_BUSY_N] }
|
|
202
|
+
}
|
|
154
203
|
const stageSummary = st => histSummary(st.hist, { meanUs: st.f64[1] ? st.f64[0] / st.f64[1] : 0, maxUs: st.f64[2] })
|
|
155
204
|
|
|
205
|
+
// X16: 9P counts by T-message type (0..127) and class of the file the request touched.
|
|
206
|
+
export const P9C_TYPES = 128
|
|
207
|
+
export const P9C_CLASSES = 3
|
|
208
|
+
export const P9C_NONE = 0 // no file (version, attach, flush) or not told
|
|
209
|
+
export const P9C_LOWER = 1 // a file or directory of the read-only image layers that nothing has changed
|
|
210
|
+
export const P9C_UPPER = 2 // a file or directory made or changed in the writable layer
|
|
211
|
+
export const P9C_CLASS_NAMES = ['none', 'lower', 'upper']
|
|
212
|
+
const P9C_CELLS = P9C_TYPES * P9C_CLASSES
|
|
213
|
+
// Float64 cells after the three per-cell arrays (sumUs, replyBytes, svcUs)
|
|
214
|
+
export const P9C_BUSY_START = 3 * P9C_CELLS // ms (the shared clock) when in-flight went 0 -> 1
|
|
215
|
+
export const P9C_BUSY_MS = P9C_BUSY_START + 1 // ms with at least one request in flight, over closed periods
|
|
216
|
+
export const P9C_BUSY_N = P9C_BUSY_START + 2 // closed periods
|
|
217
|
+
const P9C_F64 = P9C_BUSY_START + 4
|
|
218
|
+
// 9P2000.L T-message types, for the report.
|
|
219
|
+
export const P9_TYPE_NAMES = {
|
|
220
|
+
8: 'Tstatfs', 12: 'Tlopen', 14: 'Tlcreate', 16: 'Tsymlink', 18: 'Tmknod', 20: 'Trename', 22: 'Treadlink', 24: 'Tgetattr',
|
|
221
|
+
26: 'Tsetattr', 30: 'Txattrwalk', 32: 'Txattrcreate', 40: 'Treaddir', 50: 'Tfsync', 52: 'Tlock', 54: 'Tgetlock', 70: 'Tlink',
|
|
222
|
+
72: 'Tmkdir', 74: 'Trenameat', 76: 'Tunlinkat', 100: 'Tversion', 102: 'Tauth', 104: 'Tattach', 108: 'Tflush', 110: 'Twalk',
|
|
223
|
+
112: 'Topen', 114: 'Tcreate', 116: 'Tread', 118: 'Twrite', 120: 'Tclunk', 122: 'Tremove', 124: 'Tstat', 126: 'Twstat',
|
|
224
|
+
}
|
|
225
|
+
|
|
156
226
|
const align = (n, a) => Math.ceil(n / a) * a
|
|
157
227
|
const STAGE_BYTES = align(RTT_BUCKETS * 4, 8) + 4 * 8 // W51: one stage histogram + sum, n, max, spare
|
|
158
228
|
|
|
@@ -167,9 +237,13 @@ function layoutOf(nslots, ringBytes, pipeBytes) {
|
|
|
167
237
|
// (send -> parse) and reply read by the guest (reply written -> chan_recv returns).
|
|
168
238
|
const replyOff = tagOff + 65536 * 8
|
|
169
239
|
const stageOff = align(replyOff + 65536 * 8, 64)
|
|
170
|
-
|
|
240
|
+
// X16: per-tag type and class bytes, then the count cells, then the Float64 cells (see P9C_*)
|
|
241
|
+
const p9cOff = align(stageOff + 2 * STAGE_BYTES, 64)
|
|
242
|
+
const p9cCountOff = p9cOff + 2 * 65536
|
|
243
|
+
const p9cF64Off = align(p9cCountOff + (P9C_CELLS + 4) * 4, 64)
|
|
244
|
+
const dataOff = align(p9cF64Off + P9C_F64 * 8, 4096)
|
|
171
245
|
const total = dataOff + nslots * 2 * ringBytes + pipeBytes
|
|
172
|
-
return { statsOff, rttOff, tagOff, replyOff, stageOff, dataOff, total }
|
|
246
|
+
return { statsOff, rttOff, tagOff, replyOff, stageOff, p9cOff, p9cCountOff, p9cF64Off, dataOff, total }
|
|
173
247
|
}
|
|
174
248
|
|
|
175
249
|
const pow2 = n => n >= 64 && n <= 1 << 30 && (n & (n - 1)) === 0
|
|
@@ -177,8 +251,9 @@ const pow2 = n => n >= 64 && n <= 1 << 30 && (n & (n - 1)) === 0
|
|
|
177
251
|
/**
|
|
178
252
|
* The chan block. ports: [{port, kind}] the services listen on (kind: 1..4 or a name).
|
|
179
253
|
* ringBytes: each direction of each channel (power of two, >= 64).
|
|
254
|
+
* count9p: X16, count 9P requests by type and class (off by default; see chanCounters p9Count).
|
|
180
255
|
*/
|
|
181
|
-
export function createChanBlock({ ports = [], nslots = 8, ringBytes = 1 << 20, pipeBytes = 1 << 23 } = {}) {
|
|
256
|
+
export function createChanBlock({ ports = [], nslots = 8, ringBytes = 1 << 20, pipeBytes = 1 << 23, count9p = false } = {}) {
|
|
182
257
|
if (!pow2(ringBytes)) throw new Error(`channel ring size must be a power of two from 64 bytes to 1 GiB, got ${ringBytes}`)
|
|
183
258
|
if (!pow2(pipeBytes)) throw new Error(`console pipe size must be a power of two, got ${pipeBytes}`)
|
|
184
259
|
if (ports.length > MAX_PORTS) throw new Error(`at most ${MAX_PORTS} channel services`)
|
|
@@ -190,6 +265,7 @@ export function createChanBlock({ ports = [], nslots = 8, ringBytes = 1 << 20, p
|
|
|
190
265
|
i32[H_NSLOTS] = nslots
|
|
191
266
|
i32[H_RING] = ringBytes
|
|
192
267
|
i32[H_PIPE_RING] = pipeBytes
|
|
268
|
+
i32[H_P9COUNT] = count9p ? 1 : 0
|
|
193
269
|
const seen = new Set()
|
|
194
270
|
ports.forEach((p, i) => {
|
|
195
271
|
const kind = typeof p.kind === 'string' ? KIND_OF[p.kind] : p.kind
|
|
@@ -222,6 +298,14 @@ export function chanView(sab) {
|
|
|
222
298
|
f64: new Float64Array(sab, L.stageOff + k * STAGE_BYTES + align(RTT_BUCKETS * 4, 8), 4),
|
|
223
299
|
})
|
|
224
300
|
const pickup = stage(0), readback = stage(1)
|
|
301
|
+
// X16: the 9P count cells (used only when i32[H_P9COUNT] is set)
|
|
302
|
+
const p9c = {
|
|
303
|
+
tagType: new Uint8Array(sab, L.p9cOff, 65536),
|
|
304
|
+
tagClass: new Uint8Array(sab, L.p9cOff + 65536, 65536),
|
|
305
|
+
n: new Int32Array(sab, L.p9cCountOff, P9C_CELLS), // requests answered, by type * 3 + class
|
|
306
|
+
inflight: new Int32Array(sab, L.p9cCountOff + P9C_CELLS * 4, 2), // [requests now in flight, the most at once]
|
|
307
|
+
f: new Float64Array(sab, L.p9cF64Off, P9C_F64), // sumUs, replyBytes, svcUs (each P9C_CELLS), then the busy cells
|
|
308
|
+
}
|
|
225
309
|
const slotBase = s => HDR_INTS + s * SLOT_INTS
|
|
226
310
|
const ring = (s, dir) => ({
|
|
227
311
|
c: slotBase(s) + dir,
|
|
@@ -229,7 +313,7 @@ export function chanView(sab) {
|
|
|
229
313
|
size: ringBytes,
|
|
230
314
|
})
|
|
231
315
|
const pipe = { c: slotBase(nslots) + G2H, data: L.dataOff + nslots * 2 * ringBytes, size: pipeBytes }
|
|
232
|
-
return { sab, i32, u8, f64, rtt, tagTimes, replyTimes, pickup, readback, nslots, ringBytes, pipeBytes, slotBase, ring, pipe }
|
|
316
|
+
return { sab, i32, u8, f64, rtt, tagTimes, replyTimes, pickup, readback, p9c, nslots, ringBytes, pipeBytes, slotBase, ring, pipe }
|
|
233
317
|
}
|
|
234
318
|
|
|
235
319
|
// ---- ring primitives (non-blocking; callers do the waiting) ----------------------------
|
|
@@ -430,7 +514,9 @@ export function createChanImports({ sab, memory, exiting = () => false, now = ()
|
|
|
430
514
|
try {
|
|
431
515
|
if (Atomics.load(i32, b + S_KIND) === CHAN_P9 && len >= 7) {
|
|
432
516
|
// T-message: stamp its tag for the round-trip histogram
|
|
433
|
-
|
|
517
|
+
const t = now()
|
|
518
|
+
v.tagTimes[mem[ptr + 5] | (mem[ptr + 6] << 8)] = t
|
|
519
|
+
if (i32[H_P9COUNT]) p9cSent(v, mem[ptr + 5] | (mem[ptr + 6] << 8), mem[ptr + 4] & 127, t)
|
|
434
520
|
}
|
|
435
521
|
let done = 0
|
|
436
522
|
while (done < len) {
|
|
@@ -461,7 +547,7 @@ export function createChanImports({ sab, memory, exiting = () => false, now = ()
|
|
|
461
547
|
if (kind !== CHAN_P9) return
|
|
462
548
|
const gen = Atomics.load(i32, v.slotBase(h) + S_GEN)
|
|
463
549
|
let st = rx.get(h)
|
|
464
|
-
if (!st || st.gen !== gen) rx.set(h, (st = { gen, hdr: new Uint8Array(7), got: 0, left: 0, tag: 0 }))
|
|
550
|
+
if (!st || st.gen !== gen) rx.set(h, (st = { gen, hdr: new Uint8Array(7), got: 0, left: 0, tag: 0, size: 0 }))
|
|
465
551
|
let i = off
|
|
466
552
|
const end = off + n
|
|
467
553
|
while (i < end) {
|
|
@@ -471,18 +557,19 @@ export function createChanImports({ sab, memory, exiting = () => false, now = ()
|
|
|
471
557
|
if (st.got === 7) {
|
|
472
558
|
const size = (st.hdr[0] | (st.hdr[1] << 8) | (st.hdr[2] << 16) | (st.hdr[3] << 24)) >>> 0
|
|
473
559
|
st.tag = st.hdr[5] | (st.hdr[6] << 8)
|
|
560
|
+
st.size = size
|
|
474
561
|
st.got = 0
|
|
475
562
|
st.left = Math.max(0, size - 7)
|
|
476
|
-
if (st.left === 0) done(st.tag)
|
|
563
|
+
if (st.left === 0) done(st.tag, st.size)
|
|
477
564
|
}
|
|
478
565
|
} else {
|
|
479
566
|
const k = Math.min(st.left, end - i)
|
|
480
567
|
i += k
|
|
481
568
|
st.left -= k
|
|
482
|
-
if (st.left === 0) done(st.tag)
|
|
569
|
+
if (st.left === 0) done(st.tag, st.size)
|
|
483
570
|
}
|
|
484
571
|
}
|
|
485
|
-
function done(tag) {
|
|
572
|
+
function done(tag, size) {
|
|
486
573
|
const t0 = v.tagTimes[tag]
|
|
487
574
|
if (!(t0 > 0)) return
|
|
488
575
|
const t = now()
|
|
@@ -490,6 +577,7 @@ export function createChanImports({ sab, memory, exiting = () => false, now = ()
|
|
|
490
577
|
if (tr > 0) stageNote(v.readback, (t - tr) * 1000)
|
|
491
578
|
const us = (t - t0) * 1000
|
|
492
579
|
Atomics.add(v.rtt, rttBucket(us), 1)
|
|
580
|
+
if (i32[H_P9COUNT]) p9cDone(v, tag, us, size, t)
|
|
493
581
|
const base = v.nslots * 4
|
|
494
582
|
v.f64[base] += us
|
|
495
583
|
v.f64[base + 1] += 1
|
|
@@ -614,6 +702,8 @@ export function chanCounters(sab) {
|
|
|
614
702
|
// W51: send -> the service parses it, and reply written -> the guest's chan_recv returns
|
|
615
703
|
p9Pickup: stageSummary(v.pickup),
|
|
616
704
|
p9Readback: stageSummary(v.readback),
|
|
705
|
+
// X16: only when the block was made with count9p
|
|
706
|
+
...(i32[H_P9COUNT] ? { p9Count: p9cSummary(v, performance.timeOrigin + performance.now()) } : {}),
|
|
617
707
|
}
|
|
618
708
|
}
|
|
619
709
|
|
package/wmdpack.wasm
CHANGED
|
Binary file
|