NetBSD/lib/libarch/i386/i386_pmc_info.2

141 lines
4.6 KiB
Groff

.\" $NetBSD: i386_pmc_info.2,v 1.2 2001/11/10 08:11:04 wiz 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.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the NetBSD
.\" Foundation, Inc. and its contributors.
.\" 4. Neither the name of The NetBSD Foundation nor the names of its
.\" contributors may be used to endorse or promote products derived
.\" from this software without specific prior written permission.
.\"
.\" 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 3 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
.Fd #include <sys/types.h>
.Fd #include <machine/sysarch.h>
.Fd #include <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 PMC_TYPE_NONE, PMC_TYPE_I586, and PMC_TYPE_I686. The
.Em flags
member describes additional capabilities of the processor. Valid
values are PMC_INFO_HASTSC.
.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;
u_int64_t val;
u_int8_t event;
u_int8_t unit;
u_int8_t compare;
u_int8_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;
u_int64_t val;
u_int64_t time;
};
.Ed
.Pp
The counter to read should be specified by the
.Em counter
member. Counters are numbered from 0 to 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.