|
Packit |
577717 |
.TH LIBPFM 3 "April, 2008" "" "Linux Programmer's Manual"
|
|
Packit |
577717 |
.SH NAME
|
|
Packit |
577717 |
libpfm_amd64 - support for AMD64 processors
|
|
Packit |
577717 |
.SH SYNOPSIS
|
|
Packit |
577717 |
.nf
|
|
Packit |
577717 |
.B #include <perfmon/pfmlib.h>
|
|
Packit |
577717 |
.B #include <perfmon/pfmlib_amd64.h>
|
|
Packit |
577717 |
.sp
|
|
Packit |
577717 |
.SH DESCRIPTION
|
|
Packit |
577717 |
The libpfm library provides full support for the AMD64 processor
|
|
Packit |
577717 |
families 0Fh and 10H (K8, Barcelona, Phenom) when running in either
|
|
Packit |
577717 |
32-bit or 64-bit mode. The interface is defined in
|
|
Packit |
577717 |
\fBpfmlib_amd64.h\fR. It consists of a set of functions and structures
|
|
Packit |
577717 |
which describe and allow access to the AMD64 specific PMU
|
|
Packit |
577717 |
features. Note that it only supports AMD processors.
|
|
Packit |
577717 |
.sp
|
|
Packit |
577717 |
When AMD64 processor-specific features are needed to support a
|
|
Packit |
577717 |
measurement, their descriptions must be passed as model-specific input
|
|
Packit |
577717 |
arguments to the \fBpfm_dispatch_events()\fR function. The AMD64
|
|
Packit |
577717 |
processor-specific input arguments are described in the
|
|
Packit |
577717 |
\fBpfmlib_amd64_input_param_t\fR structure and the output parameters
|
|
Packit |
577717 |
in \fBpfmlib_amd64_output_param_t\fR. They are defined as follows:
|
|
Packit |
577717 |
.sp
|
|
Packit |
577717 |
.nf
|
|
Packit |
577717 |
typedef struct {
|
|
Packit |
577717 |
uint32_t cnt_mask;
|
|
Packit |
577717 |
uint32_t flags;
|
|
Packit |
577717 |
} pfmlib_amd64_counter_t;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
typedef struct {
|
|
Packit |
577717 |
unsigned int maxcnt;
|
|
Packit |
577717 |
unsigned int options;
|
|
Packit |
577717 |
} ibs_param_t;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
typedef struct {
|
|
Packit |
577717 |
pfmlib_amd64_counter_t pfp_amd64_counters[PMU_AMD64_MAX_COUNTERS];
|
|
Packit |
577717 |
uint32_t flags;
|
|
Packit |
577717 |
uint32_t reserved1;
|
|
Packit |
577717 |
ibs_param_t ibsfetch;
|
|
Packit |
577717 |
ibs_param_t ibsop;
|
|
Packit |
577717 |
uint64_t reserved2;
|
|
Packit |
577717 |
} pfmlib_amd64_input_param_t;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
typedef struct {
|
|
Packit |
577717 |
uint32_t ibsfetch_base;
|
|
Packit |
577717 |
uint32_t ibsop_base;
|
|
Packit |
577717 |
uint64_t reserved[7];
|
|
Packit |
577717 |
} pfmlib_amd64_output_param_t;
|
|
Packit |
577717 |
.fi
|
|
Packit |
577717 |
.LP
|
|
Packit |
577717 |
The \fBflags\fR field of \fBpfmlib_amd64_input_param_t\fR describes
|
|
Packit |
577717 |
which features of the PMU to use. Following use flags exist:
|
|
Packit |
577717 |
.TP
|
|
Packit |
577717 |
.B PFMLIB_AMD64_USE_IBSFETCH
|
|
Packit |
577717 |
Profile IBS fetch performance (see below under \fBINSTRUCTION BASED
|
|
Packit |
577717 |
SAMPLING\fR)
|
|
Packit |
577717 |
.TP
|
|
Packit |
577717 |
.B PFMLIB_AMD64_USE_IBSOP
|
|
Packit |
577717 |
Profile IBS execution performance (see below under \fBINSTRUCTION BASED
|
|
Packit |
577717 |
SAMPLING\fR)
|
|
Packit |
577717 |
.LP
|
|
Packit |
577717 |
Multiple features can be selected. Note that there are no use flags
|
|
Packit |
577717 |
needed for \fBADDITIONAL PER-EVENT FEATURES\fR.
|
|
Packit |
577717 |
.LP
|
|
Packit |
577717 |
Various typedefs for MSR encoding and decoding are available. See
|
|
Packit |
577717 |
\fBpfmlib_amd64.h\fR for details.
|
|
Packit |
577717 |
.SS ADDITIONAL PER-EVENT FEATURES
|
|
Packit |
577717 |
AMD64 processors provide a few additional per-event features for
|
|
Packit |
577717 |
counters: thresholding, inversion, edge detection,
|
|
Packit |
577717 |
virtualization. They can be set using the \fBpfp_amd64_counters\fR
|
|
Packit |
577717 |
data structure for each event. The \fBflags\fR field of
|
|
Packit |
577717 |
\fBpfmlib_amd64_counter_t\fR can be initialized as follows:
|
|
Packit |
577717 |
.TP
|
|
Packit |
577717 |
.B PFMLIB_AMD64_SEL_INV
|
|
Packit |
577717 |
Inverse the results of the \fBcnt_mask\fR comparison when set
|
|
Packit |
577717 |
.TP
|
|
Packit |
577717 |
.B PFMLIB_AMD64_SEL_EDGE
|
|
Packit |
577717 |
Enables edge detection of events.
|
|
Packit |
577717 |
.TP
|
|
Packit |
577717 |
.B PFMLIB_AMD64_SEL_GUEST
|
|
Packit |
577717 |
On AMD64 Family 10h processors only. Event is only measured when
|
|
Packit |
577717 |
processor is in guest mode.
|
|
Packit |
577717 |
.TP
|
|
Packit |
577717 |
.B PFMLIB_AMD64_SEL_HOST
|
|
Packit |
577717 |
On AMD64 Family 10h processors only. Event is only measured when
|
|
Packit |
577717 |
processor is in host mode.
|
|
Packit |
577717 |
.LP
|
|
Packit |
577717 |
The \fBcnt_mask\fR field is used to set the event threshold. The
|
|
Packit |
577717 |
value of the counter is incremented each time the number of
|
|
Packit |
577717 |
occurrences per cycle of the event is greater or equal to the value of
|
|
Packit |
577717 |
the field. When zero all occurrences are counted.
|
|
Packit |
577717 |
.SS INSTRUCTION BASED SAMPLING (IBS)
|
|
Packit |
577717 |
The libpfm_amd64 provides access to the model specific feature
|
|
Packit |
577717 |
Instruction Based Sampling (IBS). IBS has been introduced with family
|
|
Packit |
577717 |
10h.
|
|
Packit |
577717 |
.LP
|
|
Packit |
577717 |
The IBS setup is using the structures \fBpfmlib_amd64_input_param_t\fR
|
|
Packit |
577717 |
and \fBpfmlib_amd64_output_param_t\fR with its members \fBflags\fR,
|
|
Packit |
577717 |
\fBibsfetch\fR, \fBibsop\fR, \fBibsfetch_base\fR,
|
|
Packit |
577717 |
\fBibsop_base\fR. The input arguments \fBibsop\fR and \fBibsfetch\fR
|
|
Packit |
577717 |
can be set in inp_mod (type \fBpfmlib_amd64_input_param_t\fR). The
|
|
Packit |
577717 |
corresponding \fBflags\fR must be set to enable a feature.
|
|
Packit |
577717 |
.LP
|
|
Packit |
577717 |
Both, IBS execution profiling and IBS fetch profiling, require a
|
|
Packit |
577717 |
maximum count value of the periodic counter (\fBmaxcnt\fR) as
|
|
Packit |
577717 |
parameter. This is a 20 bit value, bits 3:0 are always set to
|
|
Packit |
577717 |
zero. Additionally, there is an option (\fBoptions\fR) to enable
|
|
Packit |
577717 |
randomization (\fBIBS_OPTIONS_RANDEN\fR) for IBS fetch profiling.
|
|
Packit |
577717 |
.LP
|
|
Packit |
577717 |
The IBS registers IbsFetchCtl (0xC0011030) and IbsOpCtl (0xC0011033)
|
|
Packit |
577717 |
are available as PMC and PMD in Perfmon. The function
|
|
Packit |
577717 |
\fBpfm_dispatch_events()\fR initializes these registers according to
|
|
Packit |
577717 |
the input parameters in \fBpfmlib_amd64_input_param_t\fR.
|
|
Packit |
577717 |
.LP
|
|
Packit |
577717 |
Also, \fBpfm_dispatch_events()\fR passes back the index in pfp_pmds[]
|
|
Packit |
577717 |
of the IbsOpCtl and IbsFetchCtl register. For this there are the
|
|
Packit |
577717 |
entries \fBibsfetch_base\fR and \fBibsop_base\fR in
|
|
Packit |
577717 |
\fBpfmlib_amd64_output_param_t\fR. The index may vary depending on
|
|
Packit |
577717 |
other PMU settings, especially counter settings. If using the PMU with
|
|
Packit |
577717 |
only one IBS feature and no counters, the index of the base register
|
|
Packit |
577717 |
is 0.
|
|
Packit |
577717 |
.LP
|
|
Packit |
577717 |
Example code:
|
|
Packit |
577717 |
.LP
|
|
Packit |
577717 |
.nf
|
|
Packit |
577717 |
/* initialize IBS */
|
|
Packit |
577717 |
inp_mod.ibsop.maxcnt = 0xFFFF0;
|
|
Packit |
577717 |
inp_mod.flags |= PFMLIB_AMD64_USE_IBSOP;
|
|
Packit |
577717 |
ret = pfm_dispatch_events(NULL, &inp_mod, &outp, &outp_mod);
|
|
Packit |
577717 |
if (ret != PFMLIB_SUCCESS) { ... }
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* setup PMU */
|
|
Packit |
577717 |
/* PMC_IBSOPCTL */
|
|
Packit |
577717 |
pc[0].reg_num = outp.pfp_pmcs[0].reg_num;
|
|
Packit |
577717 |
pc[0].reg_value = outp.pfp_pmcs[0].reg_value;
|
|
Packit |
577717 |
/* PMD_IBSOPCTL */
|
|
Packit |
577717 |
pd[0].reg_num = outp.pfp_pmds[0].reg_num;
|
|
Packit |
577717 |
pd[0].reg_value = 0;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* setup sampling */
|
|
Packit |
577717 |
pd[0].reg_flags = PFM_REGFL_OVFL_NOTIFY;
|
|
Packit |
577717 |
/* add range check here */
|
|
Packit |
577717 |
pd[0].reg_smpl_pmds[0] =
|
|
Packit |
577717 |
((1UL << PMD_IBSOP_NUM) - 1) << outp.pfp_pmds[0].reg_num;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* write pc and pd to PMU */
|
|
Packit |
577717 |
...
|
|
Packit |
577717 |
.fi
|
|
Packit |
577717 |
.SH ERRORS
|
|
Packit |
577717 |
Refer to the description of the \fBpfm_dispatch_events()\fR function for errors.
|
|
Packit |
577717 |
.SH SEE ALSO
|
|
Packit |
577717 |
pfm_dispatch_events(3) and set of examples shipped with the library
|
|
Packit |
577717 |
.SH AUTHORS
|
|
Packit |
577717 |
.nf
|
|
Packit |
577717 |
Stephane Eranian <eranian@gmail.com>
|
|
Packit |
577717 |
Robert Richter <robert.richter@amd.com>
|
|
Packit |
577717 |
.if
|
|
Packit |
577717 |
.PP
|