2 This file include the file which can help to get the system
3 performance, all the function will only include if the performance
6 Copyright (c) 2004 - 2009, Intel Corporation. <BR>
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "InternalBdsLib.h"
19 PERF_HEADER mPerfHeader
;
21 EFI_PHYSICAL_ADDRESS mAcpiLowMemoryBase
= 0x0FFFFFFFFULL
;
24 Get the short verion of PDB file name to be
25 used in performance data logging.
27 @param PdbFileName The long PDB file name.
28 @param GaugeString The output string to be logged by performance logger.
33 IN CONST CHAR8
*PdbFileName
,
34 OUT CHAR8
*GaugeString
42 if (PdbFileName
== NULL
) {
43 AsciiStrCpy (GaugeString
, " ");
46 for (EndIndex
= 0; PdbFileName
[EndIndex
] != 0; EndIndex
++)
49 for (Index
= 0; PdbFileName
[Index
] != 0; Index
++) {
50 if (PdbFileName
[Index
] == '\\') {
51 StartIndex
= Index
+ 1;
54 if (PdbFileName
[Index
] == '.') {
60 for (Index
= StartIndex
; Index
< EndIndex
; Index
++) {
61 GaugeString
[Index1
] = PdbFileName
[Index
];
63 if (Index1
== PERF_TOKEN_LENGTH
- 1) {
68 GaugeString
[Index1
] = 0;
75 Get the name from the Driver handle, which can be a handle with
76 EFI_LOADED_IMAGE_PROTOCOL or EFI_DRIVER_BINDING_PROTOCOL installed.
77 This name can be used in performance data logging.
79 @param Handle Driver handle.
80 @param GaugeString The output string to be logged by performance logger.
86 OUT CHAR8
*GaugeString
90 EFI_LOADED_IMAGE_PROTOCOL
*Image
;
92 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
94 AsciiStrCpy (GaugeString
, " ");
97 // Get handle name from image protocol
99 Status
= gBS
->HandleProtocol (
101 &gEfiLoadedImageProtocolGuid
,
105 if (EFI_ERROR (Status
)) {
106 Status
= gBS
->OpenProtocol (
108 &gEfiDriverBindingProtocolGuid
,
109 (VOID
**) &DriverBinding
,
112 EFI_OPEN_PROTOCOL_GET_PROTOCOL
114 if (EFI_ERROR (Status
)) {
118 // Get handle name from image protocol
120 Status
= gBS
->HandleProtocol (
121 DriverBinding
->ImageHandle
,
122 &gEfiLoadedImageProtocolGuid
,
127 PdbFileName
= PeCoffLoaderGetPdbPointer (Image
->ImageBase
);
129 if (PdbFileName
!= NULL
) {
130 GetShortPdbFileName (PdbFileName
, GaugeString
);
138 Allocates a block of memory and writes performance data of booting into it.
139 OS can processing these record.
143 WriteBootToOsPerformanceData (
148 UINT32 AcpiLowMemoryLength
;
152 CHAR8 GaugeString
[PERF_TOKEN_LENGTH
];
169 // Retrieve time stamp count as early as possible
171 Ticker
= GetPerformanceCounter ();
173 Freq
= GetPerformanceCounterProperties (&StartValue
, &EndValue
);
175 Freq
= DivU64x32 (Freq
, 1000);
177 mPerfHeader
.CpuFreq
= Freq
;
180 // Record BDS raw performance data
182 if (EndValue
>= StartValue
) {
183 mPerfHeader
.BDSRaw
= Ticker
- StartValue
;
186 mPerfHeader
.BDSRaw
= StartValue
- Ticker
;
191 // Put Detailed performance data into memory
194 Status
= gBS
->LocateHandleBuffer (
201 if (EFI_ERROR (Status
)) {
206 AcpiLowMemoryLength
= 0x4000;
207 if (mAcpiLowMemoryBase
== 0x0FFFFFFFF) {
209 // Allocate a block of memory that contain performance data to OS
211 Status
= gBS
->AllocatePages (
213 EfiReservedMemoryType
,
214 EFI_SIZE_TO_PAGES (AcpiLowMemoryLength
),
217 if (EFI_ERROR (Status
)) {
224 Ptr
= (UINT8
*) ((UINT32
) mAcpiLowMemoryBase
+ sizeof (PERF_HEADER
));
225 LimitCount
= (AcpiLowMemoryLength
- sizeof (PERF_HEADER
)) / sizeof (PERF_DATA
);
230 // Get DXE drivers performance
232 for (Index
= 0; Index
< NoHandles
; Index
++) {
235 while ((LogEntryKey
= GetPerformanceMeasurement (
242 if ((Handle
== Handles
[Index
]) && (EndTicker
!= 0)) {
243 Ticker
+= CountUp
? (EndTicker
- StartTicker
) : (StartTicker
- EndTicker
);
247 Duration
= (UINT32
) DivU64x32 (Ticker
, (UINT32
) Freq
);
251 GetNameFromHandle (Handles
[Index
], GaugeString
);
253 AsciiStrCpy (mPerfData
.Token
, GaugeString
);
254 mPerfData
.Duration
= Duration
;
256 CopyMem (Ptr
, &mPerfData
, sizeof (PERF_DATA
));
257 Ptr
+= sizeof (PERF_DATA
);
260 if (mPerfHeader
.Count
== LimitCount
) {
269 // Get inserted performance data
272 while ((LogEntryKey
= GetPerformanceMeasurement (
279 if (Handle
== NULL
&& EndTicker
!= 0) {
281 ZeroMem (&mPerfData
, sizeof (PERF_DATA
));
283 AsciiStrnCpy (mPerfData
.Token
, Token
, PERF_TOKEN_LENGTH
);
284 Ticker
= CountUp
? (EndTicker
- StartTicker
) : (StartTicker
- EndTicker
);
286 mPerfData
.Duration
= (UINT32
) DivU64x32 (Ticker
, (UINT32
) Freq
);
288 CopyMem (Ptr
, &mPerfData
, sizeof (PERF_DATA
));
289 Ptr
+= sizeof (PERF_DATA
);
292 if (mPerfHeader
.Count
== LimitCount
) {
300 mPerfHeader
.Signiture
= PERFORMANCE_SIGNATURE
;
303 // Put performance data to Reserved memory
306 (UINTN
*) (UINTN
) mAcpiLowMemoryBase
,
313 &gPerformanceProtocolGuid
,
314 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
315 sizeof (EFI_PHYSICAL_ADDRESS
),