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.
This commit is contained in:
maxv 2017-03-08 16:42:27 +00:00
parent f8e693e577
commit 279ed0db08
3 changed files with 61 additions and 58 deletions

View File

@ -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_pmc_info_args *uargs, register_t *retval)
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 x86_pmc_startstop_args *uargs,
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_pmc_read_args *uargs, register_t *retval)
if (error)
return error;
if (args.counter < 0 || args.counter >= pmc_ncounters)
if (args.counter >= pmc_ncounters)
return EINVAL;
pmc = &pmc_state[args.counter];

View File

@ -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.
@ -131,30 +131,30 @@ struct _X86_SYSARCH_L(set_ioperm_args) {
};
struct _X86_SYSARCH_L(pmc_info_args) {
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

View File

@ -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)