public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* cpuinfo_x86 and apicid
@ 2006-07-06 15:01 Stephane Eranian
  2006-07-06 15:27 ` linux-os (Dick Johnson)
  2006-07-06 16:19 ` Siddha, Suresh B
  0 siblings, 2 replies; 8+ messages in thread
From: Stephane Eranian @ 2006-07-06 15:01 UTC (permalink / raw)
  To: linux-kernel; +Cc: perfmon, 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 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.

-- 
-Stephane

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: cpuinfo_x86 and apicid
  2006-07-06 15:01 cpuinfo_x86 and apicid Stephane Eranian
@ 2006-07-06 15:27 ` linux-os (Dick Johnson)
  2006-07-06 16:19 ` Siddha, Suresh B
  1 sibling, 0 replies; 8+ messages in thread
From: linux-os (Dick Johnson) @ 2006-07-06 15:27 UTC (permalink / raw)
  To: Stephane Eranian; +Cc: Linux kernel, perfmon

[-- Attachment #1: Type: text/plain, Size: 1836 bytes --]


On Thu, 6 Jul 2006, Stephane Eranian wrote:

> 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.
>
> --
> -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/
_
\x1a\x04


****************************************************************
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 DeliveryErrors@analogic.com - and destroy all copies of this information, including any attachments, without reading or disclosing them.

Thank you.

[-- Attachment #2: whichcpu.c --]
[-- Type: TEXT/PLAIN, Size: 874 bytes --]

/*
 *  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;
}


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: cpuinfo_x86 and apicid
  2006-07-06 15:01 cpuinfo_x86 and apicid Stephane Eranian
  2006-07-06 15:27 ` linux-os (Dick Johnson)
@ 2006-07-06 16:19 ` Siddha, Suresh B
  2006-07-06 20:00   ` Stephane Eranian
  1 sibling, 1 reply; 8+ messages in thread
From: Siddha, Suresh B @ 2006-07-06 16:19 UTC (permalink / raw)
  To: Stephane Eranian; +Cc: linux-kernel, perfmon

On Thu, Jul 06, 2006 at 08:01:18AM -0700, Stephane Eranian wrote:
> 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?

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: cpuinfo_x86 and apicid
  2006-07-06 16:19 ` Siddha, Suresh B
@ 2006-07-06 20:00   ` Stephane Eranian
  2006-07-06 21:06     ` Siddha, Suresh B
  0 siblings, 1 reply; 8+ messages in thread
From: Stephane Eranian @ 2006-07-06 20:00 UTC (permalink / raw)
  To: Siddha, Suresh B; +Cc: linux-kernel, perfmon

On Thu, Jul 06, 2006 at 09:19:30AM -0700, Siddha, Suresh B wrote:
> On Thu, Jul 06, 2006 at 08:01:18AM -0700, Stephane Eranian wrote:
> > 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?
> 
> In i386, it is getting initialized in generic_identify() in common.c and
> it is getting used for example in intel_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?

-- 

-Stephane

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: cpuinfo_x86 and apicid
  2006-07-06 20:00   ` Stephane Eranian
@ 2006-07-06 21:06     ` Siddha, Suresh B
  2006-07-06 22:25       ` Stephane Eranian
  0 siblings, 1 reply; 8+ messages in thread
From: Siddha, Suresh B @ 2006-07-06 21:06 UTC (permalink / raw)
  To: Stephane Eranian; +Cc: Siddha, Suresh B, linux-kernel, perfmon

On Thu, Jul 06, 2006 at 01:00:31PM -0700, Stephane Eranian wrote:
> On Thu, Jul 06, 2006 at 09:19:30AM -0700, Siddha, Suresh B wrote:
> > On Thu, Jul 06, 2006 at 08:01:18AM -0700, Stephane Eranian wrote:
> > > 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?
> > 
> > In i386, it is getting initialized in generic_identify() in common.c and
> > it is getting used for example in intel_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?

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: cpuinfo_x86 and apicid
  2006-07-06 21:06     ` Siddha, Suresh B
@ 2006-07-06 22:25       ` Stephane Eranian
  2006-07-06 22:37         ` [perfmon] " Stephane Eranian
  0 siblings, 1 reply; 8+ messages in thread
From: Stephane Eranian @ 2006-07-06 22:25 UTC (permalink / raw)
  To: Siddha, Suresh B; +Cc: linux-kernel, perfmon

Suresh,

On Thu, Jul 06, 2006 at 02:06:13PM -0700, Siddha, Suresh B wrote:
> On Thu, Jul 06, 2006 at 01:00:31PM -0700, Stephane Eranian wrote:
> > On Thu, Jul 06, 2006 at 09:19:30AM -0700, Siddha, Suresh B wrote:
> > > On Thu, Jul 06, 2006 at 08:01:18AM -0700, Stephane Eranian wrote:
> > > > 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?
> > > 
> > > In i386, it is getting initialized in generic_identify() in common.c and
> > > it is getting used for example in intel_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?
> 
> on x86_64, it is getting initialized in identify_cpu() and further
> intel_cacheinfo.c gets linked in both i386 and x86_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.

-- 
-Stephane

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [perfmon] Re: cpuinfo_x86 and apicid
  2006-07-06 22:25       ` Stephane Eranian
@ 2006-07-06 22:37         ` Stephane Eranian
  2006-07-06 22:47           ` Siddha, Suresh B
  0 siblings, 1 reply; 8+ messages in thread
From: Stephane Eranian @ 2006-07-06 22:37 UTC (permalink / raw)
  To: Siddha, Suresh B; +Cc: perfmon, linux-kernel

Suresh,

On Thu, Jul 06, 2006 at 03:25:43PM -0700, Stephane Eranian wrote:
> > 
> 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.
> 
I meant cpuinfo_x86->apicid & 0x1.


-- 

-Stephane

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [perfmon] Re: cpuinfo_x86 and apicid
  2006-07-06 22:37         ` [perfmon] " Stephane Eranian
@ 2006-07-06 22:47           ` Siddha, Suresh B
  0 siblings, 0 replies; 8+ messages in thread
From: Siddha, Suresh B @ 2006-07-06 22:47 UTC (permalink / raw)
  To: Stephane Eranian; +Cc: Siddha, Suresh B, perfmon, linux-kernel

On Thu, Jul 06, 2006 at 03:37:45PM -0700, Stephane Eranian wrote:
> Suresh,
> 
> On Thu, Jul 06, 2006 at 03:25:43PM -0700, Stephane Eranian wrote:
> > > 
> > 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.
> > 
> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2006-07-06 22:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-06 15:01 cpuinfo_x86 and apicid Stephane Eranian
2006-07-06 15:27 ` linux-os (Dick Johnson)
2006-07-06 16:19 ` Siddha, Suresh B
2006-07-06 20:00   ` Stephane Eranian
2006-07-06 21:06     ` Siddha, Suresh B
2006-07-06 22:25       ` Stephane Eranian
2006-07-06 22:37         ` [perfmon] " Stephane Eranian
2006-07-06 22:47           ` Siddha, Suresh B

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox