Topic
  • 8 replies
  • Latest Post - ‏2010-08-20T13:01:25Z by SystemAdmin
power-rox
power-rox
4 Posts

Pinned topic What core / cpu is my process currently running on?

‏2010-07-20T16:58:55Z |
Is there a way for me to verify that my process is running on a specific core I want it to run on?

For ex, if I use numactl or XLSMPOPTS to bind my process to core 0, how can I verify that it is indeed running on core 0? (Other than using top or other such utilities)

Regards,
Updated on 2010-08-20T13:01:25Z at 2010-08-20T13:01:25Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    706 Posts

    Re: What core / cpu is my process currently running on?

    ‏2010-07-20T20:05:33Z  
    I've been curious about that as well. Will check... top does it somehow..
  • power-rox
    power-rox
    4 Posts

    Re: What core / cpu is my process currently running on?

    ‏2010-07-20T20:21:02Z  
    taskset seems to do the trick

    You can also use sched_setaffinity, sched_getaffinity
  • SystemAdmin
    SystemAdmin
    706 Posts

    Re: What core / cpu is my process currently running on?

    ‏2010-07-20T21:05:33Z  
    I've been curious about that as well. Will check... top does it somehow..
    Playing around. Found the "last CPU" in stat associated with the pid. Only checked this on SLES 11 sp1. Found it with the all-so-scientific method of manually looking and "ah, there's the CPU number".
    
    # cat /proc/<pid>/stat | awk 
    {
    'print $39'
    } 127
    

    I verified this simply by watching the corresponding field in top.

    You can always write a simple script wrapper to watch it over time.
    
    # 
    
    for i in 
    {1..100
    }; 
    
    do  cat /proc/<pid>/stat | awk 
    {
    'print $39'
    }; sleep 2; done
    

    I'm not sure if the position of the "last cpu field" is consistent across distro releases.

    Here's an example of the full "stat" contents. In this case, "26" was the last CPU field.
    
    # cat /proc/39556/stat 39556 (top) S 39526 39556 39526 34818 39556 4194560 100 0 0 0 814 1569 0 0 20 0 1 0 45020507 6160384 64 227692634112 268435456 268539708 17591925101616 17591925099008 17590285258120 0 0 0 138047495 13835058055283862384 0 0 17 26 0 0 1 0 0
    
  • SystemAdmin
    SystemAdmin
    706 Posts

    Re: What core / cpu is my process currently running on?

    ‏2010-07-20T21:06:54Z  
    • power-rox
    • ‏2010-07-20T20:21:02Z
    taskset seems to do the trick

    You can also use sched_setaffinity, sched_getaffinity
    well... taskset sets it... can you tell/confirm the pid is actually on the right CPUs?
  • power-rox
    power-rox
    4 Posts

    Re: What core / cpu is my process currently running on?

    ‏2010-07-20T21:45:24Z  
    well... taskset sets it... can you tell/confirm the pid is actually on the right CPUs?
    taskset -p <pid> shows the current cpu mask, although I was not able to make much sense of the mask, I know it works fine.

    Maybe my brain is dead for today or something.

    400 = processor 10
    800 = processor 12
    8000 = processor 15
  • power-rox
    power-rox
    4 Posts

    Re: What core / cpu is my process currently running on?

    ‏2010-07-20T21:51:48Z  
    Playing around. Found the "last CPU" in stat associated with the pid. Only checked this on SLES 11 sp1. Found it with the all-so-scientific method of manually looking and "ah, there's the CPU number".
    <pre class="jive-pre"> # cat /proc/<pid>/stat | awk { 'print $39' } 127 </pre>
    I verified this simply by watching the corresponding field in top.

    You can always write a simple script wrapper to watch it over time.
    <pre class="jive-pre"> # for i in {1..100 }; do cat /proc/<pid>/stat | awk { 'print $39' }; sleep 2; done </pre>
    I'm not sure if the position of the "last cpu field" is consistent across distro releases.

    Here's an example of the full "stat" contents. In this case, "26" was the last CPU field.
    <pre class="jive-pre"> # cat /proc/39556/stat 39556 (top) S 39526 39556 39526 34818 39556 4194560 100 0 0 0 814 1569 0 0 20 0 1 0 45020507 6160384 64 227692634112 268435456 268539708 17591925101616 17591925099008 17590285258120 0 0 0 138047495 13835058055283862384 0 0 17 26 0 0 1 0 0 </pre>
    How did you find that out? Did you start digging to the "stat" file format?
  • feafrfxvr
    feafrfxvr
    1 Post

    Re: What core / cpu is my process currently running on?

    ‏2010-08-20T07:23:28Z  
    I have the same problem
  • SystemAdmin
    SystemAdmin
    706 Posts

    Re: What core / cpu is my process currently running on?

    ‏2010-08-20T13:01:25Z  
    • feafrfxvr
    • ‏2010-08-20T07:23:28Z
    I have the same problem
    Can you elaborate on the "same problem"?
    - understanding taskset?
    - seeing which CPU a process is running on?