diff options
Diffstat (limited to 'sys/arch/amd64/include/pctr.h')
| -rw-r--r-- | sys/arch/amd64/include/pctr.h | 84 |
1 files changed, 50 insertions, 34 deletions
diff --git a/sys/arch/amd64/include/pctr.h b/sys/arch/amd64/include/pctr.h index 35c651ebffd..18e7f6fc14e 100644 --- a/sys/arch/amd64/include/pctr.h +++ b/sys/arch/amd64/include/pctr.h @@ -1,20 +1,4 @@ -/* $OpenBSD: pctr.h,v 1.1 2007/09/12 18:18:27 deraadt Exp $ */ - -/* - * Copyright (c) 2007 Mike Belopuhov - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ +/* $OpenBSD: pctr.h,v 1.2 2007/10/17 02:30:26 deraadt Exp $ */ /* * Pentium performance counter driver for OpenBSD. @@ -30,15 +14,15 @@ #include <sys/ioccom.h> +typedef u_int64_t pctrval; + #define PCTR_NUM 4 -#define PCTR_AMD_NUM PCTR_NUM -#define PCTR_INTEL_NUM 2 /* Intel supports only 2 counters */ struct pctrst { - u_int64_t pctr_hwc[PCTR_NUM]; /* Values of the hardware counters */ - u_int64_t pctr_tsc; /* Free-running 64-bit cycle counter */ - u_int64_t pctr_idl; /* Iterations of the idle loop */ - u_int32_t pctr_fn[PCTR_NUM]; /* Current settings of counters */ + u_int pctr_fn[PCTR_NUM]; /* Current settings of counters */ + pctrval pctr_tsc; /* Free-running 64-bit cycle counter */ + pctrval pctr_hwc[PCTR_NUM]; /* Values of the hardware counters */ + pctrval pctr_idl; /* Iterations of the idle loop */ }; /* Bit values in fn fields and PIOCS ioctl's */ @@ -48,16 +32,18 @@ struct pctrst { #define PCTR_EN 0x400000 /* Enable counters (counter 0 only) */ #define PCTR_I 0x800000 /* Invert counter mask */ -/* Unit Mask bits */ -#define PCTR_UM_M 0x10 /* Modified cache lines */ -#define PCTR_UM_O 0x08 /* Owned cache lines */ -#define PCTR_UM_E 0x04 /* Exclusive cache lines */ -#define PCTR_UM_S 0x02 /* Shared cache lines */ -#define PCTR_UM_I 0x01 /* Invalid cache lines */ -#define PCTR_UM_MESI (PCTR_UM_O|PCTR_UM_E|PCTR_UM_S|PCTR_UM_I) -#define PCTR_UM_MOESI (PCTR_UM_M|PCTR_UM_O|PCTR_UM_E|PCTR_UM_S|PCTR_UM_I) +/* Unit Mask values to distinguish cache coherent states */ +#define PCTR_UM_M 0x0800 /* Modified cache lines */ +#define PCTR_UM_E 0x0400 /* Exclusive cache lines */ +#define PCTR_UM_S 0x0200 /* Shared cache lines */ +#define PCTR_UM_I 0x0100 /* Invalid cache lines */ +#define PCTR_UM_MESI (PCTR_UM_M|PCTR_UM_E|PCTR_UM_S|PCTR_UM_I) +#define PCTR_UM_A 0x2000 /* Any initiator */ -/* ioctl to set which counter a device tracks. */ +#define PCTR_UM_SHIFT 8 /* Left shift for unit mask */ +#define PCTR_CM_SHIFT 24 /* Left shift for counter mask */ + +/* ioctl to set which counter a device tracks */ #define PCIOCRD _IOR('c', 1, struct pctrst) /* Read counter value */ #define PCIOCS0 _IOW('c', 8, unsigned int) /* Set counter 0 function */ #define PCIOCS1 _IOW('c', 9, unsigned int) /* Set counter 1 function */ @@ -66,13 +52,43 @@ struct pctrst { #define _PATH_PCTR "/dev/pctr" +#define rdtsc() \ +({ \ + u_int32_t hi, lo; \ + __asm __volatile("rdtsc" : "=d" (hi), "=a" (lo)); \ + ((u_int64_t)hi << 32) | (u_int64_t)lo; \ +}) + +#define rdpmc(pmc) \ +({ \ + u_int32_t hi, lo; \ + __asm __volatile("rdpmc" \ + : "=d" (hi), "=a" (lo) : "c" (pmc)); \ + hi &= 0xffffff; \ + (((u_int64_t)hi << 32) | (u_int64_t)lo); \ +}) + #ifdef _KERNEL +#define rdmsr(msr) \ +({ \ + u_int32_t hi, lo; \ + __asm __volatile("rdmsr" \ + : "=d" (hi), "=a" (lo) : "c" (msr)); \ + ((u_int64_t)hi << 32) | (u_int64_t) lo; \ +}) + +#define wrmsr(msr, v) \ +({ \ + __asm __volatile("wrmsr" : \ + : "a" ((u_int64_t)v & 0xffffffff), \ + "d" ((u_int64_t)v >> 32), "c" (msr)); \ +}) + void pctrattach(int); int pctropen(dev_t, int, int, struct proc *); int pctrclose(dev_t, int, int, struct proc *); -int pctrioctl(dev_t, u_int64_t, caddr_t, int, struct proc *); -int pctrsel(int fflag, u_int32_t, u_int32_t); +int pctrioctl(dev_t, u_long, caddr_t, int, struct proc *); #endif /* _KERNEL */ #endif /* ! _AMD64_PCTR_H_ */ |
