- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ps : task manager is not reliable , sometimes it will give you the wrong message.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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;
Or:
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;
}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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Kind regards
Thomas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page