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.\" 12*026dbd29SChristian Brueffer.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 13*026dbd29SChristian Brueffer.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14*026dbd29SChristian Brueffer.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 15*026dbd29SChristian Brueffer.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 16*026dbd29SChristian Brueffer.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 17*026dbd29SChristian Brueffer.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 18*026dbd29SChristian Brueffer.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 19*026dbd29SChristian Brueffer.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 20*026dbd29SChristian Brueffer.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 21*026dbd29SChristian Brueffer.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 22*026dbd29SChristian Brueffer.\" SUCH DAMAGE. 238fe4cbb6SJoseph Koshy.\" 248fe4cbb6SJoseph Koshy.\" $FreeBSD$ 258fe4cbb6SJoseph Koshy.\" 266455febbSJoseph Koshy.Dd September 22, 2008 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" 448fe4cbb6SJoseph Koshy.Fc 458fe4cbb6SJoseph Koshy.Ft int 468fe4cbb6SJoseph Koshy.Fn pmc_release "pmc_id_t pmc" 478fe4cbb6SJoseph Koshy.Sh DESCRIPTION 488fe4cbb6SJoseph KoshyFunction 498fe4cbb6SJoseph Koshy.Fn pmc_allocate 508fe4cbb6SJoseph Koshyallocates a performance monitoring counter that measures the events 518fe4cbb6SJoseph Koshynamed by argument 528fe4cbb6SJoseph Koshy.Fa eventspecifier , 538fe4cbb6SJoseph Koshyand writes the allocated handle to the location pointed to by argument 548fe4cbb6SJoseph Koshy.Fa pmcid . 558fe4cbb6SJoseph Koshy.Pp 568fe4cbb6SJoseph KoshyArgument 578fe4cbb6SJoseph Koshy.Fa eventspecifier 588fe4cbb6SJoseph Koshycomprises an PMC event name followed by an optional comma separated 598fe4cbb6SJoseph Koshylist of keywords and qualifiers. 608fe4cbb6SJoseph KoshyThe allowed syntax for argument 618fe4cbb6SJoseph Koshy.Fa eventspecifier 628fe4cbb6SJoseph Koshyis processor specific and is listed in section 638fe4cbb6SJoseph Koshy.Sx "EVENT SPECIFIERS" 648fe4cbb6SJoseph Koshyin the 658fe4cbb6SJoseph Koshy.Xr pmc 3 668fe4cbb6SJoseph Koshymanual page. 678fe4cbb6SJoseph Koshy.Pp 688fe4cbb6SJoseph KoshyThe desired PMC mode is specified by argument 698fe4cbb6SJoseph Koshy.Fa mode . 708fe4cbb6SJoseph KoshyLegal values for the 718fe4cbb6SJoseph Koshy.Fa mode 728fe4cbb6SJoseph Koshyargument are: 738fe4cbb6SJoseph Koshy.Bl -tag -width ".Dv PMC_MODE_SS" -compact 748fe4cbb6SJoseph Koshy.It Dv PMC_MODE_SC 758fe4cbb6SJoseph KoshyAllocate a system-scope counting PMC. 768fe4cbb6SJoseph Koshy.It Dv PMC_MODE_SS 778fe4cbb6SJoseph KoshyAllocate a system-scope sampling PMC. 788fe4cbb6SJoseph Koshy.It Dv PMC_MODE_TC 798fe4cbb6SJoseph KoshyAllocate a process-scope counting PMC. 808fe4cbb6SJoseph Koshy.It Dv PMC_MODE_TS 818fe4cbb6SJoseph KoshyAllocate a process-scope sampling PMC. 828fe4cbb6SJoseph Koshy.El 838fe4cbb6SJoseph Koshy.Pp 848fe4cbb6SJoseph KoshyMode specific modifiers may be specified using argument 858fe4cbb6SJoseph Koshy.Fa flags . 868fe4cbb6SJoseph KoshyThe flags supported at PMC allocation time are: 878fe4cbb6SJoseph Koshy.Bl -tag -width ".Dv PMC_F_LOG_PROCEXIT" -compact 888fe4cbb6SJoseph Koshy.It Dv PMC_F_DESCENDANTS 898fe4cbb6SJoseph KoshyFor process-scope PMCs, automatically track descendants of attached 908fe4cbb6SJoseph Koshyprocesses. 918fe4cbb6SJoseph Koshy.It Dv PMC_F_LOG_PROCCSW 928fe4cbb6SJoseph KoshyFor process-scope counting PMCs, generate a log event at every context 938fe4cbb6SJoseph Koshyswitch containing the incremental number of hardware events seen 948fe4cbb6SJoseph Koshyby the process during the time it was executing on the CPU. 958fe4cbb6SJoseph Koshy.It Dv PMC_F_LOG_PROCEXIT 968fe4cbb6SJoseph KoshyFor process-scope counting PMCs, accumulate hardware events seen 978fe4cbb6SJoseph Koshywhen the process was executing on a CPU and generate a log event 988fe4cbb6SJoseph Koshywhen an attached process exits. 998fe4cbb6SJoseph Koshy.El 1008fe4cbb6SJoseph KoshyPMCs allocated with flags 1018fe4cbb6SJoseph Koshy.Dv PMC_F_LOG_PROCCSW 1028fe4cbb6SJoseph Koshyand 1038fe4cbb6SJoseph Koshy.Dv PMC_F_LOG_PROCEXIT 1048fe4cbb6SJoseph Koshyneed a log file to be configured before they are started. 1058fe4cbb6SJoseph Koshy.Pp 1068fe4cbb6SJoseph KoshyFor system scope PMCs, the argument 1078fe4cbb6SJoseph Koshy.Fa cpu 1088fe4cbb6SJoseph Koshyis a non-negative value that specifies the CPU number 1098fe4cbb6SJoseph Koshythat the PMC is to be allocated on. 1108fe4cbb6SJoseph KoshyProcess scope PMC allocations should specify the constant 1118fe4cbb6SJoseph Koshy.Dv PMC_CPU_ANY 1128fe4cbb6SJoseph Koshyfor this argument. 1138fe4cbb6SJoseph Koshy.Pp 1148fe4cbb6SJoseph KoshyFunction 1158fe4cbb6SJoseph Koshy.Fn pmc_release 1168fe4cbb6SJoseph Koshyreleases the PMC denoted by argument 1178fe4cbb6SJoseph Koshy.Fa pmcid . 1188fe4cbb6SJoseph Koshy.Sh RETURN VALUES 1198fe4cbb6SJoseph KoshyIf successful, function 1208fe4cbb6SJoseph Koshy.Fn pmc_allocate 1218fe4cbb6SJoseph Koshysets the location specified by argument 1228fe4cbb6SJoseph Koshy.Fa pmcid 1238fe4cbb6SJoseph Koshyto the handle of the allocated PMC and returns 0. 1248fe4cbb6SJoseph KoshyIn case of an error, the function returns -1 and sets the global 1258fe4cbb6SJoseph Koshyvariable 1268fe4cbb6SJoseph Koshy.Va errno 1278fe4cbb6SJoseph Koshyto indicate the error. 1288fe4cbb6SJoseph Koshy.Pp 1298fe4cbb6SJoseph Koshy.Rv -std pmc_release 1308fe4cbb6SJoseph Koshy.Sh ERRORS 1318fe4cbb6SJoseph Koshy.Bl -tag -width Er 1328fe4cbb6SJoseph Koshy.It Bq Er EINVAL 1338fe4cbb6SJoseph KoshyThe argument 1348fe4cbb6SJoseph Koshy.Fa mode 1358fe4cbb6SJoseph Koshyto function 1368fe4cbb6SJoseph Koshy.Fn pmc_allocate 1378fe4cbb6SJoseph Koshyhad an invalid value. 1388fe4cbb6SJoseph Koshy.It Bq Er EINVAL 1398fe4cbb6SJoseph KoshyArgument 1408fe4cbb6SJoseph Koshy.Fa cpu 1418fe4cbb6SJoseph Koshyto function 1428fe4cbb6SJoseph Koshy.Fn pmc_allocate 1438fe4cbb6SJoseph Koshyhad an invalid CPU number. 1448fe4cbb6SJoseph Koshy.It Bq Er EINVAL 1458fe4cbb6SJoseph KoshyArgument 1468fe4cbb6SJoseph Koshy.Fa flags 1478fe4cbb6SJoseph Koshycontained flags that were unsupported or otherwise incompatible with 1488fe4cbb6SJoseph Koshythe requested PMC mode. 1498fe4cbb6SJoseph Koshy.It Bq Er EINVAL 1508fe4cbb6SJoseph KoshyArgument 1518fe4cbb6SJoseph Koshy.Fa eventspecifier 1528fe4cbb6SJoseph Koshyto function 1538fe4cbb6SJoseph Koshy.Fn pmc_allocate 1548fe4cbb6SJoseph Koshyspecified an event not supported by hardware or contained a syntax 1558fe4cbb6SJoseph Koshyerror. 1568fe4cbb6SJoseph Koshy.It Bq Er ENXIO 1578fe4cbb6SJoseph KoshyFunction 1588fe4cbb6SJoseph Koshy.Fn pmc_allocate 1596455febbSJoseph Koshyrequested the use of a hardware resource that was absent or 1608fe4cbb6SJoseph Koshyadministratively disabled. 1618fe4cbb6SJoseph Koshy.It Bq Er EOPNOTSUPP 1628fe4cbb6SJoseph KoshyThe underlying hardware does not support the capabilities needed for 1638fe4cbb6SJoseph Koshya PMC being allocated by a call to 1648fe4cbb6SJoseph Koshy.Fn pmc_allocate . 1658fe4cbb6SJoseph Koshy.It Bq Er EPERM 1668fe4cbb6SJoseph KoshyA system scope PMC allocation was attempted without adequate process 1678fe4cbb6SJoseph Koshyprivilege. 1688fe4cbb6SJoseph Koshy.It Bq Er ESRCH 1698fe4cbb6SJoseph KoshyFunction 1708fe4cbb6SJoseph Koshy.Fn pmc_release 1718fe4cbb6SJoseph Koshywas called without first having allocated a PMC. 1728fe4cbb6SJoseph Koshy.It Bq Er EINVAL 1738fe4cbb6SJoseph KoshyArgument 1748fe4cbb6SJoseph Koshy.Fa pmcid 1758fe4cbb6SJoseph Koshyto function 1768fe4cbb6SJoseph Koshy.Fn pmc_release 1778fe4cbb6SJoseph Koshydid not specify a PMC previously allocated by this process. 1788fe4cbb6SJoseph Koshy.El 1798fe4cbb6SJoseph Koshy.Sh SEE ALSO 1808fe4cbb6SJoseph Koshy.Xr pmc 3 , 1818fe4cbb6SJoseph Koshy.Xr pmc_attach 3 , 1828fe4cbb6SJoseph Koshy.Xr pmc_configure_logfile 3 , 1838fe4cbb6SJoseph Koshy.Xr pmc_start 3 , 1848fe4cbb6SJoseph Koshy.Xr hwpmc 4 185