add page cache with read-ahead and dirty writeback, file-backed and anonymous mmap with CoW, VAD-based virtual memory replacing the old user region model, PFN database with eviction and reclaim, file identity for cross-open section sharing, FAT32 path cache and per-file cluster chain cache, serial.sys for COM1 keyboard input, xHCI MSI with INTx and polled fallback, PciEnableMsiAuto, waitable input queue, KeWaitForAnyEvent, per-process thread info syscall, expanded kernel stats (PFN/PTE/VAD/file-cache/disk), pool allocation tags, async I/O user buffer locking, file flush on close, add docs.md.
This commit is contained in:
1 parent
61ec2442eb
commit
2c4a68a75f
114 files changed
+18069
-2620
No files matched your search
@@ -0,0 +1,157 @@
|
||||
// Native surface multithreaded present test.
|
||||
// Multiple user threads present one process-private surface to catch mapping and scratch-buffer races.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <ntlite/syscall.h>
|
||||
|
||||
#define SURFACE_W 96u
|
||||
#define SURFACE_H 64u
|
||||
#define THREAD_COUNT 4u
|
||||
#define ITERATIONS 32u
|
||||
|
||||
typedef struct WORKER_STATE {
|
||||
uint32_t Index;
|
||||
uint32_t Surface;
|
||||
uint8_t* Base;
|
||||
uint32_t Pitch;
|
||||
uint32_t Status;
|
||||
uint32_t IterationsDone;
|
||||
} WORKER_STATE;
|
||||
|
||||
static WORKER_STATE gWorkers[THREAD_COUNT];
|
||||
|
||||
static void print(const char* s) {
|
||||
SYS_WRITE_CONSOLE_REQUEST req = { SysSvFromCstr(s) };
|
||||
SysWriteConsole(&req);
|
||||
}
|
||||
|
||||
static void print_u64(uint64_t v) {
|
||||
char buf[32];
|
||||
int i = 0;
|
||||
if (v == 0) { print("0"); return; }
|
||||
while (v && i < (int)sizeof(buf)) {
|
||||
buf[i++] = (char)('0' + (v % 10));
|
||||
v /= 10;
|
||||
}
|
||||
while (i--) {
|
||||
char c = buf[i];
|
||||
SYS_WRITE_CONSOLE_REQUEST req = { SysSvFromParts(&c, 1) };
|
||||
SysWriteConsole(&req);
|
||||
}
|
||||
}
|
||||
|
||||
static void exit_now(int code) {
|
||||
for (;;) SysExitProcess(code);
|
||||
}
|
||||
|
||||
static void fail(const char* msg) {
|
||||
print("surface_multithread_present: ");
|
||||
print(msg);
|
||||
print("\n");
|
||||
exit_now(1);
|
||||
}
|
||||
|
||||
static void fail_status(const char* what, uint32_t status) {
|
||||
print("surface_multithread_present: ");
|
||||
print(what);
|
||||
print(" failed status=");
|
||||
print_u64(status);
|
||||
print("\n");
|
||||
exit_now(1);
|
||||
}
|
||||
|
||||
static void worker_main(uintptr_t arg) {
|
||||
WORKER_STATE* st = (WORKER_STATE*)arg;
|
||||
if (!st) SysExitThread(1);
|
||||
uint32_t bandHeight = SURFACE_H / THREAD_COUNT;
|
||||
uint32_t y0 = st->Index * bandHeight;
|
||||
uint32_t h = bandHeight;
|
||||
if (st->Index == THREAD_COUNT - 1)
|
||||
h = SURFACE_H - y0;
|
||||
|
||||
for (uint32_t iter = 0; iter < ITERATIONS; ++iter) {
|
||||
for (uint32_t y = 0; y < h; ++y) {
|
||||
uint32_t* row = (uint32_t*)(st->Base + (size_t)(y0 + y) * st->Pitch);
|
||||
for (uint32_t x = 0; x < SURFACE_W; ++x)
|
||||
row[x] = 0x00010101u * ((st->Index + 1u) * 32u + (iter & 31u));
|
||||
}
|
||||
|
||||
DISPLAY_RECT rect = { 0, (int32_t)y0, (int32_t)SURFACE_W, (int32_t)h };
|
||||
uint32_t s = SysPresentSurface(st->Surface, &rect, 1);
|
||||
if (s != SYS_STATUS_SUCCESS) {
|
||||
st->Status = s;
|
||||
SysExitThread(1);
|
||||
}
|
||||
st->IterationsDone++;
|
||||
SysYield();
|
||||
}
|
||||
|
||||
st->Status = SYS_STATUS_SUCCESS;
|
||||
SysExitThread(0);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
print("surface_multithread_present: start\n");
|
||||
|
||||
uint32_t surface = 0;
|
||||
uint32_t s = SysCreateSurface(SURFACE_W, SURFACE_H, SYS_SURFACE_FORMAT_XRGB8888,
|
||||
SYS_SURFACE_FLAG_NONE, &surface);
|
||||
if (s != SYS_STATUS_SUCCESS) fail_status("create surface", s);
|
||||
|
||||
void* base = 0;
|
||||
uint32_t pitch = 0;
|
||||
s = SysMapSurface(surface, &base, &pitch);
|
||||
if (s != SYS_STATUS_SUCCESS) fail_status("map surface", s);
|
||||
if (!base || pitch < SURFACE_W * sizeof(uint32_t)) fail("invalid mapping");
|
||||
|
||||
uint32_t handles[THREAD_COUNT];
|
||||
uint32_t tids[THREAD_COUNT];
|
||||
memset(handles, 0, sizeof(handles));
|
||||
memset(tids, 0, sizeof(tids));
|
||||
memset(gWorkers, 0, sizeof(gWorkers));
|
||||
|
||||
for (uint32_t i = 0; i < THREAD_COUNT; ++i) {
|
||||
gWorkers[i].Index = i;
|
||||
gWorkers[i].Surface = surface;
|
||||
gWorkers[i].Base = (uint8_t*)base;
|
||||
gWorkers[i].Pitch = pitch;
|
||||
gWorkers[i].Status = SYS_STATUS_PENDING;
|
||||
SYS_CREATE_THREAD_REQUEST req = {
|
||||
(uintptr_t)worker_main,
|
||||
(uintptr_t)&gWorkers[i],
|
||||
1,
|
||||
0,
|
||||
&handles[i],
|
||||
&tids[i]
|
||||
};
|
||||
s = SysCreateThread(&req);
|
||||
if (s != SYS_STATUS_SUCCESS) fail_status("create thread", s);
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < THREAD_COUNT; ++i) {
|
||||
s = SysWait(handles[i], SYS_WAIT_FLAG_NONE);
|
||||
if (s != SYS_STATUS_SUCCESS) fail_status("wait thread", s);
|
||||
SysCloseHandle(handles[i]);
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < THREAD_COUNT; ++i) {
|
||||
if (gWorkers[i].Status != SYS_STATUS_SUCCESS) {
|
||||
print("surface_multithread_present: worker ");
|
||||
print_u64(i);
|
||||
print(" status=");
|
||||
print_u64(gWorkers[i].Status);
|
||||
print(" iterations=");
|
||||
print_u64(gWorkers[i].IterationsDone);
|
||||
print("\n");
|
||||
exit_now(1);
|
||||
}
|
||||
if (gWorkers[i].IterationsDone != ITERATIONS) fail("worker iteration count mismatch");
|
||||
}
|
||||
|
||||
SysCloseHandle(surface);
|
||||
print("surface_multithread_present: PASS\n");
|
||||
exit_now(0);
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user