public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Non-zero start/stop values in XhcGetElapsedTicks
@ 2024-02-06 15:29 Henz, Patrick
  2024-02-07 21:00 ` Laszlo Ersek
  0 siblings, 1 reply; 4+ messages in thread
From: Henz, Patrick @ 2024-02-06 15:29 UTC (permalink / raw)
  To: devel; +Cc: hao.a.wu, ray.ni, Patrick Henz

From: Patrick Henz <patrick.henz@hpe.com>

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=4578

The implementation of XhcGetElapsedTicks did not account for
non-zero start and stop values for the performance counter
timer, potentially resulting in an incorrect elapsed tick
count getting returned to the caller. Account for non-zero
start and stop values when calculating the elapsed tick
count.

Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Patrick Henz <patrick.henz@hpe.com>
Reviewed-by:
---
 MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
index f4e61d223c..ff641d0130 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
@@ -2389,7 +2389,7 @@ XhcGetElapsedTicks (
     // Counter counts upwards, check for an overflow condition
     //
     if (*PreviousTick > CurrentTick) {
-      Delta = (mXhciPerformanceCounterEndValue - *PreviousTick) + CurrentTick;
+      Delta = (CurrentTick - mXhciPerformanceCounterStartValue) + (mXhciPerformanceCounterEndValue - *PreviousTick);
     } else {
       Delta = CurrentTick - *PreviousTick;
     }
@@ -2398,7 +2398,7 @@ XhcGetElapsedTicks (
     // Counter counts downwards, check for an underflow condition
     //
     if (*PreviousTick < CurrentTick) {
-      Delta = (mXhciPerformanceCounterStartValue - CurrentTick) + *PreviousTick;
+      Delta = (mXhciPerformanceCounterStartValue - CurrentTick) + (*PreviousTick - mXhciPerformanceCounterEndValue);
     } else {
       Delta = *PreviousTick - CurrentTick;
     }
-- 
2.34.1


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

end of thread, other threads:[~2024-02-09  9:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-06 15:29 [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Non-zero start/stop values in XhcGetElapsedTicks Henz, Patrick
2024-02-07 21:00 ` Laszlo Ersek
2024-02-07 21:07   ` Henz, Patrick
2024-02-09  9:42     ` Laszlo Ersek

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