public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH edk2-platforms 0/3] Platform/ARM/JunoPkg: Timer fixes
@ 2022-11-29 13:53 Rebecca Cran
  2022-11-29 13:53 ` [PATCH edk2-platforms 1/3] Platform/ARM/JunoPkg: Switch to MdeModulePkg/Universal/Metronome driver Rebecca Cran
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Rebecca Cran @ 2022-11-29 13:53 UTC (permalink / raw)
  To: devel, Ard Biesheuvel, Thomas Abraham, Sami Mujawar; +Cc: Rebecca Cran

The use of the EmbeddedPkg/MetronomeDxe driver on Juno can cause problems
with drivers that use gBS->Stall, since it takes 10x longer than
requested. For example requesting a timeout of 1 ms when doing a USB 
bulk transfer results in it taking 100 ms. Switching to the
MdeModulePkg/Universal/Metronome driver fixes this since it assumes the
timer clock ticks at least every 100 ns.

While here, set the PCD value of the timer frequency to 0 so it gets
read from the SoC instead of hard-coding it.

Also, fix the time between interrupts in TimerDxe to be 1 ms as
the driver wants.

Rebecca Cran (3):
  Platform/ARM/JunoPkg: Switch to MdeModulePkg/Universal/Metronome
    driver
  Platform/ARM/JunoPkg: Override PcdTimerPeriod to be 10000
  Platform/ARM/JunoPkg: Set PcdArmArchTimerFreqInHz to 0 to read from
    CNTFRQ_EL0

 Platform/ARM/JunoPkg/ArmJuno.dsc | 7 ++++---
 Platform/ARM/JunoPkg/ArmJuno.fdf | 2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)

-- 
2.30.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH edk2-platforms 1/3] Platform/ARM/JunoPkg: Switch to MdeModulePkg/Universal/Metronome driver
  2022-11-29 13:53 [PATCH edk2-platforms 0/3] Platform/ARM/JunoPkg: Timer fixes Rebecca Cran
@ 2022-11-29 13:53 ` Rebecca Cran
  2022-11-29 13:53 ` [PATCH edk2-platforms 2/3] Platform/ARM/JunoPkg: Override PcdTimerPeriod to be 10000 Rebecca Cran
  2022-11-29 13:53 ` [PATCH edk2-platforms 3/3] Platform/ARM/JunoPkg: Set PcdArmArchTimerFreqInHz to 0 to read from CNTFRQ_EL0 Rebecca Cran
  2 siblings, 0 replies; 6+ messages in thread
From: Rebecca Cran @ 2022-11-29 13:53 UTC (permalink / raw)
  To: devel, Ard Biesheuvel, Thomas Abraham, Sami Mujawar; +Cc: Rebecca Cran

The MetronomeDxe driver uses the PCD PcdMetronomeTickPeriod to calculate
how many ticks to wait in MicroSecondDelay. Given that the timer clock
on Juno runs at 50 MHz, it ticks every 20 ns; therefore, a setting of
1000 is wrong: for example it causes a call to gBS->Stall (1) to take
10 us.

The driver in MdeModulePkg/Universal/Metronome assumes the clock ticks
at least every 100 ns, which is the minimum allowed by the Metronome
protocol. Since that's the case on Juno, switch from
EmbeddedPkg/MetronomeDxe to MdeModulePkg/Universal/Metronome.

Signed-off-by: Rebecca Cran <rebecca@quicinc.com>
---
 Platform/ARM/JunoPkg/ArmJuno.dsc | 3 +--
 Platform/ARM/JunoPkg/ArmJuno.fdf | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/Platform/ARM/JunoPkg/ArmJuno.dsc b/Platform/ARM/JunoPkg/ArmJuno.dsc
index a00b866c5e9a..9cde4c862651 100644
--- a/Platform/ARM/JunoPkg/ArmJuno.dsc
+++ b/Platform/ARM/JunoPkg/ArmJuno.dsc
@@ -189,7 +189,6 @@ [PcdsFixedAtBuild.common]
   # ARM Architectural Timer Frequency
   #
   gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz|50000000
-  gEmbeddedTokenSpaceGuid.PcdMetronomeTickPeriod|1000
 
   gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FALSE
 
@@ -248,10 +247,10 @@ [Components.common]
   MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
   MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
   MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
+  MdeModulePkg/Universal/Metronome/Metronome.inf
   MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf
   MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf
   EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf
-  EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf
 
   MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
   MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf
diff --git a/Platform/ARM/JunoPkg/ArmJuno.fdf b/Platform/ARM/JunoPkg/ArmJuno.fdf
index fca5a78cee6c..836d3cde8781 100644
--- a/Platform/ARM/JunoPkg/ArmJuno.fdf
+++ b/Platform/ARM/JunoPkg/ArmJuno.fdf
@@ -96,10 +96,10 @@ [FV.FvMain]
   INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
   INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
   INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
+  INF MdeModulePkg/Universal/Metronome/Metronome.inf
   INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf
   INF MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf
   INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf
