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
CUDApp / nvrm / lifecycle_gates.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | /* |
| 3 | * lifecycle_gates.c -- M19R NVRM lifecycle qualification gates. |
| 4 | * |
| 5 | * Validates nvrm_free() (VA reuse, live/idempotent/stale detection, CPU |
| 6 | * unmap) and m16_native_wait_marker_ge() (monotonic serial-number wait) |
| 7 | * against the real GB10 hardware and kernel driver. New file: does not |
| 8 | * modify m16_requalify.c / m16_concurrent.c or any existing test. |
| 9 | */ |
| 10 | #include "nvrm.h" |
| 11 | #include "cpu_barrier.h" |
| 12 | #include "m16_native.h" |
| 13 | /* Every pass/fail predicate below comes from om/engine/eng.om (op LIFE, plus |
| 14 | * REQF for the release word count; src/omega_eng_gates.h). Allocation, free, |
| 15 | * msync, channel and wait calls, and their order, stay here. The C oracle is |
| 16 | * behind CUDAPP_MIGRATION_PENDING_C_LIFECYCLE. */ |
| 17 | #if defined(CUDAPP_MIGRATION_PENDING_C_LIFECYCLE) |
| 18 | #define ENG_C_PART 1 |
| 19 | #endif |
| 20 | #include "omega_eng_gates.h" |
| 21 | #include "omega_fixture_rest.h" |
| 22 | |
| 23 | #include <errno.h> |
| 24 | #include <inttypes.h> |
| 25 | #include <stdint.h> |
| 26 | #include <stdio.h> |
| 27 | #include <stdlib.h> |
| 28 | #include <string.h> |
| 29 | #include <sys/mman.h> |
| 30 | #include <time.h> |
| 31 | #include <unistd.h> |
| 32 | |
| 33 | _Static_assert(ENOMEM == 12, "eng.om life k3 expects ENOMEM 12"); |
| 34 | |
| 35 | static int g_total = 0, g_passed = 0, g_failed = 0; |
| 36 | |
| 37 | static void gate_result(const char *name, int ok) { |
| 38 | g_total = (int)omega_fixture_calc(FR_ADD, (uint64_t)g_total, 1, 0); |
| 39 | if (ok) { g_passed = (int)omega_fixture_calc(FR_ADD, (uint64_t)g_passed, 1, 0); printf("[PASS] %s\n", name); } |
| 40 | else { g_failed = (int)omega_fixture_calc(FR_ADD, (uint64_t)g_failed, 1, 0); printf("[FAIL] %s\n", name); } |
| 41 | } |
| 42 | |
| 43 | static uint64_t now_ms(void) { |
| 44 | struct timespec t; |
| 45 | clock_gettime(CLOCK_MONOTONIC, &t); |
| 46 | return omega_fixture_calc(FR_MS, (uint64_t)t.tv_sec, (uint64_t)t.tv_nsec, 0); |
| 47 | } |
| 48 | |
| 49 | /* ---- NVRM_FREE_CHURN --------------------------------------------------- |
| 50 | * 20,000 alloc/touch/free cycles, sizes cycling 4 KiB..64 MiB, total bytes |
| 51 | * churned must exceed 256 GiB (2x the machine's 128 GiB unified memory -- |
| 52 | * impossible without real nvrm_free() release), and va_next (the VA |
| 53 | * high-water mark) must stay bounded, proving reuse rather than a bump leak. |
| 54 | */ |
| 55 | #define CHURN_CYCLES 20000 |
| 56 | |
| 57 | static int gate_free_churn(Nvrm *rm, uint64_t *out_bytes, uint64_t *out_high_water_delta) { |
| 58 | uint64_t va_start = rm->va_next; |
| 59 | uint64_t va_high = rm->va_next; |
| 60 | uint64_t total_bytes = 0; |
| 61 | |
| 62 | for (int i = 0; i < CHURN_CYCLES; i++) { |
| 63 | uint64_t size = omega_fixture_calc(FR_SIZE, (uint64_t)i, 0, 0); |
| 64 | NvrmMem m; |
| 65 | if (nvrm_alloc(rm, size, &m) != 0) { |
| 66 | fprintf(stderr, " churn: nvrm_alloc failed at cycle %d (size 0x%lx): %s\n", |
| 67 | i, (unsigned long)size, rm->err); |
| 68 | return -1; |
| 69 | } |
| 70 | va_high = omega_fixture_calc(FR_MAX, rm->va_next, va_high, 0); |
| 71 | |
| 72 | volatile uint8_t *p = (volatile uint8_t *)m.cpu; |
| 73 | uint8_t first = (uint8_t)omega_fixture_calc(FR_FIRST, (uint64_t)i, 0, 0); |
| 74 | uint8_t last = (uint8_t)omega_fixture_calc(FR_LAST, (uint64_t)i, 0, 0); |
| 75 | uint64_t tail = omega_fixture_calc(FR_PREV, m.size, 0, 0); |
| 76 | p[0] = first; |
| 77 | p[tail] = last; |
| 78 | uint8_t seen_first = p[0], seen_last = p[tail]; |
| 79 | if (!omega_fixture_calc(FR_BOTH, omega_fixture_calc(FR_EQ, seen_first, first, 0), |
| 80 | omega_fixture_calc(FR_EQ, seen_last, last, 0), 0)) { |
| 81 | fprintf(stderr, " churn: readback mismatch at cycle %d\n", i); |
| 82 | nvrm_free(rm, &m); |
| 83 | return -1; |
| 84 | } |
| 85 | |
| 86 | total_bytes = omega_fixture_calc(FR_ADD, total_bytes, m.size, 0); |
| 87 | if (nvrm_free(rm, &m) != 0) { |
| 88 | fprintf(stderr, " churn: nvrm_free failed at cycle %d: %s\n", i, rm->err); |
| 89 | return -1; |
| 90 | } |
| 91 | if (omega_fixture_calc(FR_LOG, (uint64_t)i, 0, 0)) { |
| 92 | fprintf(stderr, " churn: cycle %d/%d, %" PRIu64 " bytes so far\n", i, CHURN_CYCLES, total_bytes); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | *out_bytes = total_bytes; |
| 97 | *out_high_water_delta = omega_fixture_calc(FR_SUB, va_high, va_start, 0); |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | /* ---- NVRM_FREE_UNMAPS --------------------------------------------------- |
| 102 | * After nvrm_free(), the CPU range must no longer be mapped: msync() on it |
| 103 | * must fail with ENOMEM. |
| 104 | */ |
| 105 | static int gate_free_unmaps(Nvrm *rm) { |
| 106 | NvrmMem m; |
| 107 | if (nvrm_alloc(rm, 0x4000, &m) != 0) { |
| 108 | fprintf(stderr, " unmaps: alloc failed: %s\n", rm->err); |
| 109 | return -1; |
| 110 | } |
| 111 | void *va = m.cpu; |
| 112 | size_t size = (size_t)m.size; |
| 113 | |
| 114 | if (nvrm_free(rm, &m) != 0) { |
| 115 | fprintf(stderr, " unmaps: free failed: %s\n", rm->err); |
| 116 | return -1; |
| 117 | } |
| 118 | |
| 119 | errno = 0; |
| 120 | int rc = msync(va, size, MS_ASYNC); |
| 121 | int en = errno; |
| 122 | if (!omega_gate_life(OMEGA_LIFE_UNMAPPED, (uint64_t)(int64_t)rc, (uint64_t)(int64_t)en, 0, 0, 0, 0)) { |
| 123 | if (omega_fixture_calc(FR_EQ, (uint64_t)(int64_t)rc, 0, 0)) |
| 124 | fprintf(stderr, " unmaps: msync unexpectedly succeeded on freed range %p\n", va); |
| 125 | else |
| 126 | fprintf(stderr, " unmaps: msync failed with errno %d (%s), expected ENOMEM\n", en, strerror(en)); |
| 127 | return -1; |
| 128 | } |
| 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | /* ---- NVRM_FREE_IDEMPOTENT_AND_STALE ------------------------------------ |
| 133 | * Freeing an already-zeroed NvrmMem (double free) is a silent no-op (0, no |
| 134 | * syscalls). Freeing a saved stale copy (pre-free snapshot of a struct that |
| 135 | * has since been freed through another handle) must fail with -1 and must |
| 136 | * not touch the driver. |
| 137 | */ |
| 138 | static int gate_idempotent_and_stale(Nvrm *rm) { |
| 139 | NvrmMem m; |
| 140 | if (nvrm_alloc(rm, 0x2000, &m) != 0) { |
| 141 | fprintf(stderr, " idempotent: alloc failed: %s\n", rm->err); |
| 142 | return -1; |
| 143 | } |
| 144 | NvrmMem stale = m; /* stale copy, snapshotted before the real free */ |
| 145 | |
| 146 | if (nvrm_free(rm, &m) != 0) { |
| 147 | fprintf(stderr, " idempotent: first free failed: %s\n", rm->err); |
| 148 | return -1; |
| 149 | } |
| 150 | if (!omega_gate_life(OMEGA_LIFE_ZEROED, m.handle, m.va, m.size, (uint64_t)(uintptr_t)m.cpu, 0, 0)) { |
| 151 | fprintf(stderr, " idempotent: nvrm_free did not zero the NvrmMem on success\n"); |
| 152 | return -1; |
| 153 | } |
| 154 | |
| 155 | /* Double free of the now-zeroed struct: must return 0. */ |
| 156 | if (!omega_gate_life(OMEGA_LIFE_ZERO, (uint64_t)(int64_t)nvrm_free(rm, &m), 0, 0, 0, 0, 0)) { |
| 157 | fprintf(stderr, " idempotent: double free of zeroed struct returned nonzero\n"); |
| 158 | return -1; |
| 159 | } |
| 160 | |
| 161 | /* Free of the stale (already-freed-elsewhere) copy: must return -1. */ |
| 162 | if (!omega_gate_life(OMEGA_LIFE_NONZERO, (uint64_t)(int64_t)nvrm_free(rm, &stale), 0, 0, 0, 0, 0)) { |
| 163 | fprintf(stderr, " idempotent: freeing stale copy unexpectedly succeeded\n"); |
| 164 | return -1; |
| 165 | } |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | /* ---- NVRM_ALLOC_AFTER_FREE_REUSES_VA ------------------------------------ |
| 170 | * Allocate, free, allocate the same size again: must get the same VA back. |
| 171 | */ |
| 172 | static int gate_alloc_after_free_reuses_va(Nvrm *rm) { |
| 173 | NvrmMem a, b; |
| 174 | if (nvrm_alloc(rm, 0x8000, &a) != 0) { |
| 175 | fprintf(stderr, " reuse: first alloc failed: %s\n", rm->err); |
| 176 | return -1; |
| 177 | } |
| 178 | uint64_t va = a.va; |
| 179 | if (nvrm_free(rm, &a) != 0) { |
| 180 | fprintf(stderr, " reuse: free failed: %s\n", rm->err); |
| 181 | return -1; |
| 182 | } |
| 183 | if (nvrm_alloc(rm, 0x8000, &b) != 0) { |
| 184 | fprintf(stderr, " reuse: second alloc failed: %s\n", rm->err); |
| 185 | return -1; |
| 186 | } |
| 187 | int ok = omega_gate_life(OMEGA_LIFE_EQ, b.va, va, 0, 0, 0, 0); |
| 188 | if (!ok) { |
| 189 | fprintf(stderr, " reuse: expected va 0x%lx, got 0x%lx\n", |
| 190 | (unsigned long)va, (unsigned long)b.va); |
| 191 | } |
| 192 | nvrm_free(rm, &b); |
| 193 | return (int32_t)(uint32_t)omega_fixture_calc(FR_RESULT, (uint64_t)ok, 0, 0); |
| 194 | } |
| 195 | |
| 196 | static int gate_injected_free_failure(int uvm_failure) { |
| 197 | Nvrm rm; |
| 198 | if (nvrm_open(&rm) != 0) return -1; |
| 199 | NvrmMem m; |
| 200 | if (nvrm_alloc(&rm, 0x4000, &m) != 0) { nvrm_close(&rm); return -1; } |
| 201 | uint64_t va = m.va; |
| 202 | uint32_t free_before = rm.free_count; |
| 203 | if (uvm_failure) rm.inject_uvm_free_failure = 1; |
| 204 | else rm.inject_rm_free_failure = 1; |
| 205 | int frc = nvrm_free(&rm, &m); |
| 206 | int refused = omega_gate_life(OMEGA_LIFE_QUARANTINE, (uint64_t)(int64_t)frc, rm.faulted, m.handle, |
| 207 | rm.live_count, rm.free_count, free_before); |
| 208 | NvrmMem other; |
| 209 | if (refused) |
| 210 | refused = omega_gate_life(OMEGA_LIFE_NONZERO, (uint64_t)(int64_t)nvrm_alloc(&rm, 0x4000, &other), 0, 0, 0, 0, 0); |
| 211 | int rrc = nvrm_free(&rm, &m); |
| 212 | uint64_t last_va = rm.free_count ? rm.free_list[omega_fixture_calc(FR_PREV, rm.free_count, 0, 0)].va : 0u; |
| 213 | int recovered_release = omega_gate_life(OMEGA_LIFE_RECOVERED, (uint64_t)(int64_t)rrc, rm.free_count, |
| 214 | free_before, last_va, va, 0); |
| 215 | nvrm_close(&rm); |
| 216 | return (int32_t)(uint32_t)omega_fixture_calc(FR_RESULT, omega_fixture_calc(FR_BOTH, refused, recovered_release, 0), 0, 0); |
| 217 | } |
| 218 | |
| 219 | static int gate_corrupt_table_refusal(void) { |
| 220 | Nvrm rm; |
| 221 | if (nvrm_open(&rm) != 0) return -1; |
| 222 | NvrmMem m; |
| 223 | if (nvrm_alloc(&rm, 0x4000, &m) != 0) { nvrm_close(&rm); return -1; } |
| 224 | void *cpu = rm.live[0].cpu; |
| 225 | rm.live[0].cpu = NULL; |
| 226 | int frc = nvrm_free(&rm, &m); |
| 227 | int refused = omega_gate_life(OMEGA_LIFE_CORRUPT, (uint64_t)(int64_t)frc, rm.faulted, rm.live_count, |
| 228 | m.handle, 0, 0); |
| 229 | rm.live[0].cpu = cpu; |
| 230 | int released = omega_gate_life(OMEGA_LIFE_ZERO, (uint64_t)(int64_t)nvrm_free(&rm, &m), 0, 0, 0, 0, 0); |
| 231 | nvrm_close(&rm); |
| 232 | return (int32_t)(uint32_t)omega_fixture_calc(FR_RESULT, omega_fixture_calc(FR_BOTH, refused, released, 0), 0, 0); |
| 233 | } |
| 234 | |
| 235 | static int gate_allocation_overflow(Nvrm *rm) { |
| 236 | NvrmMem m = {0}; |
| 237 | uint32_t before = rm->live_count; |
| 238 | uint64_t va_before = rm->va_next; |
| 239 | int r1 = nvrm_alloc(rm, UINT64_MAX, &m); |
| 240 | int r2 = 0; |
| 241 | if (omega_fixture_calc(FR_FAILED, (uint64_t)(int64_t)r1, 0, 0)) r2 = nvrm_alloc(rm, 0, &m); |
| 242 | int ok = omega_gate_life(OMEGA_LIFE_OVERFLOW, (uint64_t)(int64_t)r1, (uint64_t)(int64_t)r2, rm->live_count, |
| 243 | before, rm->va_next, va_before); |
| 244 | return (int32_t)(uint32_t)omega_fixture_calc(FR_RESULT, (uint64_t)ok, 0, 0); |
| 245 | } |
| 246 | |
| 247 | /* ---- M16_WAIT_GE_SERIAL -------------------------------------------------- |
| 248 | * Pure CPU unit test, no hardware dependency: synthetic marker + serial |
| 249 | * (RFC 1982 style) comparison against a target that has wrapped past 0. |
| 250 | */ |
| 251 | static int gate_wait_ge_serial(void) { |
| 252 | uint32_t marker; |
| 253 | |
| 254 | /* target 0xFFFFFFF0 satisfied by marker 0x00000005 (wrapped past). */ |
| 255 | marker = 0x00000005u; |
| 256 | if (!omega_gate_life(OMEGA_LIFE_ZERO, (uint64_t)(int64_t)m16_native_wait_marker_ge(&marker, 0xFFFFFFF0u, 50), 0, |
| 257 | 0, 0, 0, 0)) { |
| 258 | fprintf(stderr, " wait_ge: wrapped-past case unexpectedly failed/timed out\n"); |
| 259 | return -1; |
| 260 | } |
| 261 | |
| 262 | /* Not satisfied by 0xFFFFFFE0. Must time out, within timeout_ms + 50ms. */ |
| 263 | marker = 0xFFFFFFE0u; |
| 264 | uint64_t t0 = now_ms(); |
| 265 | int rc = m16_native_wait_marker_ge(&marker, 0xFFFFFFF0u, 100); |
| 266 | uint64_t elapsed = omega_fixture_calc(FR_SUB, now_ms(), t0, 0); |
| 267 | if (!omega_gate_life(OMEGA_LIFE_NONZERO, (uint64_t)(int64_t)rc, 0, 0, 0, 0, 0)) { |
| 268 | fprintf(stderr, " wait_ge: not-yet-satisfied case unexpectedly returned success\n"); |
| 269 | return -1; |
| 270 | } |
| 271 | if (!omega_gate_life(OMEGA_LIFE_LE, elapsed, 150, 0, 0, 0, 0)) { |
| 272 | fprintf(stderr, " wait_ge: timeout took %" PRIu64 "ms, expected <= 150ms\n", elapsed); |
| 273 | return -1; |
| 274 | } |
| 275 | return 0; |
| 276 | } |
| 277 | |
| 278 | /* ---- GPU_SUBMIT_AFTER_CHURN ---------------------------------------------- |
| 279 | * After churn, open a channel and do one real submit + wait (same pattern |
| 280 | * as m16/m16_native.c + m16/m16_requalify.c) to prove the device context |
| 281 | * is still healthy after 20,000 alloc/free cycles. |
| 282 | */ |
| 283 | static int gate_gpu_submit_after_churn(Nvrm *rm) { |
| 284 | if (nvrm_channel(rm) != 0) { |
| 285 | fprintf(stderr, " submit: nvrm_channel failed: %s\n", rm->err); |
| 286 | return -1; |
| 287 | } |
| 288 | NvrmMem pb, marker_mem; |
| 289 | if (nvrm_alloc(rm, 0x1000, &pb) != 0) { |
| 290 | fprintf(stderr, " submit: pushbuffer alloc failed: %s\n", rm->err); |
| 291 | return -1; |
| 292 | } |
| 293 | if (nvrm_alloc(rm, 0x1000, &marker_mem) != 0) { |
| 294 | fprintf(stderr, " submit: marker alloc failed: %s\n", rm->err); |
| 295 | return -1; |
| 296 | } |
| 297 | volatile uint32_t *marker = (volatile uint32_t *)marker_mem.cpu; |
| 298 | *marker = 0; |
| 299 | |
| 300 | uint32_t methods[32]; |
| 301 | int nwords = m16_native_build_release(methods, marker_mem.va, 0x19c0ffee, rm->compute_class); |
| 302 | if (!omega_gate_reqf(OMEGA_REQF_WORDS, nwords)) { |
| 303 | fprintf(stderr, " submit: build_release failed\n"); |
| 304 | return -1; |
| 305 | } |
| 306 | memcpy(pb.cpu, methods, (size_t)nwords * sizeof(uint32_t)); |
| 307 | nvrm_cpu_barrier(); |
| 308 | |
| 309 | if (nvrm_submit(rm, &pb, 0, (uint32_t)nwords) != 0) { |
| 310 | fprintf(stderr, " submit: nvrm_submit failed: %s\n", rm->err); |
| 311 | return -1; |
| 312 | } |
| 313 | if (!omega_gate_life(OMEGA_LIFE_ZERO, (uint64_t)(int64_t)m16_native_wait_marker_ge(marker, 0x19c0ffee, 2000), 0, |
| 314 | 0, 0, 0, 0)) { |
| 315 | fprintf(stderr, " submit: timeout waiting for marker; actual=0x%08x\n", *marker); |
| 316 | return -1; |
| 317 | } |
| 318 | if (!omega_gate_life(OMEGA_LIFE_EQ, *marker, 0x19c0ffeeu, 0, 0, 0, 0)) { |
| 319 | fprintf(stderr, " submit: unexpected final marker value 0x%08x\n", *marker); |
| 320 | return -1; |
| 321 | } |
| 322 | nvrm_retire(rm, rm->put); |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | |
| 327 | /* omega#523: the compute-object RM_ALLOC is refused with NV_ERR_NO_MEMORY when |
| 328 | * the host has no free 2 MiB block at that instant. nvrm_channel must retry that |
| 329 | * one allocation, bounded, instead of failing the channel on the first refusal. */ |
| 330 | static int gate_channel_no_memory_retried(void) { |
| 331 | Nvrm rm; |
| 332 | if (nvrm_open(&rm) != 0) return -1; |
| 333 | rm.inject_rm_alloc_no_memory = 3; |
| 334 | rm.channel_no_memory_retry_ms = 1; |
| 335 | int rc = nvrm_channel(&rm); |
| 336 | int ok = omega_gate_life(OMEGA_LIFE_RETRIED, (uint64_t)(int64_t)rc, rm.compute_obj, rm.channel_no_memory_retries, |
| 337 | rm.inject_rm_alloc_no_memory, 0, 0); |
| 338 | if (!ok) printf(" channel after 3 injected NV_ERR_NO_MEMORY: rc=%d retries=%u err=\"%s\"\n", |
| 339 | rc, rm.channel_no_memory_retries, rm.err); |
| 340 | nvrm_close(&rm); |
| 341 | return (int32_t)(uint32_t)omega_fixture_calc(FR_RESULT, (uint64_t)ok, 0, 0); |
| 342 | } |
| 343 | |
| 344 | /* The retry is bounded: one refusal more than the budget is final, the channel |
| 345 | * has no compute object, and the error names the attempts and the host's supply |
| 346 | * of 2 MiB blocks so the next reader does not have to guess. */ |
| 347 | static int gate_channel_no_memory_bounded(void) { |
| 348 | Nvrm rm; |
| 349 | if (nvrm_open(&rm) != 0) return -1; |
| 350 | rm.inject_rm_alloc_no_memory = (uint8_t)omega_fixture_calc(FR_ADD, NVRM_CHANNEL_NO_MEMORY_RETRIES, 1, 0); |
| 351 | rm.channel_no_memory_retry_ms = 1; |
| 352 | int rc = nvrm_channel(&rm); |
| 353 | unsigned char error_text[512] = {0}; |
| 354 | _Static_assert(sizeof rm.err <= sizeof error_text, "fixture text transport bound"); |
| 355 | memcpy(error_text, rm.err, sizeof rm.err); |
| 356 | int hits = (int)omega_fixture_calc(FR_SUM3, |
| 357 | omega_fixture_text(error_text, (const unsigned char[32]){"NV_ERR_NO_MEMORY"}, 16), |
| 358 | omega_fixture_text(error_text, (const unsigned char[32]){"attempts"}, 8), |
| 359 | omega_fixture_text(error_text, (const unsigned char[32]){"2 MiB blocks"}, 12)); |
| 360 | int ok = omega_gate_life(OMEGA_LIFE_BOUNDED, (uint64_t)(int64_t)rc, rm.compute_obj, rm.channel_no_memory_retries, |
| 361 | NVRM_CHANNEL_NO_MEMORY_RETRIES, (uint64_t)hits, 0); |
| 362 | if (!ok) printf(" bounded retry: rc=%d retries=%u err=\"%s\"\n", rc, rm.channel_no_memory_retries, rm.err); |
| 363 | int closed = omega_gate_life(OMEGA_LIFE_ZERO, (uint64_t)(int64_t)nvrm_close(&rm), 0, 0, 0, 0, 0); |
| 364 | if (!closed) printf(" bounded retry: close after refused channel failed: %s\n", rm.err); |
| 365 | return (int32_t)(uint32_t)omega_fixture_calc(FR_RESULT, omega_fixture_calc(FR_BOTH, ok, closed, 0), 0, 0); |
| 366 | } |
| 367 | |
| 368 | /* The extra channel owns a subcontext as well as a FIFO. Rebuild each supported |
| 369 | * configuration on one open client and check teardown returns all tracked buffers. */ |
| 370 | static void gate_extra_channel_contexts(void) { |
| 371 | for (uint32_t n = 0; n <= NVRM_MAX_EXTRA_CHANNELS; n++) { |
| 372 | Nvrm rm; |
| 373 | int opened = (int)omega_fixture_calc(FR_EQ, (uint64_t)(int64_t)nvrm_open(&rm), 0, 0); |
| 374 | int ok = opened; |
| 375 | uint32_t baseline = opened ? rm.live_count : 0; |
| 376 | for (int round = 0; ok && round < 3; round++) { |
| 377 | int crc = nvrm_channel_n(&rm, n); |
| 378 | ok = omega_gate_life(OMEGA_LIFE_TORNDOWN, (uint64_t)(int64_t)crc, 0, rm.n_extra, n, 0, 0); |
| 379 | for (uint32_t i = 0; ok && i < n; i++) { |
| 380 | ok = omega_gate_life(OMEGA_LIFE_DISTINCT, rm.extra[i].ctxshare, rm.ctxshare, 0, 0, 0, 0); |
| 381 | for (uint32_t j = 0; ok && j < i; j++) |
| 382 | ok = omega_gate_life(OMEGA_LIFE_DISTINCT, rm.extra[i].ctxshare, rm.extra[j].ctxshare, 0, 0, 0, 0); |
| 383 | } |
| 384 | if (nvrm_channel_destroy(&rm) != 0) ok = 0; |
| 385 | if (ok) ok = omega_gate_life(OMEGA_LIFE_TORNDOWN, rm.n_extra, rm.ctxshare, rm.live_count, baseline, 0, 0); |
| 386 | for (uint32_t i = 0; ok && i < n; i++) |
| 387 | ok = omega_gate_life(OMEGA_LIFE_BOTHZERO, rm.extra[i].ctxshare, rm.extra[i].gpfifo, 0, 0, 0, 0); |
| 388 | } |
| 389 | if (opened && nvrm_close(&rm) != 0) ok = 0; |
| 390 | char name[80]; |
| 391 | snprintf(name, sizeof name, "EXTRA_CHANNEL_CONTEXTS_%u_REOPEN_AND_RELEASE", n); |
| 392 | if (!ok) fprintf(stderr, "extra channels %u: %s\n", n, rm.err); |
| 393 | gate_result(name, ok); |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | int main(int argc, char **argv) { |
| 398 | if (argc == 2 && strcmp(argv[1], "--channels-only") == 0) { |
| 399 | gate_extra_channel_contexts(); |
| 400 | printf("TOTAL: %d PASSED: %d FAILED: %d\n", g_total, g_passed, g_failed); |
| 401 | return (int)omega_fixture_calc(FR_FAILED, (uint64_t)g_failed, 0, 0); |
| 402 | } |
| 403 | if (argc != 1) { fprintf(stderr, "usage: %s [--channels-only]\n", argv[0]); return 2; } |
| 404 | printf("=== M19R NVRM LIFECYCLE GATES ===\n"); |
| 405 | |
| 406 | gate_result("M16_WAIT_GE_SERIAL", (int)omega_fixture_calc(FR_EQ, (uint64_t)(int64_t)gate_wait_ge_serial(), 0, 0)); |
| 407 | |
| 408 | Nvrm rm; |
| 409 | if (nvrm_open(&rm) != 0) { |
| 410 | fprintf(stderr, "FATAL: nvrm_open failed: %s\n", rm.err); |
| 411 | gate_result("NVRM_FREE_CHURN", 0); |
| 412 | gate_result("NVRM_FREE_UNMAPS", 0); |
| 413 | gate_result("NVRM_FREE_IDEMPOTENT_AND_STALE", 0); |
| 414 | gate_result("NVRM_ALLOC_AFTER_FREE_REUSES_VA", 0); |
| 415 | gate_result("GPU_SUBMIT_AFTER_CHURN", 0); |
| 416 | printf("TOTAL: %d PASSED: %d FAILED: %d\n", g_total, g_passed, g_failed); |
| 417 | return 1; |
| 418 | } |
| 419 | |
| 420 | uint64_t churn_bytes = 0, high_water_delta = 0; |
| 421 | int churn_rc = gate_free_churn(&rm, &churn_bytes, &high_water_delta); |
| 422 | /* churn_ok: 256 GiB of traffic, high-water delta under 2 GiB (eng.om life k8). */ |
| 423 | int churn_ok = omega_gate_life(OMEGA_LIFE_CHURN, (uint64_t)(int64_t)churn_rc, churn_bytes, high_water_delta, 0, 0, 0); |
| 424 | printf(" churn: bytes=%" PRIu64 " (%.2f GiB) high_water_delta=%" PRIu64 " (%.2f MiB)\n", |
| 425 | churn_bytes, omega_fixture_scale(churn_bytes, 0), |
| 426 | high_water_delta, omega_fixture_scale(high_water_delta, 1)); |
| 427 | gate_result("NVRM_FREE_CHURN", churn_ok); |
| 428 | |
| 429 | gate_result("NVRM_FREE_UNMAPS", (int)omega_fixture_calc(FR_EQ, (uint64_t)(int64_t)gate_free_unmaps(&rm), 0, 0)); |
| 430 | gate_result("NVRM_FREE_IDEMPOTENT_AND_STALE", (int)omega_fixture_calc(FR_EQ, (uint64_t)(int64_t)gate_idempotent_and_stale(&rm), 0, 0)); |
| 431 | gate_result("NVRM_ALLOC_AFTER_FREE_REUSES_VA", (int)omega_fixture_calc(FR_EQ, (uint64_t)(int64_t)gate_alloc_after_free_reuses_va(&rm), 0, 0)); |
| 432 | gate_result("NVRM_ALLOCATION_OVERFLOW_REFUSED", (int)omega_fixture_calc(FR_EQ, (uint64_t)(int64_t)gate_allocation_overflow(&rm), 0, 0)); |
| 433 | gate_result("GPU_SUBMIT_AFTER_CHURN", (int)omega_fixture_calc(FR_EQ, (uint64_t)(int64_t)gate_gpu_submit_after_churn(&rm), 0, 0)); |
| 434 | |
| 435 | nvrm_close(&rm); |
| 436 | gate_result("UVM_FREE_FAILURE_QUARANTINES", (int)omega_fixture_calc(FR_EQ, (uint64_t)(int64_t)gate_injected_free_failure(1), 0, 0)); |
| 437 | gate_result("RM_FREE_FAILURE_QUARANTINES", (int)omega_fixture_calc(FR_EQ, (uint64_t)(int64_t)gate_injected_free_failure(0), 0, 0)); |
| 438 | gate_result("CORRUPT_TABLE_REFUSED", (int)omega_fixture_calc(FR_EQ, (uint64_t)(int64_t)gate_corrupt_table_refusal(), 0, 0)); |
| 439 | gate_result("CHANNEL_NO_MEMORY_RETRIED", (int)omega_fixture_calc(FR_EQ, (uint64_t)(int64_t)gate_channel_no_memory_retried(), 0, 0)); |
| 440 | gate_result("CHANNEL_NO_MEMORY_BOUNDED", (int)omega_fixture_calc(FR_EQ, (uint64_t)(int64_t)gate_channel_no_memory_bounded(), 0, 0)); |
| 441 | gate_extra_channel_contexts(); |
| 442 | printf("TOTAL: %d PASSED: %d FAILED: %d\n", g_total, g_passed, g_failed); |
| 443 | return (int)omega_fixture_calc(FR_FAILED, (uint64_t)g_failed, 0, 0); |
| 444 | } |