From edaa6996f407fb19d5b152a0e754a63c7d9d4e2c Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Mon, 23 Oct 2006 22:01:25 +0000 Subject: [PATCH] - Properly implement inline versions of KeGetCurrentThread and KeGetPreviousMode/ExGetPreviousMode, as well as KeGetPcr. This should significantly increase performance. (KeGetPreviousMode is reduced to 2 lines of code instead of 15 lines with 2 expensive jumps). svn path=/trunk/; revision=24639 --- reactos/include/ddk/winddk.h | 6 ------ reactos/include/ndk/ketypes.h | 2 +- reactos/ntoskrnl/ex/sysinfo.c | 3 ++- reactos/ntoskrnl/include/internal/ex.h | 1 + reactos/ntoskrnl/include/internal/ke_x.h | 15 +++++++++++++++ reactos/ntoskrnl/include/internal/ntoskrnl.h | 3 +++ reactos/ntoskrnl/ke/thrdobj.c | 7 ++++--- 7 files changed, 26 insertions(+), 11 deletions(-) diff --git a/reactos/include/ddk/winddk.h b/reactos/include/ddk/winddk.h index 71c9603c88b..58213023121 100644 --- a/reactos/include/ddk/winddk.h +++ b/reactos/include/ddk/winddk.h @@ -8678,12 +8678,6 @@ NTAPI KeGetCurrentThread( VOID); -NTKERNELAPI -KPROCESSOR_MODE -NTAPI -KeGetPreviousMode( - VOID); - NTKERNELAPI ULONG NTAPI diff --git a/reactos/include/ndk/ketypes.h b/reactos/include/ndk/ketypes.h index ca11ac4341d..6cb747dafa7 100644 --- a/reactos/include/ndk/ketypes.h +++ b/reactos/include/ndk/ketypes.h @@ -95,7 +95,7 @@ Author: // #define K0IPCR ((ULONG_PTR)(KIP0PCRADDRESS)) #define PCR ((volatile KPCR * const)K0IPCR) -#ifdef _WE_USE_THE_SAME_PCR_ADDRESS +#if !defined(CONFIG_SMP) && !defined(NT_BUILD) #define KeGetPcr() PCR #else #define KeGetPcr() ((volatile KPCR * const)__readfsdword(0x1C)) diff --git a/reactos/ntoskrnl/ex/sysinfo.c b/reactos/ntoskrnl/ex/sysinfo.c index 27888f155bd..1cab664394d 100644 --- a/reactos/ntoskrnl/ex/sysinfo.c +++ b/reactos/ntoskrnl/ex/sysinfo.c @@ -30,11 +30,12 @@ LIST_ENTRY ExpFirmwareTableProviderListHead; /* * @implemented */ +#undef ExGetPreviousMode KPROCESSOR_MODE NTAPI ExGetPreviousMode (VOID) { - return (KPROCESSOR_MODE)PsGetCurrentThread()->Tcb.PreviousMode; + return KeGetPreviousMode(); } /* diff --git a/reactos/ntoskrnl/include/internal/ex.h b/reactos/ntoskrnl/include/internal/ex.h index 15f82953381..a1966334320 100644 --- a/reactos/ntoskrnl/include/internal/ex.h +++ b/reactos/ntoskrnl/include/internal/ex.h @@ -47,6 +47,7 @@ PVOID ExpNlsSectionPointer; #define ExInitializeRundownProtection _ExInitializeRundownProtection #define ExWaitForRundownProtectionRelease _ExWaitForRundownProtectionRelease #define ExRundownCompleted _ExRundownCompleted +#define ExGetPreviousMode KeGetPreviousMode /* INITIALIZATION FUNCTIONS *************************************************/ diff --git a/reactos/ntoskrnl/include/internal/ke_x.h b/reactos/ntoskrnl/include/internal/ke_x.h index f90b97a99f4..5f051e849ac 100644 --- a/reactos/ntoskrnl/include/internal/ke_x.h +++ b/reactos/ntoskrnl/include/internal/ke_x.h @@ -1263,3 +1263,18 @@ KiComputeNewPriority(IN PKTHREAD Thread) return Priority; } +PRKTHREAD +FORCEINLINE +KeGetCurrentThread(VOID) +{ + /* Return the current thread */ + return ((PKIPCR)KeGetPcr())->PrcbData.CurrentThread; +} + +UCHAR +FORCEINLINE +KeGetPreviousMode(VOID) +{ + /* Return the current mode */ + return KeGetCurrentThread()->PreviousMode; +} diff --git a/reactos/ntoskrnl/include/internal/ntoskrnl.h b/reactos/ntoskrnl/include/internal/ntoskrnl.h index aab97128eb1..d62290a1dbb 100644 --- a/reactos/ntoskrnl/include/internal/ntoskrnl.h +++ b/reactos/ntoskrnl/include/internal/ntoskrnl.h @@ -17,6 +17,9 @@ #ifdef _NTOSKRNL_ +#define KeGetCurrentThread _KeGetCurrentThread +#define KeGetPreviousMode _KeGetPreviousMode + #include "ke.h" #include "i386/mm.h" #include "i386/fpu.h" diff --git a/reactos/ntoskrnl/ke/thrdobj.c b/reactos/ntoskrnl/ke/thrdobj.c index e2f63f6ab85..83290b40744 100644 --- a/reactos/ntoskrnl/ke/thrdobj.c +++ b/reactos/ntoskrnl/ke/thrdobj.c @@ -882,18 +882,19 @@ NTAPI KeGetCurrentThread(VOID) { /* Return the current thread on this PCR */ - return ((PKIPCR)KeGetPcr())->PrcbData.CurrentThread; + return _KeGetCurrentThread(); } /* * @implemented */ -KPROCESSOR_MODE +#undef KeGetPreviousMode +UCHAR NTAPI KeGetPreviousMode(VOID) { /* Return the previous mode of this thread */ - return KeGetCurrentThread()->PreviousMode; + return _KeGetPreviousMode(); } /*