xref: /openbsd-src/usr.bin/pctr/pctr.1 (revision 8295c78d7618cbce64c95d373e993f5b6087a53a)
1*8295c78dSsobrado.\"	$OpenBSD: pctr.1,v 1.13 2008/07/08 21:39:52 sobrado Exp $
29eecd0bfSderaadt.\"
39eecd0bfSderaadt.\" Copyright (c) 2007 Mike Belopuhov, Aleksey Lomovtsev
49eecd0bfSderaadt.\"
59eecd0bfSderaadt.\" Permission to use, copy, modify, and distribute this software for any
69eecd0bfSderaadt.\" purpose with or without fee is hereby granted, provided that the above
79eecd0bfSderaadt.\" copyright notice and this permission notice appear in all copies.
89eecd0bfSderaadt.\"
99eecd0bfSderaadt.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
109eecd0bfSderaadt.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
119eecd0bfSderaadt.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
129eecd0bfSderaadt.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
139eecd0bfSderaadt.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
149eecd0bfSderaadt.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
159eecd0bfSderaadt.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
169eecd0bfSderaadt.\"
1733b6299dSdownsj.\"
1833b6299dSdownsj.\" Copyright (c) 1998, Jason Downs.  All rights reserved.
1933b6299dSdownsj.\"
2033b6299dSdownsj.\" Redistribution and use in source and binary forms, with or without
2133b6299dSdownsj.\" modification, are permitted provided that the following conditions
2233b6299dSdownsj.\" are met:
2333b6299dSdownsj.\" 1. Redistributions of source code must retain the above copyright
2433b6299dSdownsj.\"    notice, this list of conditions and the following disclaimer.
2533b6299dSdownsj.\" 2. Redistributions in binary form must reproduce the above copyright
2633b6299dSdownsj.\"    notice, this list of conditions and the following disclaimer in the
2733b6299dSdownsj.\"    documentation and/or other materials provided with the distribution.
2833b6299dSdownsj.\"
2933b6299dSdownsj.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS
3033b6299dSdownsj.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
3133b6299dSdownsj.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
3233b6299dSdownsj.\" DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
3333b6299dSdownsj.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
3433b6299dSdownsj.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
3533b6299dSdownsj.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
3633b6299dSdownsj.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3733b6299dSdownsj.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3833b6299dSdownsj.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3933b6299dSdownsj.\" SUCH DAMAGE.
4033b6299dSdownsj.\"
41*8295c78dSsobrado.Dd $Mdocdate: July 8 2008 $
4233b6299dSdownsj.Dt PCTR 1
4333b6299dSdownsj.Os
4433b6299dSdownsj.Sh NAME
4533b6299dSdownsj.Nm pctr
469e171883Saaron.Nd display CPU performance counters
4733b6299dSdownsj.Sh SYNOPSIS
48c3444d0bSaaron.Nm pctr
49bab42e23Sjmc.Op Fl AEeIiklMSu
509eecd0bfSderaadt.Op Fl f Ar funct
519eecd0bfSderaadt.Op Fl m Ar umask
529eecd0bfSderaadt.Op Fl s Ar ctr
53bab42e23Sjmc.Op Fl t Ar thold
5433b6299dSdownsj.Sh DESCRIPTION
5533b6299dSdownsjThe
5633b6299dSdownsj.Nm
5733b6299dSdownsjprogram is a sample implementation of how to access the
5833b6299dSdownsj.Xr pctr 4
599eecd0bfSderaadtpseudo device available on many i386 and amd64 compatible machines.
6033b6299dSdownsj.Pp
6133b6299dSdownsjBy default, the
6233b6299dSdownsj.Nm
6333b6299dSdownsjcommand displays the current values of the TSC and any vendor specific
6433b6299dSdownsjcounter registers.
65ad32b772Saaron.Pp
66ad32b772SaaronThe options are as follows:
67f1ba3473Saaron.Bl -tag -width Ds
689eecd0bfSderaadt.It Fl A
69bab42e23SjmcSome bus events differentiate between the originating physical processor
70bab42e23Sjmc(a bus agent) and other agents on the bus.
719eecd0bfSderaadtSpecifying this option allows counting on all bus agents.
729eecd0bfSderaadtThis is supported on Intel processors only.
739eecd0bfSderaadt.It Fl E
749eecd0bfSderaadtEnables counting exclusive cache coherency state (supported on Intel
759eecd0bfSderaadtprocessors only).
76bab42e23Sjmc.It Fl e
77bab42e23SjmcEnables Edge Detect.
78bab42e23SjmcIt is mandatory to enable Edge Detect with certain counter functions.
799eecd0bfSderaadt.It Fl f Ar funct
809eecd0bfSderaadtSpecifies a function number in hexadecimal to program the counter,
819eecd0bfSderaadtspecified by the
829eecd0bfSderaadt.Fl s
839eecd0bfSderaadtoption.
849eecd0bfSderaadt.It Fl I
859eecd0bfSderaadtEnables counting invalid cache coherency state (supported on Intel
869eecd0bfSderaadtprocessors only).
87bab42e23Sjmc.It Fl i
88bab42e23SjmcInvert the result of the threshold comparison, so that both greater than
89bab42e23Sjmcand less than comparisons can be made.
909eecd0bfSderaadt.It Fl k
91bab42e23SjmcCount events occurring in kernel mode.
929eecd0bfSderaadtSpecification of either
939eecd0bfSderaadt.Fl k
949eecd0bfSderaadtor
959eecd0bfSderaadt.Fl u
969eecd0bfSderaadtoptions is mandatory.
979eecd0bfSderaadt.It Fl l
989eecd0bfSderaadtList all possible vendor specific counters available on the current processor.
99bab42e23Sjmc.It Fl M
100bab42e23SjmcEnables counting modified cache coherency state (supported on Intel
101bab42e23Sjmcprocessors only).
1029eecd0bfSderaadt.It Fl m Ar umask
1039eecd0bfSderaadtSpecifies a Unit Mask value for a function, specified by the
1049eecd0bfSderaadt.Fl f
1059eecd0bfSderaadtoption.
106*8295c78dSsobrado.It Fl S
107*8295c78dSsobradoEnables counting shared cache coherency state (supported on Intel
108*8295c78dSsobradoprocessors only).
1099eecd0bfSderaadt.It Fl s Ar ctr
1109eecd0bfSderaadtProgram counter number
1119eecd0bfSderaadt.Ar ctr
112bab42e23Sjmcwith the function number specified by the
1139eecd0bfSderaadt.Fl f
1149eecd0bfSderaadtoption.
115bab42e23SjmcA list of all possible functions supported on the current processor
116bab42e23Sjmccan be obtained by the
1179eecd0bfSderaadt.Fl l
1189eecd0bfSderaadtoption output.
1199eecd0bfSderaadt.It Fl t Ar thold
1209eecd0bfSderaadtSpecifies an increment threshold.
1219eecd0bfSderaadtThe counter
1229eecd0bfSderaadt.Ar ctr
123bab42e23Sjmcwill be incremented if the number of events occurring during one cycle is
1249eecd0bfSderaadtgreater or equal to
1259eecd0bfSderaadt.Ar thold .
1269eecd0bfSderaadt.It Fl u
127bab42e23SjmcCount events occurring in user mode.
1289eecd0bfSderaadtSpecification of either
1299eecd0bfSderaadt.Fl k
1309eecd0bfSderaadtor
1319eecd0bfSderaadt.Fl u
1329eecd0bfSderaadtoptions is mandatory.
13333b6299dSdownsj.El
1349eecd0bfSderaadt.Sh EXAMPLES
1359eecd0bfSderaadtThe following command, executed from the command line, will set the first
1369eecd0bfSderaadtperformance counter to count the number of cacheable L1 data cache reads
137bab42e23Sjmcin user and kernel modes on an Intel Core2 Duo processor:
1389eecd0bfSderaadt.Bd -unfilled -offset indent
1399eecd0bfSderaadt# pctr -s 0 -f 40 -uk -MESI
1409eecd0bfSderaadt.Ed
141ad32b772Saaron.Pp
1429eecd0bfSderaadtTo reset the counter run the following command:
1439eecd0bfSderaadt.Bd -unfilled -offset indent
1449eecd0bfSderaadt# pctr -s 0 -f 0
1459eecd0bfSderaadt.Ed
14633b6299dSdownsj.Sh SEE ALSO
14733b6299dSdownsj.Xr pctr 4
1489eecd0bfSderaadt.Pp
1499eecd0bfSderaadtOS and Kernel Developer's Guide for AMD NPT Family 0Fh Processors.
1509eecd0bfSderaadt.Pp
1519eecd0bfSderaadtIntel 64 and IA-32 Architectures Software Developer's Manual.
1529eecd0bfSderaadtVolume 3B: System Programming Guide, Part 2.
1539eecd0bfSderaadtAppendix A: Performance Monitoring Events.
15433b6299dSdownsj.Sh HISTORY
15533b6299dSdownsjThe
15633b6299dSdownsj.Nm
15733b6299dSdownsjprogram appeared in
1589eecd0bfSderaadt.Ox 2.0
1599eecd0bfSderaadtbut was subsequently rewritten in
160c1ae9e1aSmikeb.Ox 4.3 .
1619eecd0bfSderaadt.Sh CAVEATS
162bab42e23SjmcIt is strongly advised to look through the manual for a particular processor
1639eecd0bfSderaadtbefore programming a counter and interpreting the results.
164