diff options
Diffstat (limited to 'EDK/Foundation/Library/EdkIIGlueLib/Library/SmmFirmwarePerformanceLib')
5 files changed, 457 insertions, 0 deletions
diff --git a/EDK/Foundation/Library/EdkIIGlueLib/Library/SmmFirmwarePerformanceLib/EdkIIGlueSmmFirmwarePerformanceLib.cif b/EDK/Foundation/Library/EdkIIGlueLib/Library/SmmFirmwarePerformanceLib/EdkIIGlueSmmFirmwarePerformanceLib.cif new file mode 100644 index 0000000..ef6464a --- /dev/null +++ b/EDK/Foundation/Library/EdkIIGlueLib/Library/SmmFirmwarePerformanceLib/EdkIIGlueSmmFirmwarePerformanceLib.cif @@ -0,0 +1,11 @@ +<component> + name = "EdkIIGlueSmmFirmwarePerformanceLib" + category = ModulePart + LocalRoot = "Edk\Foundation\Library\EdkIIGlueLib\Library\SmmFirmwarePerformanceLib" + RefName = "EdkIIGlueSmmFirmwarePerformanceLib" +[files] +"EdkIIGlueSmmFirmwarePerformanceLib.sdl" +"EdkIIGlueSmmFirmwarePerformanceLib.mak" +"EdkIIGlueSmmFirmwarePerformanceLib.inf" +"EdkIIGlueSmmPerformanceLib.c" +<endComponent> diff --git a/EDK/Foundation/Library/EdkIIGlueLib/Library/SmmFirmwarePerformanceLib/EdkIIGlueSmmFirmwarePerformanceLib.inf b/EDK/Foundation/Library/EdkIIGlueLib/Library/SmmFirmwarePerformanceLib/EdkIIGlueSmmFirmwarePerformanceLib.inf new file mode 100644 index 0000000..8568f7f --- /dev/null +++ b/EDK/Foundation/Library/EdkIIGlueLib/Library/SmmFirmwarePerformanceLib/EdkIIGlueSmmFirmwarePerformanceLib.inf @@ -0,0 +1,81 @@ +#/*++ +# +# Copyright (c) 2011 - 2012, Intel Corporation +# All rights reserved. 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 +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# Module Name: +# +# EdkIIGlueSmmFirmwarePerformanceLib.inf +# +# Abstract: +# +# Component description file for SmmFirmwarePerformanceLib +# +#--*/ + +[defines] +BASE_NAME = EdkIIGlueSmmFirmwarePerformanceLib +COMPONENT_TYPE = LIBRARY + +[sources.common] + EdkIIGlueSmmPerformanceLib.c + +[sources.ia32] + +[sources.x64] + +[sources.ipf] + +[sources.ebc] + + +[includes.common] + . + ..\..\Include + ..\..\include\Library + $(EDK_SOURCE)\Foundation + $(EDK_SOURCE)\Foundation\Framework + $(EDK_SOURCE)\Foundation\Efi + $(EDK_SOURCE)\Foundation\Include + $(EDK_SOURCE)\Foundation\Efi\Include + $(EDK_SOURCE)\Foundation\Framework\Include + $(EDK_SOURCE)\Foundation\Include\IndustryStandard + $(EDK_SOURCE)\Foundation\Core\Dxe + $(EDK_SOURCE)\Foundation\Library\Dxe\Include + $(EDK_SOURCE)\Foundation\Cpu\Pentium\Include + +[libraries.common] + EdkIIGlueBaseTimerLibLocalApic + EdkIIGlueUefiLib + EdkIIGlueBaseTimerLibTsc + +[libraries.ia32] + +[libraries.x64] + +[libraries.ebc] + + +[nmake.common] + C_FLAGS = $(C_FLAGS) /D EDKII_GLUE_LIBRARY_IMPLEMENTATION + LIB_STD_FLAGS = $(LIB_STD_FLAGS) /IGNORE:4006 /IGNORE:4221 + +[nmake.ia32] + C_FLAGS = $(C_FLAGS) /D MDE_CPU_IA32 + +[nmake.x64] + C_FLAGS = $(C_FLAGS) /D MDE_CPU_X64 + +[nmake.ipf] + C_FLAGS = $(C_FLAGS) /D MDE_CPU_IPF + +[nmake.ebc] + EBC_C_STD_FLAGS = $(EBC_C_STD_FLAGS) /D EDKII_GLUE_LIBRARY_IMPLEMENTATION + EBC_LIB_STD_FLAGS = $(EBC_LIB_STD_FLAGS) /IGNORE:4006 /IGNORE:4221 + EBC_C_STD_FLAGS = $(EBC_C_STD_FLAGS) /D MDE_CPU_EBC
\ No newline at end of file diff --git a/EDK/Foundation/Library/EdkIIGlueLib/Library/SmmFirmwarePerformanceLib/EdkIIGlueSmmFirmwarePerformanceLib.mak b/EDK/Foundation/Library/EdkIIGlueLib/Library/SmmFirmwarePerformanceLib/EdkIIGlueSmmFirmwarePerformanceLib.mak new file mode 100644 index 0000000..b53d2ee --- /dev/null +++ b/EDK/Foundation/Library/EdkIIGlueLib/Library/SmmFirmwarePerformanceLib/EdkIIGlueSmmFirmwarePerformanceLib.mak @@ -0,0 +1,79 @@ +#********************************************************************** +#********************************************************************** +#** ** +#** (C)Copyright 1985-2011, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#********************************************************************** +#********************************************************************** + +#********************************************************************** +# $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/IntelEDK/EdkIIGlue/EdkIIGlueSmmFirmwarePerformanceLib/EdkIIGlueSmmFirmwarePerformanceLib.mak 1 1/20/12 3:59a Jeffch $ +# +# $Revision: 1 $ +# +# $Date: 1/20/12 3:59a $ +#********************************************************************** +# Revision History +# ---------------- +# $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/IntelEDK/EdkIIGlue/EdkIIGlueSmmFirmwarePerformanceLib/EdkIIGlueSmmFirmwarePerformanceLib.mak $ +# +# 1 1/20/12 3:59a Jeffch +# Create Intel EDK 1117 Patch 7. +# +# 1 9/27/11 6:22a Wesleychen +# Intel EDK initially releases. +# +# +#********************************************************************** +#<AMI_FHDR_START> +# +# Name: EdkIIGlueSmmFirmwarePerformanceLib.mak +# +# Description: +# +#<AMI_FHDR_END> +#********************************************************************** + + +$(EdkIIGlueSmmFirmwarePerformanceLib_LIB) : EdkIIGlueSmmFirmwarePerformanceLib + +EdkIIGlueSmmFirmwarePerformanceLib : $(BUILD_DIR)\EdkIIGlueSmmFirmwarePerformanceLib.mak EdkIIGlueSmmFirmwarePerformanceLibBin + +$(BUILD_DIR)\EdkIIGlueSmmFirmwarePerformanceLib.mak : $(EdkIIGlueSmmFirmwarePerformanceLib_DIR)\$(@B).cif $(EdkIIGlueSmmFirmwarePerformanceLib_DIR)\$(@B).mak $(BUILD_RULES) + $(CIF2MAK) $(EdkIIGlueSmmFirmwarePerformanceLib_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS) + +EdkIIGlueSmmFirmwarePerformanceLibBin : $(EdkIIGlueBaseTimerLibLocalApic_LIB) $(EdkIIGlueUefiLib_LIB) $(EdkIIGlueBaseTimerLibTsc_LIB) $(EDKGUIDLIB) $(ARCHPROTOCOLLIB) +!IF "$(x64_BUILD)"=="1" + $(MAKE) /$(MAKEFLAGS) $(EDKIIGLUE_DEFAULTS)\ + BUILD_DIR=$(BUILD_DIR)\ + /f $(BUILD_DIR)\EdkIIGlueSmmFirmwarePerformanceLib.mak all\ + TYPE=LIBRARY "PARAMETERS=LIBRARY_NAME=$$(EdkIIGlueSmmFirmwarePerformanceLib_LIB)" + $(MAKE) /$(MAKEFLAGS) $(EDKIIGLUE_DEFAULTS)\ + BUILD_DIR=$(BUILD_DIR)\IA32\ + /f $(BUILD_DIR)\EdkIIGlueSmmFirmwarePerformanceLib.mak all\ + TYPE=PEI_LIBRARY "PARAMETERS=LIBRARY_NAME=$$(EdkIIGlueSmmFirmwarePerformanceLib_LIB)" +!ELSE + $(MAKE) /$(MAKEFLAGS) $(EDKIIGLUE_DEFAULTS)\ + BUILD_DIR=$(BUILD_DIR)\ + /f $(BUILD_DIR)\EdkIIGlueSmmFirmwarePerformanceLib.mak all\ + TYPE=LIBRARY "PARAMETERS=LIBRARY_NAME=$$(EdkIIGlueSmmFirmwarePerformanceLib_LIB)" +!ENDIF +#********************************************************************** +#********************************************************************** +#** ** +#** (C)Copyright 1985-2011, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#********************************************************************** +#**********************************************************************
\ No newline at end of file diff --git a/EDK/Foundation/Library/EdkIIGlueLib/Library/SmmFirmwarePerformanceLib/EdkIIGlueSmmFirmwarePerformanceLib.sdl b/EDK/Foundation/Library/EdkIIGlueLib/Library/SmmFirmwarePerformanceLib/EdkIIGlueSmmFirmwarePerformanceLib.sdl new file mode 100644 index 0000000..dd89ca3 --- /dev/null +++ b/EDK/Foundation/Library/EdkIIGlueLib/Library/SmmFirmwarePerformanceLib/EdkIIGlueSmmFirmwarePerformanceLib.sdl @@ -0,0 +1,25 @@ +TOKEN + Name = "EdkIIGlueSmmFirmwarePerformanceLib_SUPPORT" + Value = "1" + Help = "Main switch to enable EdkIIGlueSmmFirmwarePerformanceLib support in Project" + TokenType = Boolean + TargetEQU = Yes + TargetMAK = Yes + Master = Yes +End + +TOKEN + Name = "EdkIIGlueSmmFirmwarePerformanceLib_LIB" + Value = "$$(LIB_BUILD_DIR)\EdkIIGlueSmmFirmwarePerformanceLib.lib" + TokenType = Expression + TargetMAK = Yes +End + +PATH + Name = "EdkIIGlueSmmFirmwarePerformanceLib_DIR" +End + +MODULE + Help = "Includes EdkIIGlueSmmFirmwarePerformanceLib.mak to Project" + File = "EdkIIGlueSmmFirmwarePerformanceLib.mak" +End
\ No newline at end of file diff --git a/EDK/Foundation/Library/EdkIIGlueLib/Library/SmmFirmwarePerformanceLib/EdkIIGlueSmmPerformanceLib.c b/EDK/Foundation/Library/EdkIIGlueLib/Library/SmmFirmwarePerformanceLib/EdkIIGlueSmmPerformanceLib.c new file mode 100644 index 0000000..880a502 --- /dev/null +++ b/EDK/Foundation/Library/EdkIIGlueLib/Library/SmmFirmwarePerformanceLib/EdkIIGlueSmmPerformanceLib.c @@ -0,0 +1,261 @@ +/*++ + +Copyright (c) 2011 - 2012, Intel Corporation +All rights reserved. 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 +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + + +Module Name: + + EdkIIGlueSmmPerformanceLib.c + +Abstract: + + SMM Library for FPDT performance logging. + +--*/ + +#include "EdkIIGlueDxe.h" +#include EFI_PROTOCOL_DEFINITION (Fpdt) +#include EFI_PROTOCOL_DEFINITION (FirmwarePerformance) + +UINT64 *mStartTicker; +UINT32 mFunctionNumber; + +RUNTIME_MODULE_PERF_RECORD *mRuntimeModulePerfRecord = NULL; +RUNTIME_FUNCTION_PERF_RECORD *mRuntimeFunctionPerfRecord = NULL; + +EFI_GUID gFpdtPerformanceProtocolGuid = FPDT_PERFORMANCE_PROTOCOL_GUID; +EFI_GUID gEfiEventReadyToBootGuid = EFI_EVENT_GROUP_READY_TO_BOOT; + +EFI_STATUS +StartMeasureEx ( + IN EFI_HANDLE Handle, + IN UINT16 *Token, + IN UINT16 *Host, + IN UINT64 Timestamp, + IN UINT16 Identifier + ) +/*++ + +Routine Description: + + Start measurement according to token field. Inserts data into pre-allocatede memory buffer + Updates FPDT table using protocol API + +Arguments: + + Handle - Handle to measure + Token - Token to measure + Host - Host to measure + Timestamp - Ticker as start tick + Identifier - Identifier for a record + +Returns: + + EFI_SUCCESS - Located protocol successfully, and buffer is updated with new record + EFI_BUFFER_TOO_SMALL - Allocated memory is not enough to store new function + EFI_NOT_FOUND - Failure in update + +--*/ +{ + EFI_STATUS Status; + UINT32 Index; + UINT32 RmptTableLength; + + FPDT_PERFORMANCE_PROTOCOL *FpdtProtocol; + VOID *TableAddress; + EFI_GUID *GuidName; + RUNTIME_PERF_TABLE_HEADER *RuntimePerfTableHeader; + + RmptTableLength = 0; + + if (!StrCmp(Token, SMM_MODULE_TOK)) { + // + // Create RMPT table. The input Identifier specifies the max number of functions in this module. + // + mFunctionNumber = Identifier; + RmptTableLength = sizeof (RUNTIME_PERF_TABLE_HEADER) + + sizeof (RUNTIME_MODULE_PERF_RECORD) + + (sizeof(RUNTIME_FUNCTION_PERF_RECORD) * mFunctionNumber); + + // + // Allocate reseved memory for RMPT table + // + Status = (gBS->AllocatePool) (EfiReservedMemoryType, RmptTableLength, &TableAddress); + ZeroMem (TableAddress, RmptTableLength); + + Status = (gBS->AllocatePool) (EfiReservedMemoryType, sizeof (UINT64) * mFunctionNumber, &mStartTicker); + ZeroMem (mStartTicker, (sizeof (UINT64) * mFunctionNumber)); + + RuntimePerfTableHeader = (RUNTIME_PERF_TABLE_HEADER *) TableAddress; + mRuntimeModulePerfRecord = (RUNTIME_MODULE_PERF_RECORD *) ((UINT8 *) TableAddress + sizeof (RUNTIME_PERF_TABLE_HEADER)); + mRuntimeFunctionPerfRecord = (RUNTIME_FUNCTION_PERF_RECORD *) ((UINT8 *) mRuntimeModulePerfRecord + sizeof (RUNTIME_MODULE_PERF_RECORD)); + + // + // Fill RMPT table header + // + RuntimePerfTableHeader->Signature = RMPT_SIG; + RuntimePerfTableHeader->Length = RmptTableLength; + + GuidName = GetGuidFromHandle (Handle); + if (GuidName != NULL) { + (gBS->CopyMem) (&(RuntimePerfTableHeader->Guid), GuidName, sizeof (EFI_GUID)); + } + // + // Fill mRuntimeModulePerfRecord. + // + mRuntimeModulePerfRecord->RuntimeRecType = RUNTIME_MODULE_REC_TYPE; + mRuntimeModulePerfRecord->Revision = RECORD_REVISION_1; + mRuntimeModulePerfRecord->Reclength = sizeof (RUNTIME_MODULE_PERF_RECORD); + + // + // Call FPDT performance protocol to add RMPT table pointer record into FPDT table. + // + Status = (gBS->LocateProtocol) ( + &gFpdtPerformanceProtocolGuid, + NULL, + &FpdtProtocol + ); + ASSERT_EFI_ERROR (Status); + + if (!EFI_ERROR(Status)) { + Status = FpdtProtocol->UpdateRecord ( + FpdtProtocol, + Handle, + RUNTIME_MODULE_TABLE_PTR_TYPE, + (UINT64) TableAddress, + 0 + ); + ASSERT_EFI_ERROR (Status); + } + } + + if (!StrCmp (Token, SMM_FUNCTION_TOK)) { + // + // Add function record into RMPT table. + // The input Identifier is the function ID. + // + // + // Add function record into Record buffer. + // + for (Index = 0; Index < mFunctionNumber; Index++) { + if (mRuntimeFunctionPerfRecord[Index].RuntimeRecType == 0) { + // + // Fucntion ID is not found in Record buffer. + // + break; + } + + if (mRuntimeFunctionPerfRecord[Index].FunctionId == Identifier) { + // + // This function ID is found in Record buffer. + // + break; + } + } + + if (Index == mFunctionNumber) { + // + // Function record buffer is not enough to store new function. + // + return EFI_BUFFER_TOO_SMALL; + } + + if (mRuntimeFunctionPerfRecord[Index].RuntimeRecType == 0) { + // + // New function ID is found. Need to add it into FunctionRecord buffer. + // + mRuntimeFunctionPerfRecord[Index].RuntimeRecType = RUNTIME_FUNCTION_REC_TYPE; + mRuntimeFunctionPerfRecord[Index].Revision = RECORD_REVISION_1; + mRuntimeFunctionPerfRecord[Index].Reclength = sizeof (RUNTIME_FUNCTION_PERF_RECORD); + mRuntimeFunctionPerfRecord[Index].FunctionId = Identifier; + } + // + // Record start tick. + // + mStartTicker[Index] = GetTimeInNanoSec (Timestamp); + } + + return EFI_SUCCESS; +} + +EFI_STATUS +EndMeasureEx ( + IN EFI_HANDLE Handle, + IN UINT16 *Token, + IN UINT16 *Host, + IN UINT64 Timestamp, + IN UINT16 Identifier + ) +/*++ + +Routine Description: + + End measurement according to token field. Inserts data into pre-allocatede memory buffer + +Arguments: + + Handle - Handle to measure + Token - Token to measure + Host - Host to measure + Timestamp - Ticker as start tick + Identifier - Identifier for a record + +Returns: + + EFI_SUCCESS - Located protocol successfully, and buffer is updated with new record + EFI_BUFFER_TOO_SMALL - Allocated memory is not enough to store new function + EFI_NOT_FOUND - Fucntion ID is not found in Record buffer. + +--*/ +{ + UINT32 Index; + + if (!StrCmp (Token, SMM_FUNCTION_TOK)) { + // + // Update function record into RMPT table. + // The input Identifier is the function ID. + // + // + // Update function record into Record buffer. + // + for (Index = 0; Index < mFunctionNumber; Index++) { + if (mRuntimeFunctionPerfRecord[Index].RuntimeRecType == 0) { + // + // Fucntion ID is not found in Record buffer. + // + return EFI_NOT_FOUND; + } + + if (mRuntimeFunctionPerfRecord[Index].FunctionId == Identifier) { + // + // This function ID has been added. + // + break; + } + } + + if (Index == mFunctionNumber) { + // + // Fucntion ID is not found in Record buffer. + // + return EFI_NOT_FOUND; + } + + mRuntimeFunctionPerfRecord[Index].FunctionCallCount++; + mRuntimeFunctionPerfRecord[Index].FunctionResidency += (GetTimeInNanoSec (Timestamp)) - mStartTicker[Index]; + // + // Update Module Record. + // + mRuntimeModulePerfRecord->ModuleCallCount++; + mRuntimeModulePerfRecord->ModuleResidency += (GetTimeInNanoSec (Timestamp)) - mStartTicker[Index]; + } + + return EFI_SUCCESS; +}
\ No newline at end of file |