xref: /netbsd-src/external/gpl3/binutils.old/dist/gprofng/common/hwcentry.h (revision c42dbd0ed2e61fe6eda8590caa852ccf34719964)
1*c42dbd0eSchristos /* Copyright (C) 2021 Free Software Foundation, Inc.
2*c42dbd0eSchristos    Contributed by Oracle.
3*c42dbd0eSchristos 
4*c42dbd0eSchristos    This file is part of GNU Binutils.
5*c42dbd0eSchristos 
6*c42dbd0eSchristos    This program is free software; you can redistribute it and/or modify
7*c42dbd0eSchristos    it under the terms of the GNU General Public License as published by
8*c42dbd0eSchristos    the Free Software Foundation; either version 3, or (at your option)
9*c42dbd0eSchristos    any later version.
10*c42dbd0eSchristos 
11*c42dbd0eSchristos    This program is distributed in the hope that it will be useful,
12*c42dbd0eSchristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
13*c42dbd0eSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*c42dbd0eSchristos    GNU General Public License for more details.
15*c42dbd0eSchristos 
16*c42dbd0eSchristos    You should have received a copy of the GNU General Public License
17*c42dbd0eSchristos    along with this program; if not, write to the Free Software
18*c42dbd0eSchristos    Foundation, 51 Franklin Street - Fifth Floor, Boston,
19*c42dbd0eSchristos    MA 02110-1301, USA.  */
20*c42dbd0eSchristos 
21*c42dbd0eSchristos #ifndef _HWCENTRY_H
22*c42dbd0eSchristos #define _HWCENTRY_H
23*c42dbd0eSchristos 
24*c42dbd0eSchristos #ifndef LIBCOLLECTOR_SRC /* not running in libcollector */
25*c42dbd0eSchristos #include <stdio.h>  /* FILE */
26*c42dbd0eSchristos #endif  /* --- LIBCOLLECTOR_SRC --- */
27*c42dbd0eSchristos #include <stdlib.h> /* size_t */
28*c42dbd0eSchristos #include "hwc_cpus.h"
29*c42dbd0eSchristos #include "gp-time.h"
30*c42dbd0eSchristos 
31*c42dbd0eSchristos #ifdef __cplusplus
32*c42dbd0eSchristos extern "C"
33*c42dbd0eSchristos {
34*c42dbd0eSchristos #endif
35*c42dbd0eSchristos 
36*c42dbd0eSchristos   /* ABS backtrack types */
37*c42dbd0eSchristos   typedef enum
38*c42dbd0eSchristos   {
39*c42dbd0eSchristos     /* !! Lowest 2 bits are used to indicate load and store, respectively !! */
40*c42dbd0eSchristos     /* Example: On SPARC, backtrack.c did this: if (ABS_memop & inst_type) ... */
41*c42dbd0eSchristos     ABST_NONE               = 0x0,
42*c42dbd0eSchristos     ABST_LOAD               = 0x1,
43*c42dbd0eSchristos     ABST_STORE              = 0x2,
44*c42dbd0eSchristos     ABST_LDST               = 0x3,
45*c42dbd0eSchristos     ABST_COUNT              = 0x4,
46*c42dbd0eSchristos     ABST_US_DTLBM           = 0xF,
47*c42dbd0eSchristos     ABST_NOPC               = 0x100,
48*c42dbd0eSchristos     ABST_CLKDS              = 0x103,     // Obsolete
49*c42dbd0eSchristos     ABST_EXACT              = 0x203,
50*c42dbd0eSchristos     ABST_LDST_SPARC64       = 0x303,
51*c42dbd0eSchristos     ABST_EXACT_PEBS_PLUS1   = 0x403
52*c42dbd0eSchristos     /* full description below... */
53*c42dbd0eSchristos   } ABST_type;
54*c42dbd0eSchristos 
55*c42dbd0eSchristos #define ABST_PLUS_BY_DEFAULT(n) ((n)==ABST_EXACT || (n)==ABST_EXACT_PEBS_PLUS1)
56*c42dbd0eSchristos #define ABST_BACKTRACK_ENABLED(n) ((n)!=ABST_NONE && (n)!=ABST_NOPC)
57*c42dbd0eSchristos #define ABST_MEMSPACE_ENABLED(n)  ((n)!=ABST_NONE && (n)!=ABST_NOPC && (n)!=ABST_COUNT)
58*c42dbd0eSchristos 
59*c42dbd0eSchristos   /* ABS determines the type of backtracking available for a particular metric.
60*c42dbd0eSchristos    * Backtracking is enabled with the "+" in "-h +<countername>...".
61*c42dbd0eSchristos    *
62*c42dbd0eSchristos    * When Backtracking is not possible:
63*c42dbd0eSchristos    *
64*c42dbd0eSchristos    *  ABST_NONE=0:     Either the user did not specify "+", or backtracking
65*c42dbd0eSchristos    *                   is not applicable to the metric, for example:
66*c42dbd0eSchristos    *                     clk cycles,
67*c42dbd0eSchristos    *                     instruct counts (dispatch + branch + prefetch),
68*c42dbd0eSchristos    *                     i$,
69*c42dbd0eSchristos    *                     FP ops
70*c42dbd0eSchristos    *  ABST_NOPC=0x100  Used for non-program-related external events, for example:
71*c42dbd0eSchristos    *                     system interface events,
72*c42dbd0eSchristos    *                     memory controller counters
73*c42dbd0eSchristos    *                   Of all ABST_type options, only ABST_NOPC prevents hwprofile.c
74*c42dbd0eSchristos    *                     from recording PC/stack information.
75*c42dbd0eSchristos    *
76*c42dbd0eSchristos    * When backtracking is allowed:
77*c42dbd0eSchristos    *
78*c42dbd0eSchristos    *  ABST_LOAD=1:     data read events, used with metrics like:
79*c42dbd0eSchristos    *                     D$, E$, P$ read misses and hits.
80*c42dbd0eSchristos    *                     [DC+EC+PC]_rd*, Re_*_miss*,
81*c42dbd0eSchristos    *                     EC_snoop_cb(?)
82*c42dbd0eSchristos    *  ABST_STORE=2:    data write events, used with metrics like:
83*c42dbd0eSchristos    *                     D$ writes and write related misses
84*c42dbd0eSchristos    *                     DC_wr/wr-miss, EC_wb, WC=writecache, Rstall_storeQ
85*c42dbd0eSchristos    *                     [EC+PC=pcache]_snoop_inv(?), WC_snoop_cb(?),
86*c42dbd0eSchristos    *  ABST_LDST=3:     data reads/writes, used with metrics like:
87*c42dbd0eSchristos    *                     E$ references, misses.
88*c42dbd0eSchristos    *  ABST_COUNT=4:    dedicated assembly instruction: '%hi(0xfc000)'
89*c42dbd0eSchristos    *                     See SW_count_n metric on sparc.
90*c42dbd0eSchristos    *  ABST_US_DTLBM=0xF: for load-store on Sparc -- seems to be used only
91*c42dbd0eSchristos    *                     for "unskidded DTLB_miss" with DTLB_miss metric.
92*c42dbd0eSchristos    *                     Checks two adjacent instructions for Data access.
93*c42dbd0eSchristos    *  ABST_CLKDS=0x103: data reads/writes, used with Clock-based Dataspace
94*c42dbd0eSchristos    *                     profiling.  Ultrasparc T2 and earlier.
95*c42dbd0eSchristos    *  ABST_EXACT=0x203: data reads/writes, precise trap with no skid
96*c42dbd0eSchristos    *  ABST_LDST_SPARC64=0x303: Fujitsu SPARC64 load/store
97*c42dbd0eSchristos    *  ABST_EXACT_PEBS_PLUS1=0x403: data reads/writes, precise sampling with 1 instr. skid
98*c42dbd0eSchristos    */
99*c42dbd0eSchristos 
100*c42dbd0eSchristos   /* Hwcentry - structure for defining a counter.
101*c42dbd0eSchristos    *   Some fields have different usage when returned from
102*c42dbd0eSchristos    *   hwc_lookup(), hwc_post_lookup(), or hwc_scan_*().
103*c42dbd0eSchristos    *   Each function will describe its return values in more detail.
104*c42dbd0eSchristos    */
105*c42dbd0eSchristos   typedef struct
106*c42dbd0eSchristos   {
107*c42dbd0eSchristos     char *name;         /* user HWC specification */
108*c42dbd0eSchristos     char *int_name;     /* internal HWC specification */
109*c42dbd0eSchristos     regno_t reg_num;    /* register in CPU, aka picnum, or REGNO_ANY */
110*c42dbd0eSchristos     char *metric;       /* descriptive name, for well-known counters only */
111*c42dbd0eSchristos     volatile int val;   /* default or actual overflow value */
112*c42dbd0eSchristos     int timecvt;        /* multiplier to convert metric to time, 0 if N/A */
113*c42dbd0eSchristos     ABST_type memop;    /* type of backtracking allowed */
114*c42dbd0eSchristos     char *short_desc;   /* optional one-liner description, or NULL */
115*c42dbd0eSchristos     int type;           /* Type of perf_event_attr */
116*c42dbd0eSchristos     long long config;   /* perf_event_type -specific configuration */
117*c42dbd0eSchristos     /* the fields above this line are expected, in order, by the tables in hwctable.c */
118*c42dbd0eSchristos     /* ================================================== */
119*c42dbd0eSchristos     /* the fields below this line are more flexible */
120*c42dbd0eSchristos     int sort_order;     /* "tag" to associate experiment record with HWC def */
121*c42dbd0eSchristos     regno_t *reg_list;  /* if not NULL, legal values for <reg_num> field above */
122*c42dbd0eSchristos     /* Note: reg_list will be terminated by REGNO_ANY */
123*c42dbd0eSchristos     /* Max size of array is MAX_PICS */
124*c42dbd0eSchristos     hrtime_t min_time;  /* target minimum time between overflow events.  0 is off.  See HWCTIME_* macros */
125*c42dbd0eSchristos     hrtime_t min_time_default; /* if min_time==HWCTIME_AUTO, use this value instead.  0 is off. */
126*c42dbd0eSchristos     int ref_val;    /* if min_time==HWCTIME_AUTO, use this time.  0 is off. */
127*c42dbd0eSchristos     int lval, hval; /* temporary to allow DBX to build until dbx glue.cc fixed */
128*c42dbd0eSchristos   } Hwcentry;
129*c42dbd0eSchristos 
130*c42dbd0eSchristos   // Hwcentry.min_time canned values
131*c42dbd0eSchristos #define HWCTIME_TBD ((hrtime_t)( -1LL)) /* self-adjusting enabled but nsecs not yet selected */
132*c42dbd0eSchristos #define HWCTIME_HI  (   1 * 1000 * 1000LL ) /*   1 msec represented in nsecs */
133*c42dbd0eSchristos #define HWCTIME_ON  (  10 * 1000 * 1000LL ) /*  10 msec represented in nsecs */
134*c42dbd0eSchristos #define HWCTIME_LO  ( 100 * 1000 * 1000LL ) /* 100 msec represented in nsecs */
135*c42dbd0eSchristos 
136*c42dbd0eSchristos #define HWC_VAL_HI(refVal) (((refVal)/10) + 1)
137*c42dbd0eSchristos #define HWC_VAL_ON(refVal) (refVal)
138*c42dbd0eSchristos #define HWC_VAL_LO(refVal) (((refVal)*10)/100*100 + 1)  // zero's out lower digits, add 1
139*c42dbd0eSchristos #define HWC_VAL_CUSTOM(refVal, targetNanoSec) ((double)(refVal)*(targetNanoSec)/HWCTIME_ON)
140*c42dbd0eSchristos 
141*c42dbd0eSchristos #define HWCENTRY_USES_SAMPLING(h)   ((h)->memop==ABST_EXACT_PEBS_PLUS1)
142*c42dbd0eSchristos 
143*c42dbd0eSchristos   extern int hwc_lookup (int forKernel, hrtime_t min_time_default,
144*c42dbd0eSchristos 			 const char *uname, Hwcentry *list[], unsigned listsz,
145*c42dbd0eSchristos 			 char **emsg, char **wmsg);
146*c42dbd0eSchristos   /* Parses counter cmdline string.  Returns counter definitions.
147*c42dbd0eSchristos    * Input:
148*c42dbd0eSchristos    *   <forKernel> lookup using which table: 0-collect or 1-er_kernel
149*c42dbd0eSchristos    *   <min_time_default> minimum nseconds between events if Hwcentry.min_time == HWCTIME_TBD.  0 to disable.
150*c42dbd0eSchristos    *   <uname> command line HWC definition of format:
151*c42dbd0eSchristos    *           <ctr_def>...[{','|(whitespace)}<ctr_n_def>] where
152*c42dbd0eSchristos    *           <ctr_def> == [+]<ctr>[/<reg#>][,<interval>]
153*c42dbd0eSchristos    *   <list> array of pointers to store counter definitions
154*c42dbd0eSchristos    *   <listsz> number of elements in <list>
155*c42dbd0eSchristos    * Returns:
156*c42dbd0eSchristos    *   Success:
157*c42dbd0eSchristos    *     Returns number of valid counters in <list> and <list>'s elements
158*c42dbd0eSchristos    *     will be initialized as follows:
159*c42dbd0eSchristos    *
160*c42dbd0eSchristos    *     <list[]->name>:
161*c42dbd0eSchristos    *       Copy of the <uname> with the following modification:
162*c42dbd0eSchristos    *         if backtracking is not supported, the + will be removed.
163*c42dbd0eSchristos    *     <list[]->int_name>:
164*c42dbd0eSchristos    *       For well-known and convenience ctrs, the internal HWC specification,
165*c42dbd0eSchristos    *         e.g. BSQ_cache_reference~emask=0x0100.
166*c42dbd0eSchristos    *       For raw ctrs, this will be a copy of <name>.
167*c42dbd0eSchristos    *     <list[]->reg_num>:
168*c42dbd0eSchristos    *       Register number if specified by user or table, REGNO_ANY otherwise.
169*c42dbd0eSchristos    *     <list[]->metric>:
170*c42dbd0eSchristos    *       For well-known counters, descriptive name, e.g. "D$ Read Misses".
171*c42dbd0eSchristos    *       NULL otherwise.
172*c42dbd0eSchristos    *     <list[]->val>:
173*c42dbd0eSchristos    *       Overflow value selected by user, default value otherwise.
174*c42dbd0eSchristos    *     <list[]->timecvt>:
175*c42dbd0eSchristos    *       Value from tables.
176*c42dbd0eSchristos    *     <list[]->memop>:
177*c42dbd0eSchristos    *       If + is selected and backtracking is allowed, value from table.
178*c42dbd0eSchristos    *       ABST_NONE or ABST_NOPC otherwise.
179*c42dbd0eSchristos    *
180*c42dbd0eSchristos    *     It is the responsibility of the caller to free 'name' and 'int_name'.
181*c42dbd0eSchristos    *     'metric' is a static string and shouldn't be freed.
182*c42dbd0eSchristos    *     'emsg' will point to NULL
183*c42dbd0eSchristos    *
184*c42dbd0eSchristos    *   Failure:
185*c42dbd0eSchristos    *     Frees all allocated elements.
186*c42dbd0eSchristos    *     emsg will point to a string with an error message to print
187*c42dbd0eSchristos    *     returns -1
188*c42dbd0eSchristos    */
189*c42dbd0eSchristos 
190*c42dbd0eSchristos   extern char *hwc_validate_ctrs (int forKernel, Hwcentry *list[], unsigned listsz);
191*c42dbd0eSchristos   /* Validates that the vector of specified HW counters can be loaded (more-or-less)
192*c42dbd0eSchristos    *   Some invalid combinations, especially on Linux will not be detected
193*c42dbd0eSchristos    */
194*c42dbd0eSchristos 
195*c42dbd0eSchristos   extern int hwc_get_cpc_cpuver ();
196*c42dbd0eSchristos   /* Return the cpc_cpuver for this system.  Other possible values:
197*c42dbd0eSchristos    *   CPUVER_GENERIC=0,           CPU could not be determined, but HWCs are ok.
198*c42dbd0eSchristos    *   CPUVER_UNDEFINED=-1,        HWCs are not available.
199*c42dbd0eSchristos    */
200*c42dbd0eSchristos 
201*c42dbd0eSchristos   extern char *hwc_get_docref (char *buf, size_t buflen);
202*c42dbd0eSchristos   /* Return a CPU HWC document reference, or NULL. */
203*c42dbd0eSchristos 
204*c42dbd0eSchristos   // TBR
205*c42dbd0eSchristos   extern char *hwc_get_default_cntrs ();
206*c42dbd0eSchristos   /* Return a default HW counter string; may be NULL, or zero-length */
207*c42dbd0eSchristos   /* NULL means none is defined in the table; or zero-length means string defined could not be loaded */
208*c42dbd0eSchristos 
209*c42dbd0eSchristos   extern char *hwc_get_default_cntrs2 (int forKernel, int style);
210*c42dbd0eSchristos   /* like hwc_get_default_cntrs() for style==1 */
211*c42dbd0eSchristos   /* but allows other styles of formatting as well */
212*c42dbd0eSchristos   /* deprecate and eventually remove hwc_get_default_cntrs() */
213*c42dbd0eSchristos 
214*c42dbd0eSchristos   extern char *hwc_get_orig_default_cntrs ();
215*c42dbd0eSchristos   /* Get the default HW counter string as set in the table */
216*c42dbd0eSchristos   /* NULL means none is defined in the table */
217*c42dbd0eSchristos 
218*c42dbd0eSchristos   extern void hwc_update_val (Hwcentry *ctr);
219*c42dbd0eSchristos   /* Check time-based intervals and update Hwcentry.val as needed */
220*c42dbd0eSchristos 
221*c42dbd0eSchristos   extern char *hwc_get_cpuname (char *buf, size_t buflen);
222*c42dbd0eSchristos   /* Return the cpc cpu name for this system, or NULL. */
223*c42dbd0eSchristos 
224*c42dbd0eSchristos   extern unsigned hwc_get_max_regs ();
225*c42dbd0eSchristos   /* Return number of counters registers for this system. */
226*c42dbd0eSchristos 
227*c42dbd0eSchristos   extern unsigned hwc_get_max_concurrent (int forKernel);
228*c42dbd0eSchristos   /* Return the max number of simultaneous counters for this system. */
229*c42dbd0eSchristos 
230*c42dbd0eSchristos   extern char **hwc_get_attrs (int forKernel);
231*c42dbd0eSchristos   /* Return:
232*c42dbd0eSchristos    *   Array of attributes (strings) supported by this system.
233*c42dbd0eSchristos    *   Last element in array is null.
234*c42dbd0eSchristos    *   Array and its elements should NOT be freed by the caller.
235*c42dbd0eSchristos    */
236*c42dbd0eSchristos 
237*c42dbd0eSchristos   extern unsigned hwc_scan_attrs (void (*action)(const char *attr,
238*c42dbd0eSchristos 						 const char *desc));
239*c42dbd0eSchristos   /* Scan the HW counter attributes, and call function for each attribute.
240*c42dbd0eSchristos    * Input:
241*c42dbd0eSchristos    *   <action>:
242*c42dbd0eSchristos    *     If NULL, no action is performed, but count is still returned.
243*c42dbd0eSchristos    *     Otherwise called for each type of attributes, or if none exist,
244*c42dbd0eSchristos    *       called once with NULL parameter.
245*c42dbd0eSchristos    * Return: count of times <action> would have been called w/ non-NULL data.
246*c42dbd0eSchristos    */
247*c42dbd0eSchristos 
248*c42dbd0eSchristos   extern Hwcentry *hwc_post_lookup (Hwcentry * pret_ctr, char *uname,
249*c42dbd0eSchristos 				    char * int_name, int cpc_cpuver);
250*c42dbd0eSchristos   /* When post-processing a run, look up a Hwcentry for given type of system.
251*c42dbd0eSchristos    * Input:
252*c42dbd0eSchristos    *   <pret_ctr>: storage for counter definition
253*c42dbd0eSchristos    *   <uname>: well-known name, convenience name, or complete HWC defintion.
254*c42dbd0eSchristos    *   <int_name>: Hwcentry->int_name or NULL for don't care
255*c42dbd0eSchristos    *   <cpc_cpuver>: version of cpu used for experiment.
256*c42dbd0eSchristos    * Return:
257*c42dbd0eSchristos    *   <pret_ctr>'s elements set as follows:
258*c42dbd0eSchristos    *
259*c42dbd0eSchristos    *     <pret_ctr->name>:
260*c42dbd0eSchristos    *       Copy of <uname> with the following modifications:
261*c42dbd0eSchristos    *         1) + and /<regnum> will be stripped off
262*c42dbd0eSchristos    *         2) attributes will be sorted and values will shown in hex.
263*c42dbd0eSchristos    *     <pret_ctr->int_name>:
264*c42dbd0eSchristos    *       For well-known/convenience counters, the internal HWC specification
265*c42dbd0eSchristos    *         from the table, e.g. BSQ_cache_reference~emask=0x0100.
266*c42dbd0eSchristos    *       Otherwise, a copy of <uname>.
267*c42dbd0eSchristos    *     <pret_ctr->reg_num>:
268*c42dbd0eSchristos    *       Register number if specified by user or table,
269*c42dbd0eSchristos    *       REGNO_ANY othewise.
270*c42dbd0eSchristos    *     <pret_ctr->metric>:
271*c42dbd0eSchristos    *       For well-known counters, descriptive name, e.g. "D$ Read Misses".
272*c42dbd0eSchristos    *       NULL otherwise.
273*c42dbd0eSchristos    *     <pret_ctr->timecvt>:
274*c42dbd0eSchristos    *       For well-known/convenience/hidden counters, value from table.
275*c42dbd0eSchristos    *       0 otherwise.
276*c42dbd0eSchristos    *     <pret_ctr->memop>:
277*c42dbd0eSchristos    *       For well-known/convenience/hidden counters, value from table.
278*c42dbd0eSchristos    *       ABST_NONE otherwise.
279*c42dbd0eSchristos    *     <pret_ctr->sort_order>:
280*c42dbd0eSchristos    *       Set to 0.
281*c42dbd0eSchristos    *
282*c42dbd0eSchristos    *     It is the responsibility of the caller to free 'name' and 'int_name'.
283*c42dbd0eSchristos    *     'metric' is a static string and shouldn't be freed.
284*c42dbd0eSchristos    */
285*c42dbd0eSchristos 
286*c42dbd0eSchristos   extern Hwcentry **hwc_get_std_ctrs (int forKernel);
287*c42dbd0eSchristos   /* Return:
288*c42dbd0eSchristos    *   Array of well-known counters supported by this system.
289*c42dbd0eSchristos    *   Last element in array will be NULL.
290*c42dbd0eSchristos    *   Array and its elements should NOT be freed by the caller.
291*c42dbd0eSchristos    */
292*c42dbd0eSchristos 
293*c42dbd0eSchristos   extern unsigned hwc_scan_std_ctrs (void (*action)(const Hwcentry *));
294*c42dbd0eSchristos   /* Call <action> for each well-known counter.
295*c42dbd0eSchristos    * Input:
296*c42dbd0eSchristos    *   <action>:
297*c42dbd0eSchristos    *     If NULL, no action is performed, but count is still returned.
298*c42dbd0eSchristos    *     Otherwise called for each type of attributes, or if none exist,
299*c42dbd0eSchristos    *       called once with NULL parameter.
300*c42dbd0eSchristos    * Return:
301*c42dbd0eSchristos    *   Count of times <action> would have been called w/ non-NULL data.
302*c42dbd0eSchristos    *   If <action> is not NULL, Hwcentry fields will be set as follows:
303*c42dbd0eSchristos    *     <ctr->name>:
304*c42dbd0eSchristos    *       HWC alias name, e.g. dcrm.
305*c42dbd0eSchristos    *     <ctr->int_name>:
306*c42dbd0eSchristos    *       The internal HWC specification, e.g. BSQ_cache_reference~emask=0x0100.
307*c42dbd0eSchristos    *     <ctr->reg_num>:
308*c42dbd0eSchristos    *       Register number if specified by the table, REGNO_ANY otherwise.
309*c42dbd0eSchristos    *     <ctr->metric>:
310*c42dbd0eSchristos    *       Descriptive name, e.g. "D$ Read Misses".
311*c42dbd0eSchristos    *     <ctr->lval>:
312*c42dbd0eSchristos    *       Low-resolution overflow value.
313*c42dbd0eSchristos    *     <ctr->val>:
314*c42dbd0eSchristos    *       Default overflow value.
315*c42dbd0eSchristos    *     <ctr->hval>:
316*c42dbd0eSchristos    *       High-resolution overflow value.
317*c42dbd0eSchristos    *     <ctr->timecvt>:
318*c42dbd0eSchristos    *       multiplier to convert metric to time, 0 otherwise.
319*c42dbd0eSchristos    *     <ctr->memop>:
320*c42dbd0eSchristos    *       ABST_* type for this counter.
321*c42dbd0eSchristos    *     <ctr->reg_list>:
322*c42dbd0eSchristos    *       Array of legal <reg_num> values.  Terminated by REGNO_ANY.
323*c42dbd0eSchristos    *
324*c42dbd0eSchristos    *     Note: All fields point to static data, none should be freed.
325*c42dbd0eSchristos    */
326*c42dbd0eSchristos 
327*c42dbd0eSchristos   extern Hwcentry **hwc_get_raw_ctrs (int forKernel);
328*c42dbd0eSchristos   /* Return:
329*c42dbd0eSchristos    *   Table of raw (not well-known) counters supported by this system.
330*c42dbd0eSchristos    *   Last element in array will be NULL.
331*c42dbd0eSchristos    *   Table and its elements should NOT be freed by the caller.
332*c42dbd0eSchristos    */
333*c42dbd0eSchristos 
334*c42dbd0eSchristos   extern unsigned hwc_scan_raw_ctrs (void (*action)(const Hwcentry *));
335*c42dbd0eSchristos   /* Call <action> for each raw counter.
336*c42dbd0eSchristos    * Input:
337*c42dbd0eSchristos    *   <action>:
338*c42dbd0eSchristos    *     If NULL, no action is performed, but count is still returned.
339*c42dbd0eSchristos    *     Otherwise called for each type of attributes, or if none exist,
340*c42dbd0eSchristos    *       called once with NULL parameter.
341*c42dbd0eSchristos    * Return:
342*c42dbd0eSchristos    *   Count of times <action> would have been called w/ non-NULL data.
343*c42dbd0eSchristos    *   If <action> is not NULL, Hwcentry fields will be set as follows:
344*c42dbd0eSchristos    *     <ctr->name>:
345*c42dbd0eSchristos    *       HWC raw name without attributes, e.g. BSQ_cache_reference.
346*c42dbd0eSchristos    *     <ctr->int_name>:
347*c42dbd0eSchristos    *       NULL.
348*c42dbd0eSchristos    *     <ctr->metric>:
349*c42dbd0eSchristos    *       NULL.
350*c42dbd0eSchristos    *     The remainder of the fields are the same as for
351*c42dbd0eSchristos    *       hwc_scan_std_ctrs().
352*c42dbd0eSchristos    *
353*c42dbd0eSchristos    *     Note: All fields point to static data, none should be freed.
354*c42dbd0eSchristos    */
355*c42dbd0eSchristos 
356*c42dbd0eSchristos   extern void
357*c42dbd0eSchristos   hwc_usage (int forKernel, const char *cmd, const char *dataspace_msg);
358*c42dbd0eSchristos   /* Print an i18n'd description of "-h" usage, used by collect and er_kernel.
359*c42dbd0eSchristos    */
360*c42dbd0eSchristos 
361*c42dbd0eSchristos   extern void hwc_usage_f (int forKernel, FILE *f, const char *cmd,
362*c42dbd0eSchristos 			   const char *dataspace_msg, int show_syntax,
363*c42dbd0eSchristos 			   int show_short_desc);
364*c42dbd0eSchristos   /* Print an i18n'd description of "-h" usage to a FILE.  Used by GUI. */
365*c42dbd0eSchristos 
366*c42dbd0eSchristos   extern char *hwc_rate_string (const Hwcentry *pctr, int force_numeric_format);
367*c42dbd0eSchristos   /* Returns {"on"|"hi"|"lo"|""|<value>}.  Return value must be freed by caller. */
368*c42dbd0eSchristos 
369*c42dbd0eSchristos   extern char *hwc_i18n_metric (const Hwcentry *ctr);
370*c42dbd0eSchristos   /* Get a basic lable for a counter, properly i18n'd.
371*c42dbd0eSchristos    *   Note: NOT MT SAFE.
372*c42dbd0eSchristos    * Examples:
373*c42dbd0eSchristos    *   CPU Cycles
374*c42dbd0eSchristos    *   DC_rd Events
375*c42dbd0eSchristos    * Pseudocode:
376*c42dbd0eSchristos    *   if(ctr->metric != NULL) {
377*c42dbd0eSchristos    *	    sprintf(metricbuf, PTXT(ctr->metric) );
378*c42dbd0eSchristos    *   } else if (ctr->name != NULL) {
379*c42dbd0eSchristos    *	    sprintf(metricbuf, GTXT("%s Events"), ctr->name );
380*c42dbd0eSchristos    *   } else if (ctr->int_name != NULL) {
381*c42dbd0eSchristos    *	    sprintf(metricbuf, GTXT("%s Events"), ctr->int_name );
382*c42dbd0eSchristos    *   }
383*c42dbd0eSchristos    * Return: pointer to a buffer containing the above description.
384*c42dbd0eSchristos    */
385*c42dbd0eSchristos 
386*c42dbd0eSchristos   extern char *hwc_hwcentry_string (char *buf, size_t buflen, const Hwcentry *ctr);
387*c42dbd0eSchristos   /* Get a i18n'd description of a HW counter's options.
388*c42dbd0eSchristos    *   Examples of well-known counters:
389*c42dbd0eSchristos    *     cycles[/{0|1}],9999991 ('CPU Cycles', alias for Cycle_cnt; CPU-cycles)
390*c42dbd0eSchristos    *     dcr[/0],1000003 ('D$ Read Refs', alias for DC_rd; load events)
391*c42dbd0eSchristos    *   Examples of raw counters:
392*c42dbd0eSchristos    *     Cycle_cnt[/{0|1}],1000003 (CPU-cycles)
393*c42dbd0eSchristos    *     DC_rd[/0],1000003 (load events)
394*c42dbd0eSchristos    * Return: <buf>, filled in.
395*c42dbd0eSchristos    */
396*c42dbd0eSchristos 
397*c42dbd0eSchristos   extern char *hwc_hwcentry_specd_string (char *buf, size_t buflen, const Hwcentry *ctr);
398*c42dbd0eSchristos   /* Get a i18n'd description of a HW counter's specific configuration.
399*c42dbd0eSchristos    *   Examples of well-known counters:
400*c42dbd0eSchristos    *     cycles,9999991 ('CPU Cycles')
401*c42dbd0eSchristos    *     +dcr/0,1000003 ('D$ Read Refs')
402*c42dbd0eSchristos    *   Examples of raw counters:
403*c42dbd0eSchristos    *     Cycle_cnt,1000003
404*c42dbd0eSchristos    *     +DC_rd/0,1000003
405*c42dbd0eSchristos    * Return: <buf>, filled in.
406*c42dbd0eSchristos    */
407*c42dbd0eSchristos 
408*c42dbd0eSchristos   extern const char *hwc_memop_string (ABST_type memop);
409*c42dbd0eSchristos   /* Get a i18n'd description of a variable of type ABST_type.
410*c42dbd0eSchristos    * Return: pointer to static string.
411*c42dbd0eSchristos    */
412*c42dbd0eSchristos 
413*c42dbd0eSchristos #ifdef __cplusplus
414*c42dbd0eSchristos }
415*c42dbd0eSchristos #endif
416*c42dbd0eSchristos 
417*c42dbd0eSchristos #endif
418