summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordm <dm@openbsd.org>1996-08-08 21:37:31 +0000
committerdm <dm@openbsd.org>1996-08-08 21:37:31 +0000
commitb2fed764536321a20b656ca630ecdb47092772d6 (patch)
tree0069872b34e8221894b60267a44281f00c859fe4
parentFixed usage sumary and order of args in man page to be consistent. (diff)
downloadwireguard-openbsd-b2fed764536321a20b656ca630ecdb47092772d6.tar.xz
wireguard-openbsd-b2fed764536321a20b656ca630ecdb47092772d6.zip
Sadly, the performance counters don't seem to work on the pentium pro.
I'll have to find out how the P6 works and add support.
-rw-r--r--sys/arch/i386/i386/pctr.c51
1 files changed, 39 insertions, 12 deletions
diff --git a/sys/arch/i386/i386/pctr.c b/sys/arch/i386/i386/pctr.c
index 9724f62aad9..f1500d9559a 100644
--- a/sys/arch/i386/i386/pctr.c
+++ b/sys/arch/i386/i386/pctr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pctr.c,v 1.1 1996/08/08 18:47:07 dm Exp $ */
+/* $OpenBSD: pctr.c,v 1.2 1996/08/08 21:37:31 dm Exp $ */
/*
* Pentium performance counter driver for OpenBSD.
@@ -16,6 +16,7 @@
#include <machine/cpu.h>
pctrval pctr_idlcnt; /* Gets incremented in locore.s */
+static int cpuid;
#define rdtsc() \
({ \
@@ -39,12 +40,30 @@ pctrattach (int num)
{
if (num > 1)
panic ("no more than one pctr device");
+
+ __asm __volatile ("cli\n"
+ "\tpushfl\n"
+ "\tpopl %%eax\n"
+ "\tmovl %%eax,%%ecx\n"
+ "\txorl %1,%%eax\n"
+ "\tpushl %%eax\n"
+ "\tpopfl\n"
+ "\tpushfl\n"
+ "\tpopl %%eax\n"
+ "\tpushl %%ecx\n"
+ "\tpopfl\n"
+ "\tcmpl %%eax,%%ecx\n"
+ "\tmov $0,%0\n"
+ "\tje 1f\n"
+ "\tcpuid\n"
+ "1:\tsti"
+ : "=a" (cpuid) : "i" (PSL_ID) : "edx", "ecx", "ebx");
}
int
pctropen (dev_t dev, int oflags, int devtype, struct proc *p)
{
- if (minor (dev) || cpu_class < CPUCLASS_586)
+ if (minor (dev))
return ENXIO;
return 0;
}
@@ -102,21 +121,29 @@ pctrioctl (dev_t dev, int cmd, caddr_t data, int fflag, struct proc *p)
struct pctrst *st;
st = (void *) data;
- msr11 = rdmsr (0x11);
- st->pctr_fn[0] = msr11 & 0xffff;
- st->pctr_fn[1] = msr11 >> 16;
- __asm __volatile ("cli");
- st->pctr_tsc = rdtsc ();
- st->pctr_hwc[0] = rdmsr (0x12);
- st->pctr_hwc[1] = rdmsr (0x13);
- __asm __volatile ("sti");
+ if (cpuid == 1) {
+ msr11 = rdmsr (0x11);
+ st->pctr_fn[0] = msr11 & 0xffff;
+ st->pctr_fn[1] = msr11 >> 16;
+ __asm __volatile ("cli");
+ st->pctr_tsc = rdtsc ();
+ st->pctr_hwc[0] = rdmsr (0x12);
+ st->pctr_hwc[1] = rdmsr (0x13);
+ __asm __volatile ("sti");
+ }
+ else {
+ bzero (st, sizeof (*st));
+ if (cpuid)
+ st->pctr_tsc = rdtsc ();
+ }
st->pctr_idl = pctr_idlcnt;
return 0;
- break;
}
case PCIOCS0:
case PCIOCS1:
- return pctrset (fflag, cmd, *(u_short *) data);
+ if (cpuid == 1)
+ return pctrset (fflag, cmd, *(u_short *) data);
+ return EINVAL;
default:
return EINVAL;
}