up.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Uniprocessor-only support functions. The counterpart to kernel/smp.c
  3. */
  4. #include <linux/interrupt.h>
  5. #include <linux/kernel.h>
  6. #include <linux/export.h>
  7. #include <linux/smp.h>
  8. int smp_call_function_single(int cpu, void (*func) (void *info), void *info,
  9. int wait)
  10. {
  11. unsigned long flags;
  12. WARN_ON(cpu != 0);
  13. local_irq_save(flags);
  14. func(info);
  15. local_irq_restore(flags);
  16. return 0;
  17. }
  18. EXPORT_SYMBOL(smp_call_function_single);
  19. int on_each_cpu(smp_call_func_t func, void *info, int wait)
  20. {
  21. unsigned long flags;
  22. local_irq_save(flags);
  23. func(info);
  24. local_irq_restore(flags);
  25. return 0;
  26. }
  27. EXPORT_SYMBOL(on_each_cpu);
  28. /*
  29. * Note we still need to test the mask even for UP
  30. * because we actually can get an empty mask from
  31. * code that on SMP might call us without the local
  32. * CPU in the mask.
  33. */
  34. void on_each_cpu_mask(const struct cpumask *mask,
  35. smp_call_func_t func, void *info, bool wait)
  36. {
  37. unsigned long flags;
  38. if (cpumask_test_cpu(0, mask)) {
  39. local_irq_save(flags);
  40. func(info);
  41. local_irq_restore(flags);
  42. }
  43. }
  44. EXPORT_SYMBOL(on_each_cpu_mask);
  45. /*
  46. * Preemption is disabled here to make sure the cond_func is called under the
  47. * same condtions in UP and SMP.
  48. */
  49. void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info),
  50. smp_call_func_t func, void *info, bool wait,
  51. gfp_t gfp_flags)
  52. {
  53. unsigned long flags;
  54. preempt_disable();
  55. if (cond_func(0, info)) {
  56. local_irq_save(flags);
  57. func(info);
  58. local_irq_restore(flags);
  59. }
  60. preempt_enable();
  61. }
  62. EXPORT_SYMBOL(on_each_cpu_cond);