up.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 smp_call_function_single_async(int cpu, struct call_single_data *csd)
  20. {
  21. unsigned long flags;
  22. local_irq_save(flags);
  23. csd->func(csd->info);
  24. local_irq_restore(flags);
  25. return 0;
  26. }
  27. EXPORT_SYMBOL(smp_call_function_single_async);
  28. int on_each_cpu(smp_call_func_t func, void *info, int wait)
  29. {
  30. unsigned long flags;
  31. local_irq_save(flags);
  32. func(info);
  33. local_irq_restore(flags);
  34. return 0;
  35. }
  36. EXPORT_SYMBOL(on_each_cpu);
  37. /*
  38. * Note we still need to test the mask even for UP
  39. * because we actually can get an empty mask from
  40. * code that on SMP might call us without the local
  41. * CPU in the mask.
  42. */
  43. void on_each_cpu_mask(const struct cpumask *mask,
  44. smp_call_func_t func, void *info, bool wait)
  45. {
  46. unsigned long flags;
  47. if (cpumask_test_cpu(0, mask)) {
  48. local_irq_save(flags);
  49. func(info);
  50. local_irq_restore(flags);
  51. }
  52. }
  53. EXPORT_SYMBOL(on_each_cpu_mask);
  54. /*
  55. * Preemption is disabled here to make sure the cond_func is called under the
  56. * same condtions in UP and SMP.
  57. */
  58. void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info),
  59. smp_call_func_t func, void *info, bool wait,
  60. gfp_t gfp_flags)
  61. {
  62. unsigned long flags;
  63. preempt_disable();
  64. if (cond_func(0, info)) {
  65. local_irq_save(flags);
  66. func(info);
  67. local_irq_restore(flags);
  68. }
  69. preempt_enable();
  70. }
  71. EXPORT_SYMBOL(on_each_cpu_cond);