Is there a way to do this in C using inline assembly, if so, how?
Thanks,
Joseph
Get Number Of Cpu's
Re: Get Number Of Cpu's
easily?
You can parse the SMP/xAPIC tables and that will tell you info about all processors (logical/physical) that are attached to the mobo.
Also, IIRC, there is a CPUID function that returns the logical processor count. Check the AMD CPUID specs, I think it gets talked about there.
You can parse the SMP/xAPIC tables and that will tell you info about all processors (logical/physical) that are attached to the mobo.
Also, IIRC, there is a CPUID function that returns the logical processor count. Check the AMD CPUID specs, I think it gets talked about there.
Website: https://joscor.com
Re: Get Number Of Cpu's
I've got this on one of this forum's pages:
and this:
I think the second is more useable (maybe, just for me ). The forum's page is called "multiprocessor stuff".
Hope, it helps.
Daniel.
Code: Select all
uint16 cpu_number;
asm {
STR AX
MOV [cpu_number], AX
}
cpu_number = (cpu_number - index_of_first_tss) >> 3;
Code: Select all
#define MAX_CPU 12
unsigned int num_cpus = 1;
static unsigned int cpu_ids[MAX_CPU];
#define APIC_ID ((unsigned int *) (apic + 0x020))
static volatile unsigned int apic_read (unsigned int *addr)
{
return *addr;
}
unsigned ArchThisCpu(void)
{
if (num_cpus == 1)
return 0;
else
return cpu_ids[(apic_read(APIC_ID) & 0xffffffff) >> 24];
}
Hope, it helps.
Daniel.
Don't think a ****, but in ukrainian schools English is TOO BAD!
-
- Member
- Posts: 48
- Joined: Mon Aug 13, 2007 2:30 pm
Re: Get Number Of Cpu's
Ok, thanks for the help everyone, I appreciate it.
Joseph
Joseph
Re: Get Number Of Cpu's
The intel manuals have plenty of pages on CPUID as well,
Modular Interface Kernel With a lot of bugs
Re: Get Number Of Cpu's
ckeck this code out via svn http://sourceforge.net/projects/jeko i used the cpu code from it. real easy to implement
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Get Number Of Cpu's
The only correct way to go about this is by parsing the ACPI, or if that isn't present, MP tables.
Problems with the other versions:
The code snippets by djsilence is a way to get the number of the current running processor, of which the first assumes that all the processors have been started up by the OS already. Since you'll probably be starting off CPU #0 you know nothing about the presence of other ones.
CPUID can only tell you the processor count for the current die - i.e. it is accurate only if you have one multicore chip. If you have more physical processors then the processor will only tell you what's on itself, and miss the other processor. And the relevant CPUID page is completely missing on older processors even though they can just as well be SMP.
I haven't looked at Jeko's code, but I expect it to use the tables.
Problems with the other versions:
The code snippets by djsilence is a way to get the number of the current running processor, of which the first assumes that all the processors have been started up by the OS already. Since you'll probably be starting off CPU #0 you know nothing about the presence of other ones.
CPUID can only tell you the processor count for the current die - i.e. it is accurate only if you have one multicore chip. If you have more physical processors then the processor will only tell you what's on itself, and miss the other processor. And the relevant CPUID page is completely missing on older processors even though they can just as well be SMP.
I haven't looked at Jeko's code, but I expect it to use the tables.