New Process & Thread time locking and experimental DPC accounting support.

svn path=/trunk/; revision=10315
This commit is contained in:
James Tabor 2004-07-29 23:28:48 +00:00
parent a769548161
commit acb7361211
3 changed files with 38 additions and 23 deletions

View file

@ -29,14 +29,6 @@
#include "arch/ke.h" #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 ************************************************/ /* INTERNAL KERNEL FUNCTIONS ************************************************/
#ifdef __USE_W32API #ifdef __USE_W32API
@ -106,6 +98,12 @@ KiDeliverNormalApc(VOID);
BOOLEAN STDCALL KeRemoveQueueApc (PKAPC Apc); BOOLEAN STDCALL KeRemoveQueueApc (PKAPC Apc);
PLIST_ENTRY STDCALL KeRundownQueue(IN PKQUEUE Queue); 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 *************************************************/ /* INITIALIZATION FUNCTIONS *************************************************/
VOID KeInitExceptions(VOID); VOID KeInitExceptions(VOID);

View file

@ -18,7 +18,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -42,12 +42,16 @@
#define NDEBUG #define NDEBUG
#include <internal/debug.h> #include <internal/debug.h>
extern volatile ULONGLONG KeTickCount;
/* TYPES *******************************************************************/ /* TYPES *******************************************************************/
/* GLOBALS ******************************************************************/ /* GLOBALS ******************************************************************/
static LIST_ENTRY DpcQueueHead; /* Head of the list of pending DPCs */ static LIST_ENTRY DpcQueueHead; /* Head of the list of pending DPCs */
static KSPIN_LOCK DpcQueueLock; /* Lock for the above list */ static KSPIN_LOCK DpcQueueLock; /* Lock for the above list */
static ULONGLONG DpcTimeInside = 0;
/* /*
* Number of pending DPCs. This is inspected by * Number of pending DPCs. This is inspected by
* the idle thread to determine if the queue needs to * 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; ULONG DpcQueueSize = 0;
/*
* Number of DPC's Processed.
*/
ULONG DpcCount = 0;
/* FUNCTIONS ****************************************************************/ /* FUNCTIONS ****************************************************************/
/* /*
@ -102,6 +111,9 @@ KiDispatchInterrupt(VOID)
KeRaiseIrql(HIGH_LEVEL, &oldlvl); KeRaiseIrql(HIGH_LEVEL, &oldlvl);
KiAcquireSpinLock(&DpcQueueLock); KiAcquireSpinLock(&DpcQueueLock);
DpcTimeInside = KeTickCount;
DpcCount = DpcCount + DpcQueueSize;
while (!IsListEmpty(&DpcQueueHead)) while (!IsListEmpty(&DpcQueueHead))
{ {
current_entry = RemoveHeadList(&DpcQueueHead); current_entry = RemoveHeadList(&DpcQueueHead);
@ -120,6 +132,8 @@ KiDispatchInterrupt(VOID)
KeRaiseIrql(HIGH_LEVEL, &oldlvl); KeRaiseIrql(HIGH_LEVEL, &oldlvl);
KiAcquireSpinLock(&DpcQueueLock); KiAcquireSpinLock(&DpcQueueLock);
} }
KiDpcTime += (KeTickCount - DpcTimeInside);
KiReleaseSpinLock(&DpcQueueLock); KiReleaseSpinLock(&DpcQueueLock);
KeLowerIrql(oldlvl); KeLowerIrql(oldlvl);
} }

View file

@ -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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -27,6 +27,7 @@
#define NDEBUG #define NDEBUG
#include <internal/debug.h> #include <internal/debug.h>
/* GLOBALS ****************************************************************/ /* GLOBALS ****************************************************************/
/* /*
@ -39,9 +40,9 @@ LARGE_INTEGER SystemBootTime = { 0 };
#endif #endif
CHAR KiTimerSystemAuditing = 0; CHAR KiTimerSystemAuditing = 0;
volatile ULONG KiKernelTime; volatile ULONGLONG KiKernelTime;
volatile ULONG KiUserTime; volatile ULONGLONG KiUserTime;
volatile ULONG KiDpcTime; volatile ULONGLONG KiDpcTime;
/* /*
* Number of timer interrupts since initialisation * Number of timer interrupts since initialisation
@ -73,7 +74,6 @@ static KDPC ExpireTimerDpc;
extern ULONG PiNrRunnableThreads; extern ULONG PiNrRunnableThreads;
extern HANDLE PsIdleThreadHandle; extern HANDLE PsIdleThreadHandle;
#define MICROSECONDS_PER_TICK (10000) #define MICROSECONDS_PER_TICK (10000)
#define TICKS_TO_CALIBRATE (1) #define TICKS_TO_CALIBRATE (1)
#define CALIBRATE_PERIOD (MICROSECONDS_PER_TICK * TICKS_TO_CALIBRATE) #define CALIBRATE_PERIOD (MICROSECONDS_PER_TICK * TICKS_TO_CALIBRATE)
@ -644,7 +644,6 @@ KiUpdateSystemTime(KIRQL oldIrql,
*/ */
KeTickCount++; KeTickCount++;
SharedUserData->TickCountLow++; SharedUserData->TickCountLow++;
KiAcquireSpinLock(&TimerValueLock); KiAcquireSpinLock(&TimerValueLock);
Time.u.LowPart = SharedUserData->InterruptTime.LowPart; Time.u.LowPart = SharedUserData->InterruptTime.LowPart;
@ -717,8 +716,8 @@ KiUpdateProcessThreadTime(VOID)
* Make sure no counting can take place until Processes and Threads are * Make sure no counting can take place until Processes and Threads are
* running! * running!
*/ */
if ((PsInitialSystemProcess == NULL) || if ((PsInitialSystemProcess == NULL) || (PsIdleThreadHandle == NULL) ||
(PsIdleThreadHandle == NULL) || (KiTimerSystemAuditing == 0)) (KiTimerSystemAuditing == 0))
{ {
return; return;
} }
@ -728,18 +727,22 @@ KiUpdateProcessThreadTime(VOID)
DPRINT("KiKernelTime %u, KiUserTime %u \n", KiKernelTime, KiUserTime); DPRINT("KiKernelTime %u, KiUserTime %u \n", KiKernelTime, KiUserTime);
/* Over kill with locks. */
KiAcquireSpinLock(&TimeLock); KiAcquireSpinLock(&TimeLock);
if (CurrentThread->PreviousMode == UserMode) if (CurrentThread->PreviousMode == UserMode)
{ {
++CurrentThread->UserTime; /* Lock the process & thread time. This should lock everything
++CurrentProcess->UserTime; * all the way down to the process & thread stuct.
*/
InterlockedIncrement((LONG *)&CurrentProcess->UserTime);
InterlockedIncrement((LONG *)&CurrentThread->UserTime);
++KiUserTime; ++KiUserTime;
} }
if (CurrentThread->PreviousMode == KernelMode) if (CurrentThread->PreviousMode == KernelMode)
{ {
++CurrentProcess->KernelTime; InterlockedIncrement((LONG *)&CurrentProcess->KernelTime);
++CurrentThread->KernelTime; InterlockedIncrement((LONG *)&CurrentThread->KernelTime);
++KiKernelTime; ++KiKernelTime;
} }
@ -777,8 +780,8 @@ KeUpdateRunTime(
STDCALL STDCALL
VOID VOID
KeUpdateSystemTime( KeUpdateSystemTime(
IN PKTRAP_FRAME TrapFrame, IN PKTRAP_FRAME TrapFrame,
IN ULONG Increment IN ULONG Increment
) )
{ {
UNIMPLEMENTED; UNIMPLEMENTED;