[NTOSKRNL] Print boot cycles on x64 just like on x86
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Sat, 27 Aug 2022 14:09:41 +0000 (16:09 +0200)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Thu, 24 Nov 2022 19:17:58 +0000 (21:17 +0200)
ntoskrnl/include/internal/amd64/ke.h
ntoskrnl/ke/amd64/kiinit.c

index 97fa0f9..318b119 100644 (file)
@@ -1,6 +1,10 @@
 #ifndef __NTOSKRNL_INCLUDE_INTERNAL_AMD64_KE_H
 #define __NTOSKRNL_INCLUDE_INTERNAL_AMD64_KE_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define X86_EFLAGS_TF           0x00000100 /* Trap flag */
 #define X86_EFLAGS_IF           0x00000200 /* Interrupt Enable flag */
 #define X86_EFLAGS_IOPL         0x00003000 /* I/O Privilege Level bits */
@@ -363,7 +367,21 @@ KiUserTrap(IN PKTRAP_FRAME TrapFrame)
     return !!(TrapFrame->SegCs & MODE_MASK);
 }
 
-#define Ki386PerfEnd()
+//
+// PERF Code
+//
+FORCEINLINE
+VOID
+Ki386PerfEnd(VOID)
+{
+    extern ULONGLONG BootCyclesEnd, BootCycles;
+    BootCyclesEnd = __rdtsc();
+    DbgPrint("Boot took %I64u cycles!\n", BootCyclesEnd - BootCycles);
+    DbgPrint("Interrupts: %u System Calls: %u Context Switches: %u\n",
+             KeGetCurrentPrcb()->InterruptCount,
+             KeGetCurrentPrcb()->KeSystemCalls,
+             KeGetContextSwitches(KeGetCurrentPrcb()));
+}
 
 struct _KPCR;
 
@@ -455,6 +473,10 @@ KiSetTrapContext(
     _In_ PCONTEXT Context,
     _In_ KPROCESSOR_MODE RequestorMode);
 
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
 #endif /* __NTOSKRNL_INCLUDE_INTERNAL_AMD64_KE_H */
 
 /* EOF */
index 3108104..6581929 100644 (file)
@@ -34,6 +34,8 @@ UCHAR DECLSPEC_ALIGN(16) KiDoubleFaultStackData[KERNEL_STACK_SIZE] = {0};
 ULONG_PTR P0BootStack = (ULONG_PTR)&P0BootStackData[KERNEL_STACK_SIZE];
 ULONG_PTR KiDoubleFaultStack = (ULONG_PTR)&KiDoubleFaultStackData[KERNEL_STACK_SIZE];
 
+ULONGLONG BootCycles, BootCyclesEnd;
+
 void KiInitializeSegments();
 void KiSystemCallEntry64();
 void KiSystemCallEntry32();
@@ -382,6 +384,9 @@ KiSystemStartup(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
     ULONG64 InitialStack;
     PKIPCR Pcr;
 
+    /* Boot cycles timestamp */
+    BootCycles = __rdtsc();
+
     /* HACK */
     FrLdrDbgPrint = LoaderBlock->u.I386.CommonDataArea;
     //FrLdrDbgPrint("Hello from KiSystemStartup!!!\n");