From: Duan Yayong Date: Thu, 28 Nov 2024 03:48:26 +0000 (+0800) Subject: kern/i386/tsc_pmtimer: The GRUB menu gets stuck due to failed calibration X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2a1f66e721d2231c3f7d80733c33cd808f0155d;p=thirdparty%2Fgrub.git kern/i386/tsc_pmtimer: The GRUB menu gets stuck due to failed calibration 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 Signed-off-by: Li Yongqiang Signed-off-by: Sun Ming Reviewed-by: Daniel Kiper --- diff --git a/grub-core/kern/i386/tsc_pmtimer.c b/grub-core/kern/i386/tsc_pmtimer.c index 5c03c510a..dd044590d 100644 --- a/grub-core/kern/i386/tsc_pmtimer.c +++ b/grub-core/kern/i386/tsc_pmtimer.c @@ -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; }