MdeModulepkg DxeSmmPerformanceLib: Dump all PEI/DXE/SMM performance data.

For boot performance dump, as current behavior.
It depends on which PerformanceLib instance the DP application linked to.
For example, if DxePerfrmanceLib(MdeModulePkg\Library\DxePerformanceLib)
got linked, it will try to dump PEI and DXE performance data; and if
DxeSmmPerfrmanceLib(MdeModulePkg\Library\DxeSmmPerformanceLib)
got linked, then SMM performance data are expected.

It has burden and confusion to developers about the DP application need to be linked to
different PerformanceLib instance in *.dsc and rebuilt for the performance data dump.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17548 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Star Zeng 2015-06-02 10:20:13 +00:00 committed by lzeng14
parent f41c71d26a
commit dccfb097ec
2 changed files with 244 additions and 30 deletions

View File

@ -1,11 +1,11 @@
/** @file
Performance library instance used in DXE phase to dump SMM performance data.
Performance library instance used in DXE phase to dump both PEI/DXE and SMM performance data.
This library instance allows a DXE driver or UEFI application to dump the SMM performance data.
This library instance allows a DXE driver or UEFI application to dump both PEI/DXE and SMM performance data.
StartPerformanceMeasurement(), EndPerformanceMeasurement(), StartPerformanceMeasurementEx()
and EndPerformanceMeasurementEx() are not implemented.
Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -33,9 +33,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Protocol/SmmCommunication.h>
#define SMM_PERFORMANCE_COMMUNICATION_BUFFER_SIZE (OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof (SMM_PERF_COMMUNICATE))
//
// The cached performance protocol interface.
//
EFI_SMM_COMMUNICATION_PROTOCOL *mSmmCommunication = NULL;
UINT8 mSmmPerformanceBuffer[SMM_PERFORMANCE_COMMUNICATION_BUFFER_SIZE];
GAUGE_DATA_ENTRY *mGaugeData = NULL;
@ -43,6 +41,12 @@ UINTN mGaugeNumberOfEntries = 0;
GAUGE_DATA_ENTRY_EX *mGaugeDataEx = NULL;
UINTN mGaugeNumberOfEntriesEx = 0;
//
// The cached Performance Protocol and PerformanceEx Protocol interface.
//
PERFORMANCE_PROTOCOL *mPerformance = NULL;
PERFORMANCE_EX_PROTOCOL *mPerformanceEx = NULL;
/**
The function caches the pointer to SMM Communication protocol.
@ -76,6 +80,51 @@ GetCommunicationProtocol (
return Status;
}
/**
The function caches the pointers to PerformanceEx protocol and Performance Protocol.
The function locates PerformanceEx protocol and Performance Protocol from protocol database.
@retval EFI_SUCCESS PerformanceEx protocol or Performance Protocol is successfully located.
@retval EFI_NOT_FOUND Both PerformanceEx protocol and Performance Protocol are not located to log performance.
**/
EFI_STATUS
GetPerformanceProtocol (
VOID
)
{
EFI_STATUS Status;
PERFORMANCE_PROTOCOL *Performance;
PERFORMANCE_EX_PROTOCOL *PerformanceEx;
if (mPerformanceEx != NULL || mPerformance != NULL) {
return EFI_SUCCESS;
}
Status = gBS->LocateProtocol (&gPerformanceExProtocolGuid, NULL, (VOID **) &PerformanceEx);
if (!EFI_ERROR (Status)) {
ASSERT (PerformanceEx != NULL);
//
// Cache PerformanceEx Protocol.
//
mPerformanceEx = PerformanceEx;
return EFI_SUCCESS;
}
Status = gBS->LocateProtocol (&gPerformanceProtocolGuid, NULL, (VOID **) &Performance);
if (!EFI_ERROR (Status)) {
ASSERT (Performance != NULL);
//
// Cache performance protocol.
//
mPerformance = Performance;
return EFI_SUCCESS;
}
return EFI_NOT_FOUND;
}
/**
Creates a record for the beginning of a performance measurement.
@ -214,17 +263,122 @@ EndPerformanceMeasurement (
return RETURN_SUCCESS;
}
/**
Attempts to retrieve a performance measurement log entry from the performance measurement log.
It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,
and then assign the Identifier with 0.
Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
zero on entry, then an attempt is made to retrieve the first entry from the performance log,
and the key for the second entry in the log is returned. If the performance log is empty,
then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
retrieved and an implementation specific non-zero key value that specifies the end of the performance
log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
is retrieved and zero is returned. In the cases where a performance log entry can be returned,
the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.
If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
If Handle is NULL, then ASSERT().
If Token is NULL, then ASSERT().
If Module is NULL, then ASSERT().
If StartTimeStamp is NULL, then ASSERT().
If EndTimeStamp is NULL, then ASSERT().
If Identifier is NULL, then ASSERT().
@param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
0, then the first performance measurement log entry is retrieved.
On exit, the key of the next performance log entry.
@param Handle Pointer to environment specific context used to identify the component
being measured.
@param Token Pointer to a Null-terminated ASCII string that identifies the component
being measured.
@param Module Pointer to a Null-terminated ASCII string that identifies the module
being measured.
@param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
was started.
@param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
was ended.
@param Identifier Pointer to the 32-bit identifier that was recorded.
@return The key for the next performance log entry (in general case).
**/
UINTN
EFIAPI
GetByPerformanceProtocol (
IN UINTN LogEntryKey,
OUT CONST VOID **Handle,
OUT CONST CHAR8 **Token,
OUT CONST CHAR8 **Module,
OUT UINT64 *StartTimeStamp,
OUT UINT64 *EndTimeStamp,
OUT UINT32 *Identifier
)
{
EFI_STATUS Status;
GAUGE_DATA_ENTRY_EX *GaugeData;
Status = GetPerformanceProtocol ();
if (EFI_ERROR (Status)) {
return 0;
}
if (mPerformanceEx != NULL) {
Status = mPerformanceEx->GetGaugeEx (LogEntryKey++, &GaugeData);
} else if (mPerformance != NULL) {
Status = mPerformance->GetGauge (LogEntryKey++, (GAUGE_DATA_ENTRY **) &GaugeData);
} else {
ASSERT (FALSE);
return 0;
}
//
// Make sure that LogEntryKey is a valid log entry key,
//
ASSERT (Status != EFI_INVALID_PARAMETER);
if (EFI_ERROR (Status)) {
//
// The LogEntryKey is the last entry (equals to the total entry number).
//
return 0;
}
ASSERT (GaugeData != NULL);
*Handle = (VOID *) (UINTN) GaugeData->Handle;
*Token = GaugeData->Token;
*Module = GaugeData->Module;
*StartTimeStamp = GaugeData->StartTimeStamp;
*EndTimeStamp = GaugeData->EndTimeStamp;
if (mPerformanceEx != NULL) {
*Identifier = GaugeData->Identifier;
} else {
*Identifier = 0;
}
return LogEntryKey;
}
/**
Retrieves all previous logged performance measurement.
Function will use SMM communicate protocol to get all previous SMM performance measurement data.
If success, data buffer will be returned. If fail function will return NULL.
@param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
0, then the first performance measurement log entry is retrieved.
On exit, the key of the next performance log entry.
@retval !NULL Get all gauge data success.
@retval NULL Get all guage data failed.
**/
GAUGE_DATA_ENTRY *
EFIAPI
GetAllSmmGaugeData (VOID)
GetAllSmmGaugeData (
IN UINTN LogEntryKey
)
{
EFI_STATUS Status;
EFI_SMM_COMMUNICATE_HEADER *SmmCommBufferHeader;
@ -232,9 +386,20 @@ GetAllSmmGaugeData (VOID)
UINTN CommSize;
UINTN DataSize;
if (LogEntryKey != 0) {
if (mGaugeData != NULL) {
return mGaugeData;
}
} else {
//
// Reget the SMM guage data at the first entry get.
//
if (mGaugeData != NULL) {
FreePool (mGaugeData);
mGaugeData = NULL;
mGaugeNumberOfEntries = 0;
}
}
Status = GetCommunicationProtocol ();
if (EFI_ERROR (Status)) {
@ -289,12 +454,18 @@ GetAllSmmGaugeData (VOID)
Function will use SMM communicate protocol to get all previous SMM performance measurement data.
If success, data buffer will be returned. If fail function will return NULL.
@param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
0, then the first performance measurement log entry is retrieved.
On exit, the key of the next performance log entry.
@retval !NULL Get all gauge data success.
@retval NULL Get all guage data failed.
**/
GAUGE_DATA_ENTRY_EX *
EFIAPI
GetAllSmmGaugeDataEx (VOID)
GetAllSmmGaugeDataEx (
IN UINTN LogEntryKey
)
{
EFI_STATUS Status;
EFI_SMM_COMMUNICATE_HEADER *SmmCommBufferHeader;
@ -302,9 +473,20 @@ GetAllSmmGaugeDataEx (VOID)
UINTN CommSize;
UINTN DataSize;
if (LogEntryKey != 0) {
if (mGaugeDataEx != NULL) {
return mGaugeDataEx;
}
} else {
//
// Reget the SMM guage data at the first entry get.
//
if (mGaugeDataEx != NULL) {
FreePool (mGaugeDataEx);
mGaugeDataEx = NULL;
mGaugeNumberOfEntriesEx = 0;
}
}
Status = GetCommunicationProtocol ();
if (EFI_ERROR (Status)) {
@ -418,29 +600,59 @@ GetPerformanceMeasurementEx (
ASSERT (EndTimeStamp != NULL);
ASSERT (Identifier != NULL);
mGaugeDataEx = GetAllSmmGaugeDataEx();
mGaugeDataEx = GetAllSmmGaugeDataEx (LogEntryKey);
if (mGaugeDataEx != NULL) {
if (LogEntryKey >= mGaugeNumberOfEntriesEx) {
//
// Make sure that LogEntryKey is a valid log entry key.
// Try to get the data by Performance Protocol.
//
ASSERT (LogEntryKey <= mGaugeNumberOfEntriesEx);
if (LogEntryKey == mGaugeNumberOfEntriesEx) {
return 0;
LogEntryKey = LogEntryKey - mGaugeNumberOfEntriesEx;
LogEntryKey = GetByPerformanceProtocol (
LogEntryKey,
Handle,
Token,
Module,
StartTimeStamp,
EndTimeStamp,
Identifier
);
if (LogEntryKey == 0) {
//
// Last entry.
//
return LogEntryKey;
} else {
return (LogEntryKey + mGaugeNumberOfEntriesEx);
}
}
GaugeData = &mGaugeDataEx[LogEntryKey++];
*Identifier = GaugeData->Identifier;
} else {
mGaugeData = GetAllSmmGaugeData();
mGaugeData = GetAllSmmGaugeData (LogEntryKey);
if (mGaugeData != NULL) {
if (LogEntryKey >= mGaugeNumberOfEntries) {
//
// Make sure that LogEntryKey is a valid log entry key.
// Try to get the data by Performance Protocol.
//
ASSERT (LogEntryKey <= mGaugeNumberOfEntries);
if (LogEntryKey == mGaugeNumberOfEntries) {
return 0;
LogEntryKey = LogEntryKey - mGaugeNumberOfEntries;
LogEntryKey = GetByPerformanceProtocol (
LogEntryKey,
Handle,
Token,
Module,
StartTimeStamp,
EndTimeStamp,
Identifier
);
if (LogEntryKey == 0) {
//
// Last entry.
//
return LogEntryKey;
} else {
return (LogEntryKey + mGaugeNumberOfEntries);
}
}
GaugeData = (GAUGE_DATA_ENTRY_EX *) &mGaugeData[LogEntryKey++];

View File

@ -1,11 +1,11 @@
## @file
# Performance library instance used in DXE phase to dump SMM performance data.
#
# This library instance allows a DXE driver or UEFI application to dump the SMM performance data.
# This library instance allows a DXE driver or UEFI application to dump both PEI/DXE and SMM performance data.
# StartPerformanceMeasurement(), EndPerformanceMeasurement(), StartPerformanceMeasurementEx()
# and EndPerformanceMeasurementEx() are not implemented.
#
# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
@ -50,6 +50,8 @@
MemoryAllocationLib
[Guids]
gPerformanceProtocolGuid ## SOMETIMES_CONSUMES ## UNDEFINED # Locate protocol
gPerformanceExProtocolGuid ## SOMETIMES_CONSUMES ## UNDEFINED # Locate protocol
gSmmPerformanceProtocolGuid ## SOMETIMES_PRODUCES ## UNDEFINED # Used to do smm communication
gSmmPerformanceExProtocolGuid ## SOMETIMES_PRODUCES ## UNDEFINED # Used to do smm communication