Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.7 KiB

  1. //++
  2. //
  3. // Module Name:
  4. //
  5. // gettickc.c
  6. //
  7. // Abstract:
  8. //
  9. // This module implements the system service that returns the number
  10. // of milliseconds since the system was booted.
  11. //
  12. // Author:
  13. //
  14. // Bernard Lint
  15. //
  16. // Revision History:
  17. //
  18. // Based on gettick.s (wcheung)
  19. //
  20. //--
  21. #include "exp.h"
  22. #undef NtGetTickCount
  23. ULONG
  24. NtGetTickCount (
  25. VOID
  26. )
  27. /*++
  28. Routine Description:
  29. This function computes the number of milliseconds since the system
  30. was booted. The computation is performed by multiplying the clock
  31. interrupt count by a scaled fixed binary multiplier and then right
  32. shifting the 64-bit result to extract the 32-bit millisecond count.
  33. The multiplier fraction is scaled by 24 bits. Thus for a 100 Hz clock
  34. rate, there are 10 ticks per millisecond, and the multiplier is
  35. 0x0a000000 (10 << 24). For a 128 Hz clock rate, there are 7.8125, or
  36. 7 13/16 ticks per millisecond, and so the multiplier is 0x07d00000.
  37. This effectively replaces a (slow) divide instruction with a (fast)
  38. multiply instruction. The multiplier value is only calculated once
  39. based on the TimeIncrement value (clock tick interval in 100ns units).
  40. N.B. The tick count value wraps every 2^32 milliseconds (49.71 days).
  41. Arguments:
  42. None.
  43. Return Value:
  44. The number of milliseconds since the system was booted is returned
  45. as the function value.
  46. --*/
  47. {
  48. ULONGLONG Product;
  49. //
  50. // compute unsigned 64-bit product
  51. //
  52. Product = KeTickCount.QuadPart * ExpTickCountMultiplier;
  53. //
  54. // shift off 24-bit fraction part and
  55. // return the 32-bit canonical ULONG integer part.
  56. //
  57. return ((ULONG)(Product >> 24));
  58. }
  59.