Andrew, Mike,
Shubba actually asked the question for me. I'm new to the UEFI world so
please excuse the beginner's questions.
To add a bit more context, I'm not trying to get a delay, but sample an
accurate time t1, run a workload and sample a time t2 right after.
1. About GetPerformanceCounter/Properties both returning 0: it seems to be
using the X86TimerLib instance (found it out adding some print statement in
it) so I may miss something obvious elsewhere. I traced the issue up until
GetNextGuidHob(), which returns NULL. I have honestly no idea what it means.
2. Andrew, how about GetTimestamp()? I also tried using it but I'm running
into another issue when locating the protocol (LocateProtocol or
LocateHandleBuffer both return error 14, "not found"). I
added MdeModulePkg/Universal/TimestampDxe/TimestampDxe.inf to the
Components section in my .dsc, and gEfiTimestampProtocolGuid in the .inf.
Clearly, I'm missing something...
Here's what I tried:
EFI_STATUS Status = EFI_SUCCESS;
UINTN HandleCount;
EFI_HANDLE *HandleBuffer;
Status = gBS->LocateProtocol(&gEfiTimestampProtocolGuid,
NULL,
(VOID**)&gTimestamp);
and
Status = gBS->LocateHandleBuffer(ByProtocol,
&gEfiTimestampProtocolGuid,
NULL,
&HandleCount,
&HandleBuffer);
Both returns 14.
Thanks for the help,
Estelle
On Thu, Feb 4, 2016 at 9:50 AM, Kinney, Michael D <
[email protected]> wrote:
> Shubha,
>
> The TimerLib class MdePkg/Include/Library/TimerLib.h has a function to
> convert
> TimerLin ticks to ns:
>
> /**
> Converts elapsed ticks of performance counter to time in nanoseconds.
>
> This function converts the elapsed ticks of running performance counter
> to
> time value in unit of nanoseconds.
>
> @param Ticks The number of elapsed ticks of running performance
> counter.
>
> @return The elapsed time in nanoseconds.
>
> **/
> UINT64
> EFIAPI
> GetTimeInNanoSecond (
> IN UINT64 Ticks
> );
>
>
>
> You can use the TimerLib to get a start tick value and end tick value using
>
> /**
> Retrieves the current value of a 64-bit free running performance counter.
>
> The counter can either count up by 1 or count down by 1. If the physical
> performance counter counts by a larger increment, then the counter values
> must be translated. The properties of the counter can be retrieved from
> GetPerformanceCounterProperties().
>
> @return The current value of the free running performance counter.
>
> **/
> UINT64
> EFIAPI
> GetPerformanceCounter (
> VOID
> );
>
>
>
> You do have to be aware that the performance counter can count up or down
> and
> Can also rollover. These attributes are available from the following
> TimerLib
> API:
>
> /**
> Retrieves the 64-bit frequency in Hz and the range of performance counter
> values.
>
> If StartValue is not NULL, then the value that the performance counter
> starts
> with immediately after is it rolls over is returned in StartValue. If
> EndValue is not NULL, then the value that the performance counter end
> with
> immediately before it rolls over is returned in EndValue. The 64-bit
> frequency of the performance counter in Hz is always returned. If
> StartValue
> is less than EndValue, then the performance counter counts up. If
> StartValue
> is greater than EndValue, then the performance counter counts down. For
> example, a 64-bit free running counter that counts up would have a
> StartValue
> of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counter
> that counts down would have a StartValue of 0xFFFFFF and an EndValue of
> 0.
>
> @param StartValue The value the performance counter starts with when it
> rolls over.
> @param EndValue The value that the performance counter ends with
> before
> it rolls over.
>
> @return The frequency in Hz.
>
> **/
> UINT64
> EFIAPI
> GetPerformanceCounterProperties (
> OUT UINT64 *StartValue, OPTIONAL
> OUT UINT64 *EndValue OPTIONAL
> );
>
> I agree with Andrew. If GetPerformanceCounter() is always returning 0,
> then
> you are likely using the wrong TimerLib instance or the HW counter the
> TimerLib is accessing has not been initialized yet.
>
> There is a NULL template of the TimerLib in MdePkg called
> BaseTimerLibNullTemplate
> And it always returns 0. That lib is intended to be a starting point for
> a new
> TimerLib for a new type of timer HW.
>
> Best regards,
>
> Mike
>
> > -----Original Message-----
> > From: edk2-devel [mailto:[email protected]] On Behalf Of
> Andrew Fish
> > Sent: Thursday, February 4, 2016 9:40 AM
> > To: Shubha Ramani <[email protected]>
> > Cc: [email protected]
> > Subject: Re: [edk2] How do you get current timestamp in ms or ns ?
> >
> >
> > > On Feb 4, 2016, at 9:35 AM, Shubha Ramani <[email protected]>
> wrote:
> > >
> > > Hello Andrew Fish ? Anyone ? Does anyone know the answer to this
> question in EDK2 ?
> > > Shubha Shubha D. [email protected]
> > > [email protected]
> > >
> > > On Wednesday, February 3, 2016 10:54 AM, Shubha Ramani <
> [email protected]>
> > wrote:
> > >
> > >
> > > Is there an EDK2 API which returns the current timetamp or current
> number of ticks
> > thathave elapsed in nanoseconds or milliseconds ?
> >
> > Number of ticks since what? EFI does not have the concept of a
> timestamp. You can use
> > gBS->Stall() to get a delay.
> >
> > > I have tried GetTime() and it returns the time in seconds. I need
> higher resolution
> > thanseconds.
> > > I also tried GetPerformanceCounter() but I get 0 for some reason.
> >
> > You have likely linked against the wrong instance of the TimerLib.
> >
> > Thanks,
> >
> > Andrew Fish
> >
> > > Thanks !
> > > Shubha Shubha D. [email protected]
> > > [email protected]
> > >
> > >
> > > _______________________________________________
> > > edk2-devel mailing list
> > > [email protected]
> > > https://lists.01.org/mailman/listinfo/edk2-devel
> >
> > _______________________________________________
> > edk2-devel mailing list
> > [email protected]
> > https://lists.01.org/mailman/listinfo/edk2-devel
> _______________________________________________
> edk2-devel mailing list
> [email protected]
> https://lists.01.org/mailman/listinfo/edk2-devel
>
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel