public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Dandan Bi <dandan.bi@intel.com>
To: edk2-devel@lists.01.org
Cc: Liming Gao <liming.gao@intel.com>, Ruiyu Ni <ruiyu.ni@intel.com>
Subject: [patch 6/9] ShellPkg/dp: Update dp tool to parse new Perf record
Date: Tue, 19 Jun 2018 15:24:02 +0800	[thread overview]
Message-ID: <20180619072405.142872-7-dandan.bi@intel.com> (raw)
In-Reply-To: <20180619072405.142872-1-dandan.bi@intel.com>

Since performance library instances have been updated
to create new FPDT records for new Perf macros.
So enhance dp tool to parse the new FPDT records.
Enhancement mainly includes:
1. parse the single records for PERF_EVENT macro
2. Parse the new added FPDT_DUAL_GUID_STRING_EVENT_RECORD

Cc: Liming Gao <liming.gao@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
---
 ShellPkg/DynamicCommand/DpDynamicCommand/Dp.c | 75 +++++++++++++++++++++++----
 ShellPkg/DynamicCommand/DpDynamicCommand/Dp.h |  1 +
 2 files changed, 66 insertions(+), 10 deletions(-)

diff --git a/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.c b/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.c
index 38766613175..925341303a4 100644
--- a/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.c
+++ b/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.c
@@ -428,15 +428,29 @@ GetMeasurementInfo (
       break;
     default:
       ASSERT(FALSE);
     }
 
-    if (AsciiStrCmp (Measurement->Token, ALit_PEIM) == 0) {
-      Measurement->Handle         = &(((FPDT_GUID_EVENT_RECORD *)RecordHeader)->Guid);
+    if (Measurement->Token != NULL && AsciiStrCmp (Measurement->Token, ALit_PEIM) == 0) {
+      Measurement->Handle         = &(((FPDT_DYNAMIC_STRING_EVENT_RECORD *)RecordHeader)->Guid);
     } else {
       GetHandleFormModuleGuid(ModuleGuid, &StartHandle);
-      Measurement->Handle         = StartHandle;
+      Measurement->Handle = StartHandle;
+      //
+      // When no perf entry to record the PEI and DXE phase,
+      // For start image, we need detect the PEIM and non PEIM here.
+      //
+      if (Measurement->Token == NULL) {
+        if (StartHandle == NULL && !IsZeroGuid (ModuleGuid)) {
+          Measurement->Token      = ALit_PEIM;
+          Measurement->Module     = ALit_PEIM;
+          Measurement->Handle     = ModuleGuid;
+        } else {
+          Measurement->Token      = ALit_START_IMAGE;
+          Measurement->Module     = ALit_START_IMAGE;
+        }
+      }
     }
     break;
 
   case FPDT_DYNAMIC_STRING_EVENT_TYPE:
     ModuleGuid                    = &(((FPDT_DYNAMIC_STRING_EVENT_RECORD *)RecordHeader)->Guid);
@@ -481,15 +495,27 @@ GetMeasurementInfo (
       break;
     }
 
     Measurement->Module           = ((FPDT_DYNAMIC_STRING_EVENT_RECORD *)RecordHeader)->String;
 
-    if (AsciiStrCmp (Measurement->Token, ALit_PEIM) == 0) {
+    if (Measurement->Token != NULL && AsciiStrCmp (Measurement->Token, ALit_PEIM) == 0) {
       Measurement->Handle         = &(((FPDT_DYNAMIC_STRING_EVENT_RECORD *)RecordHeader)->Guid);
     } else {
       GetHandleFormModuleGuid(ModuleGuid, &StartHandle);
       Measurement->Handle = StartHandle;
+      //
+      // When no perf entry to record the PEI and DXE phase,
+      // For start image, we need detect the PEIM and non PEIM here.
+      //
+      if (Measurement->Token == NULL  && (Measurement->Identifier == MODULE_START_ID || Measurement->Identifier == MODULE_END_ID)) {
+        if (StartHandle == NULL && !IsZeroGuid (ModuleGuid)) {
+          Measurement->Token      = ALit_PEIM;
+          Measurement->Handle     = ModuleGuid;
+        } else {
+          Measurement->Token      = ALit_START_IMAGE;
+        }
+      }
     }
     break;
 
   case FPDT_GUID_QWORD_EVENT_TYPE:
     ModuleGuid                    = &(((FPDT_GUID_QWORD_EVENT_RECORD *)RecordHeader)->Guid);
@@ -551,10 +577,24 @@ GetMeasurementInfo (
     }
     GetHandleFormModuleGuid(ModuleGuid, &StartHandle);
     Measurement->Handle = StartHandle;
     break;
 
+  case FPDT_DUAL_GUID_STRING_EVENT_TYPE:
+    ModuleGuid                    = &(((FPDT_DUAL_GUID_STRING_EVENT_RECORD *)RecordHeader)->Guid1);
+    Measurement->Identifier       = ((UINT32)((FPDT_DUAL_GUID_STRING_EVENT_RECORD *)RecordHeader)->ProgressID);
+    if (IsStart) {
+      Measurement->StartTimeStamp = ((FPDT_DUAL_GUID_STRING_EVENT_RECORD *)RecordHeader)->Timestamp;
+    } else {
+      Measurement->EndTimeStamp   = ((FPDT_DUAL_GUID_STRING_EVENT_RECORD *)RecordHeader)->Timestamp;
+    }
+    Measurement->Token            = ((FPDT_DUAL_GUID_STRING_EVENT_RECORD *)RecordHeader)->String;
+    Measurement->Module           = ((FPDT_DUAL_GUID_STRING_EVENT_RECORD *)RecordHeader)->String;
+    GetHandleFormModuleGuid(ModuleGuid, &StartHandle);
+    Measurement->Handle = StartHandle;
+    break;
+
   default:
     break;
   }
 }
 
