LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to find what task is running on a particular cpu core ? (http://www.linuxquestions.org/questions/linux-general-1/how-to-find-what-task-is-running-on-a-particular-cpu-core-832888/)

summer_intern 09-17-2010 03:28 PM

How to find what task is running on a particular cpu core ?
 
Hello ,

I am using Kernel 2.6.35.4 on an Intel Core2Duo based system.
1) I have to find on which core a particular task is running on .
OR
2) I have to just log whenever my task is scheduled on any of the cores with the cpu core number & timestamp info.
I am ready to modify the kernel to do printk or some logging .
I guess there used to be 2 fields called 'processor' and 'last_processor' in task_struct in older kernels which probably had this information .

So what do I do to find out on which core a particular task is running on ?

Or ,

Are there any utilities that are simple-to-use and can display the tasks that are running on each of the cores , including the cpu core info ? top , mpstat etc do not tell you on which cpu core a task is running on .

rayfordj 09-17-2010 09:18 PM

top will, not by default, but if you add the field according to the man page on my system.

Code:

      j: P  --  Last used CPU (SMP)
          A number representing the last used processor.  In a true SMP  envi-
          ronment  this  will likely change frequently since the kernel inten-
          tionally uses weak affinity.  Also, the very act of running top  may
          break  this  weak  affinity  and cause more processes to change CPUs
          more often (because of the extra demand for cpu time).

Code:

user@system ~]$ top
f
j
<enter>


syg00 09-17-2010 09:29 PM

Simplest is to use /proc/<pid>/stat (which is where top is getting it from in all likelihood).
But as per above, this is "last processor" dispatched on. Given the way the scheduler attempts to keep tasks on the same processor, this should normally suffice.


All times are GMT -5. The time now is 12:33 AM.