VirtualBox

Ignore:
Timestamp:
Sep 11, 2019 8:46:37 AM (5 years ago)
Author:
vboxsync
Message:

Devices/EFI/FirmwareNew: Start upgrade process to edk2-stable201908 (compiles on Windows and works to some extent), bugref:4643

Location:
trunk/src/VBox/Devices/EFI/FirmwareNew
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/EFI/FirmwareNew

  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c

    r77662 r80721  
    1010Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
    1111(C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>
    12 This program and the accompanying materials
    13 are licensed and made available under the terms and conditions of the BSD License
    14 which accompanies this distribution.  The full text of the license may be found at
    15 http://opensource.org/licenses/bsd-license.php
    16 
    17 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
    18 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     12SPDX-License-Identifier: BSD-2-Clause-Patent
    1913
    2014**/
     
    2418
    2519#include <Guid/ExtendedFirmwarePerformance.h>
     20#include <Guid/PerformanceMeasurement.h>
    2621
    2722#include <Library/PerformanceLib.h>
     
    3429
    3530#define  STRING_SIZE            (FPDT_STRING_EVENT_RECORD_NAME_LENGTH * sizeof (CHAR8))
    36 #define  MAX_RECORD_SIZE        (sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD) + STRING_SIZE)
     31#define  PEI_MAX_RECORD_SIZE    (sizeof (FPDT_DUAL_GUID_STRING_EVENT_RECORD) + STRING_SIZE)
     32
     33
     34/**
     35  Return the pointer to the FPDT record in the allocated memory.
     36
     37  @param  RecordSize                The size of FPDT record.
     38  @param  FpdtRecordPtr             Pointer the FPDT record in the allocated memory.
     39  @param  PeiPerformanceLogHeader   Pointer to the header of the PEI Performance records in the GUID Hob.
     40
     41  @retval EFI_SUCCESS               Successfully get the pointer to the FPDT record.
     42  @retval EFI_OUT_OF_RESOURCES      Ran out of space to store the records.
     43**/
     44EFI_STATUS
     45GetFpdtRecordPtr (
     46  IN     UINT8                     RecordSize,
     47  IN OUT FPDT_RECORD_PTR           *FpdtRecordPtr,
     48  IN OUT FPDT_PEI_EXT_PERF_HEADER  **PeiPerformanceLogHeader
     49)
     50{
     51  UINT16                                PeiPerformanceLogEntries;
     52  UINTN                                 PeiPerformanceSize;
     53  UINT8                                 *PeiFirmwarePerformance;
     54  EFI_HOB_GUID_TYPE                     *GuidHob;
     55
     56  //
     57  // Get the number of PeiPerformanceLogEntries form PCD.
     58  //
     59  PeiPerformanceLogEntries = (UINT16) (PcdGet16 (PcdMaxPeiPerformanceLogEntries16) != 0 ?
     60                                       PcdGet16 (PcdMaxPeiPerformanceLogEntries16) :
     61                                       PcdGet8 (PcdMaxPeiPerformanceLogEntries));
     62
     63  //
     64  // Create GUID HOB Data.
     65  //
     66  GuidHob = GetFirstGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid);
     67  PeiFirmwarePerformance = NULL;
     68  while (GuidHob != NULL) {
     69    //
     70    // PEI Performance HOB was found, then return the existing one.
     71    //
     72    PeiFirmwarePerformance  = (UINT8*)GET_GUID_HOB_DATA (GuidHob);
     73    *PeiPerformanceLogHeader = (FPDT_PEI_EXT_PERF_HEADER *)PeiFirmwarePerformance;
     74    if (!(*PeiPerformanceLogHeader)->HobIsFull && (*PeiPerformanceLogHeader)->SizeOfAllEntries + RecordSize > (PeiPerformanceLogEntries * PEI_MAX_RECORD_SIZE)) {
     75      (*PeiPerformanceLogHeader)->HobIsFull = TRUE;
     76    }
     77    if (!(*PeiPerformanceLogHeader)->HobIsFull && (*PeiPerformanceLogHeader)->SizeOfAllEntries + RecordSize <= (PeiPerformanceLogEntries * PEI_MAX_RECORD_SIZE)) {
     78      FpdtRecordPtr->RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(PeiFirmwarePerformance + sizeof (FPDT_PEI_EXT_PERF_HEADER) + (*PeiPerformanceLogHeader)->SizeOfAllEntries);
     79      break;
     80    }
     81    //
     82    // Previous HOB is used, then find next one.
     83    //
     84    GuidHob = GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, GET_NEXT_HOB (GuidHob));
     85  }
     86
     87  if (GuidHob == NULL) {
     88    //
     89    // PEI Performance HOB was not found, then build one.
     90    //
     91    PeiPerformanceSize      = sizeof (FPDT_PEI_EXT_PERF_HEADER) +
     92                              PEI_MAX_RECORD_SIZE * PeiPerformanceLogEntries;
     93    PeiFirmwarePerformance  = (UINT8*)BuildGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, PeiPerformanceSize);
     94    if (PeiFirmwarePerformance != NULL) {
     95      ZeroMem (PeiFirmwarePerformance, PeiPerformanceSize);
     96      (*PeiPerformanceLogHeader) = (FPDT_PEI_EXT_PERF_HEADER *)PeiFirmwarePerformance;
     97      FpdtRecordPtr->RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(PeiFirmwarePerformance + sizeof (FPDT_PEI_EXT_PERF_HEADER));
     98    }
     99  }
     100
     101  if (PeiFirmwarePerformance == NULL) {
     102    //
     103    // there is no enough resource to store performance data
     104    //
     105    return EFI_OUT_OF_RESOURCES;
     106  }
     107
     108  return EFI_SUCCESS;
     109}
    37110
    38111/**
     
    101174
    102175/**
    103   Get the FPDT record info.
    104 
    105   @param  IsStart                 TRUE if the performance log is start log.
    106   @param  Handle                  Pointer to environment specific context used
    107                                   to identify the component being measured.
    108   @param  Token                   Pointer to a Null-terminated ASCII string
    109                                   that identifies the component being measured.
    110   @param  Module                  Pointer to a Null-terminated ASCII string
    111                                   that identifies the module being measured.
    112   @param  RecordInfo              On return, pointer to the info of the record.
    113 
    114   @retval EFI_SUCCESS             Get record info successfully.
    115   @retval EFI_UNSUPPORTED         No matched FPDT record.
     176  Get the FPDT record identifier.
     177
     178  @param Attribute                The attribute of the Record.
     179                                  PerfStartEntry: Start Record.
     180                                  PerfEndEntry: End Record.
     181  @param  Handle                  Pointer to environment specific context used to identify the component being measured.
     182  @param  String                  Pointer to a Null-terminated ASCII string that identifies the component being measured.
     183  @param  ProgressID              On return, pointer to the ProgressID.
     184
     185  @retval EFI_SUCCESS              Get record info successfully.
     186  @retval EFI_INVALID_PARAMETER    No matched FPDT record.
    116187
    117188**/
    118189EFI_STATUS
    119 GetFpdtRecordInfo (
    120   IN BOOLEAN                 IsStart,
     190GetFpdtRecordId (
     191  IN BOOLEAN                 Attribute,
    121192  IN CONST VOID              *Handle,
    122   IN CONST CHAR8             *Token,
    123   IN CONST CHAR8             *Module,
    124   OUT FPDT_BASIC_RECORD_INFO *RecordInfo
    125   )
    126 {
    127   UINTN     StringSize;
    128   UINT16    RecordType;
    129 
    130   RecordType = FPDT_DYNAMIC_STRING_EVENT_TYPE;
    131 
     193  IN CONST CHAR8             *String,
     194  OUT UINT16                 *ProgressID
     195  )
     196{
    132197  //
    133198  // Get the ProgressID based on the Token.
    134199  // When PcdEdkiiFpdtStringRecordEnableOnly is TRUE, all records are with type of FPDT_DYNAMIC_STRING_EVENT_TYPE.
    135200  //
    136   if (Token != NULL) {
    137     if (AsciiStrCmp (Token, LOAD_IMAGE_TOK) == 0) {               // "LoadImage:"
    138       if (IsStart) {
    139         RecordInfo->ProgressID = MODULE_LOADIMAGE_START_ID;
     201  if (String != NULL) {
     202    if (AsciiStrCmp (String, LOAD_IMAGE_TOK) == 0) {               // "LoadImage:"
     203      if (Attribute == PerfStartEntry) {
     204        *ProgressID = MODULE_LOADIMAGE_START_ID;
    140205      } else {
    141         RecordInfo->ProgressID = MODULE_LOADIMAGE_END_ID;
     206        *ProgressID = MODULE_LOADIMAGE_END_ID;
    142207      }
    143       if(!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
    144         RecordType = FPDT_GUID_QWORD_EVENT_TYPE;
     208    } else if (AsciiStrCmp (String, SEC_TOK) == 0 ||               // "SEC"
     209               AsciiStrCmp (String, PEI_TOK) == 0) {               // "PEI"
     210      if (Attribute == PerfStartEntry) {
     211        *ProgressID = PERF_CROSSMODULE_START_ID;
     212      } else {
     213        *ProgressID = PERF_CROSSMODULE_END_ID;
    145214      }
    146     } else if (AsciiStrCmp (Token, SEC_TOK) == 0 ||               // "SEC"
    147                AsciiStrCmp (Token, PEI_TOK) == 0) {               // "PEI"
    148       if (IsStart) {
    149         RecordInfo->ProgressID = PERF_CROSSMODULE_START_ID;
     215    } else if (AsciiStrCmp (String, PEIM_TOK) == 0) {              // "PEIM"
     216      if (Attribute == PerfStartEntry) {
     217        *ProgressID = MODULE_START_ID;
    150218      } else {
    151         RecordInfo->ProgressID = PERF_CROSSMODULE_END_ID;
    152       }
    153     } else if (AsciiStrCmp (Token, PEIM_TOK) == 0) {              // "PEIM"
    154       if (IsStart) {
    155         RecordInfo->ProgressID = MODULE_START_ID;
    156       } else {
    157         RecordInfo->ProgressID = MODULE_END_ID;
    158       }
    159       if(!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
    160         RecordType = FPDT_GUID_EVENT_TYPE;
     219        *ProgressID = MODULE_END_ID;
    161220      }
    162221    } else {                                                      //Pref used in Modules.
    163       if (IsStart) {
    164         RecordInfo->ProgressID = PERF_INMODULE_START_ID;
     222      if (Attribute == PerfStartEntry) {
     223        *ProgressID = PERF_INMODULE_START_ID;
    165224      } else {
    166         RecordInfo->ProgressID = PERF_INMODULE_END_ID;
     225        *ProgressID = PERF_INMODULE_END_ID;
    167226      }
    168227    }
    169   } else if (Module != NULL || Handle != NULL) {                  //Pref used in Modules.
    170     if (IsStart) {
    171       RecordInfo->ProgressID = PERF_INMODULE_START_ID;
     228  } else if (Handle != NULL) {                                    //Pref used in Modules.
     229    if (Attribute == PerfStartEntry) {
     230      *ProgressID = PERF_INMODULE_START_ID;
    172231    } else {
    173       RecordInfo->ProgressID = PERF_INMODULE_END_ID;
     232      *ProgressID = PERF_INMODULE_END_ID;
    174233    }
    175234  } else {
    176     return EFI_UNSUPPORTED;
    177   }
    178 
    179   //
    180   // Get the Guid and string.
    181   //
    182   if(PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
    183     RecordInfo->RecordSize = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD) + STRING_SIZE;
     235    return EFI_INVALID_PARAMETER;
     236  }
     237
     238  return EFI_SUCCESS;
     239}
     240
     241/**
     242  Copies the string from Source into Destination and updates Length with the
     243  size of the string.
     244
     245  @param Destination - destination of the string copy
     246  @param Source      - pointer to the source string which will get copied
     247  @param Length      - pointer to a length variable to be updated
     248
     249**/
     250VOID
     251CopyStringIntoPerfRecordAndUpdateLength (
     252  IN OUT CHAR8  *Destination,
     253  IN     CONST CHAR8  *Source,
     254  IN OUT UINT8  *Length
     255  )
     256{
     257  UINTN  StringLen;
     258  UINTN  DestMax;
     259
     260  ASSERT (Source != NULL);
     261
     262  if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
     263    DestMax = STRING_SIZE;
    184264  } else {
    185     switch (RecordType) {
    186     case FPDT_GUID_EVENT_TYPE:
    187       RecordInfo->RecordSize = sizeof (FPDT_GUID_EVENT_RECORD);
    188       break;
    189 
    190     case FPDT_GUID_QWORD_EVENT_TYPE:
    191       RecordInfo->RecordSize = sizeof (FPDT_GUID_QWORD_EVENT_RECORD);
    192       break;
    193 
    194     case FPDT_DYNAMIC_STRING_EVENT_TYPE:
    195       if (Token != NULL) {
    196         StringSize = AsciiStrSize (Token);
    197       } else if (Module != NULL) {
    198         StringSize = AsciiStrSize (Module);
    199       } else {
    200         StringSize = STRING_SIZE;
    201       }
    202       RecordInfo->RecordSize  = (UINT8)(sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD) + StringSize);
    203       break;
    204 
    205     default:
    206       //
    207       // Other type is unsupported in PEI phase yet, return EFI_UNSUPPORTED
    208       //
    209       return EFI_UNSUPPORTED;
    210     }
    211   }
    212   RecordInfo->Type = RecordType;
    213   return EFI_SUCCESS;
    214 }
     265    DestMax = AsciiStrSize (Source);
     266    if (DestMax > STRING_SIZE) {
     267      DestMax = STRING_SIZE;
     268    }
     269  }
     270  StringLen = AsciiStrLen (Source);
     271  if (StringLen >= DestMax) {
     272    StringLen = DestMax -1;
     273  }
     274
     275  AsciiStrnCpyS(Destination, DestMax, Source, StringLen);
     276  *Length += (UINT8)DestMax;
     277
     278  return;
     279}
     280
    215281
    216282/**
    217283  Convert PEI performance log to FPDT String boot record.
    218284
    219   @param  IsStart                 TRUE if the performance log is start log.
    220   @param  Handle                  Pointer to environment specific context used
    221                                   to identify the component being measured.
    222   @param  Token                   Pointer to a Null-terminated ASCII string
    223                                   that identifies the component being measured.
    224   @param  Module                  Pointer to a Null-terminated ASCII string
    225                                   that identifies the module being measured.
    226   @param  Ticker                  64-bit time stamp.
    227   @param  Identifier              32-bit identifier. If the value is 0, the created record
    228                                   is same as the one created by StartGauge of PERFORMANCE_PROTOCOL.
    229 
    230   @retval EFI_SUCCESS              Add FPDT boot record.
    231   @retval EFI_OUT_OF_RESOURCES     There are not enough resources to record the measurement.
    232   @retval EFI_UNSUPPORTED          No matched FPDT record.
     285  @param CallerIdentifier  - Image handle or pointer to caller ID GUID.
     286  @param Guid              - Pointer to a GUID.
     287  @param String            - Pointer to a string describing the measurement.
     288  @param Ticker            - 64-bit time stamp.
     289  @param Address           - Pointer to a location in memory relevant to the measurement.
     290  @param PerfId            - Performance identifier describing the type of measurement.
     291  @param Attribute         - The attribute of the measurement. According to attribute can create a start
     292                             record for PERF_START/PERF_START_EX, or a end record for PERF_END/PERF_END_EX,
     293                             or a general record for other Perf macros.
     294
     295  @retval EFI_SUCCESS           - Successfully created performance record.
     296  @retval EFI_OUT_OF_RESOURCES  - Ran out of space to store the records.
     297  @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL
     298                                  pointer or invalid PerfId.
    233299
    234300**/
    235301EFI_STATUS
    236 InsertPeiFpdtMeasurement (
    237   IN BOOLEAN      IsStart,
    238   IN CONST VOID   *Handle,  OPTIONAL
    239   IN CONST CHAR8  *Token,   OPTIONAL
    240   IN CONST CHAR8  *Module,  OPTIONAL
    241   IN UINT64       Ticker,
    242   IN UINT32       Identifier
    243   )
    244 {
    245   EFI_HOB_GUID_TYPE                     *GuidHob;
    246   UINTN                                 PeiPerformanceSize;
    247   UINT8                                 *PeiFirmwarePerformance;
    248   FPDT_PEI_EXT_PERF_HEADER              *PeiPerformanceLogHeader;
     302InsertFpdtRecord (
     303  IN CONST VOID                        *CallerIdentifier,  OPTIONAL
     304  IN CONST VOID                        *Guid,    OPTIONAL
     305  IN CONST CHAR8                       *String,  OPTIONAL
     306  IN       UINT64                      Ticker,
     307  IN       UINT64                      Address,  OPTIONAL
     308  IN       UINT16                      PerfId,
     309  IN       PERF_MEASUREMENT_ATTRIBUTE  Attribute
     310  )
     311{
    249312  FPDT_RECORD_PTR                       FpdtRecordPtr;
    250   FPDT_BASIC_RECORD_INFO                RecordInfo;
    251313  CONST VOID                            *ModuleGuid;
    252   UINTN                                 DestMax;
    253   UINTN                                 StrLength;
    254314  CONST CHAR8                           *StringPtr;
    255315  EFI_STATUS                            Status;
    256   UINT16                                PeiPerformanceLogEntries;
    257316  UINT64                                TimeStamp;
     317  FPDT_PEI_EXT_PERF_HEADER              *PeiPerformanceLogHeader;
    258318
    259319  StringPtr = NULL;
     
    262322
    263323  //
    264   // Get record info (type, size, ProgressID and Module Guid).
    265   //
    266   Status = GetFpdtRecordInfo (IsStart, Handle, Token, Module, &RecordInfo);
     324  // 1. Get the Perf Id for records from PERF_START/PERF_END, PERF_START_EX/PERF_END_EX.
     325  //    notes: For other Perf macros (Attribute == PerfEntry), their Id is known.
     326  //
     327  if (Attribute != PerfEntry) {
     328    //
     329    // If PERF_START_EX()/PERF_END_EX() have specified the ProgressID,it has high priority.
     330    // !!! Note: If the Perf is not the known Token used in the core but have same
     331    // ID with the core Token, this case will not be supported.
     332    // And in currtnt usage mode, for the unkown ID, there is a general rule:
     333    // If it is start pref: the lower 4 bits of the ID should be 0.
     334    // If it is end pref: the lower 4 bits of the ID should not be 0.
     335    // If input ID doesn't follow the rule, we will adjust it.
     336    //
     337    if ((PerfId != 0) && (IsKnownID (PerfId)) && (!IsKnownTokens (String))) {
     338      return EFI_UNSUPPORTED;
     339    } else if ((PerfId != 0) && (!IsKnownID (PerfId)) && (!IsKnownTokens (String))) {
     340      if (Attribute == PerfStartEntry && ((PerfId & 0x000F) != 0)) {
     341        PerfId &= 0xFFF0;
     342      } else if ((Attribute == PerfEndEntry) && ((PerfId & 0x000F) == 0)) {
     343        PerfId += 1;
     344      }
     345    } else if (PerfId == 0) {
     346      Status = GetFpdtRecordId (Attribute, CallerIdentifier, String, &PerfId);
     347      if (EFI_ERROR (Status)) {
     348        return Status;
     349      }
     350    }
     351  }
     352
     353  //
     354  // 2. Get the buffer to store the FPDT record.
     355  //
     356  Status = GetFpdtRecordPtr (PEI_MAX_RECORD_SIZE, &FpdtRecordPtr, &PeiPerformanceLogHeader);
    267357  if (EFI_ERROR (Status)) {
    268358    return Status;
     
    270360
    271361  //
    272   // If PERF_START()/PERF_END() have specified the ProgressID,it has high priority.
    273   // !!! Note: If the Perf is not the known Token used in the core but have same
    274   // ID with the core Token, this case will not be supported.
    275   // And in currtnt usage mode, for the unkown ID, there is a general rule:
    276   // If it is start pref: the lower 4 bits of the ID should be 0.
    277   // If it is end pref: the lower 4 bits of the ID should not be 0.
    278   // If input ID doesn't follow the rule, we will adjust it.
    279   //
    280   if ((Identifier != 0) && (IsKnownID (Identifier)) && (!IsKnownTokens (Token))) {
    281     return EFI_UNSUPPORTED;
    282   } else if ((Identifier != 0) && (!IsKnownID (Identifier)) && (!IsKnownTokens (Token))) {
    283     if (IsStart && ((Identifier & 0x000F) != 0)) {
    284       Identifier &= 0xFFF0;
    285     } else if ((!IsStart) && ((Identifier & 0x000F) == 0)) {
    286       Identifier += 1;
    287     }
    288     RecordInfo.ProgressID = (UINT16)Identifier;
    289   }
    290 
    291   //
    292   // Get the number of PeiPerformanceLogEntries form PCD.
    293   //
    294   PeiPerformanceLogEntries = (UINT16) (PcdGet16 (PcdMaxPeiPerformanceLogEntries16) != 0 ?
    295                                        PcdGet16 (PcdMaxPeiPerformanceLogEntries16) :
    296                                        PcdGet8 (PcdMaxPeiPerformanceLogEntries));
    297 
    298   //
    299   // Create GUID HOB Data.
    300   //
    301   GuidHob = GetFirstGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid);
    302   PeiFirmwarePerformance = NULL;
    303   while (GuidHob != NULL) {
    304     //
    305     // PEI Performance HOB was found, then return the existing one.
    306     //
    307     PeiFirmwarePerformance  = (UINT8*)GET_GUID_HOB_DATA (GuidHob);
    308     PeiPerformanceLogHeader = (FPDT_PEI_EXT_PERF_HEADER *)PeiFirmwarePerformance;
    309     if (!PeiPerformanceLogHeader->HobIsFull && PeiPerformanceLogHeader->SizeOfAllEntries + RecordInfo.RecordSize > PeiPerformanceLogEntries * MAX_RECORD_SIZE) {
    310       PeiPerformanceLogHeader->HobIsFull = TRUE;
    311     }
    312     if (!PeiPerformanceLogHeader->HobIsFull && PeiPerformanceLogHeader->SizeOfAllEntries + RecordInfo.RecordSize <= PeiPerformanceLogEntries * MAX_RECORD_SIZE) {
    313       FpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(PeiFirmwarePerformance + sizeof (FPDT_PEI_EXT_PERF_HEADER) + PeiPerformanceLogHeader->SizeOfAllEntries);
    314       break;
    315     }
    316     //
    317     // Previous HOB is used, then find next one.
    318     //
    319     GuidHob = GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, GET_NEXT_HOB (GuidHob));
    320   }
    321 
    322   if (GuidHob == NULL) {
    323     //
    324     // PEI Performance HOB was not found, then build one.
    325     //
    326     PeiPerformanceSize      = sizeof (FPDT_PEI_EXT_PERF_HEADER) +
    327                               MAX_RECORD_SIZE * PeiPerformanceLogEntries;
    328     PeiFirmwarePerformance  = (UINT8*)BuildGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, PeiPerformanceSize);
    329     if (PeiFirmwarePerformance != NULL) {
    330       ZeroMem (PeiFirmwarePerformance, PeiPerformanceSize);
    331     }
    332     PeiPerformanceLogHeader = (FPDT_PEI_EXT_PERF_HEADER *)PeiFirmwarePerformance;
    333     FpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(PeiFirmwarePerformance + sizeof (FPDT_PEI_EXT_PERF_HEADER));
    334   }
    335 
    336   if (PeiFirmwarePerformance == NULL) {
    337     //
    338     // there is no enough resource to store performance data
    339     //
    340     return EFI_OUT_OF_RESOURCES;
    341   }
    342 
    343   //
    344   // Get the TimeStamp.
     362  // 3 Get the TimeStamp.
    345363  //
    346364  if (Ticker == 0) {
     
    354372
    355373  //
    356   // Get the ModuleGuid.
    357   //
    358   if (Handle != NULL) {
    359     ModuleGuid = Handle;
     374  // 4.Get the ModuleGuid.
     375  //
     376  if (CallerIdentifier != NULL) {
     377    ModuleGuid = CallerIdentifier;
    360378  } else {
    361379    ModuleGuid = &gEfiCallerIdGuid;
    362380  }
    363381
    364   switch (RecordInfo.Type) {
    365   case FPDT_GUID_EVENT_TYPE:
    366     FpdtRecordPtr.GuidEvent->Header.Type       = FPDT_GUID_EVENT_TYPE;
    367     FpdtRecordPtr.GuidEvent->Header.Length     = RecordInfo.RecordSize;;
    368     FpdtRecordPtr.GuidEvent->Header.Revision   = FPDT_RECORD_REVISION_1;
    369     FpdtRecordPtr.GuidEvent->ProgressID        = RecordInfo.ProgressID;
    370     FpdtRecordPtr.GuidEvent->Timestamp         = TimeStamp;
    371     CopyMem (&FpdtRecordPtr.GuidEvent->Guid, ModuleGuid, sizeof (EFI_GUID));
    372     PeiPerformanceLogHeader->SizeOfAllEntries += RecordInfo.RecordSize;
     382  //
     383  // 5. Fill in the FPDT record according to different Performance Identifier.
     384  //
     385  switch (PerfId) {
     386  case MODULE_START_ID:
     387  case MODULE_END_ID:
     388    StringPtr = PEIM_TOK;
     389    if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
     390      FpdtRecordPtr.GuidEvent->Header.Type       = FPDT_GUID_EVENT_TYPE;
     391      FpdtRecordPtr.GuidEvent->Header.Length     = sizeof (FPDT_GUID_EVENT_RECORD);
     392      FpdtRecordPtr.GuidEvent->Header.Revision   = FPDT_RECORD_REVISION_1;
     393      FpdtRecordPtr.GuidEvent->ProgressID        = PerfId;
     394      FpdtRecordPtr.GuidEvent->Timestamp         = TimeStamp;
     395      CopyMem (&FpdtRecordPtr.GuidEvent->Guid, ModuleGuid, sizeof (EFI_GUID));
     396    }
    373397    break;
    374398
    375   case FPDT_GUID_QWORD_EVENT_TYPE:
    376     FpdtRecordPtr.GuidQwordEvent->Header.Type     = FPDT_GUID_QWORD_EVENT_TYPE;
    377     FpdtRecordPtr.GuidQwordEvent->Header.Length   = RecordInfo.RecordSize;;
    378     FpdtRecordPtr.GuidQwordEvent->Header.Revision = FPDT_RECORD_REVISION_1;
    379     FpdtRecordPtr.GuidQwordEvent->ProgressID      = RecordInfo.ProgressID;
    380     FpdtRecordPtr.GuidQwordEvent->Timestamp       = TimeStamp;
    381     PeiPerformanceLogHeader->LoadImageCount++;
    382     FpdtRecordPtr.GuidQwordEvent->Qword           = PeiPerformanceLogHeader->LoadImageCount;
    383     CopyMem (&FpdtRecordPtr.GuidQwordEvent->Guid, ModuleGuid, sizeof (EFI_GUID));
    384     PeiPerformanceLogHeader->SizeOfAllEntries += RecordInfo.RecordSize;
     399  case MODULE_LOADIMAGE_START_ID:
     400  case MODULE_LOADIMAGE_END_ID:
     401    StringPtr = LOAD_IMAGE_TOK;
     402    if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
     403      FpdtRecordPtr.GuidQwordEvent->Header.Type     = FPDT_GUID_QWORD_EVENT_TYPE;
     404      FpdtRecordPtr.GuidQwordEvent->Header.Length   = sizeof (FPDT_GUID_QWORD_EVENT_RECORD);
     405      FpdtRecordPtr.GuidQwordEvent->Header.Revision = FPDT_RECORD_REVISION_1;
     406      FpdtRecordPtr.GuidQwordEvent->ProgressID      = PerfId;
     407      FpdtRecordPtr.GuidQwordEvent->Timestamp       = TimeStamp;
     408      if (PerfId == MODULE_LOADIMAGE_START_ID) {
     409        PeiPerformanceLogHeader->LoadImageCount++;
     410      }
     411      FpdtRecordPtr.GuidQwordEvent->Qword           = PeiPerformanceLogHeader->LoadImageCount;
     412      CopyMem (&FpdtRecordPtr.GuidQwordEvent->Guid, ModuleGuid, sizeof (EFI_GUID));
     413    }
    385414    break;
    386415
    387   case FPDT_DYNAMIC_STRING_EVENT_TYPE:
     416  case PERF_EVENTSIGNAL_START_ID:
     417  case PERF_EVENTSIGNAL_END_ID:
     418  case PERF_CALLBACK_START_ID:
     419  case PERF_CALLBACK_END_ID:
     420    if (String == NULL || Guid == NULL) {
     421      return EFI_INVALID_PARAMETER;
     422    }
     423    StringPtr = String;
     424    if (AsciiStrLen (String) == 0) {
     425      StringPtr = "unknown name";
     426    }
     427    if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
     428      FpdtRecordPtr.DualGuidStringEvent->Header.Type      = FPDT_DUAL_GUID_STRING_EVENT_TYPE;
     429      FpdtRecordPtr.DualGuidStringEvent->Header.Length    = sizeof (FPDT_DUAL_GUID_STRING_EVENT_RECORD);
     430      FpdtRecordPtr.DualGuidStringEvent->Header.Revision  = FPDT_RECORD_REVISION_1;
     431      FpdtRecordPtr.DualGuidStringEvent->ProgressID       = PerfId;
     432      FpdtRecordPtr.DualGuidStringEvent->Timestamp        = TimeStamp;
     433      CopyMem (&FpdtRecordPtr.DualGuidStringEvent->Guid1, ModuleGuid, sizeof (FpdtRecordPtr.DualGuidStringEvent->Guid1));
     434      CopyMem (&FpdtRecordPtr.DualGuidStringEvent->Guid2, Guid, sizeof (FpdtRecordPtr.DualGuidStringEvent->Guid2));
     435      CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DualGuidStringEvent->String, StringPtr, &FpdtRecordPtr.DualGuidStringEvent->Header.Length);
     436    }
     437    break;
     438
     439  case PERF_EVENT_ID:
     440  case PERF_FUNCTION_START_ID:
     441  case PERF_FUNCTION_END_ID:
     442  case PERF_INMODULE_START_ID:
     443  case PERF_INMODULE_END_ID:
     444  case PERF_CROSSMODULE_START_ID:
     445  case PERF_CROSSMODULE_END_ID:
     446    if (String != NULL && AsciiStrLen (String) != 0) {
     447      StringPtr = String;
     448    } else {
     449      StringPtr = "unknown name";
     450    }
     451    if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
     452      FpdtRecordPtr.DynamicStringEvent->Header.Type       = FPDT_DYNAMIC_STRING_EVENT_TYPE;
     453      FpdtRecordPtr.DynamicStringEvent->Header.Length     = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);
     454      FpdtRecordPtr.DynamicStringEvent->Header.Revision   = FPDT_RECORD_REVISION_1;
     455      FpdtRecordPtr.DynamicStringEvent->ProgressID        = PerfId;
     456      FpdtRecordPtr.DynamicStringEvent->Timestamp         = TimeStamp;
     457      CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, ModuleGuid, sizeof (EFI_GUID));
     458      CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DynamicStringEvent->String, StringPtr, &FpdtRecordPtr.DynamicStringEvent->Header.Length);
     459    }
     460    break;
     461
     462  default:
     463    if (Attribute != PerfEntry) {
     464     if (String != NULL && AsciiStrLen (String) != 0) {
     465       StringPtr = String;
     466     } else {
     467       StringPtr = "unknown name";
     468     }
     469     if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
     470       FpdtRecordPtr.DynamicStringEvent->Header.Type       = FPDT_DYNAMIC_STRING_EVENT_TYPE;
     471       FpdtRecordPtr.DynamicStringEvent->Header.Length     = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);
     472       FpdtRecordPtr.DynamicStringEvent->Header.Revision   = FPDT_RECORD_REVISION_1;
     473       FpdtRecordPtr.DynamicStringEvent->ProgressID        = PerfId;
     474       FpdtRecordPtr.DynamicStringEvent->Timestamp         = TimeStamp;
     475       CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, ModuleGuid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));
     476       CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DynamicStringEvent->String, StringPtr, &FpdtRecordPtr.DynamicStringEvent->Header.Length);
     477     }
     478  } else {
     479    return EFI_INVALID_PARAMETER;
     480  }
     481   break;
     482  }
     483
     484  //
     485  // 5.2 When PcdEdkiiFpdtStringRecordEnableOnly==TRUE, create string record for all Perf entries.
     486  //
     487  if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
    388488    FpdtRecordPtr.DynamicStringEvent->Header.Type       = FPDT_DYNAMIC_STRING_EVENT_TYPE;
    389     FpdtRecordPtr.DynamicStringEvent->Header.Length     = RecordInfo.RecordSize;
     489    FpdtRecordPtr.DynamicStringEvent->Header.Length     = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);
    390490    FpdtRecordPtr.DynamicStringEvent->Header.Revision   = FPDT_RECORD_REVISION_1;
    391     FpdtRecordPtr.DynamicStringEvent->ProgressID        = RecordInfo.ProgressID;
     491    FpdtRecordPtr.DynamicStringEvent->ProgressID        = PerfId;
    392492    FpdtRecordPtr.DynamicStringEvent->Timestamp         = TimeStamp;
    393     CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, ModuleGuid, sizeof (EFI_GUID));
    394     PeiPerformanceLogHeader->SizeOfAllEntries += RecordInfo.RecordSize;
    395 
    396     if (Token != NULL) {
    397       StringPtr                     = Token;
    398     } else if (Module != NULL) {
    399       StringPtr                     = Module;
    400     }
    401     if (StringPtr != NULL && AsciiStrLen (StringPtr) != 0) {
    402       DestMax                       = (RecordInfo.RecordSize - sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD)) / sizeof (CHAR8);
    403       StrLength                     = AsciiStrLen (StringPtr);
    404       if (StrLength >= DestMax) {
    405         StrLength                   = DestMax -1;
    406       }
    407       AsciiStrnCpyS (FpdtRecordPtr.DynamicStringEvent->String, DestMax, StringPtr, StrLength);
     493    if (Guid != NULL) {
     494      //
     495      // Cache the event guid in string event record.
     496      //
     497      CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, Guid, sizeof (EFI_GUID));
    408498    } else {
    409       AsciiStrCpyS (FpdtRecordPtr.DynamicStringEvent->String, FPDT_STRING_EVENT_RECORD_NAME_LENGTH, "unknown name");
    410     }
    411     break;
    412 
    413   default:
    414     //
    415     // Record is not supported in current PEI phase, return EFI_ABORTED
    416     //
    417     return EFI_UNSUPPORTED;
    418   }
     499      CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, ModuleGuid, sizeof (EFI_GUID));
     500    }
     501    CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DynamicStringEvent->String, StringPtr, &FpdtRecordPtr.DynamicStringEvent->Header.Length);
     502  }
     503
     504  //
     505  // 6. Update the length of the used buffer after fill in the record.
     506  //
     507  PeiPerformanceLogHeader->SizeOfAllEntries += FpdtRecordPtr.RecordHeader->Length;
    419508
    420509  return EFI_SUCCESS;
     
    455544  )
    456545{
    457   return InsertPeiFpdtMeasurement (TRUE, Handle, Token, Module, TimeStamp, Identifier);
     546  CONST CHAR8     *String;
     547
     548  if (Token != NULL) {
     549    String = Token;
     550  } else if (Module != NULL) {
     551    String = Module;
     552  } else {
     553    String = NULL;
     554  }
     555
     556  return (RETURN_STATUS)InsertFpdtRecord (Handle, NULL, String, TimeStamp, 0, (UINT16)Identifier, PerfStartEntry);
     557
    458558}
    459559
     
    490590  )
    491591{
    492   return InsertPeiFpdtMeasurement (FALSE, Handle, Token, Module, TimeStamp, Identifier);
     592  CONST CHAR8     *String;
     593
     594  if (Token != NULL) {
     595    String = Token;
     596  } else if (Module != NULL) {
     597    String = Module;
     598  } else {
     599    String = NULL;
     600  }
     601
     602  return (RETURN_STATUS)InsertFpdtRecord (Handle, NULL, String, TimeStamp, 0, (UINT16)Identifier, PerfEndEntry);
    493603}
    494604
     
    583693  )
    584694{
    585   return InsertPeiFpdtMeasurement (TRUE, Handle, Token, Module, TimeStamp, 0);
     695  return StartPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);
    586696}
    587697
     
    615725  )
    616726{
    617   return InsertPeiFpdtMeasurement (FALSE, Handle, Token, Module, TimeStamp, 0);
     727  return EndPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);
    618728}
    619729
     
    693803  return (BOOLEAN) ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);
    694804}
     805
     806/**
     807  Create performance record with event description and a timestamp.
     808
     809  @param CallerIdentifier  - Image handle or pointer to caller ID GUID
     810  @param Guid              - Pointer to a GUID
     811  @param String            - Pointer to a string describing the measurement
     812  @param Address           - Pointer to a location in memory relevant to the measurement
     813  @param Identifier        - Performance identifier describing the type of measurement
     814
     815  @retval RETURN_SUCCESS           - Successfully created performance record
     816  @retval RETURN_OUT_OF_RESOURCES  - Ran out of space to store the records
     817  @retval RETURN_INVALID_PARAMETER - Invalid parameter passed to function - NULL
     818                                     pointer or invalid PerfId
     819
     820**/
     821RETURN_STATUS
     822EFIAPI
     823LogPerformanceMeasurement (
     824  IN CONST VOID   *CallerIdentifier,
     825  IN CONST VOID   *Guid,    OPTIONAL
     826  IN CONST CHAR8  *String,  OPTIONAL
     827  IN UINT64       Address, OPTIONAL
     828  IN UINT32       Identifier
     829  )
     830{
     831  return (RETURN_STATUS)InsertFpdtRecord (CallerIdentifier, Guid, String, 0, Address, (UINT16)Identifier, PerfEntry);
     832}
     833
     834/**
     835  Check whether the specified performance measurement can be logged.
     836
     837  This function returns TRUE when the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set
     838  and the Type disable bit in PcdPerformanceLibraryPropertyMask is not set.
     839
     840  @param Type        - Type of the performance measurement entry.
     841
     842  @retval TRUE         The performance measurement can be logged.
     843  @retval FALSE        The performance measurement can NOT be logged.
     844
     845**/
     846BOOLEAN
     847EFIAPI
     848LogPerformanceMeasurementEnabled (
     849  IN  CONST UINTN        Type
     850  )
     851{
     852  //
     853  // When Performance measurement is enabled and the type is not filtered, the performance can be logged.
     854  //
     855  if (PerformanceMeasurementEnabled () && (PcdGet8(PcdPerformanceLibraryPropertyMask) & Type) == 0) {
     856    return TRUE;
     857  }
     858  return FALSE;
     859}
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf

    r77662 r80721  
    88#  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
    99# (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
    10 #  This program and the accompanying materials
    11 #  are licensed and made available under the terms and conditions of the BSD License
    12 #  which accompanies this distribution.  The full text of the license may be found at
    13 #  http://opensource.org/licenses/bsd-license.php
    14 #
    15 #  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
    16 #  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     10#  SPDX-License-Identifier: BSD-2-Clause-Patent
    1711#
    1812##
     
    3024# The following information is for reference only and not required by the build tools.
    3125#
    32 #  VALID_ARCHITECTURES           = IA32 X64 IPF EBC (EBC is for build only)
     26#  VALID_ARCHITECTURES           = IA32 X64 EBC (EBC is for build only)
    3327#
    3428
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.uni

    r77662 r80721  
    66// so that it can be taken over by DxeCorePerformanceLib.
    77//
    8 // Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
     8// Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
    99//
    10 // This program and the accompanying materials
    11 // are licensed and made available under the terms and conditions of the BSD License
    12 // which accompanies this distribution.  The full text of the license may be found at
    13 // http://opensource.org/licenses/bsd-license.php
    14 //
    15 // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
    16 // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     10// SPDX-License-Identifier: BSD-2-Clause-Patent
    1711//
    1812// **/
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette