Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.

Sending instructions to one core

xt_knight
Beginner
659 Views
I was wondering how to send a specific instruction to one core in a dual-core CPU. For example, I want to read the thermal status of the second core. I can't find out how to send a rdmsr instruction to the second core.

Is there another way by which I am supposed to be able to retrieve the temperature from the DTS (digital temperature sensor) of one core?
0 Kudos
5 Replies
James_M_Intel1
Employee
659 Views

A common way of doing this is to create a thread that is forced to run on the target core. If using Windows, for example, look at the SetThreadAffinityMask() function.

0 Kudos
xt_knight
Beginner
659 Views
Thanks. I had thought of setting affinity but wasn't sure whether or not the RDMSR would just be sent to the first core anyway. So I will get the temperature of the second core by sending IA32_THERM_STATUS on a thread that's bound to the second core? Or are you not certain of that?
0 Kudos
James_M_Intel1
Employee
659 Views
I've not tested it, but I believe that is correct.
0 Kudos
prasadae
Beginner
659 Views
if you are on Linux, you can write a kernel module with the following: int temperature[NR_CPUS]; void get_temp(int cpu) { int this_cpu = smp_processor_id(); if(this_cpu == cpu) __temp_read(NULL); else smp_call_function_single(cpu,__temp_read,NULL,1,1); return temperature[cpu]; } void __temp_read(void *info) { u32 low,high; int cpu = get_cpu(); rdmsr(IA32_THERM_STATUS,low,high) temperature[cpu] = low | MASK; // get temp }
0 Kudos
Dmitry_Vyukov
Valued Contributor I
659 Views
Quoting - prasadae
if you are on Linux, you can write a kernel module with the following: int temperature[NR_CPUS]; void get_temp(int cpu) { int this_cpu = smp_processor_id(); if(this_cpu == cpu) __temp_read(NULL); else smp_call_function_single(cpu,__temp_read,NULL,1,1); return temperature[cpu]; } void __temp_read(void *info) { u32 low,high; int cpu = get_cpu(); rdmsr(IA32_THERM_STATUS,low,high) temperature[cpu] = low | MASK; // get temp }

Or just use Linux NUMA API:

http://linux.die.net/man/3/numa_run_on_node

numa_run_on_node_mask() runs the current thread and its children only on nodes specified in nodemask. They will not migrate to CPUs of other nodes until the node affinity is reset with a new call to numa_run_on_node_mask(). Passing numa_all_nodes permits the kernel to schedule on all nodes again.


0 Kudos
Reply