diff options
author | Jason Downs <downsj@cvs.openbsd.org> | 1998-05-25 08:01:43 +0000 |
---|---|---|
committer | Jason Downs <downsj@cvs.openbsd.org> | 1998-05-25 08:01:43 +0000 |
commit | 2daf65acd28fc0686f3d342c34f31b3b524946cf (patch) | |
tree | e6d735b96cd4b5a4aef7d09355ff2f747d831aa1 /sys | |
parent | 2497316a2a77a2cc043fa01815bf5c83410d23cf (diff) |
Major cleanup of configuration code; don't assume all the world is Intel, and
don't duplicate the work of locore.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/i386/i386/pctr.c | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/sys/arch/i386/i386/pctr.c b/sys/arch/i386/i386/pctr.c index fed2df1579b..fd35848162c 100644 --- a/sys/arch/i386/i386/pctr.c +++ b/sys/arch/i386/i386/pctr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pctr.c,v 1.10 1997/08/16 16:31:18 mickey Exp $ */ +/* $OpenBSD: pctr.c,v 1.11 1998/05/25 08:01:42 downsj Exp $ */ /* * Pentium performance counter driver for OpenBSD. @@ -20,12 +20,23 @@ #include <machine/psl.h> #include <machine/pctr.h> #include <machine/cpu.h> +#include <machine/specialreg.h> pctrval pctr_idlcnt; /* Gets incremented in locore.s */ -static int usetsc; -static int usep5ctr; -static int usep6ctr; +/* Pull in the cpuid values from locore.s */ +extern int cpu_id; +extern int cpu_feature; +extern char cpu_vendor[]; + +static int isintel; +static int iscyrix; + +#define usetsc (cpu_feature & CPUID_TSC) +#define usep5ctr (isintel && (((cpu_id >> 8) & 15) == 5) && \ + (((cpu_id >> 4) & 15) > 0)) +/* I believe Cyrix supports RDPMC. */ +#define usep6ctr ((isintel || iscyrix) && ((cpu_id >> 8) & 15) == 6) void pctrattach __P((int)); int pctropen __P((dev_t, int, int, struct proc *)); @@ -35,19 +46,12 @@ int pctrioctl __P((dev_t, int, caddr_t, int, struct proc *)); void pctrattach (int num) { - pctrval id; - - if (num > 1) { - printf ("Ignoring pctr device #%d\n", num); - printf ("(config file should read `pseudo-device pctr 1')\n"); + if (num > 1) return; - } - id = __cpuid (); - usetsc = __hastsc (id); - usep5ctr = __hasp5ctr (id); - usep6ctr = __hasp6ctr (id); - + isintel = (strcmp(cpu_vendor, "GenuineIntel") == 0); + iscyrix = (strcmp(cpu_vendor, "CyrixInstead") == 0); + if (usep6ctr) /* Enable RDTSC and RDPMC instructions from user-level. */ __asm __volatile (".byte 0xf,0x20,0xe0 # movl %%cr4,%%eax\n" @@ -63,11 +67,9 @@ pctrattach (int num) :: "i" (~CR4_TSD) : "eax"); if (usep6ctr) - printf ("pctr: Pentium Pro user-level " - "performance counters enabled\n"); + printf ("pctr: 686-class user-level performance counters enabled\n"); else if (usep5ctr) - printf ("pctr: Pentium performance counters and user-level " - "cycle counter enabled\n"); + printf ("pctr: 586-class performance counters and user-level cycle counter enabled\n"); else if (usetsc) printf ("pctr: user-level cycle counter enabled\n"); else @@ -150,7 +152,7 @@ p6ctrsel (int fflag, u_int cmd, u_int fn) wrmsr (msrsel, fn); wrmsr (msrval, 0); - return 0; + return 0; } static __inline void |