Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5005837

rework win32 timebeginperiod usage

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P5 P5
    • 9
    • 1.5.1, 2.0, 1.3.1, 5.0
    • hotspot
    • generic, x86
    • generic, windows_nt, windows_2000, windows_xp

      The Win32 platform-specific os::sleep() operation calls timeBeginPeriod() and timeEndPeriod(), which are exported from winmm.dll.

      timeBeginPeriod and timeEndPeriod can cause (a) time-of-day clock skew, and (b) degraded perforamnce because of the increased interrupt rate. For sleep requests that are "long" (perhaps > 1sec) or are a multiple of 10 msecs we should consider avoiding timeBeginPeriod-timeEndPeriod.

      Remarks:

      * See the java-3d timer/timertest demo
      * See http://www.sysinternals.com/ntw2k/info/timer.shtml for a description of how timeBeginPeriod and timeEndPeriod are implemented.

      Thoughts:
      * Defer loading winmm.dll
      * We should measure the cost of the calls to timePeriodBegin and timePeriodEnd. If either operation is expensive we could (a) use a process-specific globals "timerUsers" and "currentResolution" to avoid redundant timePeriodBegin and timePeriodEnd calls. We would define a timeperiodbegin call as redundant if the current resolution is already >= the requested resolution. (b) call timePeriodBegin only to increase the resolution. Periodically, perhaps in the watcher thread, if high res timers haven't been required in the last N secs, restore (decrease) the resolution with timePeriodEnd. That is, we'd defer calling timePeriodEnd. The intent is to eliminate chains of calls to timeperiodbegin and timeperiodend that simply increase and then decrease the timer resolution.

      * Before calling timeperiodbegin() we should verify that the system supports the requested resolution via:

          TIMECAPS tc;
          if (timeGetDevCaps(&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR) {
              // Error; application can't continue.
          }
          const UINT wTimerRes =
              min(max(tc.wPeriodMin, TARGET_RESOLUTION), tc.wPeriodMax);
          timeBeginPeriod(wTimerRes);

      ###@###.### 2004-03-01
      ###@###.### 10/8/04 14:08 GMT

            Unassigned Unassigned
            dice Dave Dice
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: