smp_processor_id.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * lib/smp_processor_id.c
  3. *
  4. * DEBUG_PREEMPT variant of smp_processor_id().
  5. */
  6. #include <linux/export.h>
  7. #include <linux/kallsyms.h>
  8. #include <linux/sched.h>
  9. notrace unsigned int debug_smp_processor_id(void)
  10. {
  11. int this_cpu = raw_smp_processor_id();
  12. if (likely(preempt_count()))
  13. goto out;
  14. if (irqs_disabled())
  15. goto out;
  16. /*
  17. * Kernel threads bound to a single CPU can safely use
  18. * smp_processor_id():
  19. */
  20. if (cpumask_equal(tsk_cpus_allowed(current), cpumask_of(this_cpu)))
  21. goto out;
  22. /*
  23. * It is valid to assume CPU-locality during early bootup:
  24. */
  25. if (system_state != SYSTEM_RUNNING)
  26. goto out;
  27. /*
  28. * Avoid recursion:
  29. */
  30. preempt_disable_notrace();
  31. if (!printk_ratelimit())
  32. goto out_enable;
  33. printk(KERN_ERR "BUG: using smp_processor_id() in preemptible [%08x] "
  34. "code: %s/%d\n",
  35. preempt_count() - 1, 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_notrace();
  40. out:
  41. return this_cpu;
  42. }
  43. EXPORT_SYMBOL(debug_smp_processor_id);