[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v2 1/2] x86/time: split CMOS time fetching into wrapper
Split the logic that deals with probing and fetching the CMOS time into a separate helper. While moving the code also take the opportunity to reduce the scope of some local variables. No functional change intended. Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx> --- Changes since v1: - New in this version. --- xen/arch/x86/time.c | 72 +++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c index a97d78484105..272ca2468ea6 100644 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -1245,29 +1245,14 @@ static void __get_cmos_time(struct rtc_time *rtc) rtc->year += 100; } -static unsigned long get_cmos_time(void) +/* Returns true when fetching time from CMOS is successful. */ +static bool read_cmos_time(struct rtc_time *rtc, bool cmos_rtc_probe) { - unsigned long res, flags; - struct rtc_time rtc; unsigned int seconds = 60; - static bool __read_mostly cmos_rtc_probe; - boolean_param("cmos-rtc-probe", cmos_rtc_probe); - - if ( efi_enabled(EFI_RS) ) - { - res = efi_get_time(); - if ( res ) - return res; - } - - if ( likely(!(acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_CMOS_RTC)) ) - cmos_rtc_probe = false; - else if ( system_state < SYS_STATE_smp_boot && !cmos_rtc_probe ) - panic("System with no CMOS RTC advertised must be booted from EFI" - " (or with command line option \"cmos-rtc-probe\")\n"); for ( ; ; ) { + unsigned long flags; s_time_t start, t1, t2; spin_lock_irqsave(&rtc_lock, flags); @@ -1285,33 +1270,56 @@ static unsigned long get_cmos_time(void) } while ( (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) && t2 < MILLISECS(3) ); - __get_cmos_time(&rtc); + __get_cmos_time(rtc); spin_unlock_irqrestore(&rtc_lock, flags); - if ( likely(!cmos_rtc_probe) || - t1 > SECONDS(1) || t2 >= MILLISECS(3) || - rtc.sec >= 60 || rtc.min >= 60 || rtc.hour >= 24 || - !rtc.day || rtc.day > 31 || - !rtc.mon || rtc.mon > 12 ) - break; + if ( likely(!cmos_rtc_probe) ) + return true; + + if ( t1 > SECONDS(1) || t2 >= MILLISECS(3) || + rtc->sec >= 60 || rtc->min >= 60 || rtc->hour >= 24 || + !rtc->day || rtc->day > 31 || + !rtc->mon || rtc->mon > 12 ) + return false; if ( seconds < 60 ) { - if ( rtc.sec != seconds ) - { - cmos_rtc_probe = false; + if ( rtc->sec != seconds ) acpi_gbl_FADT.boot_flags &= ~ACPI_FADT_NO_CMOS_RTC; - } - break; + return true; } process_pending_softirqs(); - seconds = rtc.sec; + seconds = rtc->sec; } - if ( unlikely(cmos_rtc_probe) ) + ASSERT_UNREACHABLE(); + return false; +} + +static unsigned long get_cmos_time(void) +{ + struct rtc_time rtc; + static bool __read_mostly cmos_rtc_probe; + boolean_param("cmos-rtc-probe", cmos_rtc_probe); + + if ( efi_enabled(EFI_RS) ) + { + unsigned long res = efi_get_time(); + + if ( res ) + return res; + } + + if ( likely(!(acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_CMOS_RTC)) ) + cmos_rtc_probe = false; + else if ( system_state < SYS_STATE_smp_boot && !cmos_rtc_probe ) + panic("System with no CMOS RTC advertised must be booted from EFI" + " (or with command line option \"cmos-rtc-probe\")\n"); + + if ( unlikely(!read_cmos_time(&rtc, cmos_rtc_probe)) ) panic("No CMOS RTC found - system must be booted from EFI\n"); return mktime(rtc.year, rtc.mon, rtc.day, rtc.hour, rtc.min, rtc.sec); -- 2.46.0
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |