Module Name:    src
Committed By:   maxv
Date:           Wed Mar  8 16:42:27 UTC 2017

Modified Files:
        src/sys/arch/i386/i386: pmc.c
        src/sys/arch/x86/include: sysarch.h
        src/usr.bin/pmc: pmc.c

Log Message:
Add a version argument, set to 1, and check it in usr.bin/pmc. Use uint32_t
instead uint8_t since we now need 12bit selectors (10h family). And while
here KNF.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/i386/i386/pmc.c
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/x86/include/sysarch.h
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/pmc/pmc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/i386/i386/pmc.c
diff -u src/sys/arch/i386/i386/pmc.c:1.23 src/sys/arch/i386/i386/pmc.c:1.24
--- src/sys/arch/i386/i386/pmc.c:1.23	Sat Feb 18 15:56:03 2017
+++ src/sys/arch/i386/i386/pmc.c	Wed Mar  8 16:42:27 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmc.c,v 1.23 2017/02/18 15:56:03 maxv Exp $	*/
+/*	$NetBSD: pmc.c,v 1.24 2017/03/08 16:42:27 maxv Exp $	*/
 
 /*
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmc.c,v 1.23 2017/02/18 15:56:03 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmc.c,v 1.24 2017/03/08 16:42:27 maxv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -275,6 +275,7 @@ sys_pmc_info(struct lwp *l, struct x86_p
 
 	memset(&rv, 0, sizeof(rv));
 
+	rv.vers = PMC_VERSION;
 	rv.type = pmc_type;
 	rv.flags = pmc_flags;
 
@@ -297,7 +298,7 @@ sys_pmc_startstop(struct lwp *l, struct 
 	if (error)
 		return error;
 
-	if (args.counter < 0 || args.counter >= pmc_ncounters)
+	if (args.counter >= pmc_ncounters)
 		return EINVAL;
 
 	start = (args.flags & (PMC_SETUP_KERNEL|PMC_SETUP_USER)) != 0;
@@ -338,7 +339,7 @@ sys_pmc_read(struct lwp *l, struct x86_p
 	if (error)
 		return error;
 
-	if (args.counter < 0 || args.counter >= pmc_ncounters)
+	if (args.counter >= pmc_ncounters)
 		return EINVAL;
 	pmc = &pmc_state[args.counter];
 

Index: src/sys/arch/x86/include/sysarch.h
diff -u src/sys/arch/x86/include/sysarch.h:1.9 src/sys/arch/x86/include/sysarch.h:1.10
--- src/sys/arch/x86/include/sysarch.h:1.9	Wed Jul  7 01:14:53 2010
+++ src/sys/arch/x86/include/sysarch.h	Wed Mar  8 16:42:27 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysarch.h,v 1.9 2010/07/07 01:14:53 chs Exp $	*/
+/*	$NetBSD: sysarch.h,v 1.10 2017/03/08 16:42:27 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -34,62 +34,62 @@
 
 #define X86_GET_LDT		0
 #define X86_SET_LDT		1
-#define	X86_IOPL		2
-#define	X86_GET_IOPERM		3
-#define	X86_SET_IOPERM		4
-#define	X86_OLD_VM86		5
-#define	X86_PMC_INFO		8
-#define	X86_PMC_STARTSTOP	9
-#define	X86_PMC_READ		10
+#define X86_IOPL		2
+#define X86_GET_IOPERM		3
+#define X86_SET_IOPERM		4
+#define X86_OLD_VM86		5
+#define X86_PMC_INFO		8
+#define X86_PMC_STARTSTOP	9
+#define X86_PMC_READ		10
 #define X86_GET_MTRR		11
 #define X86_SET_MTRR		12
-#define	X86_VM86		13
-#define	X86_GET_GSBASE		14
-#define	X86_GET_FSBASE		15
-#define	X86_SET_GSBASE		16
-#define	X86_SET_FSBASE		17
+#define X86_VM86		13
+#define X86_GET_GSBASE		14
+#define X86_GET_FSBASE		15
+#define X86_SET_GSBASE		16
+#define X86_SET_FSBASE		17
 
 #ifdef _KERNEL
-#define	_X86_SYSARCH_L(x)	x86_##x
-#define	_X86_SYSARCH_U(x)	X86_##x
+#define _X86_SYSARCH_L(x)	x86_##x
+#define _X86_SYSARCH_U(x)	X86_##x
 #elif defined(__i386__)
-#define	_X86_SYSARCH_L(x)	i386_##x
-#define	_X86_SYSARCH_U(x)	I386_##x
+#define _X86_SYSARCH_L(x)	i386_##x
+#define _X86_SYSARCH_U(x)	I386_##x
 #define I386_GET_LDT		X86_GET_LDT
 #define I386_SET_LDT		X86_SET_LDT
-#define	I386_IOPL		X86_IOPL
-#define	I386_GET_IOPERM		X86_GET_IOPERM
-#define	I386_SET_IOPERM		X86_SET_IOPERM
-#define	I386_OLD_VM86		X86_OLD_VM86
-#define	I386_PMC_INFO		X86_PMC_INFO
-#define	I386_PMC_STARTSTOP	X86_PMC_STARTSTOP
-#define	I386_PMC_READ		X86_PMC_READ
+#define I386_IOPL		X86_IOPL
+#define I386_GET_IOPERM		X86_GET_IOPERM
+#define I386_SET_IOPERM		X86_SET_IOPERM
+#define I386_OLD_VM86		X86_OLD_VM86
+#define I386_PMC_INFO		X86_PMC_INFO
+#define I386_PMC_STARTSTOP	X86_PMC_STARTSTOP
+#define I386_PMC_READ		X86_PMC_READ
 #define I386_GET_MTRR		X86_GET_MTRR
 #define I386_SET_MTRR		X86_SET_MTRR
-#define	I386_VM86		X86_VM86
-#define	I386_GET_GSBASE		X86_GET_GSBASE
-#define	I386_GET_FSBASE		X86_GET_FSBASE
-#define	I386_SET_GSBASE		X86_SET_GSBASE
-#define	I386_SET_FSBASE		X86_SET_FSBASE
+#define I386_VM86		X86_VM86
+#define I386_GET_GSBASE		X86_GET_GSBASE
+#define I386_GET_FSBASE		X86_GET_FSBASE
+#define I386_SET_GSBASE		X86_SET_GSBASE
+#define I386_SET_FSBASE		X86_SET_FSBASE
 #else
-#define	_X86_SYSARCH_L(x)	x86_64_##x
-#define	_X86_SYSARCH_U(x)	X86_64_##x
+#define _X86_SYSARCH_L(x)	x86_64_##x
+#define _X86_SYSARCH_U(x)	X86_64_##x
 #define X86_64_GET_LDT		X86_GET_LDT
 #define X86_64_SET_LDT		X86_SET_LDT
-#define	X86_64_IOPL		X86_IOPL
-#define	X86_64_GET_IOPERM	X86_GET_IOPERM
-#define	X86_64_SET_IOPERM	X86_SET_IOPERM
-#define	X86_64_OLD_VM86		X86_OLD_VM86
-#define	X86_64_PMC_INFO		X86_PMC_INFO
-#define	X86_64_PMC_STARTSTOP	X86_PMC_STARTSTOP
-#define	X86_64_PMC_READ		X86_PMC_READ
+#define X86_64_IOPL		X86_IOPL
+#define X86_64_GET_IOPERM	X86_GET_IOPERM
+#define X86_64_SET_IOPERM	X86_SET_IOPERM
+#define X86_64_OLD_VM86		X86_OLD_VM86
+#define X86_64_PMC_INFO		X86_PMC_INFO
+#define X86_64_PMC_STARTSTOP	X86_PMC_STARTSTOP
+#define X86_64_PMC_READ		X86_PMC_READ
 #define X86_64_GET_MTRR		X86_GET_MTRR
 #define X86_64_SET_MTRR		X86_SET_MTRR
-#define	X86_64_VM86		X86_VM86
+#define X86_64_VM86		X86_VM86
 #define X86_64_GET_GSBASE	X86_GET_GSBASE
-#define	X86_64_GET_FSBASE	X86_GET_FSBASE
+#define X86_64_GET_FSBASE	X86_GET_FSBASE
 #define X86_64_SET_GSBASE	X86_SET_GSBASE
-#define	X86_64_SET_FSBASE	X86_SET_FSBASE
+#define X86_64_SET_FSBASE	X86_SET_FSBASE
 #endif
 
 /*
@@ -131,30 +131,30 @@ struct _X86_SYSARCH_L(set_ioperm_args) {
 };
 
 struct _X86_SYSARCH_L(pmc_info_args) {
-	int	type;
-	int	flags;
+	int vers;
+	int type;
+	int flags;
 };
 
+#define	PMC_VERSION		1
+
 #define	PMC_TYPE_NONE		0
 #define	PMC_TYPE_I586		1
 #define	PMC_TYPE_I686		2
 #define	PMC_TYPE_K7		3
+#define	PMC_TYPE_F10H		4
 
 #define	PMC_INFO_HASTSC		0x01
 
-#ifdef __i386__
 #define	PMC_NCOUNTERS		4
-#else
-#define	PMC_NCOUNTERS		2
-#endif
 
 struct _X86_SYSARCH_L(pmc_startstop_args) {
-	int counter;
+	uint32_t counter;
 	uint64_t val;
-	uint8_t event;
-	uint8_t unit;
-	uint8_t compare;
-	uint8_t flags;
+	uint32_t event;
+	uint32_t unit;
+	uint32_t compare;
+	uint32_t flags;
 };
 
 #define	PMC_SETUP_KERNEL	0x01

Index: src/usr.bin/pmc/pmc.c
diff -u src/usr.bin/pmc/pmc.c:1.18 src/usr.bin/pmc/pmc.c:1.19
--- src/usr.bin/pmc/pmc.c:1.18	Sat Feb 18 16:48:38 2017
+++ src/usr.bin/pmc/pmc.c	Wed Mar  8 16:42:27 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmc.c,v 1.18 2017/02/18 16:48:38 maxv Exp $	*/
+/*	$NetBSD: pmc.c,v 1.19 2017/03/08 16:42:27 maxv Exp $	*/
 
 /*
  * Copyright 2000 Wasabi Systems, Inc.
@@ -37,7 +37,7 @@
 #include <sys/cdefs.h>
 
 #ifndef lint
-__RCSID("$NetBSD: pmc.c,v 1.18 2017/02/18 16:48:38 maxv Exp $");
+__RCSID("$NetBSD: pmc.c,v 1.19 2017/03/08 16:42:27 maxv Exp $");
 #endif
 
 #include <sys/types.h>
@@ -426,6 +426,8 @@ main(int argc, char **argv)
 
 	if (x86_pmc_info(&pmcinfo) < 0)
 		errx(2, "PMC support is not compiled into the kernel");
+	if (pmcinfo.vers != 1)
+		errx(2, "Wrong PMC version");
 
 	pncp = pmc_lookup_cpu(pmcinfo.type);
 	if (pncp == NULL)

Reply via email to