]> git.proxmox.com Git - mirror_edk2.git/blame - PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
PcAtChipsetPkg AcpiTimerLib: Get more accurate TSC Frequency
[mirror_edk2.git] / PcAtChipsetPkg / Library / AcpiTimerLib / DxeAcpiTimerLib.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// Cached performance counter frequency\r
41//\r
42UINT64 mPerformanceCounterFrequency = 0;\r
43\r
44/**\r
45 Internal function to retrieves the 64-bit frequency in Hz.\r
46\r
47 Internal function to retrieves the 64-bit frequency in Hz.\r
48\r
49 @return The frequency in Hz.\r
50\r
51**/\r
52UINT64\r
53InternalGetPerformanceCounterFrequency (\r
54 VOID\r
55 ) \r
56{\r
83d1ffb9 57 if (mPerformanceCounterFrequency == 0) {\r
62b8b5be 58 mPerformanceCounterFrequency = InternalCalculateTscFrequency ();\r
83d1ffb9
LG
59 }\r
60 return mPerformanceCounterFrequency;\r
61}\r