Author: aandrejevic
Date: Mon Oct 28 02:25:54 2013
New Revision: 60783
URL:
http://svn.reactos.org/svn/reactos?rev=60783&view=rev
Log:
[NTVDM]
Improve performance by computing the resolution required by the PIT,
and then using the standard tick count instead of performance counters
when that resolution is low.
Modified:
branches/ntvdm/subsystems/ntvdm/ntvdm.c
branches/ntvdm/subsystems/ntvdm/timer.c
branches/ntvdm/subsystems/ntvdm/timer.h
Modified: branches/ntvdm/subsystems/ntvdm/ntvdm.c
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/ntvdm.c?…
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/ntvdm.c [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/ntvdm/ntvdm.c [iso-8859-1] Mon Oct 28 02:25:54 2013
@@ -151,19 +151,37 @@
/* Main loop */
while (VdmRunning)
{
+ /* Get the resolution of the system timer */
+ DWORD TimerResolution = PitGetResolution();
+
/* Get the current number of ticks */
CurrentTickCount = GetTickCount();
- /* Get the current performance counter value */
- QueryPerformanceCounter(&Counter);
-
- /* Get the number of PIT ticks that have passed */
- TimerTicks = ((Counter.QuadPart - LastTimerTick.QuadPart)
- * PIT_BASE_FREQUENCY) / Frequency.QuadPart;
+ if (TimerResolution > 1000)
+ {
+ /* Get the current performance counter value */
+ QueryPerformanceCounter(&Counter);
+
+ /* Get the number of PIT ticks that have passed */
+ TimerTicks = ((Counter.QuadPart - LastTimerTick.QuadPart)
+ * PIT_BASE_FREQUENCY) / Frequency.QuadPart;
+ }
+ else
+ {
+ /* Use the standard tick count */
+ Counter.QuadPart = CurrentTickCount;
+
+ /* Get the number of PIT ticks that have passed */
+ TimerTicks = ((Counter.QuadPart - LastTimerTick.QuadPart)
+ * PIT_BASE_FREQUENCY) / 1000;
+ }
/* Update the PIT */
- for (i = 0; i < TimerTicks; i++) PitDecrementCount();
- LastTimerTick = Counter;
+ if (TimerTicks > 0)
+ {
+ for (i = 0; i < TimerTicks; i++) PitDecrementCount();
+ LastTimerTick = Counter;
+ }
/* Check for vertical retrace */
if ((CurrentTickCount - LastVerticalRefresh) >= 16)
Modified: branches/ntvdm/subsystems/ntvdm/timer.c
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/timer.c?…
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/timer.c [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/ntvdm/timer.c [iso-8859-1] Mon Oct 28 02:25:54 2013
@@ -233,4 +233,23 @@
}
}
+DWORD PitGetResolution(VOID)
+{
+ INT i;
+ DWORD MinReloadValue = 65536;
+
+ for (i = 0; i < PIT_CHANNELS; i++)
+ {
+ DWORD ReloadValue = PitChannels[i].ReloadValue;
+
+ /* 0 means 65536 */
+ if (ReloadValue == 0) ReloadValue = 65536;
+
+ if (ReloadValue < MinReloadValue) MinReloadValue = ReloadValue;
+ }
+
+ /* Return the frequency resolution */
+ return PIT_BASE_FREQUENCY / MinReloadValue;
+}
+
/* EOF */
Modified: branches/ntvdm/subsystems/ntvdm/timer.h
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/timer.h?…
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/timer.h [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/ntvdm/timer.h [iso-8859-1] Mon Oct 28 02:25:54 2013
@@ -49,6 +49,7 @@
BYTE PitReadData(BYTE Channel);
VOID PitWriteData(BYTE Channel, BYTE Value);
VOID PitDecrementCount();
+DWORD PitGetResolution(VOID);
#endif // _TIMER_H_