@@ -578,10 +618,18 @@ SearchMeasurement (
           (AsciiStrCmp (mMeasurementList[Index].Token, EndMeasureMent->Token) == 0) &&
           (AsciiStrCmp (mMeasurementList[Index].Module, EndMeasureMent->Module) == 0)) {
         mMeasurementList[Index].EndTimeStamp = EndMeasureMent->EndTimeStamp;
         break;
       }
+    } else if (EndMeasureMent->Identifier == PERF_CROSSMODULE_END_ID) {
+      if (mMeasurementList[Index].EndTimeStamp == 0 &&
+         (AsciiStrCmp (mMeasurementList[Index].Token, EndMeasureMent->Token) == 0) &&
+         (AsciiStrCmp (mMeasurementList[Index].Module, EndMeasureMent->Module) == 0) &&
+         mMeasurementList[Index].Identifier == PERF_CROSSMODULE_START_ID) {
+        mMeasurementList[Index].EndTimeStamp = EndMeasureMent->EndTimeStamp;
+        break;
+      }
     } else {
       if (mMeasurementList[Index].EndTimeStamp == 0 && mMeasurementList[Index].Handle == EndMeasureMent->Handle &&
          (AsciiStrCmp (mMeasurementList[Index].Token, EndMeasureMent->Token) == 0) &&
          (AsciiStrCmp (mMeasurementList[Index].Module, EndMeasureMent->Module) == 0)) {
         mMeasurementList[Index].EndTimeStamp = EndMeasureMent->EndTimeStamp;
@@ -618,29 +666,36 @@ BuildMeasurementList (
     RecordHeader      = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER*) PerformanceTablePtr;
     StartRecordEvent  = (UINT8 *)RecordHeader;
     StartProgressId   = ((FPDT_GUID_EVENT_RECORD *)StartRecordEvent)->ProgressID;
 
     //
+    // If the record with ProgressId 0, the record doesn't appear in pairs. The timestamp in the record is the EndTimeStamp, its StartTimeStamp is 0.
     // If the record is the start record, fill the info to the measurement in the mMeasurementList.
     // If the record is the end record, find the related start measurement in the mMeasurementList and fill the EndTimeStamp.
     //
-    if (((StartProgressId >= PERF_EVENTSIGNAL_START_ID && ((StartProgressId & 0x000F) == 0)) ||
+    if (StartProgressId == 0) {
+      GetMeasurementInfo (RecordHeader, FALSE, &(mMeasurementList[mMeasurementNum]));
+      mMeasurementNum ++;
+    } else if (((StartProgressId >= PERF_EVENTSIGNAL_START_ID && ((StartProgressId & 0x000F) == 0)) ||
         (StartProgressId < PERF_EVENTSIGNAL_START_ID && ((StartProgressId & 0x0001) != 0)))) {
       //
       // Since PEIM and StartImage has same Type and ID when PCD PcdEdkiiFpdtStringRecordEnableOnly = FALSE
       // So we need to identify these two kinds of record through different phase.
       //
-      if (AsciiStrCmp (((FPDT_DYNAMIC_STRING_EVENT_RECORD *)StartRecordEvent)->String, ALit_PEI) == 0) {
-        mPeiPhase = TRUE;
-      } else if (AsciiStrCmp (((FPDT_DYNAMIC_STRING_EVENT_RECORD *)StartRecordEvent)->String, ALit_DXE) == 0) {
-        mDxePhase = TRUE;
-        mPeiPhase = FALSE;
+      if(StartProgressId == PERF_CROSSMODULE_START_ID ){
+        if (AsciiStrCmp (((FPDT_DYNAMIC_STRING_EVENT_RECORD *)StartRecordEvent)->String, ALit_PEI) == 0) {
+          mPeiPhase = TRUE;
+        } else if (AsciiStrCmp (((FPDT_DYNAMIC_STRING_EVENT_RECORD *)StartRecordEvent)->String, ALit_DXE) == 0) {
+          mDxePhase = TRUE;
+          mPeiPhase = FALSE;
+        }
       }
       // Get measurement info form the start record to the mMeasurementList.
       GetMeasurementInfo (RecordHeader, TRUE, &(mMeasurementList[mMeasurementNum]));
       mMeasurementNum ++;
     } else {
+      ZeroMem(&MeasureMent, sizeof(MEASUREMENT_RECORD));
       GetMeasurementInfo (RecordHeader, FALSE, &MeasureMent);
       SearchMeasurement (&MeasureMent);
     }
     TableLength         += RecordHeader->Length;
     PerformanceTablePtr += RecordHeader->Length;
diff --git a/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.h b/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.h
index aae021334d6..96bc89db8dc 100644
--- a/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.h
+++ b/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.h
@@ -39,10 +39,11 @@
 #include <Library/PcdLib.h>
 #include <Library/SortLib.h>
 #include <Library/HiiLib.h>
 #include <Library/FileHandleLib.h>
 #include <Library/UefiHiiServicesLib.h>
+#include <Library/Performancelib.h>
 
 extern EFI_HANDLE mDpHiiHandle;
 
 #define DP_MAJOR_VERSION        2
 #define DP_MINOR_VERSION        5
-- 
2.14.3.windows.1



  parent reply	other threads:[~2018-06-19  7:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-19  7:23 [patch 0/9] Add new Perf macros Dandan Bi
2018-06-19  7:23 ` [patch 1/9] MdeModulePkg: Add PERFORMANCE_MEASUREMENT_PROTOCOL Dandan Bi
2018-06-19  7:23 ` [patch 2/9] MdeModulePkg: Update Performance instances to use new protocol Dandan Bi
2018-06-19  7:23 ` [patch 3/9] MdePkg/PerformanceLib.h: Add new Perf macros Dandan Bi
2018-06-19  7:24 ` [patch 4/9] MdeModulePkg/ExtendedFirmwarePerf: Remove PerfId definitions Dandan Bi
2018-06-19  7:24 ` [patch 5/9] MdeModulePkg: Update performance library instances Dandan Bi
2018-06-19  7:24 ` Dandan Bi [this message]
2018-06-19  7:24 ` [patch 7/9] MdeModulePkg: Use new added Perf macros Dandan Bi
2018-06-19  7:24 ` [patch 8/9] SecurityPkg: " Dandan Bi
2018-06-19  7:24 ` [patch 9/9] UefiCpuPkg: " Dandan Bi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180619072405.142872-7-dandan.bi@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox