2 * intel_pt_decoder.h: Intel Processor Trace support
3 * Copyright (c) 2013-2014, Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 #ifndef INCLUDE__INTEL_PT_DECODER_H__
17 #define INCLUDE__INTEL_PT_DECODER_H__
23 #include "intel-pt-insn-decoder.h"
25 #define INTEL_PT_IN_TX (1 << 0)
26 #define INTEL_PT_ABORT_TX (1 << 1)
27 #define INTEL_PT_ASYNC (1 << 2)
29 enum intel_pt_sample_type {
30 INTEL_PT_BRANCH = 1 << 0,
31 INTEL_PT_INSTRUCTION = 1 << 1,
32 INTEL_PT_TRANSACTION = 1 << 2,
35 enum intel_pt_period_type {
37 INTEL_PT_PERIOD_INSTRUCTIONS,
38 INTEL_PT_PERIOD_TICKS,
43 INTEL_PT_ERR_NOMEM = 1,
56 enum intel_pt_param_flags {
58 * FUP packet can contain next linear instruction pointer instead of
59 * current linear instruction pointer.
61 INTEL_PT_FUP_WITH_NLIP = 1 << 0,
64 struct intel_pt_state {
65 enum intel_pt_sample_type type;
70 uint64_t tot_insn_cnt;
72 uint64_t est_timestamp;
75 enum intel_pt_insn_op insn_op;
81 struct intel_pt_buffer {
82 const unsigned char *buf;
85 uint64_t ref_timestamp;
89 struct intel_pt_params {
90 int (*get_trace)(struct intel_pt_buffer *buffer, void *data);
91 int (*walk_insn)(struct intel_pt_insn *intel_pt_insn,
92 uint64_t *insn_cnt_ptr, uint64_t *ip, uint64_t to_ip,
93 uint64_t max_insn_cnt, void *data);
95 bool return_compression;
97 enum intel_pt_period_type period_type;
98 unsigned max_non_turbo_ratio;
99 unsigned int mtc_period;
100 uint32_t tsc_ctc_ratio_n;
101 uint32_t tsc_ctc_ratio_d;
102 enum intel_pt_param_flags flags;
105 struct intel_pt_decoder;
107 struct intel_pt_decoder *intel_pt_decoder_new(struct intel_pt_params *params);
108 void intel_pt_decoder_free(struct intel_pt_decoder *decoder);
110 const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder);
112 unsigned char *intel_pt_find_overlap(unsigned char *buf_a, size_t len_a,
113 unsigned char *buf_b, size_t len_b,
114 bool have_tsc, bool *consecutive);
116 int intel_pt__strerror(int code, char *buf, size_t buflen);