-  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf
 
   INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
   INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH edk2-platforms 2/3] Platform/ARM/JunoPkg: Override PcdTimerPeriod to be 10000
  2022-11-29 13:53 [PATCH edk2-platforms 0/3] Platform/ARM/JunoPkg: Timer fixes Rebecca Cran
  2022-11-29 13:53 ` [PATCH edk2-platforms 1/3] Platform/ARM/JunoPkg: Switch to MdeModulePkg/Universal/Metronome driver Rebecca Cran
@ 2022-11-29 13:53 ` Rebecca Cran
  2022-12-05  9:22   ` [edk2-devel] " PierreGondois
  2022-11-29 13:53 ` [PATCH edk2-platforms 3/3] Platform/ARM/JunoPkg: Set PcdArmArchTimerFreqInHz to 0 to read from CNTFRQ_EL0 Rebecca Cran
  2 siblings, 1 reply; 6+ messages in thread
From: Rebecca Cran @ 2022-11-29 13:53 UTC (permalink / raw)
  To: devel, Ard Biesheuvel, Thomas Abraham, Sami Mujawar; +Cc: Rebecca Cran

The PCD PcdTimerPeriod is used in TimerDxe to calculate how many ticks
to wait between timer interrupts. The default value of 100000 results
in waiting 10 ms, while the driver wants interrupts to occur every 1ms.

Override the value of PcdTimerPeriod in ArmJuno.dsc to be 10000.

Signed-off-by: Rebecca Cran <rebecca@quicinc.com>
---
 Platform/ARM/JunoPkg/ArmJuno.dsc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Platform/ARM/JunoPkg/ArmJuno.dsc b/Platform/ARM/JunoPkg/ArmJuno.dsc
index 9cde4c862651..9b63a8914f03 100644
--- a/Platform/ARM/JunoPkg/ArmJuno.dsc
+++ b/Platform/ARM/JunoPkg/ArmJuno.dsc
@@ -189,6 +189,7 @@ [PcdsFixedAtBuild.common]
   # ARM Architectural Timer Frequency
   #
   gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz|50000000
+  gEmbeddedTokenSpaceGuid.PcdTimerPeriod|10000
 
   gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FALSE
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH edk2-platforms 3/3] Platform/ARM/JunoPkg: Set PcdArmArchTimerFreqInHz to 0 to read from CNTFRQ_EL0
  2022-11-29 13:53 [PATCH edk2-platforms 0/3] Platform/ARM/JunoPkg: Timer fixes Rebecca Cran
  2022-11-29 13:53 ` [PATCH edk2-platforms 1/3] Platform/ARM/JunoPkg: Switch to MdeModulePkg/Universal/Metronome driver Rebecca Cran
  2022-11-29 13:53 ` [PATCH edk2-platforms 2/3] Platform/ARM/JunoPkg: Override PcdTimerPeriod to be 10000 Rebecca Cran
@ 2022-11-29 13:53 ` Rebecca Cran
  2 siblings, 0 replies; 6+ messages in thread
From: Rebecca Cran @ 2022-11-29 13:53 UTC (permalink / raw)
  To: devel, Ard Biesheuvel, Thomas Abraham, Sami Mujawar; +Cc: Rebecca Cran

If PcdArmArchTimerFreqInHz is zero, the value of the timer frequency
will be read from CNTFRQ_EL0. Avoid hard-coding the value in ArmJuno.dsc
and instead let the ArmArchTimerLib driver read it from the SoC.

Signed-off-by: Rebecca Cran <rebecca@quicinc.com>
---
 Platform/ARM/JunoPkg/ArmJuno.dsc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Platform/ARM/JunoPkg/ArmJuno.dsc b/Platform/ARM/JunoPkg/ArmJuno.dsc
index 9b63a8914f03..e40005862072 100644
--- a/Platform/ARM/JunoPkg/ArmJuno.dsc
+++ b/Platform/ARM/JunoPkg/ArmJuno.dsc
@@ -188,7 +188,8 @@ [PcdsFixedAtBuild.common]
   #
   # ARM Architectural Timer Frequency
   #
-  gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz|50000000
+  # Set to 0 so ArmArchTimerLib will read its value from CNTFRQ_EL0
+  gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz|0
   gEmbeddedTokenSpaceGuid.PcdTimerPeriod|10000
 
   gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FALSE
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [edk2-devel] [PATCH edk2-platforms 2/3] Platform/ARM/JunoPkg: Override PcdTimerPeriod to be 10000
  2022-11-29 13:53 ` [PATCH edk2-platforms 2/3] Platform/ARM/JunoPkg: Override PcdTimerPeriod to be 10000 Rebecca Cran
@ 2022-12-05  9:22   ` PierreGondois
  2022-12-05 11:48     ` Rebecca Cran
  0 siblings, 1 reply; 6+ messages in thread
From: PierreGondois @ 2022-12-05  9:22 UTC (permalink / raw)
  To: devel, quic_rcran, Ard Biesheuvel, Thomas Abraham, Sami Mujawar
  Cc: Rebecca Cran

