stop_machine.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. diables preeempt. */
  7. #include <linux/cpu.h>
  8. #include <asm/system.h>
  9. #if defined(CONFIG_STOP_MACHINE) && defined(CONFIG_SMP)
  10. #define ALL_CPUS ~0U
  11. /**
  12. * stop_machine_run: 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. * @cpu: if @cpu == n, run @fn() on cpu n
  16. * if @cpu == NR_CPUS, run @fn() on any cpu
  17. * if @cpu == ALL_CPUS, run @fn() on every online CPU.
  18. *
  19. * Description: This causes a thread to be scheduled on every cpu,
  20. * each of which disables interrupts. The result is that noone is
  21. * holding a spinlock or inside any other preempt-disabled region when
  22. * @fn() runs.
  23. *
  24. * This can be thought of as a very heavy write lock, equivalent to
  25. * grabbing every spinlock in the kernel. */
  26. int stop_machine_run(int (*fn)(void *), void *data, unsigned int cpu);
  27. /**
  28. * __stop_machine_run: freeze the machine on all CPUs and run this function
  29. * @fn: the function to run
  30. * @data: the data ptr for the @fn
  31. * @cpu: the cpu to run @fn on (or any, if @cpu == NR_CPUS.
  32. *
  33. * Description: This is a special version of the above, which assumes cpus
  34. * won't come or go while it's being called. Used by hotplug cpu.
  35. */
  36. int __stop_machine_run(int (*fn)(void *), void *data, unsigned int cpu);
  37. #else
  38. static inline int stop_machine_run(int (*fn)(void *), void *data,
  39. unsigned int cpu)
  40. {
  41. int ret;
  42. local_irq_disable();
  43. ret = fn(data);
  44. local_irq_enable();
  45. return ret;
  46. }
  47. #endif /* CONFIG_SMP */
  48. #endif /* _LINUX_STOP_MACHINE */