'\" te .\" Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. .TH cpc_npic 3CPC "2 Jan 2014" "SunOS 5.11" "CPU Performance Counters Library Functions" .SH NAME cpc_npic, cpc_smpl_npic, cpc_caps, cpc_cciname, cpc_smpl_iname, cpc_cpuref, cpc_walk_events_all, cpc_walk_events_all_common, cpc_walk_generic_events_all, cpc_walk_events_pic, cpc_walk_events_pic_common, cpc_walk_generic_events_pic, cpc_walk_attrs, cpc_walk_attrs_common, cpc_walk_smpl_recitems, cpc_get_smpl_max_rec_count, cpc_walk_smpl_recitems_req \- determine CPU performance counter configuration .SH SYNOPSIS .LP .nf cc [ \fIflag\fR\&.\|.\|. ] \fIfile\fR\&.\|.\|. \fB-lcpc\fR [ \fIlibrary\fR\&.\|.\|. ] #include .fi .LP .nf \fBuint_t\fR \fBcpc_npic\fR(\fBcpc_t *\fR\fIcpc\fR); .fi .LP .nf \fBuint_t\fR \fBcpc_smpl_npic\fR(\fBcpc_t *\fR\fIcpc\fR); .fi .LP .nf \fBuint_t\fR \fBcpc_caps\fR(\fBcpc_t *\fR\fIcpc\fR); .fi .LP .nf \fBconst char *\fR\fBcpc_cciname\fR(\fBcpc_t *\fR\fIcpc\fR); .fi .LP .nf \fBconst char *\fR\fBcpc_smpl_iname\fR(\fBcpc_t *\fR\fIcpc\fR); .fi .LP .nf \fBconst char *\fR\fBcpc_cpuref\fR(\fBcpc_t *\fR\fIcpc\fR); .fi .LP .nf \fBvoid\fR \fBcpc_walk_events_all\fR(\fBcpc_t *\fR\fIcpc\fR, \fBvoid *\fR\fIarg\fR, \fBvoid\fR (*\fIaction\fR)(\fBvoid *\fR\fIarg\fR, const char *\fIevent\fR)); .fi .LP .nf \fBvoid\fR \fBcpc_walk_events_all_common\fR(\fBcpc_t *\fR\fIcpc\fR, \fBvoid *\fR\fIarg\fR, \fBint\fR \fItarget\fR, \fBvoid (*\fR\fIaction\fR) (\fBvoid *\fR\fIarg\fR, \fBconst char *\fR\fIevent\fR)); .fi .LP .nf \fBvoid\fR \fBcpc_walk_generic_events_all\fR(\fBcpc_t *\fR\fIcpc\fR, \fBvoid *\fR\fIarg\fR, \fBvoid\fR (*\fIaction\fR)(\fBvoid *\fR\fIarg\fR, \fBconst char *\fR\fIevent\fR)); .fi .LP .nf \fBvoid\fR \fBcpc_walk_events_pic\fR(\fBcpc_t *\fR\fIcpc\fR, \fBuint_t\fR \fIpicno\fR, \fBvoid *\fR\fIarg\fR, \fBvoid\fR (*\fIaction\fR)(\fBvoid *\fR\fIarg\fR, uint_t \fIpicno\fR, const char *\fIevent\fR)); .fi .LP .nf \fBvoid\fR \fBcpc_walk_events_pic_common\fR(\fBcpc_t *\fR\fIcpc\fR, \fBuint_t\fR \fIpicno\fR, \fBvoid *\fR\fIarg\fR, \fBint\fR \fItarget\fR, \fBvoid (*\fR\fIaction\fR)(\fBvoid *\fR\fIarg\fR, \fBuint_t\fR \fIpicno\fR, \fBconst char *\fR\fIevent\fR)); .fi .LP .nf \fBvoid\fR \fBcpc_walk_generic_events_pic\fR(\fBcpc_t *\fR\fIcpc\fR, \fBuint_t\fR \fIpicno\fR, \fBvoid *\fR\fIarg\fR, \fBvoid\fR (*\fIaction\fR)(\fBvoid *\fR\fIarg\fR, \fBuint_t\fR \fIpicno\fR, \fBconst char *\fR\fIevent\fR)); .fi .LP .nf \fBvoid\fR \fBcpc_walk_attrs\fR(\fBcpc_t *\fR\fIcpc\fR, \fBvoid *\fR\fIarg\fR, \fBvoid\fR (*\fIaction\fR)(\fBvoid *\fR\fIarg\fR, \fBconst char *\fR\fIattr\fR)); .fi .LP .nf \fBvoid\fR \fBcpc_walk_attrs_common\fR(\fBcpc_t *\fR\fIcpc\fR, \fBvoid *\fR\fIarg\fR, \fBint\fR \fItarget\fR, \fBvoid (*\fR\fIaction\fR) (\fBvoid *\fR\fIarg\fR, \fBconst char *\fR\fIattr\fR)); .fi .LP .nf \fBvoid\fR \fBcpc_walk_smpl_recitems\fR(\fBcpc_t *\fR\fIcpc\fR, \fBvoid *\fR\fIarg\fR, \fBvoid (*\fR\fIaction\fR)(\fBvoid *\fR\fIarg\fR, \fBconst char *\fR\fIname\fR, \fBint\fR \fIrecord_item_index\fR)); .fi .LP .nf \fBvoid\fR \fBcpc_walk_smpl_recitems_req\fR(\fBcpc_t *\fR\fIcpc\fR, \fBcpc_set_t *\fR\fIset\fR, \fBint\fR \fIrequest_index\fR, \fBvoid *\fR\fIarg\fR, \fBvoid (*\fR\fIaction\fR)(\fBvoid *\fR\fIarg\fR, \fBcpc_set_t *\fR\fIset\fR, \fBint\fR \fIrequest_index\fR, \fBconst char *\fR\fIname\fR, \fBint\fR \fIrecord_item_index\fR)); .fi .LP .nf \fBint\fR \fBcpc_get_smpl_max_rec_count\fR(\fBcpc_t *\fR\fIcpc\fR, \fBuint_t\fR \fImax_rec_count\fR); .fi .SH DESCRIPTION .sp .LP The \fBcpc_cciname()\fR function returns a printable description of the processor performance counter interfaces, for example, the string UltraSPARC III+ & IV. This name should not be assumed to be the same as the name the manufacturer might otherwise ascribe to the processor. It simply names the performance counter interfaces as understood by the system, and thus names the set of performance counter events that can be described by that interface. .sp .LP The \fBcpc_smpl_iname()\fR function returns the hardware sampling implementation name available on the processor. Currently, only \fIPEBS\fR for Intel Precise Events Based Sampling is supported as the hardware sampling implementation name. .sp .LP The \fBcpc_cpuref()\fR function returns a string that describes a reference work that should be consulted to (allow a human to) understand the semantics of the performance counter events that are known to the system. The string returned might be substantially longer than 80 characters. Callers printing to a terminal might want to insert line breaks as appropriate. .sp .LP The \fBcpc_npic()\fR function returns the number of performance counters for CPC accessible on the processor. On the processor that shares the performance counters between CPC and SMPL, the reported number is still the one counting the performance counters that could be used for CPC. Therefore, the number may contain the one for the performance counters that could be also used for SMPL. .sp .LP The \fBcpc_smpl_npic()\fR function returns the number of performance counters for SMPL accessible on the processor. On the processor that shares the performance counters between CPC and SMPL, the reported number is still the one counting the performance counters that could be used for SMPL. Therefore, the number may contain the one for the performance counters that could be also used for CPC. If the specified \fIcpc\fR has not been successfully opened for SMPL, \fBcpc_smpl_npic()\fR sets \fBEINVAL\fR to \fBerrno\fR and returns 0. .sp .LP The \fBcpc_caps()\fR function returns a bitmap containing the bitwise inclusive-OR of zero or more flags that describe the capabilities of the processor. If \fBCPC_CAP_OVERFLOW_INTERRUPT\fR is present, the processor can generate an interrupt when a hardware performance counter overflows. If \fBCPC_CAP_OVERFLOW_PRECISE\fR is present, the processor can determine precisely which counter overflowed, thereby affecting the behavior of the overflow notification mechanism described in \fBcpc_bind_curlwp\fR(3CPC). If \fBCPC_CAP_SMPL\fR is present, the hardware sampling is available on the processor. If \fBCPC_CAP_OVERFLOW_SMPL\fR is present, the hardware sampling available on the processor supports the overflow. If \fBcpc_open()\fR with \fBCPC_VER_CURRENT\fR successfully returned a CPC handle, it is still unknown if the CPC handle can work not only for CPC but also SMPL. To determine if the CPC handle can work for SMPL, \fBcpc_caps()\fR needs to be used to check \fBCPC_CAP_SMPL\fR is present in the returned capabilities. .sp .LP The system maintains a list of performance counter events supported by the underlying processor. Some processors are able to count all events on all hardware counters, while other processors restrict certain events to be counted only on specific hardware counters. The system also maintains a list of processor-specific attributes that can be used for advanced configuration of the performance counter hardware. These functions allow applications to determine what events and attributes are supported by the underlying processor. The reference work pointed to by \fBcpc_cpuref()\fR should be consulted to understand the reasons for and use of the attributes. .sp .LP The \fBcpc_walk_events_all()\fR function calls the \fIaction\fR function on each element of a global \fIevent\fR list that supports CPC. The \fIaction\fR function is called with each event supported by the processor, regardless of which counter is capable of counting it. The \fIaction\fR function is called only once for each event, even if that event can be counted on more than one counter. .sp .LP The \fBcpc_walk_events_all_common()\fR function calls the \fIaction\fR function on each element of a global \fIevent\fR list that supports the performance monitoring type specified by \fItarget\fR. The supported performance monitoring type is either \fBCPC_CPC\fR for specifying the CPC performance events or \fICPC_SMPL\fR for specifying the SMPL performance events. The \fBcpc_walk_events_all_common()\fR function with \fICPC_CPC\fR as target is equivalent to \fBcpc_walk_events_all()\fR. .sp .LP The Supported macros for \fItarget\fR are: .sp .ne 2 .mk .na \fB\fBCPC_CPC\fR\fR .ad .RS 12n .rt for specifying CPC performance monitoring type .RE .sp .ne 2 .mk .na \fB\fBCPC_SMPL\fR\fR .ad .RS 12n .rt for specifying SMPL performance monitoring type .RE .sp .LP The \fBcpc_walk_events_pic()\fR function calls the \fIaction\fR function with each CPC event supported by the counter indicated by the \fIpicno\fR argument, where \fIpicno\fR ranges from 0 to the value returned by \fBcpc_npic()\fR. .sp .LP The \fBcpc_walk_events_pic_common()\fR function calls the \fIaction\fR function with each event associated with the performance monitoring type specified by \fItarget\fR and supported by the counter indicated by \fIpicno\fR argument, where \fIpicno\fR ranges [0, value returned by \fBcpc_npic()\fR) when \fItarget\fR is \fICPC_CPC\fR, or [0, value returned by \fBcpc_smpl_npic()\fR) when \fItarget\fR is \fICPC_SMPL\fR. .sp .LP The system maintains a list of platform independent performance counter events known as generic events (see \fBgeneric_events\fR(3CPC)). .sp .LP The \fBcpc_walk_generic_events_all()\fR function calls the action function on each generic event available on the processor. The action function is called for each generic event, regardless of which counter is capable of counting it. The action function is called only once for each event, even if that event can be counted on more than one counter. .sp .LP The \fBcpc_walk_generic_events_pic()\fR function calls the action function with each generic event supported by the counter indicated by the \fIpicno\fR argument, where \fIpicno\fR ranges from 0 to the value returned by \fBcpc_npic()\fR. .sp .LP The system maintains a list of attributes that can be used to enable advanced features of the performance counters on the underlying processor. The \fBcpc_walk_attrs()\fR function calls the \fIaction\fR function for each attribute name supported for CPC. .sp .LP The \fBcpc_walk_attrs_common()\fR function calls the \fIaction\fR function for each attribute name supported for the performance monitoring type specified by \fItarget\fR. The function \fBcpc_walk_attrs_common()\fR with \fBCPC_CPC\fR as \fItarget\fR is equivalent to \fBcpc_walk_attrs()\fR. .sp .LP See the reference material as returned by \fBcpc_cpuref\fR(3CPC) for the semantics use of attributes. .sp .LP The result of the SMPL request is stored in the CPC buffers. It can be accessed as a form of SMPL record that is an array of uint64_t objects by using \fBcpc_buf_smpl_get_record()\fR and \fBcpc_buf_smpl_get_item()\fR. How many record items are contained in a SMPL record and what kind of record items are included in the SMPL record are platform dependent. The format of the SMPL record is the layout of record items within a record. The format of the SMPL record is common among any SMPL events and any SMPL performance counters on the same processor. The validity of the kind of record items included in the SMPL record are may vary depending on the type of SMPL performance counter used and the type of SMPL event that is requested. The \fBcpc_walk_smpl_recitems()\fR function is used to determine the kind of record items that are contained in the SMPL record on this processor. And, \fBcpc_walk_smpl_recitems_req()\fR function is used to determine the valid record items in the SMPL record for a certain SMPL request. .sp .LP The \fBcpc_walk_smpl_recitems()\fR function calls the \fIaction\fR function on each item in the SMPL record. \fIname\fR is the name string of the SMPL record item. \fIrecord_item_index\fR is the integer value index to refer the item in the SMPL record. .sp .LP The \fBcpc_walk_smpl_recitems_req()\fR function calls \fIaction\fR function on each item in the SMPL record supported by the SMPL request specified by \fIset\fR and \fIrequest_index_name\fR is the name string of the SMPL record item. \fIrecord_item_index\fR is the integer value index to refer the item in the SMPL record. .sp .LP The \fBcpc_get_smpl_max_rec_count()\fR function returns the maximum number of SMPL records per a request supported by the kernel for the sampling hardware on the processor into the \fBuint_t\fR object pointed to by \fImax_rec_count\fR. The request indicates that one performance monitoring request is added by \fBcpc_set_add_request()\fR. When adding a SMPL request using \fBcpc_set_add_request()\fR, the application needs to specify the number of SMPL records that should be collected for the request, using \fIsmpl_nrecs\fR attribute. The kernel limits the maximum number of SMPL records for one request that can be returned to the application at one time, depending on the underlying sampling hardware. The \fBcpc_get_smpl_max_rec_count()\fR returns the maximum number that can be specified to \fIsmpl_nrecs\fR attribute. .SH RETURN VALUES .sp .LP The \fBcpc_cciname()\fR function always returns a printable description of the processor performance counter interfaces. .sp .LP The \fBcpc_smpl_iname()\fR function always returns a printable description of the hardware sampling implementation available on the processor. .sp .LP The \fBcpc_cpuref()\fR function always returns a string that describes a reference work. .sp .LP The \fBcpc_npic()\fR function always returns the number of performance counters accessible on the processor. .sp .LP The \fBcpc_smpl_npic()\fR function always returns the number of performance counters for SMPL accessible on the processor. .sp .LP The \fBcpc_caps()\fR function always returns a bitmap containing the bitwise inclusive-OR of zero or more flags that describe the capabilities of the processor. .sp .LP If the user-defined function specified by \fIaction\fR is not called, the \fBcpc_walk_events_all()\fR, \fBcpc_walk_events_all_common()\fR, \fBcpc_walk_events_pic()\fR, \fBcpc_walk_events_pic_common()\fR, \fBcpc_walk_attrs()\fR, \fBcpc_walk_attrs_common()\fR, \fBcpc_walk_generic_events_pic()\fR, \fBcpc_walk_smpl_recitems()\fR, and \fBcpc_walk_smpl_recitems_req()\fR functions set \fBerrno\fR to indicate the error. .sp .LP The \fBcpc_get_smpl_max_rec_count()\fR sets \fBerrno\fR to \fBEINVAL\fR and returns -1 if \fIcpc\fR was not successfully opened for SMPL. Otherwise, \fBcpc_get_smpl_max_rec_count()\fR returns 0. .SH ERRORS .sp .LP The \fBcpc_walk_events_all()\fR, \fBcpc_walk_events_all_common()\fR, \fBcpc_walk_events_pic()\fR, \fBcpc_walk_events_pic_common()\fR, \fBcpc_walk_attrs()\fR, \fBcpc_walk_attrs_common()\fR, \fBcpc_walk_generic_events_pic()\fR, \fBcpc_walk_smpl_recitems()\fR, and \fBcpc_walk_smpl_recitems_req()\fR functions will fail if: .sp .ne 2 .mk .na \fB\fBENOMEM\fR\fR .ad .RS 10n .rt There is not enough memory available. .RE .sp .LP The \fBcpc_get_smpl_max_rec_count()\fR function will fail if: .sp .ne 2 .mk .na \fB\fBEINVAL\fR\fR .ad .RS 10n .rt \fICPC\fR was not successfully opened with SMPL. .RE .SH ATTRIBUTES .sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPEATTRIBUTE VALUE _ Interface StabilityCommitted _ MT-LevelSafe .TE .SH SEE ALSO .sp .LP \fBcpc_bind_curlwp\fR(3CPC), \fBgeneric_events\fR(3CPC), \fBlibcpc\fR(3LIB), \fBattributes\fR(5)