11

Are there kernel functions in Linux that would return the number of the physical core and logical core (in case of Hyperthreading) on which a kernel module is running ?

Sathyajith Bhat
  • 21,321
  • 22
  • 95
  • 134
vjain27
  • 3,514
  • 9
  • 41
  • 60

1 Answers1

15

Have a look at the end of include/linux/smp.h: smp_processor_id() gives you the number of the current executing CPU. get_cpu() will do the same and will also disable preemption so that you will stay on that CPU until put_cpu() is called.

From user-space, you can use sched_getcpu() or getcpu() to obtain the same information.

Gnurou
  • 7,923
  • 3
  • 22
  • 32