smpcommon.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * SMP stuff which is common to all sub-architectures.
  3. */
  4. #include <linux/module.h>
  5. #include <asm/smp.h>
  6. DEFINE_PER_CPU(unsigned long, this_cpu_off);
  7. EXPORT_PER_CPU_SYMBOL(this_cpu_off);
  8. /* Initialize the CPU's GDT. This is either the boot CPU doing itself
  9. (still using the master per-cpu area), or a CPU doing it for a
  10. secondary which will soon come up. */
  11. __cpuinit void init_gdt(int cpu)
  12. {
  13. struct desc_struct *gdt = get_cpu_gdt_table(cpu);
  14. pack_descriptor((u32 *)&gdt[GDT_ENTRY_PERCPU].a,
  15. (u32 *)&gdt[GDT_ENTRY_PERCPU].b,
  16. __per_cpu_offset[cpu], 0xFFFFF,
  17. 0x80 | DESCTYPE_S | 0x2, 0x8);
  18. per_cpu(this_cpu_off, cpu) = __per_cpu_offset[cpu];
  19. per_cpu(cpu_number, cpu) = cpu;
  20. }
  21. /**
  22. * smp_call_function(): Run a function on all other CPUs.
  23. * @func: The function to run. This must be fast and non-blocking.
  24. * @info: An arbitrary pointer to pass to the function.
  25. * @nonatomic: Unused.
  26. * @wait: If true, wait (atomically) until function has completed on other CPUs.
  27. *
  28. * Returns 0 on success, else a negative status code.
  29. *
  30. * If @wait is true, then returns once @func has returned; otherwise
  31. * it returns just before the target cpu calls @func.
  32. *
  33. * You must not call this function with disabled interrupts or from a
  34. * hardware interrupt handler or from a bottom half handler.
  35. */
  36. int smp_call_function(void (*func) (void *info), void *info, int nonatomic,
  37. int wait)
  38. {
  39. return smp_call_function_mask(cpu_online_map, func, info, wait);
  40. }
  41. EXPORT_SYMBOL(smp_call_function);
  42. /**
  43. * smp_call_function_single - Run a function on a specific CPU
  44. * @cpu: The target CPU. Cannot be the calling CPU.
  45. * @func: The function to run. This must be fast and non-blocking.
  46. * @info: An arbitrary pointer to pass to the function.
  47. * @nonatomic: Unused.
  48. * @wait: If true, wait until function has completed on other CPUs.
  49. *
  50. * Returns 0 on success, else a negative status code.
  51. *
  52. * If @wait is true, then returns once @func has returned; otherwise
  53. * it returns just before the target cpu calls @func.
  54. */
  55. int smp_call_function_single(int cpu, void (*func) (void *info), void *info,
  56. int nonatomic, int wait)
  57. {
  58. /* prevent preemption and reschedule on another processor */
  59. int ret;
  60. int me = get_cpu();
  61. if (cpu == me) {
  62. local_irq_disable();
  63. func(info);
  64. local_irq_enable();
  65. put_cpu();
  66. return 0;
  67. }
  68. ret = smp_call_function_mask(cpumask_of_cpu(cpu), func, info, wait);
  69. put_cpu();
  70. return ret;
  71. }
  72. EXPORT_SYMBOL(smp_call_function_single);