[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/2] xen/riscv: use the SBI SRST extension to reboot in machine_restart()



> [ ... 118 lines skipped ... ]
>  #include <asm/sbi.h>
> @@ -17,11 +18,10 @@ void machine_halt(void)
>  
>  void machine_restart(unsigned int delay_millisecs)
>  {
> -    /*
> -     * TODO: mdelay(delay_millisecs)
> -     * TODO: Probe for #SRST support, where sbi_system_reset() has a
> -     *       shutdown/reboot parameter.
> -     */
> +    mdelay(delay_millisecs);
mdelay() alone doesn't guarantee that the console output has been flushed
before the reset. Arm and x86 both start machine_restart() with:

    watchdog_disable();
    console_start_sync();
    spin_debug_disable();

- watchdog_disable() isn't needed: CONFIG_WATCHDOG is only set on x86 (NMI
  watchdog), so it expands to a no-op on RISC-V.

- console_start_sync() is the one we want: it drains the serial TX buffer and
  makes any later printk() synchronous.

- spin_debug_disable() isn't needed either: lock debugging checks only run
  once spin_debug_enable() has been called, which only x86 does at boot.
  On RISC-V (as on Arm) they are never active.

Stopping the other harts first (as Arm/x86 do) shouldn't be needed either:
OpenSBI's sbi_system_reset() already sends a HALT IPI to every other hart
in the domain and stops the current one before calling the platform reset
device. As this is an M-mode IPI, it is taken even if the hart is running
with interrupts disabled in S-mode.

So I would go for something like:

void machine_restart(unsigned int delay_millisecs)
{
    /* Flush pending console output and make later printk() synchronous. */
    console_start_sync();

    mdelay(delay_millisecs);

    /* OpenSBI halts the other harts itself before resetting the system. */
    sbi_system_reset(SBI_SRST_RESET_TYPE_COLD_REBOOT,
                     SBI_SRST_RESET_REASON_NONE);

    /* Fall back to halting if SRST isn't supported or failed. */
    machine_halt();
}

What do you think?

-- 
Baptiste Le Duc <baptiste.le-duc@xxxxxxxxxx>



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.