3

I am running CC compiler over SUN/Solaris, I have more then 64 threads assigned by the OS to different cores. I am interested to know if there is method to get the core id for different threads during run time?

I am not setting affinity for those threads, i use psrset to create the processor set.

Michael
  • 2,827
  • 4
  • 30
  • 47
  • 3
    Isn't that information invalid the second you get it? I mean the thread could be running on a different core already. – Christian.K Jul 16 '12 at 11:16
  • @Christian.K - Actually, as far as i know if you are setting the processor set, and you run less threads than the set size, the OS tries to map a thread per single set slot, it may be that the thread may run on different cores eventually, but i am still interested on what core it runs at a specific moment. – Michael Jul 16 '12 at 11:21
  • Sorry for being pedantic ;-) But my point was exactly about the "specific moment". At the moment you look at the value, the thread could be off to another processor. – Christian.K Jul 16 '12 at 11:36

2 Answers2

2

I found the answer: getcpuid() on Solaris returns the core id (even for hyper thread): i have tested it and it works great. http://www.unix.com/man-page/all/3c/getcpuid/

Michael
  • 2,827
  • 4
  • 30
  • 47
1

I don't know if there are Solaris-specific system calls for this, but you could use the portable hwloc library and its hwloc_get_last_cpu_location function.

dpi
  • 1,919
  • 17
  • 17
  • Thanks, it seems exactly what i need, one of my biggest problems is that i can't install nothing on this server. Is there any built-in function of cc compiler or even some asm command that i may use in order to achieve the same result. One more option is that i will bind threads from start, and then i may use the threads id to map the core id back - here my problem is that i don't know how much threads will be created in run-time. – Michael Jul 16 '12 at 11:54