diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 1997-08-16 16:31:19 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 1997-08-16 16:31:19 +0000 |
commit | 7119c1eca561749e9c03ab6fafecce9305466aab (patch) | |
tree | 951dd08901ea09eadf4a41c9ee9aa0339e90e19f /sys/arch | |
parent | c1e1723f1db13dba035df79eb32645106801b510 (diff) |
tabs and consistensy
Diffstat (limited to 'sys/arch')
-rw-r--r-- | sys/arch/i386/i386/pctr.c | 245 |
1 files changed, 123 insertions, 122 deletions
diff --git a/sys/arch/i386/i386/pctr.c b/sys/arch/i386/i386/pctr.c index 60a83f7005e..fed2df1579b 100644 --- a/sys/arch/i386/i386/pctr.c +++ b/sys/arch/i386/i386/pctr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pctr.c,v 1.9 1997/06/15 13:45:13 dm Exp $ */ +/* $OpenBSD: pctr.c,v 1.10 1997/08/16 16:31:18 mickey Exp $ */ /* * Pentium performance counter driver for OpenBSD. @@ -35,164 +35,165 @@ 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"); - return; - } - - id = __cpuid (); - usetsc = __hastsc (id); - usep5ctr = __hasp5ctr (id); - usep6ctr = __hasp6ctr (id); - - if (usep6ctr) - /* Enable RDTSC and RDPMC instructions from user-level. */ - asm volatile (".byte 0xf,0x20,0xe0 # movl %%cr4,%%eax\n" - "\tandl %0,%%eax\n" - "\torl %1,%%eax\n" - "\t.byte 0xf,0x22,0xe0 # movl %%cr4,%%eax" - :: "i" (~CR4_TSD), "i" (CR4_PCE) : "eax"); - else if (usetsc) - /* Enable RDTSC instruction from user-level. */ - asm volatile (".byte 0xf,0x20,0xe0 # movl %%cr4,%%eax\n" - "\tandl %0,%%eax\n" - "\t.byte 0xf,0x22,0xe0 # movl %%cr4,%%eax" - :: "i" (~CR4_TSD) : "eax"); - - if (usep6ctr) - printf ("pctr: Pentium Pro user-level performance counters enabled\n"); - else if (usep5ctr) - printf ("pctr: Pentium performance counters and user-level " - "cycle counter enabled\n"); - else if (usetsc) - printf ("pctr: user-level cycle counter enabled\n"); - else - printf ("pctr: no performance counters in CPU\n"); + pctrval id; + + if (num > 1) { + printf ("Ignoring pctr device #%d\n", num); + printf ("(config file should read `pseudo-device pctr 1')\n"); + return; + } + + id = __cpuid (); + usetsc = __hastsc (id); + usep5ctr = __hasp5ctr (id); + usep6ctr = __hasp6ctr (id); + + if (usep6ctr) + /* Enable RDTSC and RDPMC instructions from user-level. */ + __asm __volatile (".byte 0xf,0x20,0xe0 # movl %%cr4,%%eax\n" + "\tandl %0,%%eax\n" + "\torl %1,%%eax\n" + "\t.byte 0xf,0x22,0xe0 # movl %%cr4,%%eax" + :: "i" (~CR4_TSD), "i" (CR4_PCE) : "eax"); + else if (usetsc) + /* Enable RDTSC instruction from user-level. */ + __asm __volatile (".byte 0xf,0x20,0xe0 # movl %%cr4,%%eax\n" + "\tandl %0,%%eax\n" + "\t.byte 0xf,0x22,0xe0 # movl %%cr4,%%eax" + :: "i" (~CR4_TSD) : "eax"); + + if (usep6ctr) + printf ("pctr: Pentium Pro user-level " + "performance counters enabled\n"); + else if (usep5ctr) + printf ("pctr: Pentium performance counters and user-level " + "cycle counter enabled\n"); + else if (usetsc) + printf ("pctr: user-level cycle counter enabled\n"); + else + printf ("pctr: no performance counters in CPU\n"); } int pctropen (dev_t dev, int oflags, int devtype, struct proc *p) { - if (minor (dev)) - return ENXIO; - return 0; + if (minor (dev)) + return ENXIO; + return 0; } int pctrclose (dev_t dev, int oflags, int devtype, struct proc *p) { - return 0; + return 0; } static int p5ctrsel (int fflag, u_int cmd, u_int fn) { - pctrval msr11; - int msr; - int shift; - - cmd -= PCIOCS0; - if (cmd > 1) - return EINVAL; - msr = P5MSR_CTR0 + cmd; - shift = cmd ? 0x10 : 0; - - if (! (fflag & FWRITE)) - return EPERM; - if (fn >= 0x200) - return EINVAL; - - msr11 = rdmsr (0x11); - msr11 &= ~(0x1ffLL << shift); - msr11 |= fn << shift; - wrmsr (0x11, msr11); - wrmsr (msr, 0); - - return 0; + pctrval msr11; + int msr; + int shift; + + cmd -= PCIOCS0; + if (cmd > 1) + return EINVAL; + msr = P5MSR_CTR0 + cmd; + shift = cmd ? 0x10 : 0; + + if (! (fflag & FWRITE)) + return EPERM; + if (fn >= 0x200) + return EINVAL; + + msr11 = rdmsr (0x11); + msr11 &= ~(0x1ffLL << shift); + msr11 |= fn << shift; + wrmsr (0x11, msr11); + wrmsr (msr, 0); + + return 0; } -static inline void +static __inline void p5ctrrd (struct pctrst *st) { - u_int msr11; - - msr11 = rdmsr (P5MSR_CTRSEL); - st->pctr_fn[0] = msr11 & 0xffff; - st->pctr_fn[1] = msr11 >> 16; - __asm __volatile ("cli"); - st->pctr_tsc = rdtsc (); - st->pctr_hwc[0] = rdmsr (P5MSR_CTR0); - st->pctr_hwc[1] = rdmsr (P5MSR_CTR1); - __asm __volatile ("sti"); + u_int msr11; + + msr11 = rdmsr (P5MSR_CTRSEL); + st->pctr_fn[0] = msr11 & 0xffff; + st->pctr_fn[1] = msr11 >> 16; + __asm __volatile ("cli"); + st->pctr_tsc = rdtsc (); + st->pctr_hwc[0] = rdmsr (P5MSR_CTR0); + st->pctr_hwc[1] = rdmsr (P5MSR_CTR1); + __asm __volatile ("sti"); } static int p6ctrsel (int fflag, u_int cmd, u_int fn) { - int msrsel, msrval; + int msrsel, msrval; - cmd -= PCIOCS0; - if (cmd > 1) - return EINVAL; - msrsel = P6MSR_CTRSEL0 + cmd; - msrval = P6MSR_CTR0 + cmd; + cmd -= PCIOCS0; + if (cmd > 1) + return EINVAL; + msrsel = P6MSR_CTRSEL0 + cmd; + msrval = P6MSR_CTR0 + cmd; - if (! (fflag & FWRITE)) - return EPERM; - if (fn & 0x380000) - return EINVAL; + if (! (fflag & FWRITE)) + return EPERM; + if (fn & 0x380000) + return EINVAL; - wrmsr (msrval, 0); - wrmsr (msrsel, fn); - wrmsr (msrval, 0); + wrmsr (msrval, 0); + wrmsr (msrsel, fn); + wrmsr (msrval, 0); return 0; } -static inline void +static __inline void p6ctrrd (struct pctrst *st) { - st->pctr_fn[0] = rdmsr (P6MSR_CTRSEL0); - st->pctr_fn[1] = rdmsr (P6MSR_CTRSEL1); - __asm __volatile ("cli"); - st->pctr_tsc = rdtsc (); - st->pctr_hwc[0] = rdpmc (0); - st->pctr_hwc[1] = rdpmc (1); - __asm __volatile ("sti"); + st->pctr_fn[0] = rdmsr (P6MSR_CTRSEL0); + st->pctr_fn[1] = rdmsr (P6MSR_CTRSEL1); + __asm __volatile ("cli"); + st->pctr_tsc = rdtsc (); + st->pctr_hwc[0] = rdpmc (0); + st->pctr_hwc[1] = rdpmc (1); + __asm __volatile ("sti"); } int pctrioctl (dev_t dev, int cmd, caddr_t data, int fflag, struct proc *p) { - switch (cmd) { - case PCIOCRD: - { - struct pctrst *st = (void *) data; - - if (usep6ctr) - p6ctrrd (st); - else if (usep5ctr) - p5ctrrd (st); - else { - bzero (st, sizeof (*st)); - if (usetsc) - st->pctr_tsc = rdtsc (); - } - st->pctr_idl = pctr_idlcnt; - return 0; - } - case PCIOCS0: - case PCIOCS1: - if (usep6ctr) - return p6ctrsel (fflag, cmd, *(u_int *) data); - if (usep5ctr) - return p5ctrsel (fflag, cmd, *(u_int *) data); - return ENODEV; - default: - return EINVAL; - } + switch (cmd) { + case PCIOCRD: + { + struct pctrst *st = (void *) data; + + if (usep6ctr) + p6ctrrd (st); + else if (usep5ctr) + p5ctrrd (st); + else { + bzero (st, sizeof (*st)); + if (usetsc) + st->pctr_tsc = rdtsc (); + } + st->pctr_idl = pctr_idlcnt; + return 0; + } + case PCIOCS0: + case PCIOCS1: + if (usep6ctr) + return p6ctrsel (fflag, cmd, *(u_int *) data); + if (usep5ctr) + return p5ctrsel (fflag, cmd, *(u_int *) data); + return ENODEV; + default: + return EINVAL; + } } |