1bcbe65a8SJoseph Koshy.\" Copyright (c) 2003-2008 Joseph Koshy. All rights reserved. 2ebccf1e3SJoseph Koshy.\" 3ebccf1e3SJoseph Koshy.\" Redistribution and use in source and binary forms, with or without 4ebccf1e3SJoseph Koshy.\" modification, are permitted provided that the following conditions 5ebccf1e3SJoseph Koshy.\" are met: 6ebccf1e3SJoseph Koshy.\" 1. Redistributions of source code must retain the above copyright 7ebccf1e3SJoseph Koshy.\" notice, this list of conditions and the following disclaimer. 8ebccf1e3SJoseph Koshy.\" 2. Redistributions in binary form must reproduce the above copyright 9ebccf1e3SJoseph Koshy.\" notice, this list of conditions and the following disclaimer in the 10ebccf1e3SJoseph Koshy.\" documentation and/or other materials provided with the distribution. 11ebccf1e3SJoseph Koshy.\" 12ebccf1e3SJoseph Koshy.\" This software is provided by Joseph Koshy ``as is'' and 13ebccf1e3SJoseph Koshy.\" any express or implied warranties, including, but not limited to, the 14ebccf1e3SJoseph Koshy.\" implied warranties of merchantability and fitness for a particular purpose 15ebccf1e3SJoseph Koshy.\" are disclaimed. in no event shall Joseph Koshy be liable 16ebccf1e3SJoseph Koshy.\" for any direct, indirect, incidental, special, exemplary, or consequential 17ebccf1e3SJoseph Koshy.\" damages (including, but not limited to, procurement of substitute goods 18ebccf1e3SJoseph Koshy.\" or services; loss of use, data, or profits; or business interruption) 19ebccf1e3SJoseph Koshy.\" however caused and on any theory of liability, whether in contract, strict 20ebccf1e3SJoseph Koshy.\" liability, or tort (including negligence or otherwise) arising in any way 21ebccf1e3SJoseph Koshy.\" out of the use of this software, even if advised of the possibility of 22ebccf1e3SJoseph Koshy.\" such damage. 23ebccf1e3SJoseph Koshy.\" 24ebccf1e3SJoseph Koshy.\" $FreeBSD$ 25ebccf1e3SJoseph Koshy.\" 2624f2c3f3SJoseph Koshy.Dd September 16, 2008 27ebccf1e3SJoseph Koshy.Os 28ebccf1e3SJoseph Koshy.Dt PMC 3 29ebccf1e3SJoseph Koshy.Sh NAME 30c89d1cf5SJoseph Koshy.Nm pmc 31c89d1cf5SJoseph Koshy.Nd library for accessing hardware performance monitoring counters 32ebccf1e3SJoseph Koshy.Sh LIBRARY 33ebccf1e3SJoseph Koshy.Lb libpmc 34ebccf1e3SJoseph Koshy.Sh SYNOPSIS 35ebccf1e3SJoseph Koshy.In pmc.h 36ebccf1e3SJoseph Koshy.Sh DESCRIPTION 37ebccf1e3SJoseph KoshyThe 38c89d1cf5SJoseph Koshy.Lb libpmc 39c89d1cf5SJoseph Koshyprovides a programming interface that allows applications to use 40c89d1cf5SJoseph Koshyhardware performance counters to gather performance data about 41c89d1cf5SJoseph Koshyspecific processes or for the system as a whole. 42c89d1cf5SJoseph KoshyThe library is implemented using the lower-level facilities offered by 43c89d1cf5SJoseph Koshythe 44ebccf1e3SJoseph Koshy.Xr hwpmc 4 45c89d1cf5SJoseph Koshydriver. 46c89d1cf5SJoseph Koshy.Ss Key Concepts 47c89d1cf5SJoseph KoshyPerformance monitoring counters (PMCs) are represented by the library 48c89d1cf5SJoseph Koshyusing a software abstraction. 49c89d1cf5SJoseph KoshyThese 50c89d1cf5SJoseph Koshy.Dq abstract 51c89d1cf5SJoseph KoshyPMCs can have one two scopes: 52c89d1cf5SJoseph Koshy.Bl -bullet 53c89d1cf5SJoseph Koshy.It 54c89d1cf5SJoseph KoshySystem scope. 55c89d1cf5SJoseph KoshyThese PMCs measure events in a whole-system manner, i.e., independent 56c89d1cf5SJoseph Koshyof the currently executing thread. 57c89d1cf5SJoseph KoshySystem scope PMCs are allocated on specific CPUs and do not 58c89d1cf5SJoseph Koshymigrate between CPUs. 59c89d1cf5SJoseph KoshyNon-privileged process are allowed to allocate system scope PMCs if the 60c89d1cf5SJoseph Koshy.Xr hwpmc 4 61c89d1cf5SJoseph Koshysysctl tunable: 62c89d1cf5SJoseph Koshy.Va security.bsd.unprivileged_syspmcs 63c89d1cf5SJoseph Koshyis non-zero. 64c89d1cf5SJoseph Koshy.It 65c89d1cf5SJoseph KoshyProcess scope. 66c89d1cf5SJoseph KoshyThese PMCs only measure hardware events when the processes they are 67c89d1cf5SJoseph Koshyattached to are executing on a CPU. 68c89d1cf5SJoseph KoshyIn an SMP system, process scope PMCs migrate between CPUs along with 69c89d1cf5SJoseph Koshytheir target processes. 70c89d1cf5SJoseph Koshy.El 71ebccf1e3SJoseph Koshy.Pp 72c89d1cf5SJoseph KoshyOrthogonal to PMC scope, PMCs may be allocated in one of two 73c89d1cf5SJoseph Koshyoperational modes: 74c89d1cf5SJoseph Koshy.Bl -bullet 75c89d1cf5SJoseph Koshy.It 76c89d1cf5SJoseph KoshyCounting PMCs measure events according to their scope 77c89d1cf5SJoseph Koshy(system or process). 78c89d1cf5SJoseph KoshyThe application needs to explicitly read these counters 79c89d1cf5SJoseph Koshyto retrieve their value. 80c89d1cf5SJoseph Koshy.It 81c89d1cf5SJoseph KoshySampling PMCs cause the CPU to be periodically interrupted 82c89d1cf5SJoseph Koshyand information about its state of execution to be collected. 83c89d1cf5SJoseph KoshySampling PMCs are used to profile specific processes and kernel 84c89d1cf5SJoseph Koshythreads or to profile the system as a whole. 85c89d1cf5SJoseph Koshy.El 86c89d1cf5SJoseph Koshy.Pp 87c89d1cf5SJoseph KoshyThe scope and operational mode for a software PMC are specified at 88c89d1cf5SJoseph KoshyPMC allocation time. 89c89d1cf5SJoseph KoshyAn application is allowed to allocate multiple PMCs subject 90c89d1cf5SJoseph Koshyto availability of hardware resources. 91c89d1cf5SJoseph Koshy.Pp 92c89d1cf5SJoseph KoshyThe library uses human-readable strings to name the event being 93c89d1cf5SJoseph Koshymeasured by hardware. 94c89d1cf5SJoseph KoshyThe syntax used for specifying a hardware event along with additional 95c89d1cf5SJoseph Koshyevent specific qualifiers (if any) is described in detail in section 96ebccf1e3SJoseph Koshy.Sx "EVENT SPECIFIERS" 97ebccf1e3SJoseph Koshybelow. 98ebccf1e3SJoseph Koshy.Pp 99c89d1cf5SJoseph KoshyPMCs are associated with the process that allocated them and 100c89d1cf5SJoseph Koshywill be automatically reclaimed by the system when the process exits. 101c89d1cf5SJoseph KoshyAdditionally, process-scope PMCs have to be attached to one or more 102c89d1cf5SJoseph Koshytarget processes before they can perform measurements. 103c89d1cf5SJoseph KoshyA process-scope PMC may be attached to those target processes 104c89d1cf5SJoseph Koshythat its owner process would otherwise be permitted to debug. 105c89d1cf5SJoseph KoshyAn owner process may attach PMCs to itself allowing 106c89d1cf5SJoseph Koshyit to measure its own behavior. 107c89d1cf5SJoseph KoshyAdditionally, on some machine architectures, such self-attached PMCs 108c89d1cf5SJoseph Koshymay be read cheaply using specialized instructions supported by the 109c89d1cf5SJoseph Koshyprocessor. 110ebccf1e3SJoseph Koshy.Pp 111c89d1cf5SJoseph KoshyCertain kinds of PMCs require that a log file be configured before 112c89d1cf5SJoseph Koshythey may be started. 113c89d1cf5SJoseph KoshyThese include: 114c89d1cf5SJoseph Koshy.Bl -bullet -compact 115c89d1cf5SJoseph Koshy.It 116c89d1cf5SJoseph KoshySystem scope sampling PMCs. 117c89d1cf5SJoseph Koshy.It 118c89d1cf5SJoseph KoshyProcess scope sampling PMCs. 119c89d1cf5SJoseph Koshy.It 120c89d1cf5SJoseph KoshyProcess scope counting PMCs that have been configured to report PMC 121c89d1cf5SJoseph Koshyreadings on process context switches or process exits. 122c89d1cf5SJoseph Koshy.El 123c89d1cf5SJoseph KoshyUpto one log file may be configured per owner process. 124c89d1cf5SJoseph KoshyEvents logged to a log file may be subsequently analyzed using the 125c89d1cf5SJoseph Koshy.Xr pmclog 3 126c89d1cf5SJoseph Koshyfamily of functions. 127c89d1cf5SJoseph Koshy.Ss Supported CPUs 128c89d1cf5SJoseph KoshyThe CPUs known to the PMC library are named by the 129c89d1cf5SJoseph Koshy.Vt "enum pmc_cputype" 130c89d1cf5SJoseph Koshyenumeration. 131c89d1cf5SJoseph KoshySupported CPUs include: 132c89d1cf5SJoseph Koshy.Bl -tag -width PMC_CPU_INTEL_PIII -compact 133c89d1cf5SJoseph Koshy.It PMC_CPU_AMD_K7 134c89d1cf5SJoseph Koshy.Tn "AMD Athlon" 135c89d1cf5SJoseph KoshyCPUs. 136c89d1cf5SJoseph Koshy.It PMC_CPU_AMD_K8 137c89d1cf5SJoseph Koshy.Tn "AMD Athlon64" 138c89d1cf5SJoseph KoshyCPUs. 139bcbe65a8SJoseph Koshy.It PMC_CPU_INTEL_P5 140bcbe65a8SJoseph Koshy.Tn Intel 141bcbe65a8SJoseph Koshy.Tn "Pentium" 142bcbe65a8SJoseph KoshyCPUs. 143c89d1cf5SJoseph Koshy.It PMC_CPU_INTEL_P6 144c89d1cf5SJoseph Koshy.Tn Intel 145c89d1cf5SJoseph Koshy.Tn "Pentium Pro" 146c89d1cf5SJoseph KoshyCPUs. 147c89d1cf5SJoseph Koshy.It PMC_CPU_INTEL_PII 148c89d1cf5SJoseph Koshy.Tn "Intel Pentium II" 149c89d1cf5SJoseph KoshyCPUs. 150c89d1cf5SJoseph Koshy.It PMC_CPU_INTEL_PIII 151c89d1cf5SJoseph Koshy.Tn "Intel Pentium III" 152c89d1cf5SJoseph KoshyCPUs. 153c89d1cf5SJoseph Koshy.It PMC_CPU_INTEL_PM 154c89d1cf5SJoseph Koshy.Tn "Intel Pentium M" 155c89d1cf5SJoseph KoshyCPUs. 156c89d1cf5SJoseph Koshy.It PMC_CPU_INTEL_PIV 157c89d1cf5SJoseph Koshy.Tn "Intel Pentium 4" 158c89d1cf5SJoseph KoshyCPUs. 159c89d1cf5SJoseph Koshy.El 160c89d1cf5SJoseph Koshy.Ss Supported PMCs 161c89d1cf5SJoseph KoshyPMC supported by this library are named by the 162c89d1cf5SJoseph Koshy.Vt enum pmc_class 163c89d1cf5SJoseph Koshyenumeration. 164c89d1cf5SJoseph KoshySupported PMC kinds include: 165c89d1cf5SJoseph Koshy.Bl -tag -width PMC_CLASS_TSC -compact 166c89d1cf5SJoseph Koshy.It PMC_CLASS_K7 167c89d1cf5SJoseph KoshyProgrammable hardware counters present in 168c89d1cf5SJoseph Koshy.Tn "AMD Athlon" 169c89d1cf5SJoseph KoshyCPUs. 170c89d1cf5SJoseph Koshy.It PMC_CLASS_K8 171c89d1cf5SJoseph KoshyProgrammable hardware counters present in 172c89d1cf5SJoseph Koshy.Tn "AMD Athlon64" 173c89d1cf5SJoseph KoshyCPUs. 17424f2c3f3SJoseph Koshy.It PMC_CLASS_P4 17524f2c3f3SJoseph KoshyProgrammable hardware counters present in 17624f2c3f3SJoseph Koshy.Tn "Intel Pentium 4" 17724f2c3f3SJoseph KoshyCPUs. 178bcbe65a8SJoseph Koshy.It PMC_CLASS_P5 179bcbe65a8SJoseph KoshyProgrammable hardware counters present in 180bcbe65a8SJoseph Koshy.Tn Intel 181bcbe65a8SJoseph Koshy.Tn Pentium 182bcbe65a8SJoseph KoshyCPUs. 183c89d1cf5SJoseph Koshy.It PMC_CLASS_P6 184c89d1cf5SJoseph KoshyProgrammable hardware counters present in 185c89d1cf5SJoseph Koshy.Tn Intel 186c89d1cf5SJoseph Koshy.Tn "Pentium Pro" , 187c89d1cf5SJoseph Koshy.Tn "Pentium II" , 188c89d1cf5SJoseph Koshy.Tn "Pentium III" , 189c89d1cf5SJoseph Koshy.Tn "Celeron" , 190ebccf1e3SJoseph Koshyand 191c89d1cf5SJoseph Koshy.Tn "Pentium M" 192c89d1cf5SJoseph KoshyCPUs. 19324f2c3f3SJoseph Koshy.It PMC_CLASS_TSC 19424f2c3f3SJoseph KoshyThe timestamp counter on i386 and amd64 architecture CPUs. 195c89d1cf5SJoseph Koshy.El 196c89d1cf5SJoseph Koshy.Ss PMC Capabilities 197ebccf1e3SJoseph Koshy.Pp 198c89d1cf5SJoseph KoshyCapabilities of performance monitoring hardware are denoted using 199c89d1cf5SJoseph Koshythe 200c89d1cf5SJoseph Koshy.Vt "enum pmc_caps" 201c89d1cf5SJoseph Koshyenumeration. 202c89d1cf5SJoseph KoshySupported capabilities include: 203c89d1cf5SJoseph Koshy.Bl -tag -width "PMC_CAP_INTERRUPT" -compact 204c89d1cf5SJoseph Koshy.It PMC_CAP_EDGE 205c89d1cf5SJoseph KoshyThe ability to count negated to asserted transitions of the hardware 206c89d1cf5SJoseph Koshyconditions being probed for. 207c89d1cf5SJoseph Koshy.It PMC_CAP_INTERRUPT 208c89d1cf5SJoseph KoshyThe ability to interrupt the CPU. 209c89d1cf5SJoseph Koshy.It PMC_CAP_INVERT 210c89d1cf5SJoseph KoshyThe ability to invert the sense of the hardware conditions being 211c89d1cf5SJoseph Koshymeasured. 212c89d1cf5SJoseph Koshy.It PMC_CAP_READ 213c89d1cf5SJoseph KoshyPMC hardware allows the CPU to read performance counters. 214c89d1cf5SJoseph Koshy.It PMC_CAP_QUALIFIER 215c89d1cf5SJoseph KoshyThe hardware allows monitored to be further qualified in some 216c89d1cf5SJoseph Koshysystem dependent way. 217c89d1cf5SJoseph Koshy.It PMC_CAP_SYSTEM 218c89d1cf5SJoseph KoshyThe ability to restrict counting of hardware events to when the CPU is 219c89d1cf5SJoseph Koshyrunning privileged code. 220c89d1cf5SJoseph Koshy.It PMC_CAP_THRESHOLD 221c89d1cf5SJoseph KoshyThe ability to ignore simultaneous hardware events below a 222c89d1cf5SJoseph Koshyprogrammable threshold. 223c89d1cf5SJoseph Koshy.It PMC_CAP_USER 224c89d1cf5SJoseph KoshyThe ability to restrict counting of hardware events to those when the 225c89d1cf5SJoseph KoshyCPU is running unprivileged code. 226c89d1cf5SJoseph Koshy.It PMC_CAP_WRITE 227c89d1cf5SJoseph KoshyPMC hardware allows CPUs write to counters. 228c89d1cf5SJoseph Koshy.El 229c89d1cf5SJoseph Koshy.Ss Functional Grouping 230c89d1cf5SJoseph KoshyThis section contains a brief overview of the available functionality 231c89d1cf5SJoseph Koshyin the PMC library. 232c89d1cf5SJoseph KoshyEach function listed here is described further in its own manual page. 233c89d1cf5SJoseph Koshy.Bl -tag -width indent 234c89d1cf5SJoseph Koshy.It Administration 235c89d1cf5SJoseph Koshy.Bl -tag -compact 236c89d1cf5SJoseph Koshy.It Fn pmc_disable , Fn pmc_enable 237c89d1cf5SJoseph KoshyAdministratively disable (enable) specific performance monitoring 238c89d1cf5SJoseph Koshycounter hardware. 239c89d1cf5SJoseph KoshyCounters that are disabled will not be available to applications to 240c89d1cf5SJoseph Koshyuse. 241c89d1cf5SJoseph Koshy.El 242c89d1cf5SJoseph Koshy.It "Convenience Functions" 243c89d1cf5SJoseph Koshy.Bl -tag -compact 244c89d1cf5SJoseph Koshy.It Fn pmc_event_names_of_class 245c89d1cf5SJoseph KoshyReturns a list of event names supported by a given PMC type. 246c89d1cf5SJoseph Koshy.It Fn pmc_name_of_capability 247c89d1cf5SJoseph KoshyConvert a 248c89d1cf5SJoseph Koshy.Dv PMC_CAP_* 249c89d1cf5SJoseph Koshyflag to a human-readable string. 250c89d1cf5SJoseph Koshy.It Fn pmc_name_of_class 251c89d1cf5SJoseph KoshyConvert a 252c89d1cf5SJoseph Koshy.Dv PMC_CLASS_* 253c89d1cf5SJoseph Koshyconstant to a human-readable string. 254c89d1cf5SJoseph Koshy.It Fn pmc_name_of_cputype 255c89d1cf5SJoseph KoshyReturn a human-readable name for a CPU type. 256c89d1cf5SJoseph Koshy.It Fn pmc_name_of_disposition 257c89d1cf5SJoseph KoshyReturn a human-readable string describing a PMC's disposition. 258c89d1cf5SJoseph Koshy.It Fn pmc_name_of_event 259c89d1cf5SJoseph KoshyConvert a numeric event code to a human-readable string. 260c89d1cf5SJoseph Koshy.It Fn pmc_name_of_mode 261c89d1cf5SJoseph KoshyConvert a 262c89d1cf5SJoseph Koshy.Dv PMC_MODE_* 263c89d1cf5SJoseph Koshyconstant to a human-readable name. 264c89d1cf5SJoseph Koshy.It Fn pmc_name_of_state 265c89d1cf5SJoseph KoshyReturn a human-readable string describing a PMC's current state. 266c89d1cf5SJoseph Koshy.El 267c89d1cf5SJoseph Koshy.It "Library Initialization" 268c89d1cf5SJoseph Koshy.Bl -tag -compact 269c89d1cf5SJoseph Koshy.It Fn pmc_init 270c89d1cf5SJoseph KoshyInitialize the library. 271c89d1cf5SJoseph KoshyThis function must be called before any other library function. 272c89d1cf5SJoseph Koshy.El 273c89d1cf5SJoseph Koshy.It "Log File Handling" 274c89d1cf5SJoseph Koshy.Bl -tag -compact 275c89d1cf5SJoseph Koshy.It Fn pmc_configure_logfile 276c89d1cf5SJoseph KoshyConfigure a log file for 277c89d1cf5SJoseph Koshy.Xr hwpmc 4 278c89d1cf5SJoseph Koshyto write logged events to. 279c89d1cf5SJoseph Koshy.It Fn pmc_flush_logfile 280c89d1cf5SJoseph KoshyFlush all pending log data in 281c89d1cf5SJoseph Koshy.Xr hwpmc 4 Ns Ap s 282c89d1cf5SJoseph Koshybuffers. 283c89d1cf5SJoseph Koshy.It Fn pmc_writelog 284c89d1cf5SJoseph KoshyAppend arbitrary user data to the current log file. 285c89d1cf5SJoseph Koshy.El 286c89d1cf5SJoseph Koshy.It "PMC Management" 287c89d1cf5SJoseph Koshy.Bl -tag -compact 288c89d1cf5SJoseph Koshy.It Fn pmc_allocate , Fn pmc_release 289c89d1cf5SJoseph KoshyAllocate (free) a PMC. 290c89d1cf5SJoseph Koshy.It Fn pmc_attach , Fn pmc_detach 291c89d1cf5SJoseph KoshyAttach (detach) a process scope PMC to a target. 292c89d1cf5SJoseph Koshy.It Fn pmc_read , Fn pmc_write , Fn pmc_rw 293c89d1cf5SJoseph KoshyRead (write) a value from (to) a PMC. 294c89d1cf5SJoseph Koshy.It Fn pmc_start , Fn pmc_stop 295c89d1cf5SJoseph KoshyStart (stop) a software PMC. 296c89d1cf5SJoseph Koshy.It Fn pmc_set 297c89d1cf5SJoseph KoshySet the reload value for a sampling PMC. 298c89d1cf5SJoseph Koshy.El 299c89d1cf5SJoseph Koshy.It "Queries" 300c89d1cf5SJoseph Koshy.Bl -tag -compact 301c89d1cf5SJoseph Koshy.It Fn pmc_capabilities 302c89d1cf5SJoseph KoshyRetrieve the capabilities for a given PMC. 303c89d1cf5SJoseph Koshy.It Fn pmc_cpuinfo 304c89d1cf5SJoseph KoshyRetrieve information about the CPUs and PMC hardware present in the 305c89d1cf5SJoseph Koshysystem. 306c89d1cf5SJoseph Koshy.It Fn pmc_get_driver_stats 307c89d1cf5SJoseph KoshyRetrieve statistics maintained by 308c89d1cf5SJoseph Koshy.Xr hwpmc 4 . 309c89d1cf5SJoseph Koshy.It Fn pmc_ncpu 310c89d1cf5SJoseph KoshyDetermine the number of CPUs in the system. 311c89d1cf5SJoseph Koshy.It Fn pmc_npmc 312c89d1cf5SJoseph KoshyReturn the number of hardware PMCs present in a given CPU. 313c89d1cf5SJoseph Koshy.It Fn pmc_pmcinfo 314c89d1cf5SJoseph KoshyReturn information about the state of a given CPU's PMCs. 315c89d1cf5SJoseph Koshy.It Fn pmc_width 316c89d1cf5SJoseph KoshyDetermine the width of a hardware counter in bits. 317c89d1cf5SJoseph Koshy.El 318c89d1cf5SJoseph Koshy.It "x86 Architecture Specific API" 319c89d1cf5SJoseph Koshy.Bl -tag -compact 320c89d1cf5SJoseph Koshy.It Fn pmc_get_msr 321c89d1cf5SJoseph KoshyReturns the processor model specific register number 322c89d1cf5SJoseph Koshyassociated with 323c5153e19SJoseph Koshy.Fa pmc . 324c89d1cf5SJoseph KoshyApplications may then use the x86 325c89d1cf5SJoseph Koshy.Ic RDPMC 326c89d1cf5SJoseph Koshyinstruction to directly read the contents of the PMC. 327c89d1cf5SJoseph Koshy.El 328c89d1cf5SJoseph Koshy.El 3299abe909bSRuslan Ermilov.Ss Signal Handling Requirements 330ebccf1e3SJoseph KoshyApplications using PMCs are required to handle the following signals: 331c89d1cf5SJoseph Koshy.Bl -tag -width ".Dv SIGBUS" 3329abe909bSRuslan Ermilov.It Dv SIGBUS 333ebccf1e3SJoseph KoshyWhen the 334ebccf1e3SJoseph Koshy.Xr hwpmc 4 335ebccf1e3SJoseph Koshymodule is unloaded using 336ebccf1e3SJoseph Koshy.Xr kldunload 8 , 337ebccf1e3SJoseph Koshyprocesses that have PMCs allocated to them will be sent a 3389abe909bSRuslan Ermilov.Dv SIGBUS 3399abe909bSRuslan Ermilovsignal. 3409abe909bSRuslan Ermilov.It Dv SIGIO 341f263522aSJoseph KoshyThe 342f263522aSJoseph Koshy.Xr hwpmc 4 3439abe909bSRuslan Ermilovdriver will send a PMC owning process a 3449abe909bSRuslan Ermilov.Dv SIGIO 3459abe909bSRuslan Ermilovsignal if: 346f263522aSJoseph Koshy.Bl -bullet 347f263522aSJoseph Koshy.It 348f263522aSJoseph KoshyIf any process-mode PMC allocated by it loses all its 349f263522aSJoseph Koshytarget processes. 350f263522aSJoseph Koshy.It 351f263522aSJoseph KoshyIf the driver encounters an error when writing log data to a 352f263522aSJoseph Koshyconfigured log file. 353f263522aSJoseph KoshyThis error may be retrieved by a subsequent call to 354f263522aSJoseph Koshy.Fn pmc_flush_logfile . 355f263522aSJoseph Koshy.El 356ebccf1e3SJoseph Koshy.El 357c89d1cf5SJoseph Koshy.Ss Typical Program Flow 358c89d1cf5SJoseph Koshy.Bl -enum 359c89d1cf5SJoseph Koshy.It 360c89d1cf5SJoseph KoshyAn application would first invoke function 361c89d1cf5SJoseph Koshy.Fn pmc_init 362c89d1cf5SJoseph Koshyto allow the library to initialize itself. 363c89d1cf5SJoseph Koshy.It 364c89d1cf5SJoseph KoshySignal handling would then be set up. 365c89d1cf5SJoseph Koshy.It 366c89d1cf5SJoseph KoshyNext the application would allocate the PMCs it desires using function 367c89d1cf5SJoseph Koshy.Fn pmc_allocate . 368c89d1cf5SJoseph Koshy.It 369c89d1cf5SJoseph KoshyInitial values for PMCs may be set using function 370c89d1cf5SJoseph Koshy.Fn pmc_set . 371c89d1cf5SJoseph Koshy.It 372c89d1cf5SJoseph KoshyIf a log file is necessary for the PMCs to work, it would 373c89d1cf5SJoseph Koshybe configured using function 374c89d1cf5SJoseph Koshy.Fn pmc_configure_logfile . 375c89d1cf5SJoseph Koshy.It 376c89d1cf5SJoseph KoshyProcess scope PMCs would then be attached to their target processes 377c89d1cf5SJoseph Koshyusing function 378c89d1cf5SJoseph Koshy.Fn pmc_attach . 379c89d1cf5SJoseph Koshy.It 380c89d1cf5SJoseph KoshyThe PMCs would then be started using function 381c89d1cf5SJoseph Koshy.Fn pmc_start . 382c89d1cf5SJoseph Koshy.It 383c89d1cf5SJoseph KoshyOnce started, the values of counting PMCs may be read using function 384c89d1cf5SJoseph Koshy.Fn pmc_start . 385c89d1cf5SJoseph KoshyFor PMCs that write events to the log file, this logged data would be 386c89d1cf5SJoseph Koshyread and parsed using the 387c89d1cf5SJoseph Koshy.Xr pmclog 3 388c89d1cf5SJoseph Koshyfamily of functions. 389c89d1cf5SJoseph Koshy.It 390c89d1cf5SJoseph KoshyPMCs are stopped using function 391c89d1cf5SJoseph Koshy.Fn pmc_stop , 392c89d1cf5SJoseph Koshyand process scope PMCs are detached from their targets using 393c89d1cf5SJoseph Koshyfunction 394c89d1cf5SJoseph Koshy.Fn pmc_detach . 395c89d1cf5SJoseph Koshy.It 396c89d1cf5SJoseph KoshyBefore the process exits, its may release its PMCs using function 397c89d1cf5SJoseph Koshy.Fn pmc_release . 398c89d1cf5SJoseph KoshyAny configured log file may be closed using function 399c89d1cf5SJoseph Koshy.Fn pmc_configure_logfile . 400c89d1cf5SJoseph Koshy.El 401ebccf1e3SJoseph Koshy.Sh EVENT SPECIFIERS 402ebccf1e3SJoseph KoshyEvent specifiers are strings comprising of an event name, followed by 403ebccf1e3SJoseph Koshyoptional parameters modifying the semantics of the hardware event 404ebccf1e3SJoseph Koshybeing probed. 4050b844226SJoseph KoshyEvent names are PMC architecture dependent, but the PMC library defines 4060b844226SJoseph Koshymachine independent aliases for commonly used events. 407ebccf1e3SJoseph Koshy.Ss Event Name Aliases 40824f2c3f3SJoseph KoshyEvent name aliases are PMC-independent names for commonly used events. 409ebccf1e3SJoseph KoshyThe following aliases are known to this version of the 410110e1704SRuslan Ermilov.Nm pmc 411ebccf1e3SJoseph Koshylibrary: 412ebccf1e3SJoseph Koshy.Bl -tag -width indent 413ebccf1e3SJoseph Koshy.It Li branches 414ebccf1e3SJoseph KoshyMeasure the number of branches retired. 415ebccf1e3SJoseph Koshy.It Li branch-mispredicts 416ebccf1e3SJoseph KoshyMeasure the number of retired branches that were mispredicted. 417ebccf1e3SJoseph Koshy.It Li cycles 418ebccf1e3SJoseph KoshyMeasure processor cycles. 419ebccf1e3SJoseph KoshyThis event is implemented using the processor's Time Stamp Counter 420ebccf1e3SJoseph Koshyregister. 421ebccf1e3SJoseph Koshy.It Li dc-misses 422ebccf1e3SJoseph KoshyMeasure the number of data cache misses. 423ebccf1e3SJoseph Koshy.It Li ic-misses 424ebccf1e3SJoseph KoshyMeasure the number of instruction cache misses. 425ebccf1e3SJoseph Koshy.It Li instructions 426ebccf1e3SJoseph KoshyMeasure the number of instructions retired. 427ebccf1e3SJoseph Koshy.It Li interrupts 428ebccf1e3SJoseph KoshyMeasure the number of interrupts seen. 429177a2f22SJoseph Koshy.It Li unhalted-cycles 430177a2f22SJoseph KoshyMeasure the number of cycles the processor is not in a halted 431177a2f22SJoseph Koshyor sleep state. 432ebccf1e3SJoseph Koshy.El 433ebccf1e3SJoseph Koshy.Pp 43424f2c3f3SJoseph Koshy.Ss PMC Architecture Dependent Events 43524f2c3f3SJoseph KoshyPMC architecture dependent event specifiers are described in their own 43624f2c3f3SJoseph Koshyindividual manual pages: 43724f2c3f3SJoseph Koshy.Bl -column " PMC_CLASS_TSC " "MANUAL PAGE " 43824f2c3f3SJoseph Koshy.It Em "PMC Class" Ta Em "Manual Page" 43924f2c3f3SJoseph Koshy.It Li PMC_CLASS_K7 Ta Xr pmc.k7 3 44024f2c3f3SJoseph Koshy.It Li PMC_CLASS_K8 Ta Xr pmc.k8 3 44124f2c3f3SJoseph Koshy.It Li PMC_CLASS_P4 Ta Xr pmc.p4 3 44224f2c3f3SJoseph Koshy.It Li PMC_CLASS_P5 Ta Xr pmc.p5 3 44324f2c3f3SJoseph Koshy.It Li PMC_CLASS_P6 Ta Xr pmc.p6 3 44424f2c3f3SJoseph Koshy.It Li PMC_CLASS_TSC Ta Xr pmc.tsc 3 445ebccf1e3SJoseph Koshy.El 4465138c36aSJoseph Koshy.Sh COMPATIBILITY 4475138c36aSJoseph KoshyThe interface between the 448110e1704SRuslan Ermilov.Nm pmc 4495138c36aSJoseph Koshylibrary and the 4505138c36aSJoseph Koshy.Xr hwpmc 4 4515138c36aSJoseph Koshydriver is intended to be private to the implementation and may 4525138c36aSJoseph Koshychange. 4535138c36aSJoseph KoshyIn order to ease forward compatibility with future versions of the 4545138c36aSJoseph Koshy.Xr hwpmc 4 4555138c36aSJoseph Koshydriver, applications are urged to dynamically link with the 456110e1704SRuslan Ermilov.Nm pmc 4575138c36aSJoseph Koshylibrary. 4585138c36aSJoseph Koshy.Pp 4595138c36aSJoseph KoshyThe 460110e1704SRuslan Ermilov.Nm pmc 4615138c36aSJoseph KoshyAPI is 4625138c36aSJoseph Koshy.Ud 463ebccf1e3SJoseph Koshy.Sh SEE ALSO 46424f2c3f3SJoseph Koshy.Xr pmc.k7 3 , 46524f2c3f3SJoseph Koshy.Xr pmc.k8 3 , 46624f2c3f3SJoseph Koshy.Xr pmc.p4 3 , 46724f2c3f3SJoseph Koshy.Xr pmc.p5 3 , 46824f2c3f3SJoseph Koshy.Xr pmc.p6 3 , 46924f2c3f3SJoseph Koshy.Xr pmc.tsc 3 , 470f263522aSJoseph Koshy.Xr pmclog 3 , 471ebccf1e3SJoseph Koshy.Xr hwpmc 4 , 472ebccf1e3SJoseph Koshy.Xr pmccontrol 8 , 473ebccf1e3SJoseph Koshy.Xr pmcstat 8 4745138c36aSJoseph Koshy.Sh HISTORY 4755138c36aSJoseph KoshyThe 476110e1704SRuslan Ermilov.Nm pmc 4775138c36aSJoseph Koshylibrary first appeared in 4785138c36aSJoseph Koshy.Fx 6.0 . 479c89d1cf5SJoseph Koshy.Sh AUTHORS 480c89d1cf5SJoseph KoshyThe 481c89d1cf5SJoseph Koshy.Lb libpmc 482c89d1cf5SJoseph Koshylibrary was written by 483c89d1cf5SJoseph Koshy.An "Joseph Koshy" 484c89d1cf5SJoseph Koshy.Aq jkoshy@FreeBSD.org . 485