Community
cancel
Showing results for 
Search instead for 
Did you mean: 
ringoguo
Beginner
86 Views

How can i know which core is running


Hi all, I am now doing research on a 4x4 machine. I want to know what cores are running in each thread . Beside , I want to find out whether the 4 cores running in the same thread are on the same die , is there anyone who knows how to do this ? Thank you very much!
0 Kudos
7 Replies
TimP
Black Belt
86 Views

See the previous answer on similar subject. If you don't set affinity, the threads likely won't stay put long enough for a meaningful diagnosis, even if you found a way. It's usually more interesting to evaluate how performance depends on the way you allocate the threads, for example by the linux tools taskset or numactl, or Windows task manager, or by threading library function calls.
Equivalent facilities (typically environment variables) are provided by OpenMP implementations (Intel KMP_AFFINITY, gnu GOMP_AFFINITY) or MPI (e.g. IMPI_PIN_DOMAIN, IMPI_PIN_PROCS)
ringoguo
Beginner
86 Views

Yes , I know I have to set affinity. But i want to know whether an existing software is clever enough to allocate cores on the same die to a thread , that's why I need to know the logical ids of the cores and the information whether they are on the same die. Evaluating the performance is not enough for me here.
ps : task manager is not reliable , sometimes it will give you the wrong message.
SHIH_K_Intel
Employee
86 Views

Just a rough sketch of an idea to consider.

If you can attach a callback routine to the process you would be interested in, then you solve half the problem.

In the callback process, you can call an OS API to get affinity info, alternately you execute CPUID instruction to query initial APID of current thread context.When your target isa multi-threaded app, the DLL insertion may have to be sophisticated enough to walk thru each thread context owned by the process. Natually, your callback should not alter affinity setting.

Based on the initial APIC ID of each thread context, and its evolution across OS scheduler quanta, you can compare that to a system map of the CPU topology. The system map of the CPU topology can be done separately, do not inject a system topology map query as part of the dll toyour target app callback, or run currently when you're studying your target app. You should produce the system topology map before or after you're done with your injection study. Because, system topology map will not change after BIOS initialization until reboot (current OS do not suppot hot-add/ hot-removal of CPU). Producing a system topology map requires modifying affinity setting across all logical processors.

The reference coderelated to the white paper, can be used to produce your system topology map. See

http://software.intel.com/en-us/articles/intel-64-architecture-processor-topology-enumeration

Dmitry_Vyukov
Valued Contributor I
86 Views

ringoguo:

Hi all, I am now doing research on a 4x4 machine. I want to know what cores are running in each thread . Beside , I want to find out whether the 4 cores running in the same thread are on the same die , is there anyone who knows how to do this ? Thank you very much!


Depends on OS.

On Windows Vista you can use GetCurrentProcessorNumber().

On Linux you can use vgetcpu().

If they are not available, you can try to use:

__declspec(naked) unsigned get_current_proc()
{
__asm
{
mov ecx, 03Bh
lsl eax, ecx
shr eax, 0Eh
retn
}
}

But this will likely be working only on Windows Vista.

Under Windows XP you can try to use:
unsigned* idt_table;
unsigned idt_table_size;

__declspec(thread) unsigned thread_cache_idt;
__declspec(thread) unsigned thread_cache_proc;

unsigned get_current_processor()
{
#pragma pack(push, 1)
struct idt_t
{
unsigned short size;
unsigned base;
};
#pragma pack(pop)

idt_t idt;
__sidt(&idt);
if (idt.base != thread_cache_idt)
{
for (unsigned i = 0; i != idt_table_size; ++i)
{
if (idt_table == idt.base)
{
thread_cache_idt = idt.base;
thread_cache_proc = i;
break;
}
}
}
return thread_cache_proc;
}
Or:
struct current_processor_t
{
unsigned number;
unsigned timestamp;
unsigned period;
};

__declspec(thread) current_processor_t current_processor = {0, 0, 1};

__declspec(noinline) void update_current_processor()
{
current_processor_t& cp = current_processor;
cp.timestamp = *(unsigned*)0x7FFE0000; // tick count
cp.period = 10; // subject to tweaking
unsigned proc;
__asm
{
mov eax, 1;
cpuid;
shr ebx, 24;
mov proc, ebx;
}
cp.number = proc;
}

unsigned get_current_processor( )
{
current_processor_t& cp = current_processor;
if (0 == --cp.period || cp.timestamp != *(unsigned*)0x7FFE0000)
update_current_processor();
return cp.number;
}


Dmitriy V'jukov

Dmitry_Vyukov
Valued Contributor I
86 Views

ringoguo:

Hi all, I am now doing research on a 4x4 machine. I want to know what cores are running in each thread . Beside , I want to find out whether the 4 cores running in the same thread are on the same die , is there anyone who knows how to do this ? Thank you very much!


Oh, and on AMD processors you can use RDTSCP (Read Time-Stamp Counter and Processor ID) instruction.


Dmitriy V'jukov
Thomas_W_Intel
Employee
86 Views

RDTSCP is available on Nehalem architecture, too. A description is available in Section 16.11.2 of the Intel 64 and IA-32 Architectures Software Developers Manual, Volume 3A: System Programming Guide, Part 1, which is available here.

Kind regards
Thomas
yuanyuan3558
Beginner
86 Views

Wish you solve the problem as soon as possible!
Reply