EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/PeiPerformanceLib/PerformanceLib.c

Go to the documentation of this file.
00001 /*++
00002 
00003 Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>
00004 This program and the accompanying materials                          
00005 are licensed and made available under the terms and conditions of the BSD License         
00006 which accompanies this distribution.  The full text of the license may be found at        
00007 http://opensource.org/licenses/bsd-license.php                                            
00008                                                                                           
00009 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
00010 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.              
00011 
00012 
00013 Module Name:
00014 
00015   PerformanceLib.c
00016   
00017 Abstract: 
00018 
00019   Support routines used by PEI_PERF_START() and PEI_PERF_END()
00020 
00021 --*/
00022 
00023 #include "EdkIIGluePeim.h"
00024 
00025 
00026 #define MAX_PEI_PERF_LOG_ENTRIES 28
00027 
00028 
00029 STATIC
00030 VOID
00031 InternalGetTimerValue (
00032   OUT UINT64    *TimerValue
00033   )
00034 /*++
00035 
00036 Routine Description:
00037 
00038   Set TimerValue with current tick.
00039 
00040 Arguments:
00041 
00042   TimerValue  - Timer value to be set
00043 
00044 Returns:
00045 
00046   EFI_SUCCESS - TimerValue is set.
00047 
00048 --*/
00049 {
00050   *TimerValue = AsmReadTsc ();
00051 }
00052 
00053 
00054 VOID
00055 EFIAPI
00056 PeiPerfMeasure (
00057   EFI_PEI_SERVICES              **PeiServices,
00058   IN UINT16                     *Token,
00059   IN EFI_FFS_FILE_HEADER        *FileHeader,
00060   IN BOOLEAN                    EntryExit,
00061   IN UINT64                     Value
00062   )
00063 /*++
00064 
00065 Routine Description:
00066 
00067   Log a timestamp count.
00068 
00069 Arguments:
00070 
00071   PeiServices - Pointer to the PEI Core Services table
00072   
00073   Token       - Pointer to Token Name
00074   
00075   FileHeader  - Pointer to the file header
00076 
00077   EntryExit   - Indicates start or stop measurement
00078 
00079   Value       - The start time or the stop time
00080 
00081 Returns:
00082 
00083 --*/
00084 {
00085   EFI_STATUS                         Status;
00086   EFI_HOB_GUID_TYPE                  *Hob;
00087   EFI_HOB_GUID_DATA_PERFORMANCE_LOG  *PerfHobData;
00088   PEI_PERFORMANCE_MEASURE_LOG_ENTRY  *Log;
00089   EFI_PEI_PPI_DESCRIPTOR             *PerfHobDescriptor;
00090   UINT64                             TimeCount;
00091   INTN                               Index;
00092   UINTN                              Index2;
00093   EFI_GUID                           *Guid;
00094   EFI_GUID                           *CheckGuid;
00095 
00096   TimeCount = 0;
00097   //
00098   // Get the END time as early as possible to make it more accurate.
00099   //
00100   if (EntryExit) {
00101     InternalGetTimerValue (&TimeCount);
00102   }
00103 
00104   //
00105   // Locate the Pei Performance Log Hob.
00106   //
00107   Status = PeiServicesLocatePpi (
00108                              &gEfiPeiPerformanceHobGuid, 
00109                              0, 
00110                              &PerfHobDescriptor, 
00111                              NULL
00112                              );
00113 
00114   //
00115   // If the Performance Hob was not found, build and install one.
00116   //
00117   if (EFI_ERROR(Status)) {
00118     Hob = BuildGuidHob (
00119                &gEfiPeiPerformanceHobGuid, 
00120                (sizeof(EFI_HOB_GUID_DATA_PERFORMANCE_LOG) +
00121                  ((MAX_PEI_PERF_LOG_ENTRIES-1) * 
00122                  sizeof(PEI_PERFORMANCE_MEASURE_LOG_ENTRY)) +
00123                  sizeof(EFI_PEI_PPI_DESCRIPTOR)
00124                )); 
00125     Hob = (VOID *)((UINTN)Hob - sizeof (EFI_HOB_GUID_TYPE));
00126     ASSERT_EFI_ERROR (Status);
00127 
00128     PerfHobData = (EFI_HOB_GUID_DATA_PERFORMANCE_LOG *)(Hob+1);
00129     PerfHobData->NumberOfEntries = 0;
00130 
00131     PerfHobDescriptor = (EFI_PEI_PPI_DESCRIPTOR *)((UINT8 *)(PerfHobData+1) +
00132                                                      (sizeof(PEI_PERFORMANCE_MEASURE_LOG_ENTRY) *
00133                                                        (MAX_PEI_PERF_LOG_ENTRIES-1)
00134                                                      )
00135                                                   );
00136     PerfHobDescriptor->Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
00137     PerfHobDescriptor->Guid = &gEfiPeiPerformanceHobGuid;
00138     PerfHobDescriptor->Ppi = NULL;
00139 
00140     (*PeiServices)->InstallPpi (
00141                       PeiServices,
00142                       PerfHobDescriptor
00143                       );
00144   }
00145 
00146   PerfHobData = (EFI_HOB_GUID_DATA_PERFORMANCE_LOG *)(((UINT8 *)(PerfHobDescriptor)) -
00147                                                         ((sizeof(PEI_PERFORMANCE_MEASURE_LOG_ENTRY) *
00148                                                            (MAX_PEI_PERF_LOG_ENTRIES-1)
00149                                                          )
00150                                                          + sizeof(EFI_HOB_GUID_DATA_PERFORMANCE_LOG)
00151                                                       )
00152                                                      );
00153 
00154   if (PerfHobData->NumberOfEntries >= MAX_PEI_PERF_LOG_ENTRIES) {
00155     return;
00156   }
00157 
00158   if (!EntryExit) {
00159     Log = &(PerfHobData->Log[PerfHobData->NumberOfEntries]);
00160     ((*PeiServices)->SetMem) (Log, sizeof(PEI_PERFORMANCE_MEASURE_LOG_ENTRY), 0);
00161 
00162     //
00163     // If not NULL pointer, copy the file name
00164     //
00165     if (FileHeader != NULL) {
00166       Log->Name = FileHeader->Name;
00167     }
00168 
00169     //
00170     // Copy the description string
00171     //
00172     ((*PeiServices)->CopyMem) (
00173                       &(Log->DescriptionString), 
00174                       Token,
00175                       (PEI_PERF_MAX_DESC_STRING-1) * sizeof(UINT16)
00176                       );
00177 
00178     //
00179     // Get the start time as late as possible to make it more accurate.
00180     //
00181     InternalGetTimerValue (&TimeCount);
00182 
00183     //
00184     // Record the time stamp.
00185     //
00186     if (Value != 0) {
00187       Log->StartTimeCount = Value;
00188     } else {
00189       Log->StartTimeCount = TimeCount;
00190     }
00191     Log->StopTimeCount = 0;
00192 
00193     //
00194     // Increment the number of valid log entries.
00195     //
00196     PerfHobData->NumberOfEntries++;
00197 
00198   } else {
00199 
00200     for (Index = PerfHobData->NumberOfEntries-1; Index >= 0; Index--) {
00201       Log = NULL;
00202       for (Index2 = 0; Index2 < PEI_PERF_MAX_DESC_STRING; Index2++) {
00203         if (PerfHobData->Log[Index].DescriptionString[Index2] == 0) {
00204           Log = &(PerfHobData->Log[Index]);
00205           break;
00206         }
00207         if (PerfHobData->Log[Index].DescriptionString[Index2] !=
00208             Token[Index2]) {
00209           break;
00210         }
00211       }
00212       if (Log != NULL) {
00213         if (FileHeader != NULL) {
00214           Guid = &(Log->Name);
00215           CheckGuid = &(FileHeader->Name);
00216           if ((((INT32 *)Guid)[0] == ((INT32 *)CheckGuid)[0]) &&
00217               (((INT32 *)Guid)[1] == ((INT32 *)CheckGuid)[1]) &&
00218               (((INT32 *)Guid)[2] == ((INT32 *)CheckGuid)[2]) &&
00219               (((INT32 *)Guid)[3] == ((INT32 *)CheckGuid)[3]))  {
00220             if (Value != 0) {
00221               Log->StopTimeCount = Value;
00222             } else {
00223              Log->StopTimeCount = TimeCount;
00224             }
00225             break;
00226           }
00227         } else {
00228           if (Value != 0) {
00229             Log->StopTimeCount = Value;
00230           } else {
00231            Log->StopTimeCount = TimeCount;
00232           }
00233           break;
00234         }
00235       }
00236     }
00237             
00238   }
00239 
00240   return;
00241 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines