smp_processor_id.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * lib/smp_processor_id.c
  3. *
  4. * DEBUG_PREEMPT variant of smp_processor_id().
  5. */
  6. #include <linux/module.h>
  7. #include <linux/kallsyms.h>
  8. unsigned int debug_smp_processor_id(void)
  9. {
  10. unsigned long preempt_count = preempt_count();
  11. int this_cpu = raw_smp_processor_id();
  12. cpumask_t this_mask;
  13. if (likely(preempt_count))
  14. goto out;
  15. if (irqs_disabled())
  16. goto out;
  17. /*
  18. * Kernel threads bound to a single CPU can safely use
  19. * smp_processor_id():
  20. */
  21. this_mask = cpumask_of_cpu(this_cpu);
  22. if (cpus_equal(current->cpus_allowed, this_mask))
  23. goto out;
  24. /*
  25. * It is valid to assume CPU-locality during early bootup:
  26. */
  27. if (system_state != SYSTEM_RUNNING)
  28. goto out;
  29. /*
  30. * Avoid recursion:
  31. */
  32. preempt_disable();
  33. if (!printk_ratelimit())
  34. goto out_enable;
  35. printk(KERN_ERR "BUG: using smp_processor_id() in preemptible [%08x] code: %s/%d\n", preempt_count(), current->comm, current->pid);
  36. print_symbol("caller is %s\n", (long)__builtin_return_address(0));
  37. dump_stack();
  38. out_enable:
  39. preempt_enable_no_resched();
  40. out:
  41. return this_cpu;
  42. }
  43. EXPORT_SYMBOL(debug_smp_processor_id);