Skip to content

Commit

Permalink
perf intel-pt: Record address filter in AUXTRACE_INFO event
Browse files Browse the repository at this point in the history
The address filter is needed to help decode the trace, so store it in
the AUXTRACE_INFO event.

Signed-off-by: Adrian Hunter <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Masami Hiramatsu <[email protected]>
Cc: Mathieu Poirier <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
ahunter6 authored and acmel committed Sep 29, 2016
1 parent 40b746a commit c093f30
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
51 changes: 47 additions & 4 deletions tools/perf/arch/x86/util/intel-pt.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct intel_pt_recording {
size_t snapshot_ref_buf_size;
int snapshot_ref_cnt;
struct intel_pt_snapshot_ref *snapshot_refs;
size_t priv_size;
};

static int intel_pt_parse_terms_with_default(struct list_head *formats,
Expand Down Expand Up @@ -273,11 +274,37 @@ intel_pt_pmu_default_config(struct perf_pmu *intel_pt_pmu)
return attr;
}

static const char *intel_pt_find_filter(struct perf_evlist *evlist,
struct perf_pmu *intel_pt_pmu)
{
struct perf_evsel *evsel;

evlist__for_each_entry(evlist, evsel) {
if (evsel->attr.type == intel_pt_pmu->type)
return evsel->filter;
}

return NULL;
}

static size_t intel_pt_filter_bytes(const char *filter)
{
size_t len = filter ? strlen(filter) : 0;

return len ? roundup(len + 1, 8) : 0;
}

static size_t
intel_pt_info_priv_size(struct auxtrace_record *itr __maybe_unused,
struct perf_evlist *evlist __maybe_unused)
intel_pt_info_priv_size(struct auxtrace_record *itr, struct perf_evlist *evlist)
{
return INTEL_PT_AUXTRACE_PRIV_SIZE;
struct intel_pt_recording *ptr =
container_of(itr, struct intel_pt_recording, itr);
const char *filter = intel_pt_find_filter(evlist, ptr->intel_pt_pmu);

ptr->priv_size = (INTEL_PT_AUXTRACE_PRIV_MAX * sizeof(u64)) +
intel_pt_filter_bytes(filter);

return ptr->priv_size;
}

static void intel_pt_tsc_ctc_ratio(u32 *n, u32 *d)
Expand All @@ -303,9 +330,12 @@ static int intel_pt_info_fill(struct auxtrace_record *itr,
u64 tsc_bit, mtc_bit, mtc_freq_bits, cyc_bit, noretcomp_bit;
u32 tsc_ctc_ratio_n, tsc_ctc_ratio_d;
unsigned long max_non_turbo_ratio;
size_t filter_str_len;
const char *filter;
u64 *info;
int err;

if (priv_size != INTEL_PT_AUXTRACE_PRIV_SIZE)
if (priv_size != ptr->priv_size)
return -EINVAL;

intel_pt_parse_terms(&intel_pt_pmu->format, "tsc", &tsc_bit);
Expand All @@ -322,6 +352,9 @@ static int intel_pt_info_fill(struct auxtrace_record *itr,
"%lu", &max_non_turbo_ratio) != 1)
max_non_turbo_ratio = 0;

filter = intel_pt_find_filter(session->evlist, ptr->intel_pt_pmu);
filter_str_len = filter ? strlen(filter) : 0;

if (!session->evlist->nr_mmaps)
return -EINVAL;

Expand Down Expand Up @@ -357,6 +390,16 @@ static int intel_pt_info_fill(struct auxtrace_record *itr,
auxtrace_info->priv[INTEL_PT_TSC_CTC_D] = tsc_ctc_ratio_d;
auxtrace_info->priv[INTEL_PT_CYC_BIT] = cyc_bit;
auxtrace_info->priv[INTEL_PT_MAX_NONTURBO_RATIO] = max_non_turbo_ratio;
auxtrace_info->priv[INTEL_PT_FILTER_STR_LEN] = filter_str_len;

info = &auxtrace_info->priv[INTEL_PT_FILTER_STR_LEN] + 1;

if (filter_str_len) {
size_t len = intel_pt_filter_bytes(filter);

strncpy((char *)info, filter, len);
info += len >> 3;
}

return 0;
}
Expand Down
3 changes: 1 addition & 2 deletions tools/perf/util/intel-pt.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ enum {
INTEL_PT_TSC_CTC_D,
INTEL_PT_CYC_BIT,
INTEL_PT_MAX_NONTURBO_RATIO,
INTEL_PT_FILTER_STR_LEN,
INTEL_PT_AUXTRACE_PRIV_MAX,
};

#define INTEL_PT_AUXTRACE_PRIV_SIZE (INTEL_PT_AUXTRACE_PRIV_MAX * sizeof(u64))

struct auxtrace_record;
struct perf_tool;
union perf_event;
Expand Down

0 comments on commit c093f30

Please sign in to comment.