Hello Rebecca,

The default value of PcdTimerPeriod in EmbeddedPkg/EmbeddedPkg.dec
seems to be 100000 (100ns), so 10ms, and other Arm platforms have
set the value to 1000 (100ns), so 100us. I was wondering where you
found the 1ms value ?

Otherwise the other patches look good to me.

Regards,
Pierre


On 11/29/22 14:53, Rebecca Cran via groups.io wrote:
> The PCD PcdTimerPeriod is used in TimerDxe to calculate how many ticks
> to wait between timer interrupts. The default value of 100000 results
> in waiting 10 ms, while the driver wants interrupts to occur every 1ms.
> 
> Override the value of PcdTimerPeriod in ArmJuno.dsc to be 10000.
> 
> Signed-off-by: Rebecca Cran <rebecca@quicinc.com>
> ---
>   Platform/ARM/JunoPkg/ArmJuno.dsc | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/Platform/ARM/JunoPkg/ArmJuno.dsc b/Platform/ARM/JunoPkg/ArmJuno.dsc
> index 9cde4c862651..9b63a8914f03 100644
> --- a/Platform/ARM/JunoPkg/ArmJuno.dsc
> +++ b/Platform/ARM/JunoPkg/ArmJuno.dsc
> @@ -189,6 +189,7 @@ [PcdsFixedAtBuild.common]
>     # ARM Architectural Timer Frequency
>     #
>     gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz|50000000
> +  gEmbeddedTokenSpaceGuid.PcdTimerPeriod|10000
>   
>     gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FALSE
>   

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [edk2-devel] [PATCH edk2-platforms 2/3] Platform/ARM/JunoPkg: Override PcdTimerPeriod to be 10000
  2022-12-05  9:22   ` [edk2-devel] " PierreGondois
@ 2022-12-05 11:48     ` Rebecca Cran
  0 siblings, 0 replies; 6+ messages in thread
From: Rebecca Cran @ 2022-12-05 11:48 UTC (permalink / raw)
  To: Pierre Gondois, devel, quic_rcran, Ard Biesheuvel, Thomas Abraham,
	Sami Mujawar

On 12/5/22 02:22, Pierre Gondois wrote:

> The default value of PcdTimerPeriod in EmbeddedPkg/EmbeddedPkg.dec
> seems to be 100000 (100ns), so 10ms, and other Arm platforms have
> set the value to 1000 (100ns), so 100us. I was wondering where you
> found the 1ms value ?

Sorry, I misread a comment in TimerDxe.c. This patch should be dropped.

// mTimerTicks = TimerPeriod in 1ms unit * Frequency.10^-3

-- 
Rebecca Cran

> 
> Otherwise the other patches look good to me.
> 
> Regards,
> Pierre
> 
> 
> On 11/29/22 14:53, Rebecca Cran via groups.io wrote:
>> The PCD PcdTimerPeriod is used in TimerDxe to calculate how many ticks
>> to wait between timer interrupts. The default value of 100000 results
>> in waiting 10 ms, while the driver wants interrupts to occur every 1ms.
>>
>> Override the value of PcdTimerPeriod in ArmJuno.dsc to be 10000.
>>
>> Signed-off-by: Rebecca Cran <rebecca@quicinc.com>
>> ---
>>   Platform/ARM/JunoPkg/ArmJuno.dsc | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/Platform/ARM/JunoPkg/ArmJuno.dsc 
>> b/Platform/ARM/JunoPkg/ArmJuno.dsc
>> index 9cde4c862651..9b63a8914f03 100644
>> --- a/Platform/ARM/JunoPkg/ArmJuno.dsc
>> +++ b/Platform/ARM/JunoPkg/ArmJuno.dsc
>> @@ -189,6 +189,7 @@ [PcdsFixedAtBuild.common]
>>     # ARM Architectural Timer Frequency
>>     #
>>     gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz|50000000
>> +  gEmbeddedTokenSpaceGuid.PcdTimerPeriod|10000
>>     
>> gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FALSE

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-12-05 11:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-29 13:53 [PATCH edk2-platforms 0/3] Platform/ARM/JunoPkg: Timer fixes Rebecca Cran
2022-11-29 13:53 ` [PATCH edk2-platforms 1/3] Platform/ARM/JunoPkg: Switch to MdeModulePkg/Universal/Metronome driver Rebecca Cran
2022-11-29 13:53 ` [PATCH edk2-platforms 2/3] Platform/ARM/JunoPkg: Override PcdTimerPeriod to be 10000 Rebecca Cran
2022-12-05  9:22   ` [edk2-devel] " PierreGondois
2022-12-05 11:48     ` Rebecca Cran
2022-11-29 13:53 ` [PATCH edk2-platforms 3/3] Platform/ARM/JunoPkg: Set PcdArmArchTimerFreqInHz to 0 to read from CNTFRQ_EL0 Rebecca Cran

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox