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 ?
The way to tell how may cores you have is to look for "cpu cores" in your /proc/cpuinfo file. This line will show up for each virtual processor. If the number of cores shown is less than the number of virtual processors, your system is multi-threading.
The best way to check the number of CPU cores in Linux is by looking at the /proc/cpuinfo file. Open the terminal and run this command: cat /proc/cpuinfo | grep “cpu cores” | uniq |sed -n 1p |awk '{print $4}'. It will list the number of CPU cores on your system.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With