]> git.proxmox.com Git - mirror_edk2.git/blame - PcAtChipsetPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.c
PcAtChipsetPkg AcpiTimerLib: Get more accurate TSC Frequency
[mirror_edk2.git] / PcAtChipsetPkg / Library / AcpiTimerLib / BaseAcpiTimerLib.c
CommitLineData
83d1ffb9
LG
1/** @file\r
2 ACPI Timer implements one instance of Timer Library.\r
3\r
62b8b5be 4 Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR>\r
83d1ffb9
LG
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <Base.h>\r
16#include <Library/TimerLib.h>\r
17#include <Library/BaseLib.h>\r
18\r
62b8b5be
SZ
19/**\r
20 Calculate TSC frequency.\r
21\r
22 The TSC counting frequency is determined by comparing how far it counts\r
23 during a 100us period as determined by the ACPI timer. The ACPI timer is\r
24 used because it counts at a known frequency.\r
25 The TSC is sampled, followed by waiting for ACPI_TIMER_FREQUENCY / 10000\r
26 clocks of the ACPI timer, or 100us. The TSC is then sampled again. The\r
27 difference multiplied by 10000 is the TSC frequency. There will be a small\r
28 error because of the overhead of reading the ACPI timer. An attempt is\r
29 made to determine and compensate for this error.\r
30\r
31 @return The number of TSC counts per second.\r
32\r
33**/\r
34UINT64\r
35InternalCalculateTscFrequency (\r
36 VOID\r
37 );\r
38\r
83d1ffb9
LG
39/**\r
40 Internal function to retrieves the 64-bit frequency in Hz.\r
41\r
42 Internal function to retrieves the 64-bit frequency in Hz.\r
43\r
44 @return The frequency in Hz.\r
45\r
46**/\r
47UINT64\r
48InternalGetPerformanceCounterFrequency (\r
49 VOID\r
50 ) \r
51{\r
62b8b5be 52 return InternalCalculateTscFrequency ();\r
83d1ffb9 53}\r