stop_machine.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef _LINUX_STOP_MACHINE
  2. #define _LINUX_STOP_MACHINE
  3. /* "Bogolock": stop the entire machine, disable interrupts. This is a
  4. very heavy lock, which is equivalent to grabbing every spinlock
  5. (and more). So the "read" side to such a lock is anything which
  6. disables preeempt. */
  7. #include <linux/cpu.h>
  8. #include <linux/cpumask.h>
  9. #include <asm/system.h>
  10. #if defined(CONFIG_STOP_MACHINE) && defined(CONFIG_SMP)
  11. /**
  12. * stop_machine: freeze the machine on all CPUs and run this function
  13. * @fn: the function to run
  14. * @data: the data ptr for the @fn()
  15. * @cpus: the cpus to run the @fn() on (NULL = any online cpu)
  16. *
  17. * Description: This causes a thread to be scheduled on every cpu,
  18. * each of which disables interrupts. The result is that noone is
  19. * holding a spinlock or inside any other preempt-disabled region when
  20. * @fn() runs.
  21. *
  22. * This can be thought of as a very heavy write lock, equivalent to
  23. * grabbing every spinlock in the kernel. */
  24. int stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus);
  25. /**
  26. * __stop_machine: freeze the machine on all CPUs and run this function
  27. * @fn: the function to run
  28. * @data: the data ptr for the @fn
  29. * @cpus: the cpus to run the @fn() on (NULL = any online cpu)
  30. *
  31. * Description: This is a special version of the above, which assumes cpus
  32. * won't come or go while it's being called. Used by hotplug cpu.
  33. */
  34. int __stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus);
  35. #else
  36. static inline int stop_machine(int (*fn)(void *), void *data,
  37. const struct cpumask *cpus)
  38. {
  39. int ret;
  40. local_irq_disable();
  41. ret = fn(data);
  42. local_irq_enable();
  43. return ret;
  44. }
  45. #endif /* CONFIG_SMP */
  46. #endif /* _LINUX_STOP_MACHINE */