]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
kern/i386/tsc_pmtimer: The GRUB menu gets stuck due to failed calibration
authorDuan Yayong <duanyayong@bytedance.com>
Thu, 28 Nov 2024 03:48:26 +0000 (11:48 +0800)
committerDaniel Kiper <daniel.kiper@oracle.com>
Wed, 26 Feb 2025 14:51:04 +0000 (15:51 +0100)
The grub_divmod64() may return 0 but grub_tsc_calibrate_from_pmtimer()
still returns 1 saying calibration succeeded. Of course it is not true.
So, return 0 when grub_divmod64() returns 0. This way other calibration
functions can be called subsequently.

Signed-off-by: Duan Yayong <duanyayong@bytedance.com>
Signed-off-by: Li Yongqiang <liyongqiang@huaqin.com>
Signed-off-by: Sun Ming <simon.sun@huaqin.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/kern/i386/tsc_pmtimer.c

index 5c03c510a527a1ee7978eb32ead0e88edae25ca5..dd044590d5d1b774b3100e7265f3eca4728da935 100644 (file)
@@ -143,5 +143,15 @@ grub_tsc_calibrate_from_pmtimer (void)
   if (tsc_diff == 0)
     return 0;
   grub_tsc_rate = grub_divmod64 ((1ULL << 32), tsc_diff, 0);
+  /*
+   * Specifically, when the tsc_diff (end_tsc - start_tsc) is greater than (1ULL << 32),
+   * the result of grub_divmod64() becomes zero, causing grub_tsc_rate to always be zero.
+   * As a result, grub_tsc_get_time_ms() consistently returns zero, and the GRUB menu
+   * countdown gets stuck. To resolve this, we return 0 to proceed to the next calibration
+   * function when grub_tsc_rate is zero.
+   */
+  if (grub_tsc_rate == 0)
+    return 0;
+
   return 1;
 }