<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[36748] trunk/WebCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/36748">36748</a></dd>
<dt>Author</dt> <dd>sfalken@apple.com</dd>
<dt>Date</dt> <dd>2008-09-21 17:08:30 -0700 (Sun, 21 Sep 2008)</dd>
</dl>
<h3>Log Message</h3>
<pre> Improve timer resolution on WinXP.
https://bugs.webkit.org/show_bug.cgi?id=20979
Removed last-chance timer. It should not be necessary.
Change timeEndPeriod timer to fire in 300ms instead of 20ms. Calling timeBeginPeriod/timeEndPeriod too often throws off accuracy.
Remove Vista checks. We now run the same code on both XP and Vista.
Call through to JSC::getCurrentUTCTimeWithMicroseconds from WebCore::currentTime.
The code previously called GetSystemTimeAsFileTime, which is always low-resolution on XP, even within timeBeginPeriod(1).
Reviewed by Maciej Stachowiak.
* platform/win/SharedTimerWin.cpp:
(WebCore::):
(WebCore::TimerWindowWndProc):
(WebCore::setSharedTimerFireTime):
* platform/win/SystemTimeWin.cpp:
(WebCore::currentTime):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkWebCoreChangeLog">trunk/WebCore/ChangeLog</a></li>
<li><a href="#trunkWebCoreplatformwinSharedTimerWincpp">trunk/WebCore/platform/win/SharedTimerWin.cpp</a></li>
<li><a href="#trunkWebCoreplatformwinSystemTimeWincpp">trunk/WebCore/platform/win/SystemTimeWin.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/ChangeLog (36747 => 36748)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/ChangeLog 2008-09-22 00:01:21 UTC (rev 36747)
+++ trunk/WebCore/ChangeLog 2008-09-22 00:08:30 UTC (rev 36748)
</span><span class="lines">@@ -1,3 +1,24 @@
</span><ins>+2008-09-21 Steve Falkenburg <sfalken@apple.com>
+
+ Improve timer resolution on WinXP.
+ https://bugs.webkit.org/show_bug.cgi?id=20979
+
+ Removed last-chance timer. It should not be necessary.
+ Change timeEndPeriod timer to fire in 300ms instead of 20ms. Calling timeBeginPeriod/timeEndPeriod too often throws off accuracy.
+ Remove Vista checks. We now run the same code on both XP and Vista.
+
+ Call through to JSC::getCurrentUTCTimeWithMicroseconds from WebCore::currentTime.
+ The code previously called GetSystemTimeAsFileTime, which is always low-resolution on XP, even within timeBeginPeriod(1).
+
+ Reviewed by Maciej Stachowiak.
+
+ * platform/win/SharedTimerWin.cpp:
+ (WebCore::):
+ (WebCore::TimerWindowWndProc):
+ (WebCore::setSharedTimerFireTime):
+ * platform/win/SystemTimeWin.cpp:
+ (WebCore::currentTime):
+
</ins><span class="cx"> 2008-09-21 Dirk Schulze <vbs85@gmx.de>
</span><span class="cx">
</span><span class="cx"> Reviewed by eseidel. Landed by eseidel.
</span></span></pre></div>
<a id="trunkWebCoreplatformwinSharedTimerWincpp"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/platform/win/SharedTimerWin.cpp (36747 => 36748)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/platform/win/SharedTimerWin.cpp 2008-09-22 00:01:21 UTC (rev 36747)
+++ trunk/WebCore/platform/win/SharedTimerWin.cpp 2008-09-22 00:08:30 UTC (rev 36748)
</span><span class="lines">@@ -62,7 +62,6 @@
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><span class="cx"> static UINT timerID;
</span><del>-static UINT lastChanceTimerID;
</del><span class="cx"> static void (*sharedTimerFiredFunction)();
</span><span class="cx">
</span><span class="cx"> static HWND timerWindowHandle = 0;
</span><span class="lines">@@ -75,34 +74,15 @@
</span><span class="cx"> static LONG pendingTimers;
</span><span class="cx">
</span><span class="cx"> const LPCWSTR kTimerWindowClassName = L"TimerWindowClass";
</span><del>-const int timerResolution = 1;
-const int highResolutionThresholdMsec = 16;
-const int stopHighResTimerInMsec = 20;
-const int lastChanceTimerIntervalInMS = 5000;
</del><ins>+const int timerResolution = 1; // To improve timer resolution, we call timeBeginPeriod/timeEndPeriod with this value to increase timer resolution to 1ms.
+const int highResolutionThresholdMsec = 16; // Only activate high-res timer for sub-16ms timers (Windows can fire timers at 16ms intervals without changing the system resolution).
+const int stopHighResTimerInMsec = 300; // Stop high-res timer after 0.3 seconds to lessen power consumption (we don't use a smaller time since oscillating between high and low resolution breaks timer accuracy on XP).
</ins><span class="cx">
</span><span class="cx"> enum {
</span><span class="cx"> sharedTimerID = 1000,
</span><span class="cx"> endHighResTimerID = 1001,
</span><del>- lastChanceSharedTimerID = 1002,
</del><span class="cx"> };
</span><span class="cx">
</span><del>-static bool isRunningOnVistaOrLater()
-{
- static bool os = false;
- static bool initialized = false;
- if (!initialized) {
- OSVERSIONINFOEX vi = {sizeof(vi), 0};
- GetVersionEx((OSVERSIONINFO*)&vi);
-
- // NOTE: This does not work under a debugger - Vista shims Visual Studio,
- // making it believe it is xpsp2, which is inherited by debugged applications
- os = vi.dwMajorVersion >= 6;
- initialized = true;
- }
-
- return os;
-}
-
</del><span class="cx"> LRESULT CALLBACK TimerWindowWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
</span><span class="cx"> {
</span><span class="cx"> #if PLATFORM(WIN)
</span><span class="lines">@@ -122,7 +102,7 @@
</span><span class="cx"> sharedTimerFiredFunction();
</span><span class="cx"> processingCustomTimerMessage = false;
</span><span class="cx"> } else if (message == WM_TIMER) {
</span><del>- if (wParam == sharedTimerID || wParam == lastChanceSharedTimerID && !isDeferringTimers()) {
</del><ins>+ if (wParam == sharedTimerID && !isDeferringTimers()) {
</ins><span class="cx"> KillTimer(timerWindowHandle, sharedTimerID);
</span><span class="cx"> sharedTimerFiredFunction();
</span><span class="cx"> } else if (wParam == endHighResTimerID) {
</span><span class="lines">@@ -176,7 +156,6 @@
</span><span class="cx"> void setSharedTimerFireTime(double fireTime)
</span><span class="cx"> {
</span><span class="cx"> ASSERT(sharedTimerFiredFunction);
</span><del>- bool isRunningVista = isRunningOnVistaOrLater();
</del><span class="cx">
</span><span class="cx"> double interval = fireTime - currentTime();
</span><span class="cx"> unsigned intervalInMS;
</span><span class="lines">@@ -190,7 +169,7 @@
</span><span class="cx"> intervalInMS = (unsigned)interval;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- if (isRunningVista && interval < highResolutionThresholdMsec) {
</del><ins>+ if (interval < highResolutionThresholdMsec) {
</ins><span class="cx"> if (!highResTimerActive) {
</span><span class="cx"> highResTimerActive = true;
</span><span class="cx"> timeBeginPeriod(timerResolution);
</span><span class="lines">@@ -206,14 +185,13 @@
</span><span class="cx">
</span><span class="cx"> // If the queue doesn't contains input events, we use a higher priorty timer event posting mechanism.
</span><span class="cx"> if (!(queueStatus & (QS_MOUSEBUTTON | QS_KEY | QS_RAWINPUT))) {
</span><del>- if (((isRunningVista && !intervalInMS) || (!isRunningVista && intervalInMS < USER_TIMER_MINIMUM && !processingCustomTimerMessage))
- && !(queueStatus & QS_PAINT)) {
</del><ins>+ if (intervalInMS < USER_TIMER_MINIMUM && !processingCustomTimerMessage && !(queueStatus & QS_PAINT)) {
</ins><span class="cx"> // Call PostMessage immediately if the timer is already expired, unless a paint is pending.
</span><span class="cx"> // (we prioritize paints over timers)
</span><span class="cx"> if (InterlockedIncrement(&pendingTimers) == 1)
</span><span class="cx"> PostMessage(timerWindowHandle, timerFiredMessage, 0, 0);
</span><span class="cx"> timerSet = true;
</span><del>- } else if (isRunningVista) {
</del><ins>+ } else {
</ins><span class="cx"> // Otherwise, delay the PostMessage via a CreateTimerQueueTimer
</span><span class="cx"> if (!timerQueue)
</span><span class="cx"> timerQueue = CreateTimerQueue();
</span><span class="lines">@@ -230,19 +208,8 @@
</span><span class="cx"> KillTimer(timerWindowHandle, timerID);
</span><span class="cx"> timerID = 0;
</span><span class="cx"> }
</span><del>- } else {
</del><ins>+ } else
</ins><span class="cx"> timerID = SetTimer(timerWindowHandle, sharedTimerID, intervalInMS, 0);
</span><del>- if (!lastChanceTimerID) {
- // The last chance timer fires every 5 seconds to run any lost WM_TIMER based timers.
- // Failure to fire a timer is fatal to the cross-platform Timer code, since it won't re-schedule
- // timers if a timer with an earlier expiration is already pending. This results in no timers
- // firing from that point on.
- // We lose WM_TIMER messages occasionally (in the neighborhood of 1 per hour) probably due to a
- // buggy window message hook. This timer will start when the first WM_TIMER is scheduled, and will
- // fire every 5 seconds thereafter.
- lastChanceTimerID = SetTimer(timerWindowHandle, lastChanceSharedTimerID, lastChanceTimerIntervalInMS, 0);
- }
- }
</del><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void stopSharedTimer()
</span></span></pre></div>
<a id="trunkWebCoreplatformwinSystemTimeWincpp"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/platform/win/SystemTimeWin.cpp (36747 => 36748)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/platform/win/SystemTimeWin.cpp 2008-09-22 00:01:21 UTC (rev 36747)
+++ trunk/WebCore/platform/win/SystemTimeWin.cpp 2008-09-22 00:08:30 UTC (rev 36748)
</span><span class="lines">@@ -26,32 +26,17 @@
</span><span class="cx"> #include "config.h"
</span><span class="cx"> #include "SystemTime.h"
</span><span class="cx">
</span><del>-#include "NotImplemented.h"
</del><ins>+#include <JavaScriptCore/DateMath.h>
</ins><span class="cx"> #include <windows.h>
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><span class="cx"> double currentTime()
</span><span class="cx"> {
</span><del>- FILETIME ft;
- GetSystemTimeAsFileTime(&ft);
-
- // As per Windows documentation for FILETIME, copy the resulting FILETIME structure to a
- // ULARGE_INTEGER structure using memcpy (using memcpy instead of direct assignment can
- // prevent alignment faults on 64-bit Windows).
-
- ULARGE_INTEGER t;
- memcpy(&t, &ft, sizeof(t));
-
- // Windows file times are in 100s of nanoseconds.
- // To convert to seconds, we have to divide by 10,000,000, which is more quickly
- // done by multiplying by 0.0000001.
-
- // Between January 1, 1601 and January 1, 1970, there were 369 complete years,
- // of which 89 were leap years (1700, 1800, and 1900 were not leap years).
- // That is a total of 134774 days, which is 11644473600 seconds.
-
- return t.QuadPart * 0.0000001 - 11644473600.0;
</del><ins>+ // Call through to our high-resolution JSC time code, since calls like GetSystemTimeAsFileTime and ftime are only accurate within 15ms.
+ // This resolution can be improved with timeBeginPeriod/timeEndPeriod on Vista, but these calls don't
+ // improve the resolution of date/time getters (GetSystemTimeAsFileTime, ftime, etc.) on XP.
+ return JSC::getCurrentUTCTimeWithMicroseconds() * 0.001;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> float userIdleTime()
</span></span></pre>
</div>
</div>
</body>
</html>