StdLib: Eliminate TimerLib dependencies.

Implement the clock() function using the EFI time-of-day clock instead of a TimerLib instance.

Signed-off-by: darylm503
Reviewed-by: jljusten
Reviewed-by: geekboy15a


git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12683 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
darylm503 2011-11-11 00:32:31 +00:00
parent 4b3d663f7b
commit 8aa163da5a
5 changed files with 36 additions and 76 deletions

View File

@ -100,7 +100,6 @@
BaseLib BaseLib
BaseMemoryLib BaseMemoryLib
MemoryAllocationLib MemoryAllocationLib
TimerLib
LibStdLib LibStdLib
LibStdio LibStdio
LibString LibString

View File

@ -27,8 +27,9 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h>
#include <MainData.h> #include <MainData.h>
#include <sys/EfiSysCall.h> #include <unistd.h>
extern int main( int, char**); extern int main( int, char**);
extern int __sse2_available; extern int __sse2_available;
@ -149,13 +150,8 @@ ShellAppMain (
errno = 0; errno = 0;
EFIerrno = 0; EFIerrno = 0;
#ifdef NT32dvm gMD->ClocksPerSecond = 1;
gMD->ClocksPerSecond = 1; // For NT32 only gMD->AppStartTime = (clock_t)((UINT32)time(NULL));
gMD->AppStartTime = 1; // For NT32 only
#else
gMD->ClocksPerSecond = (clock_t)GetPerformanceCounterProperties( NULL, NULL);
gMD->AppStartTime = (clock_t)GetPerformanceCounter();
#endif /* NT32 dvm */
// Initialize file descriptors // Initialize file descriptors
mfd = gMD->fdarray; mfd = gMD->fdarray;

View File

@ -180,34 +180,6 @@ timesub(
/* ############### Time Manipulation Functions ########################## */ /* ############### Time Manipulation Functions ########################## */
/** The clock function determines the processor time used.
@return The clock function returns the implementation's best
approximation to the processor time used by the program since the
beginning of an implementation-defined era related only to the
program invocation. To determine the time in seconds, the value
returned by the clock function should be divided by the value of
the macro CLOCKS_PER_SEC. If the processor time used is not
available or its value cannot be represented, the function
returns the value (clock_t)(-1).
On IA32 or X64 platforms, the value returned is the number of
CPU TimeStamp Counter ticks since the appliation started.
**/
clock_t
clock(void)
{
#ifndef NT32dvm
clock_t temp;
temp = (clock_t)GetPerformanceCounter();
return temp - gMD->AppStartTime;
#else
return (clock_t)-1;
#endif /* NT32dvm */
}
/** /**
**/ **/
double double
@ -591,6 +563,28 @@ time(time_t *timer)
return CalTime; // Return calendar time in microseconds return CalTime; // Return calendar time in microseconds
} }
/** The clock function determines the processor time used.
@return The clock function returns the implementation's best
approximation to the processor time used by the program since the
beginning of an implementation-defined era related only to the
program invocation. To determine the time in seconds, the value
returned by the clock function should be divided by the value of
the macro CLOCKS_PER_SEC. If the processor time used is not
available or its value cannot be represented, the function
returns the value (clock_t)(-1).
**/
clock_t
clock(void)
{
clock_t retval;
time_t temp;
temp = time(NULL);
retval = ((clock_t)((UINT32)temp)) - gMD->AppStartTime;
return retval;
}
/* ################# Time Conversion Functions ########################## */ /* ################# Time Conversion Functions ########################## */
/* /*
Except for the strftime function, these functions each return a pointer to Except for the strftime function, these functions each return a pointer to

View File

@ -43,7 +43,6 @@
[LibraryClasses] [LibraryClasses]
UefiLib UefiLib
TimerLib
BaseLib BaseLib
UefiRuntimeServicesTableLib UefiRuntimeServicesTableLib

View File

@ -56,37 +56,8 @@
DevShell|StdLib/LibC/Uefi/Devices/daShell.inf DevShell|StdLib/LibC/Uefi/Devices/daShell.inf
DevUtility|StdLib/LibC/Uefi/Devices/daUtility.inf DevUtility|StdLib/LibC/Uefi/Devices/daUtility.inf
###
# Select the correct TimerLib instance depending upon whether running under
# an emulation environment, or not.
!ifndef $(EMULATE)
# Not running in an Emulation Environment
[LibraryClasses.IA32.UEFI_APPLICATION]
TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf
# TimerLib|PerformancePkg/Library/TscTimerLib/DxeTscTimerLib.inf
[LibraryClasses.X64.UEFI_APPLICATION]
TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf
# TimerLib|PerformancePkg/Library/TscTimerLib/DxeTscTimerLib.inf
[LibraryClasses.IPF.UEFI_APPLICATION]
PalLib|MdePkg/Library/UefiPalLib/UefiPalLib.inf
TimerLib|MdePkg/Library/SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.inf
[LibraryClasses.ARM.UEFI_APPLICATION] [LibraryClasses.ARM.UEFI_APPLICATION]
NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf
!else
# Use this instance if Running in an Emulation Environment.
[LibraryClasses.Common.UEFI_APPLICATION]
TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf
[LibraryClasses.ARM.UEFI_APPLICATION]
NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
!endif
[Components] [Components]
# BaseLib and BaseMemoryLib need to be built with the /GL- switch when using the Microsoft # BaseLib and BaseMemoryLib need to be built with the /GL- switch when using the Microsoft
@ -120,17 +91,18 @@
# These Build Options are used when building the Standard Libraries to be run # These Build Options are used when building the Standard Libraries to be run
# on real hardware. # on real hardware.
INTEL:*_*_*_CC_FLAGS = /Qfreestanding INTEL:*_*_*_CC_FLAGS = /Qfreestanding
MSFT:*_*_*_CC_FLAGS = /X /Zc:wchar_t /D NT32dvm MSFT:*_*_*_CC_FLAGS = /X /Zc:wchar_t
GCC:*_*_*_CC_FLAGS = -nostdinc -nostdlib GCC:*_*_*_CC_FLAGS = -nostdinc -nostdlib
RVCT:*_*_*_CC_FLAGS = --library_interface=none -J$(WORKSPACE)/StdLib/Include -J$(WORKSPACE)/StdLib/Include/Arm -DNT32dvm RVCT:*_*_*_CC_FLAGS = --library_interface=none -J$(WORKSPACE)/StdLib/Include -J$(WORKSPACE)/StdLib/Include/Arm
ARMGCC:*_*_*_CC_FLAGS = -nostdinc -nostdlib -Wno-unknown-pragmas -Wno-unused -Wno-format-zero-length -DNT32dvm ARMGCC:*_*_*_CC_FLAGS = -nostdinc -nostdlib -Wno-unknown-pragmas -Wno-unused -Wno-format-zero-length
!else !else
# The Build Options, below, are only used when building the Standard Libraries # The Build Options, below, are only used when building the Standard Libraries
# to be run under an emulation environment. They disable the clock() system call # to be run under an emulation environment.
# which is currently incompatible with the most emulation environments. # They disable optimization which facillitates debugging under the Emulation environment.
# Select the correct TimerLib instance, above. INTEL:*_*_IA32_CC_FLAGS = /Od
INTEL:*_*_IA32_CC_FLAGS = /Od /D NT32dvm MSFT:*_*_IA32_CC_FLAGS = /Od
MSFT:*_*_IA32_CC_FLAGS = /Od /D NT32dvm GCC:*_*_IA32_CC_FLAGS = -O0
GCC:*_*_IA32_CC_FLAGS = -O0 -DNT32dvm RVCT:*_*_*_CC_FLAGS = --library_interface=none -J$(WORKSPACE)/StdLib/Include -J$(WORKSPACE)/StdLib/Include/Arm
ARMGCC:*_*_*_CC_FLAGS = -O0 -Wno-unknown-pragmas -Wno-unused -Wno-format-zero-length
!endif !endif