xref: /freebsd/lib/libpmc/pmc_allocate.3 (revision 50f6c139970084adeefec98c658645c34b72209e)
16455febbSJoseph Koshy.\" Copyright (c) 2007-2008 Joseph Koshy.  All rights reserved.
28fe4cbb6SJoseph Koshy.\"
38fe4cbb6SJoseph Koshy.\" Redistribution and use in source and binary forms, with or without
48fe4cbb6SJoseph Koshy.\" modification, are permitted provided that the following conditions
58fe4cbb6SJoseph Koshy.\" are met:
68fe4cbb6SJoseph Koshy.\" 1. Redistributions of source code must retain the above copyright
78fe4cbb6SJoseph Koshy.\"    notice, this list of conditions and the following disclaimer.
88fe4cbb6SJoseph Koshy.\" 2. Redistributions in binary form must reproduce the above copyright
98fe4cbb6SJoseph Koshy.\"    notice, this list of conditions and the following disclaimer in the
108fe4cbb6SJoseph Koshy.\"    documentation and/or other materials provided with the distribution.
118fe4cbb6SJoseph Koshy.\"
12026dbd29SChristian Brueffer.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13026dbd29SChristian Brueffer.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14026dbd29SChristian Brueffer.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15026dbd29SChristian Brueffer.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16026dbd29SChristian Brueffer.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17026dbd29SChristian Brueffer.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18026dbd29SChristian Brueffer.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19026dbd29SChristian Brueffer.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20026dbd29SChristian Brueffer.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21026dbd29SChristian Brueffer.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22026dbd29SChristian Brueffer.\" SUCH DAMAGE.
238fe4cbb6SJoseph Koshy.\"
248fe4cbb6SJoseph Koshy.\" $FreeBSD$
258fe4cbb6SJoseph Koshy.\"
26*50f6c139SMitchell Horne.Dd April 21, 2021
278fe4cbb6SJoseph Koshy.Dt PMC_ALLOCATE 3
28aa12cea2SUlrich Spörlein.Os
298fe4cbb6SJoseph Koshy.Sh NAME
308fe4cbb6SJoseph Koshy.Nm pmc_allocate ,
318fe4cbb6SJoseph Koshy.Nm pmc_release
328fe4cbb6SJoseph Koshy.Nd allocate and free performance monitoring counters
338fe4cbb6SJoseph Koshy.Sh LIBRARY
348fe4cbb6SJoseph Koshy.Lb libpmc
358fe4cbb6SJoseph Koshy.Sh SYNOPSIS
368fe4cbb6SJoseph Koshy.In pmc.h
378fe4cbb6SJoseph Koshy.Ft int
388fe4cbb6SJoseph Koshy.Fo pmc_allocate
398fe4cbb6SJoseph Koshy.Fa "const char *eventspecifier"
408fe4cbb6SJoseph Koshy.Fa "enum pmc_mode mode"
418fe4cbb6SJoseph Koshy.Fa "uint32_t flags"
428fe4cbb6SJoseph Koshy.Fa "int cpu"
438fe4cbb6SJoseph Koshy.Fa "pmc_id_t *pmcid"
44*50f6c139SMitchell Horne.Fa "uint64_t count"
458fe4cbb6SJoseph Koshy.Fc
468fe4cbb6SJoseph Koshy.Ft int
478fe4cbb6SJoseph Koshy.Fn pmc_release "pmc_id_t pmc"
488fe4cbb6SJoseph Koshy.Sh DESCRIPTION
498fe4cbb6SJoseph KoshyFunction
508fe4cbb6SJoseph Koshy.Fn pmc_allocate
518fe4cbb6SJoseph Koshyallocates a performance monitoring counter that measures the events
528fe4cbb6SJoseph Koshynamed by argument
538fe4cbb6SJoseph Koshy.Fa eventspecifier ,
548fe4cbb6SJoseph Koshyand writes the allocated handle to the location pointed to by argument
558fe4cbb6SJoseph Koshy.Fa pmcid .
568fe4cbb6SJoseph Koshy.Pp
578fe4cbb6SJoseph KoshyArgument
588fe4cbb6SJoseph Koshy.Fa eventspecifier
598fe4cbb6SJoseph Koshycomprises an PMC event name followed by an optional comma separated
608fe4cbb6SJoseph Koshylist of keywords and qualifiers.
618fe4cbb6SJoseph KoshyThe allowed syntax for argument
628fe4cbb6SJoseph Koshy.Fa eventspecifier
638fe4cbb6SJoseph Koshyis processor specific and is listed in section
648fe4cbb6SJoseph Koshy.Sx "EVENT SPECIFIERS"
658fe4cbb6SJoseph Koshyin the
668fe4cbb6SJoseph Koshy.Xr pmc 3
678fe4cbb6SJoseph Koshymanual page.
688fe4cbb6SJoseph Koshy.Pp
698fe4cbb6SJoseph KoshyThe desired PMC mode is specified by argument
708fe4cbb6SJoseph Koshy.Fa mode .
718fe4cbb6SJoseph KoshyLegal values for the
728fe4cbb6SJoseph Koshy.Fa mode
738fe4cbb6SJoseph Koshyargument are:
748fe4cbb6SJoseph Koshy.Bl -tag -width ".Dv PMC_MODE_SS" -compact
758fe4cbb6SJoseph Koshy.It Dv PMC_MODE_SC
768fe4cbb6SJoseph KoshyAllocate a system-scope counting PMC.
778fe4cbb6SJoseph Koshy.It Dv PMC_MODE_SS
788fe4cbb6SJoseph KoshyAllocate a system-scope sampling PMC.
798fe4cbb6SJoseph Koshy.It Dv PMC_MODE_TC
808fe4cbb6SJoseph KoshyAllocate a process-scope counting PMC.
818fe4cbb6SJoseph Koshy.It Dv PMC_MODE_TS
828fe4cbb6SJoseph KoshyAllocate a process-scope sampling PMC.
838fe4cbb6SJoseph Koshy.El
848fe4cbb6SJoseph Koshy.Pp
858fe4cbb6SJoseph KoshyMode specific modifiers may be specified using argument
868fe4cbb6SJoseph Koshy.Fa flags .
878fe4cbb6SJoseph KoshyThe flags supported at PMC allocation time are:
888fe4cbb6SJoseph Koshy.Bl -tag -width ".Dv PMC_F_LOG_PROCEXIT" -compact
898fe4cbb6SJoseph Koshy.It Dv PMC_F_DESCENDANTS
908fe4cbb6SJoseph KoshyFor process-scope PMCs, automatically track descendants of attached
918fe4cbb6SJoseph Koshyprocesses.
928fe4cbb6SJoseph Koshy.It Dv PMC_F_LOG_PROCCSW
938fe4cbb6SJoseph KoshyFor process-scope counting PMCs, generate a log event at every context
948fe4cbb6SJoseph Koshyswitch containing the incremental number of hardware events seen
958fe4cbb6SJoseph Koshyby the process during the time it was executing on the CPU.
968fe4cbb6SJoseph Koshy.It Dv PMC_F_LOG_PROCEXIT
978fe4cbb6SJoseph KoshyFor process-scope counting PMCs, accumulate hardware events seen
988fe4cbb6SJoseph Koshywhen the process was executing on a CPU and generate a log event
998fe4cbb6SJoseph Koshywhen an attached process exits.
1008fe4cbb6SJoseph Koshy.El
1018fe4cbb6SJoseph KoshyPMCs allocated with flags
1028fe4cbb6SJoseph Koshy.Dv PMC_F_LOG_PROCCSW
1038fe4cbb6SJoseph Koshyand
1048fe4cbb6SJoseph Koshy.Dv PMC_F_LOG_PROCEXIT
1058fe4cbb6SJoseph Koshyneed a log file to be configured before they are started.
1068fe4cbb6SJoseph Koshy.Pp
1078fe4cbb6SJoseph KoshyFor system scope PMCs, the argument
1088fe4cbb6SJoseph Koshy.Fa cpu
1098fe4cbb6SJoseph Koshyis a non-negative value that specifies the CPU number
1108fe4cbb6SJoseph Koshythat the PMC is to be allocated on.
1118fe4cbb6SJoseph KoshyProcess scope PMC allocations should specify the constant
1128fe4cbb6SJoseph Koshy.Dv PMC_CPU_ANY
1138fe4cbb6SJoseph Koshyfor this argument.
1148fe4cbb6SJoseph Koshy.Pp
115*50f6c139SMitchell HorneThe
116*50f6c139SMitchell Horne.Fa count
117*50f6c139SMitchell Horneargument behaves identically to the
118*50f6c139SMitchell Horne.Xr pmc_set 3
119*50f6c139SMitchell Hornefunction's
120*50f6c139SMitchell Horne.Fa value
121*50f6c139SMitchell Horneargument.
122*50f6c139SMitchell HorneFor counting PMCs,
123*50f6c139SMitchell Horne.Fa count
124*50f6c139SMitchell Hornespecifies the initial value of the allocated PMC.
125*50f6c139SMitchell HorneFor sampling PMCs,
126*50f6c139SMitchell Horne.Fa count
127*50f6c139SMitchell Hornespecifies the reload count.
128*50f6c139SMitchell Horne.Pp
1298fe4cbb6SJoseph KoshyFunction
1308fe4cbb6SJoseph Koshy.Fn pmc_release
1318fe4cbb6SJoseph Koshyreleases the PMC denoted by argument
1328fe4cbb6SJoseph Koshy.Fa pmcid .
1338fe4cbb6SJoseph Koshy.Sh RETURN VALUES
1348fe4cbb6SJoseph KoshyIf successful, function
1358fe4cbb6SJoseph Koshy.Fn pmc_allocate
1368fe4cbb6SJoseph Koshysets the location specified by argument
1378fe4cbb6SJoseph Koshy.Fa pmcid
1388fe4cbb6SJoseph Koshyto the handle of the allocated PMC and returns 0.
1398fe4cbb6SJoseph KoshyIn case of an error, the function returns -1 and sets the global
1408fe4cbb6SJoseph Koshyvariable
1418fe4cbb6SJoseph Koshy.Va errno
1428fe4cbb6SJoseph Koshyto indicate the error.
1438fe4cbb6SJoseph Koshy.Pp
1448fe4cbb6SJoseph Koshy.Rv -std pmc_release
1458fe4cbb6SJoseph Koshy.Sh ERRORS
1468fe4cbb6SJoseph Koshy.Bl -tag -width Er
1478fe4cbb6SJoseph Koshy.It Bq Er EINVAL
1488fe4cbb6SJoseph KoshyThe argument
1498fe4cbb6SJoseph Koshy.Fa mode
1508fe4cbb6SJoseph Koshyto function
1518fe4cbb6SJoseph Koshy.Fn pmc_allocate
1528fe4cbb6SJoseph Koshyhad an invalid value.
1538fe4cbb6SJoseph Koshy.It Bq Er EINVAL
1548fe4cbb6SJoseph KoshyArgument
1558fe4cbb6SJoseph Koshy.Fa cpu
1568fe4cbb6SJoseph Koshyto function
1578fe4cbb6SJoseph Koshy.Fn pmc_allocate
1588fe4cbb6SJoseph Koshyhad an invalid CPU number.
1598fe4cbb6SJoseph Koshy.It Bq Er EINVAL
1608fe4cbb6SJoseph KoshyArgument
1618fe4cbb6SJoseph Koshy.Fa flags
1628fe4cbb6SJoseph Koshycontained flags that were unsupported or otherwise incompatible with
1638fe4cbb6SJoseph Koshythe requested PMC mode.
1648fe4cbb6SJoseph Koshy.It Bq Er EINVAL
1658fe4cbb6SJoseph KoshyArgument
1668fe4cbb6SJoseph Koshy.Fa eventspecifier
1678fe4cbb6SJoseph Koshyto function
1688fe4cbb6SJoseph Koshy.Fn pmc_allocate
1698fe4cbb6SJoseph Koshyspecified an event not supported by hardware or contained a syntax
1708fe4cbb6SJoseph Koshyerror.
1718fe4cbb6SJoseph Koshy.It Bq Er ENXIO
1728fe4cbb6SJoseph KoshyFunction
1738fe4cbb6SJoseph Koshy.Fn pmc_allocate
1746455febbSJoseph Koshyrequested the use of a hardware resource that was absent or
1758fe4cbb6SJoseph Koshyadministratively disabled.
1768fe4cbb6SJoseph Koshy.It Bq Er EOPNOTSUPP
1778fe4cbb6SJoseph KoshyThe underlying hardware does not support the capabilities needed for
1788fe4cbb6SJoseph Koshya PMC being allocated by a call to
1798fe4cbb6SJoseph Koshy.Fn pmc_allocate .
1808fe4cbb6SJoseph Koshy.It Bq Er EPERM
1818fe4cbb6SJoseph KoshyA system scope PMC allocation was attempted without adequate process
1828fe4cbb6SJoseph Koshyprivilege.
1838fe4cbb6SJoseph Koshy.It Bq Er ESRCH
1848fe4cbb6SJoseph KoshyFunction
1858fe4cbb6SJoseph Koshy.Fn pmc_release
1868fe4cbb6SJoseph Koshywas called without first having allocated a PMC.
1878fe4cbb6SJoseph Koshy.It Bq Er EINVAL
1888fe4cbb6SJoseph KoshyArgument
1898fe4cbb6SJoseph Koshy.Fa pmcid
1908fe4cbb6SJoseph Koshyto function
1918fe4cbb6SJoseph Koshy.Fn pmc_release
1928fe4cbb6SJoseph Koshydid not specify a PMC previously allocated by this process.
1938fe4cbb6SJoseph Koshy.El
1948fe4cbb6SJoseph Koshy.Sh SEE ALSO
1958fe4cbb6SJoseph Koshy.Xr pmc 3 ,
1968fe4cbb6SJoseph Koshy.Xr pmc_attach 3 ,
1978fe4cbb6SJoseph Koshy.Xr pmc_configure_logfile 3 ,
1988fe4cbb6SJoseph Koshy.Xr pmc_start 3 ,
1998fe4cbb6SJoseph Koshy.Xr hwpmc 4
200