|
Packit Service |
a1973e |
/*
|
|
Packit Service |
a1973e |
* Copyright (c) 2005-2007 Hewlett-Packard Development Company, L.P.
|
|
Packit Service |
a1973e |
* Contributed by Stephane Eranian <eranian@hpl.hp.com>
|
|
Packit Service |
a1973e |
*
|
|
Packit Service |
a1973e |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
a1973e |
* modify it under the terms of version 2 of the GNU General Public
|
|
Packit Service |
a1973e |
* License as published by the Free Software Foundation.
|
|
Packit Service |
a1973e |
*
|
|
Packit Service |
a1973e |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
a1973e |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
a1973e |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
a1973e |
* General Public License for more details.
|
|
Packit Service |
a1973e |
*
|
|
Packit Service |
a1973e |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
a1973e |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
a1973e |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
Packit Service |
a1973e |
* 02111-1307 USA
|
|
Packit Service |
a1973e |
*
|
|
Packit Service |
a1973e |
* This file implements the sampling format to support Intel
|
|
Packit Service |
a1973e |
* Precise Event Based Sampling (PEBS) feature of Pentium 4
|
|
Packit Service |
a1973e |
* and other Netburst-based processors. Not to be used for
|
|
Packit Service |
a1973e |
* Intel Core-based processors.
|
|
Packit Service |
a1973e |
*
|
|
Packit Service |
a1973e |
* What is PEBS?
|
|
Packit Service |
a1973e |
* ------------
|
|
Packit Service |
a1973e |
* This is a hardware feature to enhance sampling by providing
|
|
Packit Service |
a1973e |
* better precision as to where a sample is taken. This avoids the
|
|
Packit Service |
a1973e |
* typical skew in the instruction one can observe with any
|
|
Packit Service |
a1973e |
* interrupt-based sampling technique.
|
|
Packit Service |
a1973e |
*
|
|
Packit Service |
a1973e |
* PEBS also lowers sampling overhead significantly by having the
|
|
Packit Service |
a1973e |
* processor store samples instead of the OS. PMU interrupt are only
|
|
Packit Service |
a1973e |
* generated after multiple samples are written.
|
|
Packit Service |
a1973e |
*
|
|
Packit Service |
a1973e |
* Another benefit of PEBS is that samples can be captured inside
|
|
Packit Service |
a1973e |
* critical sections where interrupts are masked.
|
|
Packit Service |
a1973e |
*
|
|
Packit Service |
a1973e |
* How does it work?
|
|
Packit Service |
a1973e |
* PEBS effectively implements a Hw buffer. The Os must pass a region
|
|
Packit Service |
a1973e |
* of memory where samples are to be stored. The region can have any
|
|
Packit Service |
a1973e |
* size. The OS must also specify the sampling period to reload. The PMU
|
|
Packit Service |
a1973e |
* will interrupt when it reaches the end of the buffer or a specified
|
|
Packit Service |
a1973e |
* threshold location inside the memory region.
|
|
Packit Service |
a1973e |
*
|
|
Packit Service |
a1973e |
* The description of the buffer is stored in the Data Save Area (DS).
|
|
Packit Service |
a1973e |
* The samples are stored sequentially in the buffer. The format of the
|
|
Packit Service |
a1973e |
* buffer is fixed and specified in the PEBS documentation. The sample
|
|
Packit Service |
a1973e |
* format changes between 32-bit and 64-bit modes due to extended register
|
|
Packit Service |
a1973e |
* file.
|
|
Packit Service |
a1973e |
*
|
|
Packit Service |
a1973e |
* PEBS does not work when HyperThreading is enabled due to certain MSR
|
|
Packit Service |
a1973e |
* being shared being to two threads.
|
|
Packit Service |
a1973e |
*
|
|
Packit Service |
a1973e |
* What does the format do?
|
|
Packit Service |
a1973e |
* It provides access to the PEBS feature for both 32-bit and 64-bit
|
|
Packit Service |
a1973e |
* processors that support it.
|
|
Packit Service |
a1973e |
*
|
|
Packit Service |
a1973e |
* The same code is used for both 32-bit and 64-bit modes, but different
|
|
Packit Service |
a1973e |
* format names are used because the two modes are not compatible due to
|
|
Packit Service |
a1973e |
* data model and register file differences. Similarly the public data
|
|
Packit Service |
a1973e |
* structures describing the samples are different.
|
|
Packit Service |
a1973e |
*
|
|
Packit Service |
a1973e |
* It is important to realize that the format provides a zero-copy environment
|
|
Packit Service |
a1973e |
* for the samples, i.e,, the OS never touches the samples. Whatever the
|
|
Packit Service |
a1973e |
* processor write is directly accessible to the user.
|
|
Packit Service |
a1973e |
*
|
|
Packit Service |
a1973e |
* Parameters to the buffer can be passed via pfm_create_context() in
|
|
Packit Service |
a1973e |
* the pfm_pebs_smpl_arg structure.
|
|
Packit Service |
a1973e |
*
|
|
Packit Service |
a1973e |
* It is not possible to mix a 32-bit PEBS application on top of a 64-bit
|
|
Packit Service |
a1973e |
* host kernel.
|
|
Packit Service |
a1973e |
*/
|
|
Packit Service |
a1973e |
#ifndef __PERFMON_PEBS_P4_SMPL_H__
|
|
Packit Service |
a1973e |
#define __PERFMON_PEBS_P4_SMPL_H__ 1
|
|
Packit Service |
a1973e |
|
|
Packit Service |
a1973e |
#ifdef __cplusplus
|
|
Packit Service |
a1973e |
extern "C" {
|
|
Packit Service |
a1973e |
#endif
|
|
Packit Service |
a1973e |
|
|
Packit Service |
a1973e |
#include <perfmon/perfmon.h>
|
|
Packit Service |
a1973e |
|
|
Packit Service |
a1973e |
#ifdef __i386__
|
|
Packit Service |
a1973e |
#define PFM_PEBS_P4_SMPL_NAME "pebs32_p4"
|
|
Packit Service |
a1973e |
#else
|
|
Packit Service |
a1973e |
#define PFM_PEBS_P4_SMPL_NAME "pebs64_p4"
|
|
Packit Service |
a1973e |
#endif
|
|
Packit Service |
a1973e |
|
|
Packit Service |
a1973e |
/*
|
|
Packit Service |
a1973e |
* format specific parameters (passed at context creation)
|
|
Packit Service |
a1973e |
*/
|
|
Packit Service |
a1973e |
typedef struct {
|
|
Packit Service |
a1973e |
uint64_t cnt_reset; /* counter reset value */
|
|
Packit Service |
a1973e |
size_t buf_size; /* size of the buffer in bytes */
|
|
Packit Service |
a1973e |
size_t intr_thres; /* index of interrupt threshold entry */
|
|
Packit Service |
a1973e |
uint64_t reserved[6]; /* for future use */
|
|
Packit Service |
a1973e |
} pfm_pebs_p4_smpl_arg_t;
|
|
Packit Service |
a1973e |
|
|
Packit Service |
a1973e |
/*
|
|
Packit Service |
a1973e |
* DS Save Area as described in section 15.10.5
|
|
Packit Service |
a1973e |
*/
|
|
Packit Service |
a1973e |
typedef struct {
|
|
Packit Service |
a1973e |
unsigned long bts_buf_base;
|
|
Packit Service |
a1973e |
unsigned long bts_index;
|
|
Packit Service |
a1973e |
unsigned long bts_abs_max;
|
|
Packit Service |
a1973e |
unsigned long bts_intr_thres;
|
|
Packit Service |
a1973e |
unsigned long pebs_buf_base;
|
|
Packit Service |
a1973e |
unsigned long pebs_index;
|
|
Packit Service |
a1973e |
unsigned long pebs_abs_max;
|
|
Packit Service |
a1973e |
unsigned long pebs_intr_thres;
|
|
Packit Service |
a1973e |
uint64_t pebs_cnt_reset;
|
|
Packit Service |
a1973e |
} pfm_ds_area_p4_t;
|
|
Packit Service |
a1973e |
|
|
Packit Service |
a1973e |
/*
|
|
Packit Service |
a1973e |
* This header is at the beginning of the sampling buffer returned to the user.
|
|
Packit Service |
a1973e |
*
|
|
Packit Service |
a1973e |
* Because of PEBS alignement constraints, the actual PEBS buffer area does
|
|
Packit Service |
a1973e |
* not necessarily begin right after the header. The hdr_start_offs must be
|
|
Packit Service |
a1973e |
* used to compute the first byte of the buffer. The offset is defined as
|
|
Packit Service |
a1973e |
* the number of bytes between the end of the header and the beginning of
|
|
Packit Service |
a1973e |
* the buffer. As such the formula is:
|
|
Packit Service |
a1973e |
* actual_buffer = (unsigned long)(hdr+1)+hdr->hdr_start_offs
|
|
Packit Service |
a1973e |
*/
|
|
Packit Service |
a1973e |
typedef struct {
|
|
Packit Service |
a1973e |
uint64_t overflows; /* #overflows for buffer */
|
|
Packit Service |
a1973e |
size_t buf_size; /* bytes in the buffer */
|
|
Packit Service |
a1973e |
size_t start_offs; /* actual buffer start offset */
|
|
Packit Service |
a1973e |
uint32_t version; /* smpl format version */
|
|
Packit Service |
a1973e |
uint32_t reserved1; /* for future use */
|
|
Packit Service |
a1973e |
uint64_t reserved2[5]; /* for future use */
|
|
Packit Service |
a1973e |
pfm_ds_area_p4_t ds; /* DS management Area */
|
|
Packit Service |
a1973e |
} pfm_pebs_p4_smpl_hdr_t;
|
|
Packit Service |
a1973e |
|
|
Packit Service |
a1973e |
/*
|
|
Packit Service |
a1973e |
* PEBS record format as for both 32-bit and 64-bit modes
|
|
Packit Service |
a1973e |
*/
|
|
Packit Service |
a1973e |
typedef struct {
|
|
Packit Service |
a1973e |
unsigned long eflags;
|
|
Packit Service |
a1973e |
unsigned long ip;
|
|
Packit Service |
a1973e |
unsigned long eax;
|
|
Packit Service |
a1973e |
unsigned long ebx;
|
|
Packit Service |
a1973e |
unsigned long ecx;
|
|
Packit Service |
a1973e |
unsigned long edx;
|
|
Packit Service |
a1973e |
unsigned long esi;
|
|
Packit Service |
a1973e |
unsigned long edi;
|
|
Packit Service |
a1973e |
unsigned long ebp;
|
|
Packit Service |
a1973e |
unsigned long esp;
|
|
Packit Service |
a1973e |
#ifdef __x86_64__
|
|
Packit Service |
a1973e |
unsigned long r8;
|
|
Packit Service |
a1973e |
unsigned long r9;
|
|
Packit Service |
a1973e |
unsigned long r10;
|
|
Packit Service |
a1973e |
unsigned long r11;
|
|
Packit Service |
a1973e |
unsigned long r12;
|
|
Packit Service |
a1973e |
unsigned long r13;
|
|
Packit Service |
a1973e |
unsigned long r14;
|
|
Packit Service |
a1973e |
unsigned long r15;
|
|
Packit Service |
a1973e |
#endif
|
|
Packit Service |
a1973e |
} pfm_pebs_p4_smpl_entry_t;
|
|
Packit Service |
a1973e |
|
|
Packit Service |
a1973e |
#define PFM_PEBS_P4_SMPL_VERSION_MAJ 1U
|
|
Packit Service |
a1973e |
#define PFM_PEBS_P4_SMPL_VERSION_MIN 0U
|
|
Packit Service |
a1973e |
#define PFM_PEBS_P4_SMPL_VERSION (((PFM_PEBS_P4_SMPL_VERSION_MAJ&0xffff)<<16)|\
|
|
Packit Service |
a1973e |
(PFM_PEBS_P4_SMPL_VERSION_MIN & 0xffff))
|
|
Packit Service |
a1973e |
|
|
Packit Service |
a1973e |
#ifdef __cplusplus
|
|
Packit Service |
a1973e |
};
|
|
Packit Service |
a1973e |
#endif
|
|
Packit Service |
a1973e |
|
|
Packit Service |
a1973e |
#endif /* __PERFMON_PEBS_P4_SMPL_H__ */
|