.\" $NetBSD: i386_pmc_info.2,v 1.11 2008/04/30 13:10:50 martin Exp $ .\" .\" Copyright (c) 2001 The NetBSD Foundation, Inc. .\" All rights reserved. .\" .\" This code is derived from software contributed to The NetBSD Foundation .\" by Gregory McGarry. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" .Dd November 10, 2001 .Dt I386_PMC_INFO 2 i386 .Os .Sh NAME .Nm i386_pmc_info , .Nm i386_pmc_startstop , .Nm i386_pmc_read .Nd interface to CPU performance counters .Sh LIBRARY .Lb libi386 .Sh SYNOPSIS .In sys/types.h .In machine/sysarch.h .In machine/specialreg.h .Ft int .Fn i386_pmc_info "struct i386_pmc_info_args *ia" .Ft int .Fn i386_pmc_startstop "struct i386_pmc_startstop_args *ssa" .Ft int .Fn i386_pmc_read "struct i386_pmc_read_args *ra" .Sh DESCRIPTION These functions provide an interface to the CPU performance counters on the 586-class and 686-class processors. .Pp .Fn i386_pmc_info will return information about the available CPU counters. The information is returned in .Fa ia having the following structure: .Bd -literal struct i386_pmc_info_args { int type; int flags; }; .Ed .Pp The .Em type member describes the class of performance counters available. Valid values are: .Pp .Bl -tag -offset indent -width PMC_INFO_HASTSC -compact .It PMC_TYPE_NONE No PMC support .It PMC_TYPE_I586 586-class CPUs .It PMC_TYPE_I686 686-class Intel CPUs .It PMC_TYPE_K7 686-class AMD CPUs .El .Pp The .Em flags member describes additional capabilities of the processor. Valid values are: .Pp .Bl -tag -offset indent -width PMC_INFO_HASTSC -compact .It PMC_INFO_HASTSC CPU has time-stamp counter .El .Pp .Fn i386_pmc_startstop is used to start and stop the measurement of the CPU performance counters. The argument .Fa ssa has the following structure: .Bd -literal struct i386_pmc_startstop_args { int counter; uint64_t val; uint8_t event; uint8_t unit; uint8_t compare; uint8_t flags; }; .Ed .Pp The counter specified by the member .Em counter is started if the member .Em flags has PMC_SETUP_KERNEL or PMC_SETUP_USER set, otherwise the counter is stopped. The initial value of the counter is set to .Em val . Additional values for the .Em flags member are PMC_SETUP_EDGE and PMC_SETUP_INV. The .Em event member specifies some event written to the control register. The .Em unit member specifies the measurement units. The .Em compare member is a mask for the counter. .Pp .Fn i386_pmc_read will return information about a specific CPU counter measured during the last measurement period determined by the calling of .Fn i386_pmc_startstop . The information is returned in .Fa ra having the following structure: .Bd -literal struct i386_pmc_read_args { int counter; uint64_t val; uint64_t time; }; .Ed .Pp The counter to read should be specified by the .Em counter member. Counters are numbered from 0 to .Dv PMC_NCOUNTERS . The value of the counter is returned in the .Em val member. The time since epoch, measured in CPU clock cycles, is returned in the .Em time member. .Sh RETURN VALUES Upon successful completion zero is returned, otherwise \-1 is returned on failure.