Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find physical and logical core number in a kernel module?

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 ?

like image 723
vjain27 Avatar asked Sep 06 '11 06:09

vjain27


People also ask

How many cores does my virtual machine have Linux?

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.

How many cores does my CPU have Linux?

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.


1 Answers

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.

like image 195
Gnurou Avatar answered Oct 04 '22 06:10

Gnurou