From f8c05e5019cf6138626a0d5b1735256a8ab726be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Wed, 25 Oct 2000 22:38:23 +0000 Subject: [PATCH] Bring cpuinfo closer to what it looks like in Linux 2.2. Submitted by: R Bradford Jones --- sys/compat/linprocfs/linprocfs.c | 58 ++++++++++++++++++----- sys/compat/linprocfs/linprocfs_misc.c | 58 ++++++++++++++++++----- sys/i386/linux/linprocfs/linprocfs_misc.c | 58 ++++++++++++++++++----- 3 files changed, 141 insertions(+), 33 deletions(-) diff --git a/sys/compat/linprocfs/linprocfs.c b/sys/compat/linprocfs/linprocfs.c index 59594d5199aa..b985916bb565 100644 --- a/sys/compat/linprocfs/linprocfs.c +++ b/sys/compat/linprocfs/linprocfs.c @@ -61,8 +61,9 @@ #include #include -#include +#include #include +#include #include @@ -171,44 +172,79 @@ linprocfs_docpuinfo(curp, p, pfs, uio) char *ps; int xlen; char psbuf[512]; /* XXX - conservative */ - char *class; + int class; + int i; #if 0 extern char *cpu_model; /* Yuck */ #endif + /* We default the flags to include all non-conflicting flags, + and the Intel versions of conflicting flags. Note the space + before each name; that is significant, and should be + preserved. */ + + static char *flags[] = { + "fpu", "vme", "de", "pse", "tsc", + "msr", "pae", "mce", "cx8", "apic", + "sep", "sep", "mtrr", "pge", "mca", + "cmov", "pat", "pse36", "pn", "b19", + "b20", "b21", "mmxext", "mmx", "fxsr", + "xmm", "b26", "b27", "b28", "b29", + "3dnowext", "3dnow" + }; if (uio->uio_rw != UIO_READ) return (EOPNOTSUPP); switch (cpu_class) { case CPUCLASS_286: - class = "286"; + class = 2; break; case CPUCLASS_386: - class = "386"; + class = 3; break; case CPUCLASS_486: - class = "486"; + class = 4; break; case CPUCLASS_586: - class = "586"; + class = 5; break; case CPUCLASS_686: - class = "686"; + class = 6; break; default: - class = "unknown"; + class = 0; break; } ps = psbuf; ps += sprintf(ps, "processor : %d\n" - "cpu : %.3s\n" - "model : %.20s\n" "vendor_id : %.20s\n" + "cpu family : %d\n" + "model : %d\n" "stepping : %d\n", - 0, class, "unknown", cpu_vendor, cpu_id); + 0, cpu_vendor, class, cpu, cpu_id & 0xf); + ps += sprintf(ps, + "flags :"); + + if (!strcmp(cpu_vendor, "AuthenticAMD") && (class < 6)) { + flags[16] = "fcmov"; + } else if (!strcmp(cpu_vendor, "CyrixInstead")) { + flags[24] = "cxmmx"; + } + + for (i = 0; i < 32; i++) + if (cpu_feature & (1 << i)) + ps += sprintf(ps, " %s", flags[i]); + ps += sprintf(ps, "\n"); + if (class >= 5) { + ps += sprintf(ps, + "cpu MHz : %d.%02d\n", + (tsc_freq + 4999) / 1000000, + ((tsc_freq + 4999) / 10000) % 100); + } + xlen = ps - psbuf; xlen -= uio->uio_offset; ps = psbuf + uio->uio_offset; diff --git a/sys/compat/linprocfs/linprocfs_misc.c b/sys/compat/linprocfs/linprocfs_misc.c index 59594d5199aa..b985916bb565 100644 --- a/sys/compat/linprocfs/linprocfs_misc.c +++ b/sys/compat/linprocfs/linprocfs_misc.c @@ -61,8 +61,9 @@ #include #include -#include +#include #include +#include #include @@ -171,44 +172,79 @@ linprocfs_docpuinfo(curp, p, pfs, uio) char *ps; int xlen; char psbuf[512]; /* XXX - conservative */ - char *class; + int class; + int i; #if 0 extern char *cpu_model; /* Yuck */ #endif + /* We default the flags to include all non-conflicting flags, + and the Intel versions of conflicting flags. Note the space + before each name; that is significant, and should be + preserved. */ + + static char *flags[] = { + "fpu", "vme", "de", "pse", "tsc", + "msr", "pae", "mce", "cx8", "apic", + "sep", "sep", "mtrr", "pge", "mca", + "cmov", "pat", "pse36", "pn", "b19", + "b20", "b21", "mmxext", "mmx", "fxsr", + "xmm", "b26", "b27", "b28", "b29", + "3dnowext", "3dnow" + }; if (uio->uio_rw != UIO_READ) return (EOPNOTSUPP); switch (cpu_class) { case CPUCLASS_286: - class = "286"; + class = 2; break; case CPUCLASS_386: - class = "386"; + class = 3; break; case CPUCLASS_486: - class = "486"; + class = 4; break; case CPUCLASS_586: - class = "586"; + class = 5; break; case CPUCLASS_686: - class = "686"; + class = 6; break; default: - class = "unknown"; + class = 0; break; } ps = psbuf; ps += sprintf(ps, "processor : %d\n" - "cpu : %.3s\n" - "model : %.20s\n" "vendor_id : %.20s\n" + "cpu family : %d\n" + "model : %d\n" "stepping : %d\n", - 0, class, "unknown", cpu_vendor, cpu_id); + 0, cpu_vendor, class, cpu, cpu_id & 0xf); + ps += sprintf(ps, + "flags :"); + + if (!strcmp(cpu_vendor, "AuthenticAMD") && (class < 6)) { + flags[16] = "fcmov"; + } else if (!strcmp(cpu_vendor, "CyrixInstead")) { + flags[24] = "cxmmx"; + } + + for (i = 0; i < 32; i++) + if (cpu_feature & (1 << i)) + ps += sprintf(ps, " %s", flags[i]); + ps += sprintf(ps, "\n"); + if (class >= 5) { + ps += sprintf(ps, + "cpu MHz : %d.%02d\n", + (tsc_freq + 4999) / 1000000, + ((tsc_freq + 4999) / 10000) % 100); + } + xlen = ps - psbuf; xlen -= uio->uio_offset; ps = psbuf + uio->uio_offset; diff --git a/sys/i386/linux/linprocfs/linprocfs_misc.c b/sys/i386/linux/linprocfs/linprocfs_misc.c index 59594d5199aa..b985916bb565 100644 --- a/sys/i386/linux/linprocfs/linprocfs_misc.c +++ b/sys/i386/linux/linprocfs/linprocfs_misc.c @@ -61,8 +61,9 @@ #include #include -#include +#include #include +#include #include @@ -171,44 +172,79 @@ linprocfs_docpuinfo(curp, p, pfs, uio) char *ps; int xlen; char psbuf[512]; /* XXX - conservative */ - char *class; + int class; + int i; #if 0 extern char *cpu_model; /* Yuck */ #endif + /* We default the flags to include all non-conflicting flags, + and the Intel versions of conflicting flags. Note the space + before each name; that is significant, and should be + preserved. */ + + static char *flags[] = { + "fpu", "vme", "de", "pse", "tsc", + "msr", "pae", "mce", "cx8", "apic", + "sep", "sep", "mtrr", "pge", "mca", + "cmov", "pat", "pse36", "pn", "b19", + "b20", "b21", "mmxext", "mmx", "fxsr", + "xmm", "b26", "b27", "b28", "b29", + "3dnowext", "3dnow" + }; if (uio->uio_rw != UIO_READ) return (EOPNOTSUPP); switch (cpu_class) { case CPUCLASS_286: - class = "286"; + class = 2; break; case CPUCLASS_386: - class = "386"; + class = 3; break; case CPUCLASS_486: - class = "486"; + class = 4; break; case CPUCLASS_586: - class = "586"; + class = 5; break; case CPUCLASS_686: - class = "686"; + class = 6; break; default: - class = "unknown"; + class = 0; break; } ps = psbuf; ps += sprintf(ps, "processor : %d\n" - "cpu : %.3s\n" - "model : %.20s\n" "vendor_id : %.20s\n" + "cpu family : %d\n" + "model : %d\n" "stepping : %d\n", - 0, class, "unknown", cpu_vendor, cpu_id); + 0, cpu_vendor, class, cpu, cpu_id & 0xf); + ps += sprintf(ps, + "flags :"); + + if (!strcmp(cpu_vendor, "AuthenticAMD") && (class < 6)) { + flags[16] = "fcmov"; + } else if (!strcmp(cpu_vendor, "CyrixInstead")) { + flags[24] = "cxmmx"; + } + + for (i = 0; i < 32; i++) + if (cpu_feature & (1 << i)) + ps += sprintf(ps, " %s", flags[i]); + ps += sprintf(ps, "\n"); + if (class >= 5) { + ps += sprintf(ps, + "cpu MHz : %d.%02d\n", + (tsc_freq + 4999) / 1000000, + ((tsc_freq + 4999) / 10000) % 100); + } + xlen = ps - psbuf; xlen -= uio->uio_offset; ps = psbuf + uio->uio_offset;