smpcommon.c 2.4 KB

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