mirror of
https://github.com/reactos/reactos.git
synced 2025-07-27 07:41:51 +00:00
[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. svn path=/branches/ntvdm/; revision=60783
This commit is contained in:
parent
b8d8b21ebd
commit
97acc35c7c
3 changed files with 45 additions and 7 deletions
|
@ -151,19 +151,37 @@ INT wmain(INT argc, WCHAR *argv[])
|
||||||
/* Main loop */
|
/* Main loop */
|
||||||
while (VdmRunning)
|
while (VdmRunning)
|
||||||
{
|
{
|
||||||
|
/* Get the resolution of the system timer */
|
||||||
|
DWORD TimerResolution = PitGetResolution();
|
||||||
|
|
||||||
/* Get the current number of ticks */
|
/* Get the current number of ticks */
|
||||||
CurrentTickCount = GetTickCount();
|
CurrentTickCount = GetTickCount();
|
||||||
|
|
||||||
|
if (TimerResolution > 1000)
|
||||||
|
{
|
||||||
/* Get the current performance counter value */
|
/* Get the current performance counter value */
|
||||||
QueryPerformanceCounter(&Counter);
|
QueryPerformanceCounter(&Counter);
|
||||||
|
|
||||||
/* Get the number of PIT ticks that have passed */
|
/* Get the number of PIT ticks that have passed */
|
||||||
TimerTicks = ((Counter.QuadPart - LastTimerTick.QuadPart)
|
TimerTicks = ((Counter.QuadPart - LastTimerTick.QuadPart)
|
||||||
* PIT_BASE_FREQUENCY) / Frequency.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 */
|
/* Update the PIT */
|
||||||
|
if (TimerTicks > 0)
|
||||||
|
{
|
||||||
for (i = 0; i < TimerTicks; i++) PitDecrementCount();
|
for (i = 0; i < TimerTicks; i++) PitDecrementCount();
|
||||||
LastTimerTick = Counter;
|
LastTimerTick = Counter;
|
||||||
|
}
|
||||||
|
|
||||||
/* Check for vertical retrace */
|
/* Check for vertical retrace */
|
||||||
if ((CurrentTickCount - LastVerticalRefresh) >= 16)
|
if ((CurrentTickCount - LastVerticalRefresh) >= 16)
|
||||||
|
|
|
@ -233,4 +233,23 @@ VOID PitDecrementCount()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 */
|
/* EOF */
|
||||||
|
|
|
@ -49,6 +49,7 @@ VOID PitWriteCommand(BYTE Value);
|
||||||
BYTE PitReadData(BYTE Channel);
|
BYTE PitReadData(BYTE Channel);
|
||||||
VOID PitWriteData(BYTE Channel, BYTE Value);
|
VOID PitWriteData(BYTE Channel, BYTE Value);
|
||||||
VOID PitDecrementCount();
|
VOID PitDecrementCount();
|
||||||
|
DWORD PitGetResolution(VOID);
|
||||||
|
|
||||||
#endif // _TIMER_H_
|
#endif // _TIMER_H_
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue