debuggers.hg

changeset 22801:2d4fe1a048cd

stop_machine: Allow specified function to run on all CPUs.

Signed-off-by: Keir Fraser <keir@xen.org>
author Keir Fraser <keir@xen.org>
date Fri Jan 14 14:16:04 2011 +0000 (2011-01-14)
parents 6c9bcfb0fb84
children bb0d0141ebf7
files xen/common/stop_machine.c xen/include/xen/stop_machine.h
line diff
     1.1 --- a/xen/common/stop_machine.c	Fri Jan 14 14:07:39 2011 +0000
     1.2 +++ b/xen/common/stop_machine.c	Fri Jan 14 14:16:04 2011 +0000
     1.3 @@ -61,6 +61,10 @@ static void stopmachine_set_state(enum s
     1.4      atomic_set(&stopmachine_data.done, 0);
     1.5      smp_wmb();
     1.6      stopmachine_data.state = state;
     1.7 +}
     1.8 +
     1.9 +static void stopmachine_wait_state(void)
    1.10 +{
    1.11      while ( atomic_read(&stopmachine_data.done) != stopmachine_data.nr_cpus )
    1.12          cpu_relax();
    1.13  }
    1.14 @@ -101,16 +105,20 @@ int stop_machine_run(int (*fn)(void *), 
    1.15          tasklet_schedule_on_cpu(&per_cpu(stopmachine_tasklet, i), i);
    1.16  
    1.17      stopmachine_set_state(STOPMACHINE_PREPARE);
    1.18 +    stopmachine_wait_state();
    1.19  
    1.20      local_irq_disable();
    1.21      stopmachine_set_state(STOPMACHINE_DISABLE_IRQ);
    1.22 +    stopmachine_wait_state();
    1.23  
    1.24 -    if ( cpu == smp_processor_id() )
    1.25 +    stopmachine_set_state(STOPMACHINE_INVOKE);
    1.26 +    if ( (cpu == smp_processor_id()) || (cpu == NR_CPUS) )
    1.27          stopmachine_data.fn_result = (*fn)(data);
    1.28 -    stopmachine_set_state(STOPMACHINE_INVOKE);
    1.29 +    stopmachine_wait_state();
    1.30      ret = stopmachine_data.fn_result;
    1.31  
    1.32      stopmachine_set_state(STOPMACHINE_EXIT);
    1.33 +    stopmachine_wait_state();
    1.34      local_irq_enable();
    1.35  
    1.36      spin_unlock(&stopmachine_lock);
    1.37 @@ -140,7 +148,8 @@ static void stopmachine_action(unsigned 
    1.38              local_irq_disable();
    1.39              break;
    1.40          case STOPMACHINE_INVOKE:
    1.41 -            if ( stopmachine_data.fn_cpu == smp_processor_id() )
    1.42 +            if ( (stopmachine_data.fn_cpu == smp_processor_id()) ||
    1.43 +                 (stopmachine_data.fn_cpu == NR_CPUS) )
    1.44                  stopmachine_data.fn_result =
    1.45                      stopmachine_data.fn(stopmachine_data.fn_data);
    1.46              break;
     2.1 --- a/xen/include/xen/stop_machine.h	Fri Jan 14 14:07:39 2011 +0000
     2.2 +++ b/xen/include/xen/stop_machine.h	Fri Jan 14 14:16:04 2011 +0000
     2.3 @@ -5,7 +5,7 @@
     2.4   * stop_machine_run: freeze the machine on all CPUs and run this function
     2.5   * @fn: the function to run
     2.6   * @data: the data ptr for the @fn()
     2.7 - * @cpu: the cpu to run @fn() on (or any, if @cpu == NR_CPUS).
     2.8 + * @cpu: the cpu to run @fn() on (or all, if @cpu == NR_CPUS).
     2.9   *
    2.10   * Description: This causes every other cpu to enter a safe point, with
    2.11   * each of which disables interrupts, and finally interrupts are disabled