On Thursday 03 April 2008 17:43:02 Jerone Young wrote:
> # HG changeset patch
> # User Jerone Young <[EMAIL PROTECTED]>
> # Date 1207262487 18000
> # Node ID 7226bef216680748a50327900572c2fbc3e762b0
> # Parent  a5b2aebbc6ebd2439c655f1c047ed7e3c1991ec1
> Add idle wait support for 44x platforms
>
> This patch adds the ability for the CPU to go into wait state while in
> cpu_idle loop. This helps virtulization solutions know when the guest Linux
> kernel is in an idle state. There are two ways to do it.
>
> 1) Command line
>       idle=spin <-- CPU will spin (this is the default)
>       idle=wait <-- set CPU into wait state when idle
>
> 2) The device tree will be checked for the "/hypervisor" node
>    If this node is seen it will use "wait" for idle, so that
>    the hypervisor can know when guest Linux kernel it is in
>    an idle state.
>
> This patch, unlike the last, isolates the code to 44x platforms.
>
> Signed-off-by: Jerone Young <[EMAIL PROTECTED]>

Very nice.

> +static void ppc44x_idle(void)
> +{
> +     unsigned long msr_save;
> +
> +     msr_save = mfmsr();
> +     /* set wait state MSR */
> +     mtmsr(msr_save|MSR_WE|MSR_EE|MSR_CE);
> +     /* return to initial state */
> +     mtmsr(msr_save);
> +}
> +
> +int __init ppc44x_idle_init(void)
> +{
> +     if(of_find_node_by_path("/hypervisor") != NULL) {
> +             /* if we find /hypervisor node is in device tree,
> +                set idle mode to wait */
> +             current_mode = 1; /* wait mode */
> +     }
> +
> +     ppc_md.power_save = modes[current_mode].entry;
> +     return 0;
> +}

By the way, watch that space in "if(". Also, you need to call of_node_put().

The one thing I don't like is the hardcoded assumption that 1 means "wait". 
Instead, you could do something like this (not even compile-tested):

int __init ppc44x_idle_init(void)
{
        void *func = modes[current_mode].entry;
        struct device_node *node;

        node = of_find_node_by_path("/hypervisor") 
        if (node) {
                /* if we find /hypervisor node is in device tree,
                 * set idle mode to wait */
                func = &ppc44x_idle;
                of_node_put(node);
        }

        ppc_md.power_save = func;
        return 0;
}

Stuart, we're getting into ePAPR territory. Do you think we need to worry 
about a hypervisor not handling mtmsr(MSR_WE)? In that case, we'd need to be 
more specific than just testing for "/hypervisor". IMHO every hypervisor 
should implement it... but maybe /hypervisor/idle = "wait" would be more 
explicit and therefore better?

-- 
Hollis Blanchard
IBM Linux Technology Center
_______________________________________________
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev

Reply via email to