kern/56451: /compat/linux/proc/cpuinfo gives wrong CPU model

Simon Barner barner at in.tum.de
Thu Sep 4 10:10:12 PDT 2003


>Number:         56451
>Category:       kern
>Synopsis:       /compat/linux/proc/cpuinfo gives wrong CPU model
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Sep 04 10:10:09 PDT 2003
>Closed-Date:
>Last-Modified:
>Originator:     Simon Barner
>Release:        FreeBSD 4.9-PRERELEASE i386
>Organization:
>Environment:
System: FreeBSD zi025.glhnet.mhn.de 4.9-PRERELEASE FreeBSD 4.9-PRERELEASE #0: Thu Sep 4 17:34:02 CEST 2003 simon at zi025.glhnet.mhn.de:/usr/src/sys/compile/KISTE i386

>From dmesg:
[...]
Timecounter "i8254"  frequency 1193182 Hz
CPU: AMD-K6(tm) 3D+ Processor (400.91-MHz 586-class CPU)
Origin = "AuthenticAMD"  Id = 0x591  Stepping = 1
Features=0x8021bf<FPU,VME,DE,PSE,TSC,MSR,MCE,CX8,PGE,MMX>
AMD Features=0x80000800<SYSCALL,3DNow!>
real memory  = 201326592 (196608K bytes)
avail memory = 192172032 (187668K bytes)
Preloaded elf kernel "kernel" at 0xc03ab000.
Preloaded userconfig_script "/boot/kernel.conf" at 0xc03ab09c.
Preloaded elf module "bktr_mem.ko" at 0xc03ab0ec.
Preloaded elf module "bktr.ko" at 0xc03ab18c.
bktr_mem: memory holder loaded
netsmb_dev: loaded
K6-family MTRR support enabled (2 registers)
md0: Malloc disk
[...]

>Description:
I noticed that linprocfs' cpuinfo gives me the wrong CPU model
(according to the cpu_id, which is 0x591, it should be 9 instead of 5).

% cat /compat/linux/proc/cpuinfo 
processor       : 0
vendor_id       : AuthenticAMD
cpu family      : 5
model           : 5  <--- wrong!
stepping        : 1
flags           : fpu vme de pse tsc msr mce cx8 pge mmx
cpu MHz         : 400.91
bogomips        : 400.91

I came across the problem when I tried the latest Mplayer pre-release,
which is not yet in the ports. Its configure script uses FreeBSD's
linprocfs in order to determine the CPU it is being compiled on.

Of course, it would be an easy task to patch Mplayer's configure script,
which as a fallback cpu identification program (which uses the CPUID
assembler instruction and works correctly btw.). But, IMO this is a bug
in linprocfs and should be fixed.

>How-To-Repeat:
cat /compat/linux/proc/cpuinfo on 586+ class CPUs.

>Fix:

Since I do not know a lot about i386-class processor detection, my
suggestions might be wrong, but I'll send them anyway:

As far as I can see, the problem is here:

i386/linux/linprocfs/linprocfs_misc.c, l. 199

	switch (cpu_class) {
	case CPUCLASS_286:
		class = 2;
		break;
	case CPUCLASS_386:
		class = 3;
		break;
	case CPUCLASS_486:
		class = 4;
		break;
	case CPUCLASS_586:
		class = 5;
		break;
	case CPUCLASS_686:
		class = 6;
		break;
	default:
                class = 0;
		break;
	}

	ps = psbuf;
	ps += sprintf(ps,
			"processor\t: %d\n"
			"vendor_id\t: %.20s\n"
			"cpu family\t: %d\n"
			"model\t\t: %d\n"
			"stepping\t: %d\n",
			0, cpu_vendor, class, cpu, cpu_id & 0xf);

        ps += sprintf(ps,
                        "flags\t\t:");

Since pre-i586 CPUs do not support the CPUID instruction and cpu_id is
not set on these CPUs (I am right here?), the information is collected
from cpu_class, cpu (and cpu_id for the stepping).

AFAIK, on a i586+class CPU, one could extract all the information from the
cpu_id variable:

   0, cpu_vendor, cpu_id & 0xf00, cpu_id & 0xf0, cpu_id & 0xf);
   
I am not sure if there is a `model' specification for pre-i586 CPUs, and
if there is one, how to extract it.

Perhaps this here might be a solution, that keeps compatibility with
older CPUs, but sets the model for newer ones correctly:

   0, cpu_vendor, class, cpu_id & 0xf0, cpu_id & 0xf);
>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list