[SIGAR-60] Add multi-core AMD Opteron detection

This commit is contained in:
Doug MacEachern 2007-06-28 18:25:50 +00:00
parent 407144e707
commit 4d218a4cc4
1 changed files with 28 additions and 14 deletions

View File

@ -151,11 +151,7 @@ int sigar_os_open(sigar_t **sigar)
(*sigar)->last_proc_stat.pid = -1; (*sigar)->last_proc_stat.pid = -1;
#ifdef __i386__
(*sigar)->ht_enabled = -1; (*sigar)->ht_enabled = -1;
#else
(*sigar)->ht_enabled = 0;
#endif
if (stat(PROC_DISKSTATS, &sb) == 0) { if (stat(PROC_DISKSTATS, &sb) == 0) {
(*sigar)->iostat = IOSTAT_DISKSTATS; (*sigar)->iostat = IOSTAT_DISKSTATS;
@ -193,14 +189,16 @@ char *sigar_os_error_string(sigar_t *sigar, int err)
return NULL; return NULL;
} }
#ifdef __i386__
#define INTEL_ID 0x756e6547 #define INTEL_ID 0x756e6547
#define AMD_ID 0x68747541
static void sigar_cpuid(unsigned long request, #if defined(__i386__)
unsigned long *eax, #define SIGAR_HAS_CPUID
unsigned long *ebx, static void sigar_cpuid(sigar_uint32_t request,
unsigned long *ecx, sigar_uint32_t *eax,
unsigned long *edx) sigar_uint32_t *ebx,
sigar_uint32_t *ecx,
sigar_uint32_t *edx)
{ {
#if 0 #if 0
/* does not compile w/ -fPIC */ /* does not compile w/ -fPIC */
@ -225,10 +223,26 @@ static void sigar_cpuid(unsigned long request,
: "memory"); : "memory");
#endif #endif
} }
#elif defined(__amd64__)
#define SIGAR_HAS_CPUID
static void sigar_cpuid(unsigned int request,
unsigned int *eax,
unsigned int *ebx,
unsigned int *ecx,
unsigned int *edx)
{
/* http://svn.red-bean.com/repos/minor/trunk/gc/barriers-amd64.c */
asm volatile ("cpuid\n\t"
: "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
: "0" (request)
: "memory");
}
#endif
#ifdef SIGAR_HAS_CPUID
static int is_ht_enabled(sigar_t *sigar) static int is_ht_enabled(sigar_t *sigar)
{ {
unsigned long eax, ebx, ecx, edx; sigar_uint32_t eax, ebx, ecx, edx;
if (sigar->ht_enabled != -1) { if (sigar->ht_enabled != -1) {
/* only check once */ /* only check once */
@ -240,14 +254,14 @@ static int is_ht_enabled(sigar_t *sigar)
sigar_cpuid(0, &eax, &ebx, &ecx, &edx); sigar_cpuid(0, &eax, &ebx, &ecx, &edx);
if (ebx == INTEL_ID) { if ((ebx == INTEL_ID) || (ebx == AMD_ID)) {
sigar_cpuid(1, &eax, &ebx, &ecx, &edx); sigar_cpuid(1, &eax, &ebx, &ecx, &edx);
if (edx & (1<<28)) { if (edx & (1<<28)) {
#ifdef DETECT_HT_ENABLED #ifdef DETECT_HT_ENABLED
unsigned long apic_id = sigar_uint32_t apic_id =
(ebx & 0xFF000000) >> 24; (ebx & 0xFF000000) >> 24;
unsigned long log_id, phy_id_mask=0xFF, i=1; sigar_uint32_t log_id, phy_id_mask=0xFF, i=1;
#endif #endif
sigar->lcpu = (ebx & 0x00FF0000) >> 16; sigar->lcpu = (ebx & 0x00FF0000) >> 16;
#ifdef DETECT_HT_ENABLED #ifdef DETECT_HT_ENABLED