From acb7361211fda6effb9d2a45f2b1b8751c66e7f9 Mon Sep 17 00:00:00 2001 From: James Tabor Date: Thu, 29 Jul 2004 23:28:48 +0000 Subject: [PATCH] New Process & Thread time locking and experimental DPC accounting support. svn path=/trunk/; revision=10315 --- reactos/ntoskrnl/include/internal/ke.h | 14 +++++------- reactos/ntoskrnl/ke/dpc.c | 16 ++++++++++++- reactos/ntoskrnl/ke/timer.c | 31 ++++++++++++++------------ 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/reactos/ntoskrnl/include/internal/ke.h b/reactos/ntoskrnl/include/internal/ke.h index 49d122d2ae1..a3f26d1a0a6 100644 --- a/reactos/ntoskrnl/include/internal/ke.h +++ b/reactos/ntoskrnl/include/internal/ke.h @@ -29,14 +29,6 @@ #include "arch/ke.h" - -#ifndef __ASM__ -extern LARGE_INTEGER SystemBootTime; -extern volatile ULONG KiKernelTime; -extern volatile ULONG KiUserTime; -extern volatile ULONG KiDpcTime; -#endif - /* INTERNAL KERNEL FUNCTIONS ************************************************/ #ifdef __USE_W32API @@ -106,6 +98,12 @@ KiDeliverNormalApc(VOID); BOOLEAN STDCALL KeRemoveQueueApc (PKAPC Apc); PLIST_ENTRY STDCALL KeRundownQueue(IN PKQUEUE Queue); +extern LARGE_INTEGER SystemBootTime; +extern volatile ULONGLONG KiKernelTime; +extern volatile ULONGLONG KiUserTime; +extern volatile ULONGLONG KiDpcTime; + + /* INITIALIZATION FUNCTIONS *************************************************/ VOID KeInitExceptions(VOID); diff --git a/reactos/ntoskrnl/ke/dpc.c b/reactos/ntoskrnl/ke/dpc.c index df8388d5a63..bbbfdf85e5c 100644 --- a/reactos/ntoskrnl/ke/dpc.c +++ b/reactos/ntoskrnl/ke/dpc.c @@ -18,7 +18,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: dpc.c,v 1.31 2004/06/23 22:31:51 ion Exp $ +/* $Id: dpc.c,v 1.32 2004/07/29 23:28:31 jimtabor Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -42,12 +42,16 @@ #define NDEBUG #include +extern volatile ULONGLONG KeTickCount; + /* TYPES *******************************************************************/ /* GLOBALS ******************************************************************/ static LIST_ENTRY DpcQueueHead; /* Head of the list of pending DPCs */ static KSPIN_LOCK DpcQueueLock; /* Lock for the above list */ +static ULONGLONG DpcTimeInside = 0; + /* * Number of pending DPCs. This is inspected by * the idle thread to determine if the queue needs to @@ -55,6 +59,11 @@ static KSPIN_LOCK DpcQueueLock; /* Lock for the above list */ */ ULONG DpcQueueSize = 0; +/* + * Number of DPC's Processed. + */ +ULONG DpcCount = 0; + /* FUNCTIONS ****************************************************************/ /* @@ -102,6 +111,9 @@ KiDispatchInterrupt(VOID) KeRaiseIrql(HIGH_LEVEL, &oldlvl); KiAcquireSpinLock(&DpcQueueLock); + DpcTimeInside = KeTickCount; + DpcCount = DpcCount + DpcQueueSize; + while (!IsListEmpty(&DpcQueueHead)) { current_entry = RemoveHeadList(&DpcQueueHead); @@ -120,6 +132,8 @@ KiDispatchInterrupt(VOID) KeRaiseIrql(HIGH_LEVEL, &oldlvl); KiAcquireSpinLock(&DpcQueueLock); } + KiDpcTime += (KeTickCount - DpcTimeInside); + KiReleaseSpinLock(&DpcQueueLock); KeLowerIrql(oldlvl); } diff --git a/reactos/ntoskrnl/ke/timer.c b/reactos/ntoskrnl/ke/timer.c index bfb7ad2334a..18902792b49 100644 --- a/reactos/ntoskrnl/ke/timer.c +++ b/reactos/ntoskrnl/ke/timer.c @@ -1,4 +1,4 @@ -/* $Id: timer.c,v 1.74 2004/06/23 22:31:51 ion Exp $ +/* $Id: timer.c,v 1.75 2004/07/29 23:28:31 jimtabor Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -27,6 +27,7 @@ #define NDEBUG #include + /* GLOBALS ****************************************************************/ /* @@ -39,9 +40,9 @@ LARGE_INTEGER SystemBootTime = { 0 }; #endif CHAR KiTimerSystemAuditing = 0; -volatile ULONG KiKernelTime; -volatile ULONG KiUserTime; -volatile ULONG KiDpcTime; +volatile ULONGLONG KiKernelTime; +volatile ULONGLONG KiUserTime; +volatile ULONGLONG KiDpcTime; /* * Number of timer interrupts since initialisation @@ -73,7 +74,6 @@ static KDPC ExpireTimerDpc; extern ULONG PiNrRunnableThreads; extern HANDLE PsIdleThreadHandle; - #define MICROSECONDS_PER_TICK (10000) #define TICKS_TO_CALIBRATE (1) #define CALIBRATE_PERIOD (MICROSECONDS_PER_TICK * TICKS_TO_CALIBRATE) @@ -644,7 +644,6 @@ KiUpdateSystemTime(KIRQL oldIrql, */ KeTickCount++; SharedUserData->TickCountLow++; - KiAcquireSpinLock(&TimerValueLock); Time.u.LowPart = SharedUserData->InterruptTime.LowPart; @@ -717,8 +716,8 @@ KiUpdateProcessThreadTime(VOID) * Make sure no counting can take place until Processes and Threads are * running! */ - if ((PsInitialSystemProcess == NULL) || - (PsIdleThreadHandle == NULL) || (KiTimerSystemAuditing == 0)) + if ((PsInitialSystemProcess == NULL) || (PsIdleThreadHandle == NULL) || + (KiTimerSystemAuditing == 0)) { return; } @@ -728,18 +727,22 @@ KiUpdateProcessThreadTime(VOID) DPRINT("KiKernelTime %u, KiUserTime %u \n", KiKernelTime, KiUserTime); + /* Over kill with locks. */ KiAcquireSpinLock(&TimeLock); if (CurrentThread->PreviousMode == UserMode) { - ++CurrentThread->UserTime; - ++CurrentProcess->UserTime; + /* Lock the process & thread time. This should lock everything + * all the way down to the process & thread stuct. + */ + InterlockedIncrement((LONG *)&CurrentProcess->UserTime); + InterlockedIncrement((LONG *)&CurrentThread->UserTime); ++KiUserTime; } if (CurrentThread->PreviousMode == KernelMode) { - ++CurrentProcess->KernelTime; - ++CurrentThread->KernelTime; + InterlockedIncrement((LONG *)&CurrentProcess->KernelTime); + InterlockedIncrement((LONG *)&CurrentThread->KernelTime); ++KiKernelTime; } @@ -777,8 +780,8 @@ KeUpdateRunTime( STDCALL VOID KeUpdateSystemTime( - IN PKTRAP_FRAME TrapFrame, - IN ULONG Increment + IN PKTRAP_FRAME TrapFrame, + IN ULONG Increment ) { UNIMPLEMENTED;