<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div>Rebecca, </div><div><br></div><div>gBS->Stall() is built on top [1] of the Metronome Architectural Protocol [2]. You should look at how the platform implements the Metronome Architectural Protocol. </div><div><br></div><div>It looks like most platform implement a generic Metronome Driver[3] that just sits on top of the platforms TimerLib [4] implementation. </div><div><br></div><div>You can find the TimerLib implementations via:</div><div><p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">$ git grep TimerLib -- \*.inf | grep LIBRARY_CLASS        </span></p>
<p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf:14:  LIBRARY_CLASS                  = TimerLib</span></p>
<p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">EmbeddedPkg/Library/DebugAgentTimerLibNull/DebugAgentTimerLibNull.inf:19:  LIBRARY_CLASS                  = DebugAgentTimerLib|SEC BASE DXE_CORE</span></p>
<p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">EmulatorPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.inf:22:  LIBRARY_CLASS                  = TimerLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_DRIVER UEFI_APPLICATION</span></p>
<p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.inf:22:  LIBRARY_CLASS                  = TimerLib|DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_DRIVER UEFI_APPLICATION</span></p>
<p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.inf:22:  LIBRARY_CLASS                  = TimerLib|PEIM PEI_CORE SEC</span></p>
<p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf:23:  LIBRARY_CLASS                  = TimerLib</span></p>
<p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">MdePkg/Library/SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.inf:30:  LIBRARY_CLASS                  = TimerLib</span></p>
<p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf:17:  LIBRARY_CLASS  = TimerLib|PEI_CORE PEIM DXE_CORE</span></p>
<p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLibBhyve.inf:18:  LIBRARY_CLASS  = TimerLib</span></p>
<p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf:16:  LIBRARY_CLASS  = TimerLib|SEC</span></p>
<p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf:17:  LIBRARY_CLASS  = TimerLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_DRIVER UEFI_APPLICATION SMM_CORE</span></p>
<p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">PcAtChipsetPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf:21:  LIBRARY_CLASS                  = TimerLib|SEC PEI_CORE PEIM</span></p>
<p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf:21:  LIBRARY_CLASS                  = TimerLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER SMM_CORE</span></p>
<p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf:21:  LIBRARY_CLASS                  = TimerLib|PEI_CORE PEIM</span></p>
<p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.inf:23:  LIBRARY_CLASS                  = TimerLib|MM_CORE_STANDALONE MM_STANDALONE</span></p>
<p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf:18:  LIBRARY_CLASS                  = TimerLib</span></p>
<p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">UefiCpuPkg/Library/SecPeiDxeTimerLibUefiCpu/SecPeiDxeTimerLibUefiCpu.inf:30:  LIBRARY_CLASS                  = TimerLib</span></p>
<p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">UefiPayloadPkg/Library/AcpiTimerLib/AcpiTimerLib.inf:15:  LIBRARY_CLASS                  = TimerLib</span></p></div><div><span style="font-variant-ligatures: no-common-ligatures"><br></span></div><div><span style="font-variant-ligatures: no-common-ligatures">So I’d guess your platform is using the ArmArchTimerLi [5]. If that is the case I’d look at the value of </span><span style="caret-color: rgb(36, 41, 47); color: rgb(36, 41, 47); font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace; white-space: pre; background-color: rgb(255, 255, 255);">PcdArmArchTimerFreqInHz</span> if it is zero then I think you are running on the default ARM timer value. </div><div><br></div><div>If you are using the stock stuff and all your TimerLib instances are the same in all your drivers then the TimerLib is also abstraction the performance measure.</div><div><br></div><div>This is probably not helpful but the UEFI Spec defines that Stall() delays for at least the requested amount of time, with no upper bound on how long it can take.  </div><div><br></div>[1] <a href="https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Core/Dxe/Misc/Stall.c#L49">https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Core/Dxe/Misc/Stall.c#L49</a><div>[2] <a href="https://github.com/tianocore/edk2/blob/master/MdePkg/Include/Protocol/Metronome.h#L25">https://github.com/tianocore/edk2/blob/master/MdePkg/Include/Protocol/Metronome.h#L25</a></div><div><div><div>[3] <a href="https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Universal/Metronome/Metronome.c#L61">https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Universal/Metronome/Metronome.c#L61</a><span style="font-family: Menlo; font-size: 11px;"> </span></div><div>[4] <a href="https://github.com/tianocore/edk2/blob/master/MdePkg/Include/Library/TimerLib.h">https://github.com/tianocore/edk2/blob/master/MdePkg/Include/Library/TimerLib.h</a><span style="font-family: Menlo; font-size: 11px;"> </span></div><div>[5] <a href="https://github.com/tianocore/edk2/blob/master/ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c#L18">https://github.com/tianocore/edk2/blob/master/ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c#L18</a></div><div><br></div><div>Thanks,</div><div><br></div><div>Andrew Fish</div><div><br></div><div><br><blockquote type="cite"><div>On Nov 28, 2022, at 11:02 AM, Rebecca Cran <quic_rcran@quicinc.com> wrote:</div><br class="Apple-interchange-newline"><div><div>I've been doing some work on USB and ended up realizing that gBS->Stall(1) is taking much longer than it should: on my Juno R2 it's stalling for 100 us, while on my Raspberry Pi 4 it's 10 us.<br><br>This appears to be causing a USB bulk transfer request that asks for a 1ms timeout taking 100ms on the Juno.<br><br>I'm measuring the delay with the following code:<br><br><br>UINT64 First = GetPerformanceCounter ();<br><br>gBS->Stall (XHC_1_MICROSECOND);<br><br>UINT64 Second = GetPerformanceCounter ();<br><br>UINT64 FirstNs = GetTimeInNanoSecond (First);<br>UINT64 SecondNs = GetTimeInNanoSecond (Second);<br><br>DEBUG ((DEBUG_INFO, "Stalled for %llu ns (%llu ms)\n", (SecondNs - FirstNs), (SecondNs - FirstNs) / 1024 / 1024));<br><br><br><br>I see output such as:<br><br>Stalled for 10500 ns (0 ms)<br><br><br>-- <br>Rebecca Cran<br><br><br><br><br><br></div></div></blockquote></div><br></div></div></body></html>


 <div width="1" style="color:white;clear:both">_._,_._,_</div> <hr>   Groups.io Links:<p>   You receive all messages sent to this group.    <p> <a target="_blank" href="https://edk2.groups.io/g/devel/message/96657">View/Reply Online (#96657)</a> |    |  <a target="_blank" href="https://groups.io/mt/95317735/1813853">Mute This Topic</a>  | <a href="https://edk2.groups.io/g/devel/post">New Topic</a><br>    <a href="https://edk2.groups.io/g/devel/editsub/1813853">Your Subscription</a> | <a href="mailto:devel+owner@edk2.groups.io">Contact Group Owner</a> |  <a href="https://edk2.groups.io/g/devel/unsub">Unsubscribe</a>  [edk2-devel-archive@redhat.com]<br> <div width="1" style="color:white;clear:both">_._,_._,_</div>