2 ACPI Timer implements one instance of Timer Library.
4 Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Library/TimerLib.h>
17 #include <Library/BaseLib.h>
20 Calculate TSC frequency.
22 The TSC counting frequency is determined by comparing how far it counts
23 during a 100us period as determined by the ACPI timer. The ACPI timer is
24 used because it counts at a known frequency.
25 The TSC is sampled, followed by waiting for ACPI_TIMER_FREQUENCY / 10000
26 clocks of the ACPI timer, or 100us. The TSC is then sampled again. The
27 difference multiplied by 10000 is the TSC frequency. There will be a small
28 error because of the overhead of reading the ACPI timer. An attempt is
29 made to determine and compensate for this error.
31 @return The number of TSC counts per second.
35 InternalCalculateTscFrequency (
40 // Cached performance counter frequency
42 UINT64 mPerformanceCounterFrequency
= 0;
45 Internal function to retrieves the 64-bit frequency in Hz.
47 Internal function to retrieves the 64-bit frequency in Hz.
49 @return The frequency in Hz.
53 InternalGetPerformanceCounterFrequency (
57 if (mPerformanceCounterFrequency
== 0) {
58 mPerformanceCounterFrequency
= InternalCalculateTscFrequency ();
60 return mPerformanceCounterFrequency
;