xref: /freebsd/lib/libpmc/pmc_allocate.3 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
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.\"
24*50f6c139SMitchell Horne.Dd April 21, 2021
258fe4cbb6SJoseph Koshy.Dt PMC_ALLOCATE 3
26aa12cea2SUlrich Spörlein.Os
278fe4cbb6SJoseph Koshy.Sh NAME
288fe4cbb6SJoseph Koshy.Nm pmc_allocate ,
298fe4cbb6SJoseph Koshy.Nm pmc_release
308fe4cbb6SJoseph Koshy.Nd allocate and free performance monitoring counters
318fe4cbb6SJoseph Koshy.Sh LIBRARY
328fe4cbb6SJoseph Koshy.Lb libpmc
338fe4cbb6SJoseph Koshy.Sh SYNOPSIS
348fe4cbb6SJoseph Koshy.In pmc.h
358fe4cbb6SJoseph Koshy.Ft int
368fe4cbb6SJoseph Koshy.Fo pmc_allocate
378fe4cbb6SJoseph Koshy.Fa "const char *eventspecifier"
388fe4cbb6SJoseph Koshy.Fa "enum pmc_mode mode"
398fe4cbb6SJoseph Koshy.Fa "uint32_t flags"
408fe4cbb6SJoseph Koshy.Fa "int cpu"
418fe4cbb6SJoseph Koshy.Fa "pmc_id_t *pmcid"
42*50f6c139SMitchell Horne.Fa "uint64_t count"
438fe4cbb6SJoseph Koshy.Fc
448fe4cbb6SJoseph Koshy.Ft int
458fe4cbb6SJoseph Koshy.Fn pmc_release "pmc_id_t pmc"
468fe4cbb6SJoseph Koshy.Sh DESCRIPTION
478fe4cbb6SJoseph KoshyFunction
488fe4cbb6SJoseph Koshy.Fn pmc_allocate
498fe4cbb6SJoseph Koshyallocates a performance monitoring counter that measures the events
508fe4cbb6SJoseph Koshynamed by argument
518fe4cbb6SJoseph Koshy.Fa eventspecifier ,
528fe4cbb6SJoseph Koshyand writes the allocated handle to the location pointed to by argument
538fe4cbb6SJoseph Koshy.Fa pmcid .
548fe4cbb6SJoseph Koshy.Pp
558fe4cbb6SJoseph KoshyArgument
568fe4cbb6SJoseph Koshy.Fa eventspecifier
578fe4cbb6SJoseph Koshycomprises an PMC event name followed by an optional comma separated
588fe4cbb6SJoseph Koshylist of keywords and qualifiers.
598fe4cbb6SJoseph KoshyThe allowed syntax for argument
608fe4cbb6SJoseph Koshy.Fa eventspecifier
618fe4cbb6SJoseph Koshyis processor specific and is listed in section
628fe4cbb6SJoseph Koshy.Sx "EVENT SPECIFIERS"
638fe4cbb6SJoseph Koshyin the
648fe4cbb6SJoseph Koshy.Xr pmc 3
658fe4cbb6SJoseph Koshymanual page.
668fe4cbb6SJoseph Koshy.Pp
678fe4cbb6SJoseph KoshyThe desired PMC mode is specified by argument
688fe4cbb6SJoseph Koshy.Fa mode .
698fe4cbb6SJoseph KoshyLegal values for the
708fe4cbb6SJoseph Koshy.Fa mode
718fe4cbb6SJoseph Koshyargument are:
728fe4cbb6SJoseph Koshy.Bl -tag -width ".Dv PMC_MODE_SS" -compact
738fe4cbb6SJoseph Koshy.It Dv PMC_MODE_SC
748fe4cbb6SJoseph KoshyAllocate a system-scope counting PMC.
758fe4cbb6SJoseph Koshy.It Dv PMC_MODE_SS
768fe4cbb6SJoseph KoshyAllocate a system-scope sampling PMC.
778fe4cbb6SJoseph Koshy.It Dv PMC_MODE_TC
788fe4cbb6SJoseph KoshyAllocate a process-scope counting PMC.
798fe4cbb6SJoseph Koshy.It Dv PMC_MODE_TS
808fe4cbb6SJoseph KoshyAllocate a process-scope sampling PMC.
818fe4cbb6SJoseph Koshy.El
828fe4cbb6SJoseph Koshy.Pp
838fe4cbb6SJoseph KoshyMode specific modifiers may be specified using argument
848fe4cbb6SJoseph Koshy.Fa flags .
858fe4cbb6SJoseph KoshyThe flags supported at PMC allocation time are:
868fe4cbb6SJoseph Koshy.Bl -tag -width ".Dv PMC_F_LOG_PROCEXIT" -compact
878fe4cbb6SJoseph Koshy.It Dv PMC_F_DESCENDANTS
888fe4cbb6SJoseph KoshyFor process-scope PMCs, automatically track descendants of attached
898fe4cbb6SJoseph Koshyprocesses.
908fe4cbb6SJoseph Koshy.It Dv PMC_F_LOG_PROCCSW
918fe4cbb6SJoseph KoshyFor process-scope counting PMCs, generate a log event at every context
928fe4cbb6SJoseph Koshyswitch containing the incremental number of hardware events seen
938fe4cbb6SJoseph Koshyby the process during the time it was executing on the CPU.
948fe4cbb6SJoseph Koshy.It Dv PMC_F_LOG_PROCEXIT
958fe4cbb6SJoseph KoshyFor process-scope counting PMCs, accumulate hardware events seen
968fe4cbb6SJoseph Koshywhen the process was executing on a CPU and generate a log event
978fe4cbb6SJoseph Koshywhen an attached process exits.
988fe4cbb6SJoseph Koshy.El
998fe4cbb6SJoseph KoshyPMCs allocated with flags
1008fe4cbb6SJoseph Koshy.Dv PMC_F_LOG_PROCCSW
1018fe4cbb6SJoseph Koshyand
1028fe4cbb6SJoseph Koshy.Dv PMC_F_LOG_PROCEXIT
1038fe4cbb6SJoseph Koshyneed a log file to be configured before they are started.
1048fe4cbb6SJoseph Koshy.Pp
1058fe4cbb6SJoseph KoshyFor system scope PMCs, the argument
1068fe4cbb6SJoseph Koshy.Fa cpu
1078fe4cbb6SJoseph Koshyis a non-negative value that specifies the CPU number
1088fe4cbb6SJoseph Koshythat the PMC is to be allocated on.
1098fe4cbb6SJoseph KoshyProcess scope PMC allocations should specify the constant
1108fe4cbb6SJoseph Koshy.Dv PMC_CPU_ANY
1118fe4cbb6SJoseph Koshyfor this argument.
1128fe4cbb6SJoseph Koshy.Pp
113*50f6c139SMitchell HorneThe
114*50f6c139SMitchell Horne.Fa count
115*50f6c139SMitchell Horneargument behaves identically to the
116*50f6c139SMitchell Horne.Xr pmc_set 3
117*50f6c139SMitchell Hornefunction's
118*50f6c139SMitchell Horne.Fa value
119*50f6c139SMitchell Horneargument.
120*50f6c139SMitchell HorneFor counting PMCs,
121*50f6c139SMitchell Horne.Fa count
122*50f6c139SMitchell Hornespecifies the initial value of the allocated PMC.
123*50f6c139SMitchell HorneFor sampling PMCs,
124*50f6c139SMitchell Horne.Fa count
125*50f6c139SMitchell Hornespecifies the reload count.
126*50f6c139SMitchell Horne.Pp
1278fe4cbb6SJoseph KoshyFunction
1288fe4cbb6SJoseph Koshy.Fn pmc_release
1298fe4cbb6SJoseph Koshyreleases the PMC denoted by argument
1308fe4cbb6SJoseph Koshy.Fa pmcid .
1318fe4cbb6SJoseph Koshy.Sh RETURN VALUES
1328fe4cbb6SJoseph KoshyIf successful, function
1338fe4cbb6SJoseph Koshy.Fn pmc_allocate
1348fe4cbb6SJoseph Koshysets the location specified by argument
1358fe4cbb6SJoseph Koshy.Fa pmcid
1368fe4cbb6SJoseph Koshyto the handle of the allocated PMC and returns 0.
1378fe4cbb6SJoseph KoshyIn case of an error, the function returns -1 and sets the global
1388fe4cbb6SJoseph Koshyvariable
1398fe4cbb6SJoseph Koshy.Va errno
1408fe4cbb6SJoseph Koshyto indicate the error.
1418fe4cbb6SJoseph Koshy.Pp
1428fe4cbb6SJoseph Koshy.Rv -std pmc_release
1438fe4cbb6SJoseph Koshy.Sh ERRORS
1448fe4cbb6SJoseph Koshy.Bl -tag -width Er
1458fe4cbb6SJoseph Koshy.It Bq Er EINVAL
1468fe4cbb6SJoseph KoshyThe argument
1478fe4cbb6SJoseph Koshy.Fa mode
1488fe4cbb6SJoseph Koshyto function
1498fe4cbb6SJoseph Koshy.Fn pmc_allocate
1508fe4cbb6SJoseph Koshyhad an invalid value.
1518fe4cbb6SJoseph Koshy.It Bq Er EINVAL
1528fe4cbb6SJoseph KoshyArgument
1538fe4cbb6SJoseph Koshy.Fa cpu
1548fe4cbb6SJoseph Koshyto function
1558fe4cbb6SJoseph Koshy.Fn pmc_allocate
1568fe4cbb6SJoseph Koshyhad an invalid CPU number.
1578fe4cbb6SJoseph Koshy.It Bq Er EINVAL
1588fe4cbb6SJoseph KoshyArgument
1598fe4cbb6SJoseph Koshy.Fa flags
1608fe4cbb6SJoseph Koshycontained flags that were unsupported or otherwise incompatible with
1618fe4cbb6SJoseph Koshythe requested PMC mode.
1628fe4cbb6SJoseph Koshy.It Bq Er EINVAL
1638fe4cbb6SJoseph KoshyArgument
1648fe4cbb6SJoseph Koshy.Fa eventspecifier
1658fe4cbb6SJoseph Koshyto function
1668fe4cbb6SJoseph Koshy.Fn pmc_allocate
1678fe4cbb6SJoseph Koshyspecified an event not supported by hardware or contained a syntax
1688fe4cbb6SJoseph Koshyerror.
1698fe4cbb6SJoseph Koshy.It Bq Er ENXIO
1708fe4cbb6SJoseph KoshyFunction
1718fe4cbb6SJoseph Koshy.Fn pmc_allocate
1726455febbSJoseph Koshyrequested the use of a hardware resource that was absent or
1738fe4cbb6SJoseph Koshyadministratively disabled.
1748fe4cbb6SJoseph Koshy.It Bq Er EOPNOTSUPP
1758fe4cbb6SJoseph KoshyThe underlying hardware does not support the capabilities needed for
1768fe4cbb6SJoseph Koshya PMC being allocated by a call to
1778fe4cbb6SJoseph Koshy.Fn pmc_allocate .
1788fe4cbb6SJoseph Koshy.It Bq Er EPERM
1798fe4cbb6SJoseph KoshyA system scope PMC allocation was attempted without adequate process
1808fe4cbb6SJoseph Koshyprivilege.
1818fe4cbb6SJoseph Koshy.It Bq Er ESRCH
1828fe4cbb6SJoseph KoshyFunction
1838fe4cbb6SJoseph Koshy.Fn pmc_release
1848fe4cbb6SJoseph Koshywas called without first having allocated a PMC.
1858fe4cbb6SJoseph Koshy.It Bq Er EINVAL
1868fe4cbb6SJoseph KoshyArgument
1878fe4cbb6SJoseph Koshy.Fa pmcid
1888fe4cbb6SJoseph Koshyto function
1898fe4cbb6SJoseph Koshy.Fn pmc_release
1908fe4cbb6SJoseph Koshydid not specify a PMC previously allocated by this process.
1918fe4cbb6SJoseph Koshy.El
1928fe4cbb6SJoseph Koshy.Sh SEE ALSO
1938fe4cbb6SJoseph Koshy.Xr pmc 3 ,
1948fe4cbb6SJoseph Koshy.Xr pmc_attach 3 ,
1958fe4cbb6SJoseph Koshy.Xr pmc_configure_logfile 3 ,
1968fe4cbb6SJoseph Koshy.Xr pmc_start 3 ,
1978fe4cbb6SJoseph Koshy.Xr hwpmc 4
198