stop_machine.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. /**
  11. * stop_machine_run: freeze the machine on all CPUs and run this function
  12. * @fn: the function to run
  13. * @data: the data ptr for the @fn()
  14. * @cpu: the cpu to run @fn() on (or any, if @cpu == NR_CPUS.
  15. *
  16. * Description: This causes a thread to be scheduled on every other cpu,
  17. * each of which disables interrupts, and finally interrupts are disabled
  18. * on the current CPU. The result is that noone is holding a spinlock
  19. * or inside any other preempt-disabled region when @fn() runs.
  20. *
  21. * This can be thought of as a very heavy write lock, equivalent to
  22. * grabbing every spinlock in the kernel. */
  23. int stop_machine_run(int (*fn)(void *), void *data, unsigned int cpu);
  24. /**
  25. * __stop_machine_run: freeze the machine on all CPUs and run this function
  26. * @fn: the function to run
  27. * @data: the data ptr for the @fn
  28. * @cpu: the cpu to run @fn on (or any, if @cpu == NR_CPUS.
  29. *
  30. * Description: This is a special version of the above, which returns the
  31. * thread which has run @fn(): kthread_stop will return the return value
  32. * of @fn(). Used by hotplug cpu.
  33. */
  34. struct task_struct *__stop_machine_run(int (*fn)(void *), void *data,
  35. unsigned int cpu);
  36. #else
  37. static inline int stop_machine_run(int (*fn)(void *), void *data,
  38. unsigned int cpu)
  39. {
  40. int ret;
  41. local_irq_disable();
  42. ret = fn(data);
  43. local_irq_enable();
  44. return ret;
  45. }
  46. #endif /* CONFIG_SMP */
  47. #endif /* _LINUX_STOP_MACHINE */