- Update KeUpdateSystemTime to use variable increments.

- Update KeTickCount properly instead of an ugly timecast hack.
- Also update UserSharedData->TickCount.
- Get rid of KiRawTicks.
- Properly update KiTickOffset at the end.

svn path=/trunk/; revision=23679
This commit is contained in:
Alex Ionescu 2006-08-24 06:27:29 +00:00
parent 8b82c0d641
commit 5e7ef1d665
7 changed files with 42 additions and 23 deletions

View file

@ -246,6 +246,16 @@ Author:
//
// KUSER_SHARED_DATA Offsets
//
#ifdef __ASM__
#define USER_SHARED_DATA 0xFFDF0000
#endif
#define USER_SHARED_DATA_INTERRUPT_TIME 0x8
#define USER_SHARED_DATA_SYSTEM_TIME 0x14
#define USER_SHARED_DATA_TICK_COUNT 0x320
//
// KUSER_SHARED_DATA Offsets (this stuff is trash)
//
#define KERNEL_USER_SHARED_DATA 0x7FFE0000
#define KUSER_SHARED_PROCESSOR_FEATURES KERNEL_USER_SHARED_DATA + 0x274
#define KUSER_SHARED_SYSCALL KERNEL_USER_SHARED_DATA + 0x300

View file

@ -231,7 +231,8 @@ VOID
NTAPI
KeUpdateSystemTime(
PKTRAP_FRAME TrapFrame,
KIRQL Irql
KIRQL Irql,
ULONG Increment
);
VOID

View file

@ -258,13 +258,6 @@ BOOLEAN
STDCALL
KiRosPrintAddress(PVOID Address);
VOID
STDCALL
KeUpdateSystemTime(
PKTRAP_FRAME TrapFrame,
KIRQL Irql
);
VOID
STDCALL
KeUpdateRunTime(

View file

@ -63,6 +63,7 @@ extern LIST_ENTRY KiTimerListHead;
ULONG KeMaximumIncrement = 100000;
ULONG KeMinimumIncrement = 100000;
ULONG KeTimeAdjustment = 100000;
#define MICROSECONDS_PER_TICK (10000)
#define TICKS_TO_CALIBRATE (1)
@ -353,23 +354,23 @@ KeUpdateRunTime(IN PKTRAP_FRAME TrapFrame,
VOID
STDCALL
KeUpdateSystemTime(IN PKTRAP_FRAME TrapFrame,
IN KIRQL Irql)
IN KIRQL Irql,
IN ULONG Increment)
{
LONG OldOffset;
LARGE_INTEGER Time;
ASSERT(KeGetCurrentIrql() == PROFILE_LEVEL);
if (!KiClockSetupComplete) return;
/* Update interrupt time */
Time.LowPart = SharedUserData->InterruptTime.LowPart;
Time.HighPart = SharedUserData->InterruptTime.High1Time;
Time.QuadPart += CLOCK_INCREMENT;
Time.QuadPart += Increment;
SharedUserData->InterruptTime.High2Time = Time.u.HighPart;
SharedUserData->InterruptTime.LowPart = Time.u.LowPart;
SharedUserData->InterruptTime.High1Time = Time.u.HighPart;
/* Increase the tick offset */
KiTickOffset -= CLOCK_INCREMENT;
KiTickOffset -= Increment;
OldOffset = KiTickOffset;
/* Check if this isn't a tick yet */
@ -380,28 +381,39 @@ KeUpdateSystemTime(IN PKTRAP_FRAME TrapFrame,
}
else
{
/* This was a tick, calculate the next one */
KiTickOffset += CLOCK_INCREMENT;
/* Setup time structure for system time */
Time.LowPart = SharedUserData->SystemTime.LowPart;
Time.HighPart = SharedUserData->SystemTime.High1Time;
Time.QuadPart += CLOCK_INCREMENT;
Time.QuadPart += KeTimeAdjustment;
SharedUserData->SystemTime.High2Time = Time.HighPart;
SharedUserData->SystemTime.LowPart = Time.LowPart;
SharedUserData->SystemTime.High1Time = Time.HighPart;
/* Update tick count */
(*(PULONGLONG)&KeTickCount)++;
/* Setup time structure for tick time */
Time.LowPart = KeTickCount.LowPart;
Time.HighPart = KeTickCount.High1Time;
Time.QuadPart += 1;
KeTickCount.High2Time = Time.HighPart;
KeTickCount.LowPart = Time.LowPart;
KeTickCount.High1Time = Time.HighPart;
SharedUserData->TickCount.High2Time = Time.HighPart;
SharedUserData->TickCount.LowPart = Time.LowPart;
SharedUserData->TickCount.High1Time = Time.HighPart;
/* Update tick count in shared user data as well */
SharedUserData->TickCountLowDeprecated++;
KiRawTicks++;
/* Queue a DPC that will expire timers */
KeInsertQueueDpc(&KiExpireTimerDpc, (PVOID)TrapFrame->Eip, 0);
}
/* Update process and thread times */
if (OldOffset <= 0) KeUpdateRunTime(TrapFrame, Irql);
if (OldOffset <= 0)
{
/* This was a tick, calculate the next one */
KiTickOffset += KeMaximumIncrement;
KeUpdateRunTime(TrapFrame, Irql);
}
}
/*

View file

@ -153,8 +153,11 @@ KiInterruptDispatch (ULONG vector, PKIRQ_TRAPFRAME Trapframe)
Ke386EnableInterrupts();
//DPRINT1("Tick\n");
if (KiClockSetupComplete)
{
KeIRQTrapFrameToTrapFrame(Trapframe, &KernelTrapFrame);
KeUpdateSystemTime(&KernelTrapFrame, old_level);
KeUpdateSystemTime(&KernelTrapFrame, old_level, 100000);
}
/*
* End the system interrupt.

View file

@ -12,7 +12,7 @@
#include <internal/i386/asmmacro.S>
.intel_syntax noprefix
/* GLOBALS ******************************************************************/
/* GLOBALS *******************************************************************/
.globl _KiIdt
_KiIdt:

View file

@ -648,7 +648,7 @@ KeTerminateThread@4
KeTickCount DATA
@KeTryToAcquireGuardedMutex@4
KeUpdateRunTime@8
KeUpdateSystemTime@8
KeUpdateSystemTime@12
KeUnstackDetachProcess@4
KeUserModeCallback@20
KeWaitForMultipleObjects@32