benchmarks-mv
Measurement harnesses and evidence bundles for AIEN on the NVIDIA DGX Spark GB10. Speed is reported against the machine's physical limit and my own previous run. Attachment of AienOS.
Brought by drakestapleton
benchmarks-mv / native / queueflow / flow.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note flow.om (DRA-190): trace replay of the spark-window GPU queue under five dispatch arms at |
| 3 | note equal resources (one window slot, the same arrivals, the same per-window service and the |
| 4 | note same external eligibility times). Compiler: the omc named in omc.pin (gate.sh checks it); the |
| 5 | note held-out run's compiler is in evidence/heldout/IDENTITY.txt, which records this file before |
| 6 | note later header edits. |
| 7 | note flow FILE D0 FILE: integer TSV from export-windows.sh (11 columns); D0: the time the |
| 8 | note slot is free before the first row (0 for a trace start). |
| 9 | note Arms (PREREG.md section 4 is normative): |
| 10 | note A current: FCFS, observed service, the front window holds the line while it waits. |
| 11 | note B plain queueing baseline: A with each service capped at its own lease. |
| 12 | note Cr B plus bounded retry: the second and later retries of one failure chain are parked. |
| 13 | note Ch B plus backpressure: a window whose external condition is not met does not hold the |
| 14 | note line (eligible-first, FCFS among eligible). |
| 15 | note C Ch plus bounded retry. |
| 16 | note Output: QF lines of integers only. Every ratio, mean and threshold is evaluated outside |
| 17 | note this program (Wolfram, PREREG.md section 6). Exit 0 ok, 2 usage, 3 I/O or malformed |
| 18 | note input, 4 more than 4096 rows. |
| 19 | om2 |
| 20 | |
| 21 | const MAXN ulong 4096 |
| 22 | const RMAX long 1 |
| 23 | const RWIN long 3600 |
| 24 | const HARM long 60 |
| 25 | const GAPMAX long 3 |
| 26 | |
| 27 | global arg uchar 1024 |
| 28 | global buf uchar 1048576 |
| 29 | global ob uchar 8192 |
| 30 | global st ulong 16 |
| 31 | global num uchar 24 |
| 32 | global ca long 4096 |
| 33 | global cs long 4096 |
| 34 | global ce long 4096 |
| 35 | global cl long 4096 |
| 36 | global cc long 4096 |
| 37 | global cv long 4096 |
| 38 | global co long 4096 |
| 39 | global el long 4096 |
| 40 | global sv long 4096 |
| 41 | global fo long 4096 |
| 42 | global ar long 4096 |
| 43 | global gp long 4096 |
| 44 | global sq long 4096 |
| 45 | global ac long 4096 |
| 46 | global rc long 4096 |
| 47 | global xs long 20480 |
| 48 | global xd long 20480 |
| 49 | global xv long 20480 |
| 50 | global xa long 20480 |
| 51 | global hl long 8 |
| 52 | global wk long 4096 |
| 53 | global row long 16 |
| 54 | global gv long 16 |
| 55 | |
| 56 | text t_usage "usage: flow FILE D0\n" |
| 57 | text t_ioerr "QF error io\n" |
| 58 | text t_bad "QF error malformed line " |
| 59 | text t_big "QF error rows > 4096\n" |
| 60 | text t_nl "\n" |
| 61 | text t_sp " " |
| 62 | text t_trace "QF trace rows=" |
| 63 | text t_held " held=" |
| 64 | text t_anom " anomalies=" |
| 65 | text t_rty " retries=" |
| 66 | text t_d0 " d0=" |
| 67 | text t_arm "QF arm=" |
| 68 | text t_srv " served=" |
| 69 | text t_acc " acc=" |
| 70 | text t_drop " dropped=" |
| 71 | text t_lost " lostacc=" |
| 72 | text t_busy " busy=" |
| 73 | text t_use " useful=" |
| 74 | text t_hol " hol=" |
| 75 | text t_mina " mina=" |
| 76 | text t_maxd " maxdep=" |
| 77 | text t_soj " soj=" |
| 78 | text t_viol " viol=" |
| 79 | text t_ovl " overlap=" |
| 80 | text t_maxq " maxq=" |
| 81 | text t_rep " replayerr=" |
| 82 | text t_k "QF K arm=" |
| 83 | text t_n " n=" |
| 84 | text t_sumw " sumw=" |
| 85 | text t_p95 " p95=" |
| 86 | text t_maxw " maxw=" |
| 87 | text t_cmp "QF cmp x=" |
| 88 | text t_y " y=" |
| 89 | text t_worse " worse60=" |
| 90 | text t_bett " better60=" |
| 91 | text t_an "A" |
| 92 | text t_bn "B" |
| 93 | text t_crn "Cr" |
| 94 | text t_chn "Ch" |
| 95 | text t_cn "C" |
| 96 | |
| 97 | fn pr t view uchar * to void |
| 98 | w = write 1 t 0 len t |
| 99 | end |
| 100 | |
| 101 | fn argn i ulong to ulong |
| 102 | if ge i ulong argcnt |
| 103 | ret 0 |
| 104 | end |
| 105 | n = argread i arg 0 len arg |
| 106 | if le n 0 |
| 107 | ret 0 |
| 108 | end |
| 109 | ret ulong n |
| 110 | end |
| 111 | |
| 112 | fn oreset to void |
| 113 | put st 2 0 |
| 114 | end |
| 115 | |
| 116 | fn obyte b uchar to void |
| 117 | p = get st 2 |
| 118 | if lt p 8192 |
| 119 | put ob p b |
| 120 | put st 2 add p 1 |
| 121 | end |
| 122 | end |
| 123 | |
| 124 | fn otext t view uchar * to void |
| 125 | for i ulong len t |
| 126 | obyte get t i |
| 127 | end |
| 128 | end |
| 129 | |
| 130 | fn onum v ulong to void |
| 131 | k = ulong 0 |
| 132 | x = v |
| 133 | while true bound 21 |
| 134 | put num k uchar add rem x 10 48 |
| 135 | k = add k 1 |
| 136 | x = div x 10 |
| 137 | if eq x 0 |
| 138 | break |
| 139 | end |
| 140 | end |
| 141 | for i ulong k |
| 142 | obyte get num sub sub k 1 i |
| 143 | end |
| 144 | end |
| 145 | |
| 146 | note Signed decimal. |
| 147 | fn osnum v long to void |
| 148 | if lt v 0 |
| 149 | obyte 45 |
| 150 | onum ulong neg v |
| 151 | ret |
| 152 | end |
| 153 | onum ulong v |
| 154 | end |
| 155 | |
| 156 | fn oflush to void |
| 157 | w = write 1 ob 0 get st 2 |
| 158 | put st 2 0 |
| 159 | end |
| 160 | |
| 161 | fn lmax a long b long to long |
| 162 | if gt a b |
| 163 | ret a |
| 164 | end |
| 165 | ret b |
| 166 | end |
| 167 | |
| 168 | note Read the file named by argument 1 into buf; its length, or -1. |
| 169 | fn slurp to long |
| 170 | n = argn 1 |
| 171 | if eq n 0 |
| 172 | ret -1 |
| 173 | end |
| 174 | if ge n 1023 |
| 175 | ret -1 |
| 176 | end |
| 177 | fd = int fopen arg 0 n 0 0 |
| 178 | if lt fd 0 |
| 179 | ret -1 |
| 180 | end |
| 181 | tot = ulong 0 |
| 182 | while true bound 999999 |
| 183 | if ge tot len buf |
| 184 | c = fclose fd |
| 185 | ret -1 |
| 186 | end |
| 187 | k = read fd buf tot sub len buf tot |
| 188 | if lt k 0 |
| 189 | c2 = fclose fd |
| 190 | ret -1 |
| 191 | end |
| 192 | if eq k 0 |
| 193 | break |
| 194 | end |
| 195 | tot = add tot ulong k |
| 196 | end |
| 197 | c3 = fclose fd |
| 198 | ret long tot |
| 199 | end |
| 200 | |
| 201 | note Parse one signed decimal field of buf from p (st[4] is set to the position after it, which is |
| 202 | note the tab, newline or end). Returns the value; st[5] = 1 when the field was malformed. |
| 203 | fn pfield p ulong e ulong to long |
| 204 | i = p |
| 205 | s = long 1 |
| 206 | if lt i e |
| 207 | if eq get buf i 45 |
| 208 | s = long -1 |
| 209 | i = add i 1 |
| 210 | end |
| 211 | end |
| 212 | v = long 0 |
| 213 | nd = ulong 0 |
| 214 | while true bound 32 |
| 215 | if ge i e |
| 216 | break |
| 217 | end |
| 218 | b = get buf i |
| 219 | if or lt b 48 gt b 57 |
| 220 | break |
| 221 | end |
| 222 | if gt nd 17 |
| 223 | put st 5 1 |
| 224 | break |
| 225 | end |
| 226 | v = add mul v 10 long sub b 48 |
| 227 | nd = add nd 1 |
| 228 | i = add i 1 |
| 229 | end |
| 230 | if eq nd 0 |
| 231 | put st 5 1 |
| 232 | end |
| 233 | put st 4 i |
| 234 | ret mul s v |
| 235 | end |
| 236 | |
| 237 | note Parse the trace into the column arrays. Returns the row count, or -1 malformed (st[6] = the |
| 238 | note 1-based line), or -2 too many rows. |
| 239 | fn parse e ulong to long |
| 240 | p = ulong 0 |
| 241 | r = ulong 0 |
| 242 | while true bound 999999 |
| 243 | if ge p e |
| 244 | break |
| 245 | end |
| 246 | if ge r MAXN |
| 247 | ret -2 |
| 248 | end |
| 249 | put st 5 0 |
| 250 | for c ulong 11 |
| 251 | v = pfield p e |
| 252 | put row c v |
| 253 | q = get st 4 |
| 254 | if lt c 10 |
| 255 | if ge q e |
| 256 | put st 5 1 |
| 257 | else |
| 258 | if ne get buf q 9 |
| 259 | put st 5 1 |
| 260 | end |
| 261 | end |
| 262 | end |
| 263 | p = add q 1 |
| 264 | end |
| 265 | if ne get st 5 0 |
| 266 | put st 6 add r 1 |
| 267 | ret -1 |
| 268 | end |
| 269 | q2 = sub p 1 |
| 270 | if lt q2 e |
| 271 | if ne get buf q2 10 |
| 272 | put st 6 add r 1 |
| 273 | ret -1 |
| 274 | end |
| 275 | end |
| 276 | put ca r get row 0 |
| 277 | put cs r get row 1 |
| 278 | put ce r get row 2 |
| 279 | put cl r get row 3 |
| 280 | put cc r get row 6 |
| 281 | put cv r get row 7 |
| 282 | put co r get row 8 |
| 283 | r = add r 1 |
| 284 | end |
| 285 | ret long r |
| 286 | end |
| 287 | |
| 288 | fn held i ulong to bool |
| 289 | ret gt get cs i 0 |
| 290 | end |
| 291 | |
| 292 | note Observed derivation: front time, external eligibility time (optimistic), service, accepted. |
| 293 | note Returns the anomaly count (a window starting before it reached the front, or ending before |
| 294 | note it started). |
| 295 | fn accobs i ulong to long |
| 296 | if ne get cc i 0 |
| 297 | ret 0 |
| 298 | end |
| 299 | if eq get cv i 1 |
| 300 | ret 0 |
| 301 | end |
| 302 | ret 1 |
| 303 | end |
| 304 | |
| 305 | fn derheld i ulong f long to ulong |
| 306 | s = get cs i |
| 307 | e = get ce i |
| 308 | an = ulong 0 |
| 309 | if lt s f |
| 310 | an = add an 1 |
| 311 | end |
| 312 | if gt s f |
| 313 | put el i s |
| 314 | else |
| 315 | put el i get ar i |
| 316 | end |
| 317 | put sv i sub e s |
| 318 | if lt e s |
| 319 | an = add an 1 |
| 320 | end |
| 321 | put ac i accobs i |
| 322 | ret an |
| 323 | end |
| 324 | |
| 325 | note In-line windows: spark-window writes <id>/requested only when a --wait ticket reaches the |
| 326 | note head of the line, so a window requested 0..GAPMAX s after the previous departure was waiting |
| 327 | note before it was recorded. Model (PREREG 4.2): it shares the arrival ar of the window before it |
| 328 | note in request order and keeps the observed poll gap gp after the departure. When both windows |
| 329 | note have the same owner it is a sequential leg (sq = 1): it cannot start before that window left. |
| 330 | fn arrive i ulong d long to void |
| 331 | a = get ca i |
| 332 | g = sub a d |
| 333 | put gp i 0 |
| 334 | put sq i 0 |
| 335 | put ar i a |
| 336 | if gt d 0 |
| 337 | if ge g 0 |
| 338 | if le g GAPMAX |
| 339 | put gp i g |
| 340 | if gt i 0 |
| 341 | put ar i get ar sub i 1 |
| 342 | if eq get co i get co sub i 1 |
| 343 | put sq i 1 |
| 344 | end |
| 345 | end |
| 346 | end |
| 347 | end |
| 348 | end |
| 349 | end |
| 350 | |
| 351 | fn derive n ulong d0 long to ulong |
| 352 | d = d0 |
| 353 | an = ulong 0 |
| 354 | for i ulong n |
| 355 | arrive i d |
| 356 | f = lmax get ca i d |
| 357 | put fo i f |
| 358 | if held i |
| 359 | an = add an derheld i f |
| 360 | d = get ce i |
| 361 | else |
| 362 | put el i get ar i |
| 363 | put sv i 0 |
| 364 | put ac i 0 |
| 365 | if gt get ce i f |
| 366 | d = get ce i |
| 367 | end |
| 368 | end |
| 369 | end |
| 370 | ret an |
| 371 | end |
| 372 | |
| 373 | note Retry chains on the observed outcomes: window i is a retry when the previous window of the same |
| 374 | note owner was not accepted and i was requested 0..RWIN s after that window ended. |
| 375 | fn prevown i ulong to ulong |
| 376 | o = get co i |
| 377 | j = i |
| 378 | while gt j 0 bound 4096 |
| 379 | j = sub j 1 |
| 380 | if eq get co j o |
| 381 | ret j |
| 382 | end |
| 383 | end |
| 384 | ret MAXN |
| 385 | end |
| 386 | |
| 387 | fn chains n ulong to ulong |
| 388 | nr = ulong 0 |
| 389 | for i ulong n |
| 390 | put rc i 0 |
| 391 | p = prevown i |
| 392 | if lt p MAXN |
| 393 | g = sub get ca i get ce p |
| 394 | if eq get ac p 0 |
| 395 | if ge g 0 |
| 396 | if le g RWIN |
| 397 | put rc i add get rc p 1 |
| 398 | nr = add nr 1 |
| 399 | end |
| 400 | end |
| 401 | end |
| 402 | end |
| 403 | end |
| 404 | ret nr |
| 405 | end |
| 406 | |
| 407 | note Service of window i under a cap flag (cap 1: at most its own lease when it has one). |
| 408 | fn svc i ulong cap ulong to long |
| 409 | s = get sv i |
| 410 | l = get cl i |
| 411 | if eq cap 1 |
| 412 | if gt l 0 |
| 413 | if gt s l |
| 414 | ret l |
| 415 | end |
| 416 | end |
| 417 | end |
| 418 | ret s |
| 419 | end |
| 420 | |
| 421 | fn dropped i ulong rty ulong to bool |
| 422 | if eq rty 1 |
| 423 | ret gt get rc i RMAX |
| 424 | end |
| 425 | ret false |
| 426 | end |
| 427 | |
| 428 | fn accarm i ulong cap ulong rty ulong to long |
| 429 | if eq get ac i 0 |
| 430 | ret 0 |
| 431 | end |
| 432 | if dropped i rty |
| 433 | ret 0 |
| 434 | end |
| 435 | if eq cap 1 |
| 436 | l = get cl i |
| 437 | if gt l 0 |
| 438 | if gt get sv i l |
| 439 | ret 0 |
| 440 | end |
| 441 | end |
| 442 | end |
| 443 | ret 1 |
| 444 | end |
| 445 | |
| 446 | fn park k ulong i ulong to void |
| 447 | put xs k 0 |
| 448 | put xd k get ca i |
| 449 | put xv k 0 |
| 450 | put xa k 0 |
| 451 | end |
| 452 | |
| 453 | note Front time of window i when the slot is free at d: its arrival, or d plus its poll gap. |
| 454 | fn frontt i ulong d long to long |
| 455 | ret lmax get ar i add d get gp i |
| 456 | end |
| 457 | |
| 458 | note FCFS arm m: the window at the front holds the line until its eligibility time. |
| 459 | fn fcfs m ulong n ulong cap ulong rty ulong d0 long to void |
| 460 | d = d0 |
| 461 | h = long 0 |
| 462 | for i ulong n |
| 463 | k = add mul m MAXN i |
| 464 | if dropped i rty |
| 465 | park k i |
| 466 | continue |
| 467 | end |
| 468 | f = frontt i d |
| 469 | if held i |
| 470 | s = lmax f get el i |
| 471 | h = add h sub s f |
| 472 | t = add s svc i cap |
| 473 | put xs k s |
| 474 | put xd k t |
| 475 | put xv k 1 |
| 476 | put xa k accarm i cap rty |
| 477 | d = t |
| 478 | else |
| 479 | e = get ce i |
| 480 | if gt e f |
| 481 | h = add h sub e f |
| 482 | d = e |
| 483 | end |
| 484 | put xs k 0 |
| 485 | put xd k e |
| 486 | put xv k 0 |
| 487 | put xa k 0 |
| 488 | end |
| 489 | end |
| 490 | put hl m h |
| 491 | end |
| 492 | |
| 493 | note Candidate start of pending window j in the eligible-first arm m when the slot is free at t. |
| 494 | note A sequential leg (sq) cannot start before the leg before it has departed plus its poll gap. |
| 495 | fn ctime m ulong j ulong t long to long |
| 496 | c = lmax t lmax get ar j get el j |
| 497 | if eq get sq j 1 |
| 498 | kp = add mul m MAXN sub j 1 |
| 499 | if eq get xv kp -1 |
| 500 | ret 9223372036854775807 |
| 501 | end |
| 502 | c = lmax c add get xd kp get gp j |
| 503 | end |
| 504 | ret c |
| 505 | end |
| 506 | |
| 507 | note Next window for the eligible-first arm: the pending window with the smallest candidate |
| 508 | note start (ctime), ties to the earlier request. n when none is pending. |
| 509 | fn pick m ulong n ulong t long to ulong |
| 510 | best = n |
| 511 | bt = long 9223372036854775807 |
| 512 | for j ulong n |
| 513 | k = add mul m MAXN j |
| 514 | if eq get xv k -1 |
| 515 | c = ctime m j t |
| 516 | if lt c bt |
| 517 | bt = c |
| 518 | best = j |
| 519 | end |
| 520 | end |
| 521 | end |
| 522 | put gv 0 bt |
| 523 | ret best |
| 524 | end |
| 525 | |
| 526 | note Eligible-first arm m: a window waits for its eligibility time without holding the line. |
| 527 | fn elig m ulong n ulong cap ulong rty ulong d0 long to void |
| 528 | for i ulong n |
| 529 | k = add mul m MAXN i |
| 530 | if dropped i rty |
| 531 | park k i |
| 532 | continue |
| 533 | end |
| 534 | if held i |
| 535 | put xv k -1 |
| 536 | else |
| 537 | put xs k 0 |
| 538 | put xd k get ce i |
| 539 | put xv k 0 |
| 540 | put xa k 0 |
| 541 | end |
| 542 | end |
| 543 | t = d0 |
| 544 | for r ulong n |
| 545 | b = pick m n t |
| 546 | if ge b n |
| 547 | break |
| 548 | end |
| 549 | k = add mul m MAXN b |
| 550 | s = get gv 0 |
| 551 | u = add s svc b cap |
| 552 | put xs k s |
| 553 | put xd k u |
| 554 | put xv k 1 |
| 555 | put xa k accarm b cap rty |
| 556 | t = u |
| 557 | end |
| 558 | put hl m 0 |
| 559 | end |
| 560 | |
| 561 | note Pairwise overlap of served intervals of arm m (zero-length services never overlap). |
| 562 | fn overlap m ulong n ulong to ulong |
| 563 | c = ulong 0 |
| 564 | for i ulong n |
| 565 | k = add mul m MAXN i |
| 566 | if eq get xv k 1 |
| 567 | c = add c ovlone m n i |
| 568 | end |
| 569 | end |
| 570 | ret c |
| 571 | end |
| 572 | |
| 573 | fn ovlone m ulong n ulong i ulong to ulong |
| 574 | k = add mul m MAXN i |
| 575 | a = get xs k |
| 576 | b = get xd k |
| 577 | c = ulong 0 |
| 578 | for j ulong n |
| 579 | if gt j i |
| 580 | kj = add mul m MAXN j |
| 581 | if eq get xv kj 1 |
| 582 | if lt a get xd kj |
| 583 | if lt get xs kj b |
| 584 | c = add c 1 |
| 585 | end |
| 586 | end |
| 587 | end |
| 588 | end |
| 589 | end |
| 590 | ret c |
| 591 | end |
| 592 | |
| 593 | note Largest number of windows in the system: at some request time a_i, the count of j with |
| 594 | note a_j <= a_i < dep_j. |
| 595 | fn maxq m ulong n ulong to ulong |
| 596 | mq = ulong 0 |
| 597 | for i ulong n |
| 598 | a = get ar i |
| 599 | c = ulong 0 |
| 600 | for j ulong n |
| 601 | if le get ar j a |
| 602 | if lt a get xd add mul m MAXN j |
| 603 | c = add c 1 |
| 604 | end |
| 605 | end |
| 606 | end |
| 607 | if gt c mq |
| 608 | mq = c |
| 609 | end |
| 610 | end |
| 611 | ret mq |
| 612 | end |
| 613 | |
| 614 | fn armname m ulong to void |
| 615 | if eq m 0 |
| 616 | otext t_an |
| 617 | end |
| 618 | if eq m 1 |
| 619 | otext t_bn |
| 620 | end |
| 621 | if eq m 2 |
| 622 | otext t_crn |
| 623 | end |
| 624 | if eq m 3 |
| 625 | otext t_chn |
| 626 | end |
| 627 | if eq m 4 |
| 628 | otext t_cn |
| 629 | end |
| 630 | end |
| 631 | |
| 632 | note Accumulate per-arm sums into gv: 1 served, 2 acc, 3 dropped, 4 lostacc, 5 busy, 6 useful, |
| 633 | note 7 maxdep, 8 soj, 9 viol, 10 replayerr. |
| 634 | fn sums m ulong n ulong to void |
| 635 | for z ulong 11 |
| 636 | put gv z 0 |
| 637 | end |
| 638 | put gv 7 -9223372036854775807 |
| 639 | for i ulong n |
| 640 | k = add mul m MAXN i |
| 641 | v = get xv k |
| 642 | d = get xd k |
| 643 | put gv 8 add get gv 8 sub d get ar i |
| 644 | if lt d get ar i |
| 645 | put gv 9 add get gv 9 1 |
| 646 | end |
| 647 | if gt d get gv 7 |
| 648 | put gv 7 d |
| 649 | end |
| 650 | if eq v 1 |
| 651 | put gv 1 add get gv 1 1 |
| 652 | put gv 5 add get gv 5 sub d get xs k |
| 653 | if eq get xa k 1 |
| 654 | put gv 2 add get gv 2 1 |
| 655 | put gv 6 add get gv 6 sub d get xs k |
| 656 | end |
| 657 | end |
| 658 | if eq get ac i 1 |
| 659 | if eq get xa k 0 |
| 660 | put gv 4 add get gv 4 1 |
| 661 | end |
| 662 | end |
| 663 | if eq m 0 |
| 664 | if held i |
| 665 | if ne get xs k get cs i |
| 666 | put gv 10 add get gv 10 1 |
| 667 | end |
| 668 | end |
| 669 | end |
| 670 | end |
| 671 | end |
| 672 | |
| 673 | note Retry flag of arm m: Cr (2) and C (4) bound retries. |
| 674 | fn armrty m ulong to ulong |
| 675 | if eq m 2 |
| 676 | ret 1 |
| 677 | end |
| 678 | if eq m 4 |
| 679 | ret 1 |
| 680 | end |
| 681 | ret 0 |
| 682 | end |
| 683 | |
| 684 | note Windows parked by the retry bound in arm m (held or not). |
| 685 | fn countdrop m ulong n ulong to long |
| 686 | r = armrty m |
| 687 | c = long 0 |
| 688 | for i ulong n |
| 689 | if dropped i r |
| 690 | c = add c 1 |
| 691 | end |
| 692 | end |
| 693 | ret c |
| 694 | end |
| 695 | |
| 696 | fn armline m ulong n ulong mina long to void |
| 697 | sums m n |
| 698 | oreset |
| 699 | otext t_arm |
| 700 | armname m |
| 701 | otext t_srv |
| 702 | osnum get gv 1 |
| 703 | otext t_acc |
| 704 | osnum get gv 2 |
| 705 | otext t_drop |
| 706 | osnum countdrop m n |
| 707 | otext t_lost |
| 708 | osnum get gv 4 |
| 709 | otext t_busy |
| 710 | osnum get gv 5 |
| 711 | otext t_use |
| 712 | osnum get gv 6 |
| 713 | otext t_hol |
| 714 | osnum get hl m |
| 715 | otext t_mina |
| 716 | osnum mina |
| 717 | otext t_maxd |
| 718 | osnum get gv 7 |
| 719 | otext t_soj |
| 720 | osnum get gv 8 |
| 721 | otext t_viol |
| 722 | osnum get gv 9 |
| 723 | otext t_ovl |
| 724 | onum overlap m n |
| 725 | otext t_maxq |
| 726 | onum maxq m n |
| 727 | otext t_rep |
| 728 | osnum get gv 10 |
| 729 | otext t_nl |
| 730 | oflush |
| 731 | end |
| 732 | |
| 733 | note In K: accepted in every arm. |
| 734 | fn ink i ulong to bool |
| 735 | for m ulong 5 |
| 736 | if eq get xa add mul m MAXN i 0 |
| 737 | ret false |
| 738 | end |
| 739 | end |
| 740 | ret true |
| 741 | end |
| 742 | |
| 743 | fn sortwk n ulong to void |
| 744 | for i ulong n |
| 745 | j = i |
| 746 | while gt j 0 bound 4096 |
| 747 | x = get wk j |
| 748 | y = get wk sub j 1 |
| 749 | if ge x y |
| 750 | break |
| 751 | end |
| 752 | put wk j y |
| 753 | put wk sub j 1 x |
| 754 | j = sub j 1 |
| 755 | end |
| 756 | end |
| 757 | end |
| 758 | |
| 759 | note K-set waits of arm m: n, sum, nearest-rank p95 (rank ceil(0.95 n)), max. |
| 760 | fn kline m ulong n ulong to void |
| 761 | c = ulong 0 |
| 762 | sw = long 0 |
| 763 | for i ulong n |
| 764 | if ink i |
| 765 | w = sub get xs add mul m MAXN i get ca i |
| 766 | put wk c w |
| 767 | sw = add sw w |
| 768 | c = add c 1 |
| 769 | end |
| 770 | end |
| 771 | sortwk c |
| 772 | oreset |
| 773 | otext t_k |
| 774 | armname m |
| 775 | otext t_n |
| 776 | onum c |
| 777 | otext t_sumw |
| 778 | osnum sw |
| 779 | if gt c 0 |
| 780 | rk = div add mul c 95 99 100 |
| 781 | otext t_p95 |
| 782 | osnum get wk sub rk 1 |
| 783 | otext t_maxw |
| 784 | osnum get wk sub c 1 |
| 785 | end |
| 786 | otext t_nl |
| 787 | oflush |
| 788 | end |
| 789 | |
| 790 | note Over K: windows whose wait under arm x exceeds arm y by more than HARM s, and the reverse. |
| 791 | fn cmpline x ulong y ulong n ulong to void |
| 792 | wo = ulong 0 |
| 793 | be = ulong 0 |
| 794 | for i ulong n |
| 795 | if ink i |
| 796 | wx = get xs add mul x MAXN i |
| 797 | wy = get xs add mul y MAXN i |
| 798 | if gt sub wx wy HARM |
| 799 | wo = add wo 1 |
| 800 | end |
| 801 | if gt sub wy wx HARM |
| 802 | be = add be 1 |
| 803 | end |
| 804 | end |
| 805 | end |
| 806 | oreset |
| 807 | otext t_cmp |
| 808 | armname x |
| 809 | otext t_y |
| 810 | armname y |
| 811 | otext t_worse |
| 812 | onum wo |
| 813 | otext t_bett |
| 814 | onum be |
| 815 | otext t_nl |
| 816 | oflush |
| 817 | end |
| 818 | |
| 819 | fn parsed0 to long |
| 820 | n = argn 2 |
| 821 | if eq n 0 |
| 822 | ret -1 |
| 823 | end |
| 824 | for i ulong n |
| 825 | put buf i get arg i |
| 826 | end |
| 827 | put st 5 0 |
| 828 | v = pfield 0 n |
| 829 | if ne get st 5 0 |
| 830 | ret -1 |
| 831 | end |
| 832 | if ne get st 4 n |
| 833 | ret -1 |
| 834 | end |
| 835 | ret v |
| 836 | end |
| 837 | |
| 838 | fn main to int |
| 839 | if ne argcnt 3 |
| 840 | pr t_usage |
| 841 | ret 2 |
| 842 | end |
| 843 | d0 = parsed0 |
| 844 | if lt d0 0 |
| 845 | pr t_usage |
| 846 | ret 2 |
| 847 | end |
| 848 | sz = slurp |
| 849 | if lt sz 0 |
| 850 | pr t_ioerr |
| 851 | ret 3 |
| 852 | end |
| 853 | r = parse ulong sz |
| 854 | if eq r -2 |
| 855 | pr t_big |
| 856 | ret 4 |
| 857 | end |
| 858 | if lt r 0 |
| 859 | oreset |
| 860 | otext t_bad |
| 861 | onum get st 6 |
| 862 | otext t_nl |
| 863 | oflush |
| 864 | ret 3 |
| 865 | end |
| 866 | n = ulong r |
| 867 | an = derive n d0 |
| 868 | nr = chains n |
| 869 | nh = ulong 0 |
| 870 | mina = long 9223372036854775807 |
| 871 | for i ulong n |
| 872 | if held i |
| 873 | nh = add nh 1 |
| 874 | end |
| 875 | if lt get ca i mina |
| 876 | mina = get ca i |
| 877 | end |
| 878 | end |
| 879 | oreset |
| 880 | otext t_trace |
| 881 | onum n |
| 882 | otext t_held |
| 883 | onum nh |
| 884 | otext t_anom |
| 885 | onum an |
| 886 | otext t_rty |
| 887 | onum nr |
| 888 | otext t_d0 |
| 889 | osnum d0 |
| 890 | otext t_nl |
| 891 | oflush |
| 892 | fcfs 0 n 0 0 d0 |
| 893 | fcfs 1 n 1 0 d0 |
| 894 | fcfs 2 n 1 1 d0 |
| 895 | elig 3 n 1 0 d0 |
| 896 | elig 4 n 1 1 d0 |
| 897 | for m ulong 5 |
| 898 | armline m n mina |
| 899 | end |
| 900 | for m ulong 5 |
| 901 | kline m n |
| 902 | end |
| 903 | cmpline 4 1 n |
| 904 | cmpline 3 1 n |
| 905 | cmpline 1 0 n |
| 906 | ret 0 |
| 907 | end |