cpuinfo_x86 and apicid
Hello,
In the context of the perfmon2 subsystem for processor with HyperThreading, we need to know on which thread we are currently running. This comes from the fact that the performance counters are shared between the two threads.
We use the thread id (smt_id) because we split the counters in half between the two threads such that two threads on the same core can run with monitoring on. We are currently computing the smt_id from the apicid as returned by a CPUID instruction. This is not very efficient.
I looked through the i386 code and could not find a function nor structure that would return this smt_id. In the cpuinfo_x86 structure there is an apicid field that looks good, yet it does not seem to be initialized nor used.
Is cpuinfo_x86->apicid field obsolete?
If so, what is replacing it?
Thanks.
Signature · 1 line
-Stephane
Quoted 23 lines · Stephane Eranian
Hello,
In the context of the perfmon2 subsystem for processor with HyperThreading, we need to know on which thread we are currently running. This comes from the fact that the performance counters are shared between the two threads.
We use the thread id (
smt_id) because we split the counters in half between the two threads such that two threads on the same core can run with monitoring on. We are currently computing thesmt_idfrom the apicid as returned by a CPUID instruction. This is not very efficient.I looked through the i386 code and could not find a function nor structure that would return this
smt_id. In thecpuinfo_x86structure there is an apicid field that looks good, yet it does not seem to be initialized nor used.Is
cpuinfo_x86->apicidfield obsolete?
If so, what is replacing it?Thanks.
--
Review
Quoted 2 lines
(quoted diff) +0
-2-Stephane -
Does the attached file help? It is supposed to tell which CPU execution is occurring on. This might be modified to fill your needs.
Cheers,
Dick Johnson
Penguin : Linux version 2.6.16.4 on an i686 machine (5592.88 BogoMips). New book: http://www.AbominableFirebug.com/
_
****************************************************************
The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to [email protected] - and destroy all copies of this information, including any attachments, without reading or disclosing them.
Thank you.
/*
* This program tells you what CPU your process is executing on. * If you comment-out the usleep(10000), so you are eating all the * CPU time in your time-slice, and you execute this from two tasks, * you will note that each task gets its own CPU if you have two * CPUs. * If you leave in the usleep(), you will note that both tasks may * use the same CPU. This happens if, and only if, they are not * executing at the same time.
*/
#include <stdio.h>
int main(void);
int main()
{
int cpu, prv;
prv = -1;
for(;;)
{
__asm__ __volatile__ (
"xorl %%eax,%%eax\n"
"str %%ax\n"
"subl $0x60, %%eax\n"
"shrl $0x05, %%eax\n"
: "=a"(cpu));
if(cpu != prv)
{
prv = cpu;
printf("CPU %d\n", cpu);
}
usleep(10000);
}
return 0;
}Quoted 12 lines · Stephane Eranian
Hello,
In the context of the perfmon2 subsystem for processor with HyperThreading, we need to know on which thread we are currently running. This comes from the fact that the performance counters are shared between the two threads.
We use the thread id (
smt_id) because we split the counters in half between the two threads such that two threads on the same core can run with monitoring on. We are currently computing thesmt_idfrom the apicid as returned by a CPUID instruction. This is not very efficient.
Quoted 7 lines
I looked through the i386 code and could not find a function nor structure that would return this
smt_id. In thecpuinfo_x86structure there is an apicid field that looks good, yet it does not seem to be initialized nor used.Is
cpuinfo_x86->apicidfield obsolete?
If so, what is replacing it?
In i386, it is getting initialized in generic_identify() in common.c and it is getting used for example in intel_cacheinfo.c
thanks,
suresh
Quoted 18 lines · Suresh B
Quoted 17 lines · Stephane Eranian
Hello,
In the context of the perfmon2 subsystem for processor with HyperThreading, we need to know on which thread we are currently running. This comes from the fact that the performance counters are shared between the two threads.
We use the thread id (
smt_id) because we split the counters in half between the two threads such that two threads on the same core can run with monitoring on. We are currently computing thesmt_idfrom the apicid as returned by a CPUID instruction. This is not very efficient.I looked through the i386 code and could not find a function nor structure that would return this
smt_id. In thecpuinfo_x86structure there is an apicid field that looks good, yet it does not seem to be initialized nor used.
Quoted 6 lines
Quoted 2 lines
Is
cpuinfo_x86->apicidfield obsolete?
If so, what is replacing it?In i386, it is getting initialized in
generic_identify()incommon.cand it is getting used for example inintel_cacheinfo.c
Well, yes this is exactly what I want, except that it is not compiled for x86_64 so on a HT Xeon in 64-bit I don't get it. Why is that?
Signature · 1 line
-Stephane
Quoted 19 lines · Stephane Eranian
Quoted 18 lines · Suresh B
Quoted 17 lines · Stephane Eranian
Hello,
In the context of the perfmon2 subsystem for processor with HyperThreading, we need to know on which thread we are currently running. This comes from the fact that the performance counters are shared between the two threads.
We use the thread id (
smt_id) because we split the counters in half between the two threads such that two threads on the same core can run with monitoring on. We are currently computing thesmt_idfrom the apicid as returned by a CPUID instruction. This is not very efficient.I looked through the i386 code and could not find a function nor structure that would return this
smt_id. In thecpuinfo_x86structure there is an apicid field that looks good, yet it does not seem to be initialized nor used.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Is
cpuinfo_x86->apicidfield obsolete?
If so, what is replacing it?In i386, it is getting initialized in
generic_identify()incommon.cand it is getting used for example inintel_cacheinfo.cWell, yes this is exactly what I want, except that it is not compiled for
x86_64so on a HT Xeon in 64-bit I don't get it. Why is that?
on x86_64, it is getting initialized in identify_cpu() and further intel_cacheinfo.c gets linked in both i386 and x86_64.
thanks,
suresh
Suresh,
Quoted 23 lines · Suresh B
Quoted 22 lines · Stephane Eranian
Quoted 21 lines · Suresh B
Quoted 19 lines · Stephane Eranian
Hello,
In the context of the perfmon2 subsystem for processor with HyperThreading, we need to know on which thread we are currently running. This comes from the fact that the performance counters are shared between the two threads.
We use the thread id (
smt_id) because we split the counters in half between the two threads such that two threads on the same core can run with monitoring on. We are currently computing thesmt_idfrom the apicid as returned by a CPUID instruction. This is not very efficient.I looked through the i386 code and could not find a function nor structure that would return this
smt_id. In thecpuinfo_x86structure there is an apicid field that looks good, yet it does not seem to be initialized nor used.Is
cpuinfo_x86->apicidfield obsolete?
If so, what is replacing it?
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
In i386, it is getting initialized in
generic_identify()incommon.cand it is getting used for example inintel_cacheinfo.cWell, yes this is exactly what I want, except that it is not compiled for
x86_64so on a HT Xeon in 64-bit I don't get it. Why is that?on
x86_64, it is getting initialized inidentify_cpu()and furtherintel_cacheinfo.cgets linked in both i386 andx86_64.
Ah, yes I missed that. It works there two. I had something wrong about how I accessed cpu_data. I am used to the elegant way we do it on IA-64 but on x86_64 you have to index the cpu_data[] array with smp_processor_id(). I was pointing to cpu_data[0] on all processors.
For what I need, I can do cpuinfo_x86->apicid & 0x3 to identify which thread is running. I can now remove some more code in perfmon2.
Thanks for your help.
Signature · 1 line
-Stephane
Suresh,
Quoted 10 lines · Stephane Eranian
Quoted 1 line
Ah, yes I missed that. It works there two. I had something wrong about how I accessed
cpu_data. I am used to the elegant way we do it on IA-64 but onx86_64you have to index the cpu_data[] array withsmp_processor_id(). I was pointing to cpu_data[0] on all processors.For what I need, I can do
cpuinfo_x86->apicid&0x3to identify which thread is running. I can now remove some more code in perfmon2.
I meant cpuinfo_x86->apicid & 0x1.
Signature · 1 line
-Stephane
Quoted 10 lines · Stephane Eranian
Suresh,
Quoted 7 lines · Stephane Eranian
Quoted 1 line
Ah, yes I missed that. It works there two. I had something wrong about how I accessed
cpu_data. I am used to the elegant way we do it on IA-64 but onx86_64you have to index the cpu_data[] array withsmp_processor_id(). I was pointing to cpu_data[0] on all processors.
Quoted 4 lines
Quoted 3 lines
For what I need, I can do
cpuinfo_x86->apicid&0x3to identify which thread is running. I can now remove some more code in perfmon2.I meant
cpuinfo_x86->apicid&0x1.
Instead of hard coding, can you get the size of the mask runtime from the size of cpu_sibling_map[cpu]
And remember, physical/logical hotplug can change this sibling map.
thanks,
suresh