> On Feb 4, 2016, at 10:17 AM, Estelle Yeh <[email protected]> wrote:
> 
> 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.
> 

OK that helps. 

> 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.
> 

A HOB is a Hand-Off-Block and they are defined in the PI specification. It is 
how data is handed from PEI to DXE. 

I'm not sure what TimerLib instance you are talking about? 
>git grep X86TimerLib -- *.inf
DuetPkg/Library/DuetTimerLib/DuetTimerLib.inf:35:  X86TimerLib.c
DuetPkg/Library/DuetTimerLib/DuetTimerLib.inf:38:  X86TimerLib.c
EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/BaseTimerLibLocalApic/BaseTimerLibLocalApic.inf:28:
  X86TimerLib.c
EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/BaseTimerLibLocalApic/BaseTimerLibLocalApic.inf:32:
  X86TimerLib.c
MdePkg/Library/SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.inf:43:  X86TimerLib.c
UefiCpuPkg/Library/SecPeiDxeTimerLibUefiCpu/SecPeiDxeTimerLibUefiCpu.inf:43:  
X86TimerLib.c

The easy way to see how a driver got constructed is to look at the build 
report. It will show what library instances got used, etc.  You need to make 
sure you tell the build.exe command to generate the build report. 

  -y REPORTFILE, --report-file=REPORTFILE
                        Create/overwrite the report to the specified filename.


> 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...

The DSC is what you build. The FDF is what gets put in the ROM, so you need an 
entry in the FDF. 

> 
> 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.
> 

That is RETURN_NOT_FOUND so your platform in not producing that protocol. 
You can use %r with DEBUG & Print and it will print the name of the error, vs 
the number.

Thanks,

Andrew Fish

> Thanks for the help,
> 
> Estelle
> 
> On Thu, Feb 4, 2016 at 9:50 AM, Kinney, Michael D <[email protected] 
> <mailto:[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] 
> > <mailto:[email protected]>] On Behalf Of Andrew Fish
> > Sent: Thursday, February 4, 2016 9:40 AM
> > To: Shubha Ramani <[email protected] <mailto:[email protected]>>
> > Cc: [email protected] <mailto:[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] 
> > > <mailto:[email protected]>> wrote:
> > >
> > > Hello Andrew Fish ? Anyone ? Does anyone know the answer to this question 
> > > in EDK2 ?
> > > Shubha Shubha D. [email protected] 
> > > <mailto:[email protected]>
> > > [email protected] <mailto:[email protected]>
> > >
> > >    On Wednesday, February 3, 2016 10:54 AM, Shubha Ramani 
> > > <[email protected] <mailto:[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] 
> > > <mailto:[email protected]>
> > > [email protected] <mailto:[email protected]>
> > >
> > >
> > > _______________________________________________
> > > edk2-devel mailing list
> > > [email protected] <mailto:[email protected]>
> > > https://lists.01.org/mailman/listinfo/edk2-devel 
> > > <https://lists.01.org/mailman/listinfo/edk2-devel>
> >
> > _______________________________________________
> > edk2-devel mailing list
> > [email protected] <mailto:[email protected]>
> > https://lists.01.org/mailman/listinfo/edk2-devel 
> > <https://lists.01.org/mailman/listinfo/edk2-devel>
> _______________________________________________
> edk2-devel mailing list
> [email protected] <mailto:[email protected]>
> https://lists.01.org/mailman/listinfo/edk2-devel 
> <https://lists.01.org/mailman/listinfo/edk2-devel>
> 

_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to