6 Replies Latest reply on Sep 26, 2009 2:36 AM by stevengarcia

    How can I know which core is running

    netbear

      Hi All, I am doing some research on an AMD opteron 4X4 server . Now I need to know which cores are running in a thread . Besides , I need to know whether these cores are on the same die . So is it possible for me to get these information and how? Thank you!

        • How can I know which core is running
          avk
          Which OS?
          • How can I know which core is running
            avk
            Well, in case of Windows, if I was you, I would pay attention at GetProcessAffinityMask Win32 API function (and so on) and, probably, at RDTSCP instruction. I'm sure that you'll need to experiment in order to recognize which core on which die, because I never did this too .
              • How can I know which core is running
                jdeguara

                If you want to see where threads and processes are running under Linux then I would suggest you use the tool named top.  There are two feature to turn on that help.  The first is to add the CPU core field the process last ran on by hitting 'f' (to edit the fields) and the 'j' (to toggle last used core field).  Second you can press 'H' in the main window to toggle if it shows threads or just processes.

                Now if you want to set the affinity of a thread to a specific core than you should use the POSIX sched_{get,set}affinity().  There does not seam to be an interface from the OS to find out in a program where you are executing (except by getting your affinity and seeing it limits you to one core) so avk's response about RDTSCP is a good way to do that.  But be warned that with no limitation to the affinity then the OS could reschedule that thread on a different core at any instance. 

                Is you work somehow NUMA related?  I am just wondering if you really need to know which core your threads are on.

                I almost forgot you can find out if the cores are on the same die by looking at /proc/cpuinfo where one sees for each core which 'phyiscal id' it has and this the socket id as seen from Linux.

              • How can I know which core is running
                stevengarcia

                I like your site. This is very informative. Thank you everyone.