#include #include #include #include #include #include #include #include #define DbgPrint printf #define SEG_1_SIZE 1024 * 1024 #define SEG_X_SIZE 1024 * 1024 * 64 #define VM_MEMMAN_ITERATIONS 150 #define VM_MEMMAN_ITERATIONS2 2000 #define MemManSubtest5Count 200 int TotalBenchMarks = 0; #define MAX_BENCHMARKS 32 char *BenchMarkNames[ MAX_BENCHMARKS ]; ULONG BenchMarkRates[ MAX_BENCHMARKS ]; ULONG BenchMarkFracs[ MAX_BENCHMARKS ]; typedef struct _PERFINFO { LARGE_INTEGER StartTime; LARGE_INTEGER StopTime; PCHAR Title; ULONG Iterations; } PERFINFO, *PPERFINFO; int StartBenchMark( PCHAR Title, ULONG Iterations, PPERFINFO PerfInfo ); VOID FinishBenchMark( PPERFINFO PerfInfo ); __cdecl main() { PCHAR p1, p2, p3, p4; // pointers into new segment PCHAR pa[MemManSubtest5Count]; // array for section pointers PULONG u1; ULONG actual; // actual xfer count for read ULONG ssize; // section allocation size var ULONG ii, ix; // loop index variables PERFINFO PerfInfo; ULONG Seg1Size; ULONG SegxSize; ULONG CommitSize; NTSTATUS status; HANDLE CurrentProcessHandle, Section1; LARGE_INTEGER SectionSize; ULONG Size; ULONG ViewSize; DbgPrint("NT Memory Management test\n"); CurrentProcessHandle = NtCurrentProcess(); Size = 1024L * 1024L; p1 = NULL; status = NtAllocateVirtualMemory (CurrentProcessHandle, (PVOID *)&p1, 0, &Size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); if (!NT_SUCCESS(status)) { DbgPrint("service failed allocvm - status %X\n", status); } for (p2=p1; p2 < (p1 + Size); p2 += 4) { u1 = (PULONG)p2; *u1 = (ULONG)p2; } // for SectionSize.LowPart = 1024*1024; SectionSize.HighPart = 0; status = NtCreateSection (&Section1, SECTION_MAP_READ | SECTION_MAP_WRITE, NULL, &SectionSize, PAGE_READWRITE, SEC_COMMIT, NULL); if (!NT_SUCCESS(status)) { DbgPrint("service failed create sect - status %X\n", status); } p3 = NULL; ViewSize = 0; status = NtMapViewOfSection (Section1, CurrentProcessHandle, (PVOID *)&p3, 0L, 0, NULL, &ViewSize, ViewUnmap, 0, PAGE_READWRITE ); if (!NT_SUCCESS(status)) { DbgPrint("service failed mapview - status %X\n", status); } RtlMoveMemory ((PVOID)p3, (PVOID)p1, Size); StartBenchMark( "NT MemMan00 -- 1 Meg Copy", 150, &PerfInfo ); // // Memory Management sub-test 1 -- // // Create a 1 MB segment with commitment of the pages, // then touch each page, which should cause a fault and // a demand zero page to be allocated. // // for (ii=0; ii<150; ii++) { RtlMoveMemory ((PVOID)p3, (PVOID)p1, Size); } FinishBenchMark( &PerfInfo ); status = NtClose (Section1); if (!NT_SUCCESS(status)) { DbgPrint("service failed close sect - status %X\n", status); } status = NtUnmapViewOfSection (CurrentProcessHandle, p3); if (!NT_SUCCESS(status)) { DbgPrint("service failed - status %X\n", status); } // // Memory Management sub-test 1 -- // // Create a 1 MB segment with commitment of the pages, // then touch each page, which should cause a fault and // a demand zero page to be allocated. // // StartBenchMark( "NT MemMan01 -- create 1mb section, copy 1mb, delete", 150, &PerfInfo ); for (ii=0; ii<150; ii++) { status = NtCreateSection (&Section1, SECTION_MAP_READ | SECTION_MAP_WRITE, NULL, &SectionSize, PAGE_READWRITE, SEC_COMMIT, NULL); if (!NT_SUCCESS(status)) { DbgPrint("service failed create sect - status %X\n", status); } p3 = NULL; ViewSize = 0; status = NtMapViewOfSection (Section1, CurrentProcessHandle, (PVOID *)&p3, 0L, 0, NULL, &ViewSize, ViewUnmap, 0, PAGE_READWRITE ); if (!NT_SUCCESS(status)) { DbgPrint("service failed mapview - status %X\n", status); } RtlMoveMemory ((PVOID)p3, (PVOID)p1, Size); p4 = NULL; ViewSize = 0; status = NtMapViewOfSection (Section1, CurrentProcessHandle, (PVOID *)&p4, 0L, 0, NULL, &ViewSize, ViewUnmap, 0, PAGE_READWRITE ); if (!NT_SUCCESS(status)) { DbgPrint("service failed mapview - status %X\n", status); } status = NtClose (Section1); if (!NT_SUCCESS(status)) { DbgPrint("service failed close sect - status %X\n", status); } status = NtUnmapViewOfSection (CurrentProcessHandle, p3); if (!NT_SUCCESS(status)) { DbgPrint("service failed - status %X\n", status); } status = NtUnmapViewOfSection (CurrentProcessHandle, p4); if (!NT_SUCCESS(status)) { DbgPrint("service failed - status %X\n", status); } } FinishBenchMark( &PerfInfo ); // // Memory Management sub-test 1 -- // // Create a 1 MB segment with commitment of the pages, // then touch each page, which should cause a fault and // a demand zero page to be allocated. // // StartBenchMark( "NT MemMan02 -- alloc 1mb vm, copy 1mb, delete", 150, &PerfInfo ); for (ii=0; ii<150; ii++) { Size = 1024*1024; p3 = NULL; status = NtAllocateVirtualMemory (CurrentProcessHandle, (PVOID *)&p3, 0, &Size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); if (!NT_SUCCESS(status)) { DbgPrint("service failed allocvm - status %X\n", status); } RtlMoveMemory ((PVOID)p3, (PVOID)p1, Size); if (!NT_SUCCESS(status)) { DbgPrint("service failed close sect - status %X\n", status); } status = NtFreeVirtualMemory (CurrentProcessHandle, (PVOID *)&p3, &Size, MEM_RELEASE); if (!NT_SUCCESS(status)) { DbgPrint("service failed freevm - status %X\n", status); } } FinishBenchMark( &PerfInfo ); status = NtFreeVirtualMemory (CurrentProcessHandle, (PVOID *)&p1, &Size, MEM_RELEASE); if (!NT_SUCCESS(status)) { DbgPrint("service failed freevm - status %X\n", status); } // // start regular benchmarks. // StartBenchMark( "NT MemMan1 -- 1 Meg Seg, Create, Commit & Touch", VM_MEMMAN_ITERATIONS, &PerfInfo ); // // Memory Management sub-test 1 -- // // Create a 1 MB segment with commitment of the pages, // then touch each page, which should cause a fault and // a demand zero page to be allocated. // // for (ii=0; iiTitle = Title, PerfInfo->Iterations = Iterations ); NtQuerySystemTime( (PLARGE_INTEGER)&PerfInfo->StartTime ); return( TRUE ); } VOID FinishBenchMark( PPERFINFO PerfInfo ) { ULONG TotalMilliSeconds; ULONG IterationsPerSecond; ULONG IterationFractions; LARGE_INTEGER Delta; NtQuerySystemTime( (PLARGE_INTEGER)&PerfInfo->StopTime ); Delta.QuadPart = PerfInfo->StopTime.QuadPart - PerfInfo->StartTime.QuadPart; TotalMilliSeconds = Delta.LowPart / 10000; IterationsPerSecond = (1000 * PerfInfo->Iterations) / TotalMilliSeconds; IterationFractions = (1000 * PerfInfo->Iterations) % TotalMilliSeconds; IterationFractions = (1000 * IterationFractions) / TotalMilliSeconds; if (1) { DbgPrint( " iterations - %9d\n", PerfInfo->Iterations ); DbgPrint( " milliseconds - %9d\n", TotalMilliSeconds ); DbgPrint( " iterations/sec - %5d.%3d\n\n", IterationsPerSecond, IterationFractions ); } BenchMarkNames[ TotalBenchMarks ] = PerfInfo->Title; BenchMarkRates[ TotalBenchMarks ] = IterationsPerSecond; BenchMarkFracs[ TotalBenchMarks ] = IterationFractions; TotalBenchMarks++; }