up.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #include <linux/hypervisor.h>
  9. int smp_call_function_single(int cpu, void (*func) (void *info), void *info,
  10. int wait)
  11. {
  12. unsigned long flags;
  13. WARN_ON(cpu != 0);
  14. local_irq_save(flags);
  15. func(info);
  16. local_irq_restore(flags);
  17. return 0;
  18. }
  19. EXPORT_SYMBOL(smp_call_function_single);
  20. int smp_call_function_single_async(int cpu, struct call_single_data *csd)
  21. {
  22. unsigned long flags;
  23. local_irq_save(flags);
  24. csd->func(csd->info);
  25. local_irq_restore(flags);
  26. return 0;
  27. }
  28. EXPORT_SYMBOL(smp_call_function_single_async);
  29. int on_each_cpu(smp_call_func_t func, void *info, int wait)
  30. {
  31. unsigned long flags;
  32. local_irq_save(flags);
  33. func(info);
  34. local_irq_restore(flags);
  35. return 0;
  36. }
  37. EXPORT_SYMBOL(on_each_cpu);
  38. /*
  39. * Note we still need to test the mask even for UP
  40. * because we actually can get an empty mask from
  41. * code that on SMP might call us without the local
  42. * CPU in the mask.
  43. */
  44. void on_each_cpu_mask(const struct cpumask *mask,
  45. smp_call_func_t func, void *info, bool wait)
  46. {
  47. unsigned long flags;
  48. if (cpumask_test_cpu(0, mask)) {
  49. local_irq_save(flags);
  50. func(info);
  51. local_irq_restore(flags);
  52. }
  53. }
  54. EXPORT_SYMBOL(on_each_cpu_mask);
  55. /*
  56. * Preemption is disabled here to make sure the cond_func is called under the
  57. * same condtions in UP and SMP.
  58. */
  59. void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info),
  60. smp_call_func_t func, void *info, bool wait,
  61. gfp_t gfp_flags)
  62. {
  63. unsigned long flags;
  64. preempt_disable();
  65. if (cond_func(0, info)) {
  66. local_irq_save(flags);
  67. func(info);
  68. local_irq_restore(flags);
  69. }
  70. preempt_enable();
  71. }
  72. EXPORT_SYMBOL(on_each_cpu_cond);
  73. int smp_call_on_cpu(unsigned int cpu, int (*func)(void *), void *par, bool phys)
  74. {
  75. int ret;
  76. if (cpu != 0)
  77. return -ENXIO;
  78. if (phys)
  79. hypervisor_pin_vcpu(0);
  80. ret = func(par);
  81. if (phys)
  82. hypervisor_pin_vcpu(-1);
  83. return ret;
  84. }
  85. EXPORT_SYMBOL_GPL(smp_call_on_cpu);