perf intel-pt: Add support for efficient time interval filtering
Adrian Hunter
reviewercover perf intel-pt: Add support for efficient time interval filtering
Hi
Here are some patches to add support for efficient time interval filtering. First there are 3 patches to add perf time interval to the itrace options structure. Then changes to Intel PT to support "fast forwarding" to a particular timestamp. The filtering is added in patch "perf intel-pt: Add support for efficient time interval filtering". After that there are patches to time-utils, leading up to adding a new test and adding support multiple explicit time intervals.
The Intel PT changes make time filtering much faster because decoding is limited to the minimal time ranges needed to support the time intervals.
Adrian Hunter (19):
perf auxtrace: Add perf time interval to itrace_synth_ops
perf script: Set perf time interval in itrace_synth_ops
perf report: Set perf time interval in itrace_synth_ops
perf intel-pt: Add lookahead callback
perf intel-pt: Factor out intel_pt_8b_tsc()
perf intel-pt: Factor out intel_pt_reposition()
perf intel-pt: Add reposition parameter to intel_pt_get_data() perf intel-pt: Add intel_pt_fast_forward()
perf intel-pt: Factor out intel_pt_get_buffer()
perf intel-pt: Add support for lookahead
perf intel-pt: Add support for efficient time interval filtering perf time-utils: Treat time ranges consistently
perf time-utils: Factor out set_percent_time()
perf time-utils: Prevent percentage time range overlap
perf time-utils: Fix --time documentation
perf time-utils: Simplify perf_time__parse_for_ranges() error paths slightly perf time-utils: Make perf_time__parse_for_ranges() more logical perf tests: Add a test for time-utils
perf time-utils: Add support for multiple explicit time intervals
tools/perf/Documentation/perf-diff.txt | 14 +- tools/perf/Documentation/perf-report.txt | 9 +- tools/perf/Documentation/perf-script.txt | 9 +- tools/perf/builtin-report.c | 8 +- tools/perf/builtin-script.c | 8 +- tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 4 + tools/perf/tests/tests.h | 1 + tools/perf/tests/time-utils-test.c | 251 ++++++++++++++++ tools/perf/util/auxtrace.h | 34 +++ .../perf/util/intel-pt-decoder/intel-pt-decoder.c | 188 ++++++++++-- .../perf/util/intel-pt-decoder/intel-pt-decoder.h | 5 + tools/perf/util/intel-pt.c | 325 +++++++++++++++++++-- tools/perf/util/time-utils.c | 132 ++++++--- 14 files changed, 894 insertions(+), 95 deletions(-) create mode 100644 tools/perf/tests/time-utils-test.c
Regards
Adrian
Adrian Hunter
reviewerPATCH 1/19 perf auxtrace: Add perf time interval to itrace_synth_ops
Instruction trace decoders can optimize output based on what time intervals will be filtered, so pass that information in itrace_synth_ops.
--- tools/perf/util/auxtrace.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
tools/perf/util/auxtrace.h +34 -0
@@ -83,6 +83,8 @@ enum itrace_period_type {* @period_type: 'instructions' events period type * @initial_skip: skip N events at the beginning. * @cpu_bitmap: CPUs for which to synthesize events, or NULL for all +* @ptime_range: time intervals to trace or NULL +* @range_num: number of time intervals to trace */ struct itrace_synth_opts {bool set;
@@ -107,6 +109,8 @@ struct itrace_synth_opts {enum itrace_period_type period_type;unsigned long initial_skip;unsigned long *cpu_bitmap; +struct perf_time_interval *ptime_range; +int range_num; };/**
@@ -599,6 +603,21 @@ static inline void auxtrace__free(struct perf_session *session)" PERIOD[ns|us|ms|i|t]: specify period to sample stream\n" \" concatenate multiple options. Default is ibxwpe or cewp\n" +static inline +void itrace_synth_opts__set_time_range(struct itrace_synth_opts *opts, + struct perf_time_interval *ptime_range, + int range_num) +{ + opts->ptime_range = ptime_range; + opts->range_num = range_num; +} + +static inline +void itrace_synth_opts__clear_time_range (struct itrace_synth_opts *opts) +{ + opts->ptime_range =NULL ; + opts->range_num =0 ; +}#else
@@ -742,6 +761,21 @@ void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp,#define ITRACE_HELP "" +static inline +void itrace_synth_opts__set_time_range (struct itrace_synth_opts *opts +__maybe_unused , +struct perf_time_interval *ptime_range +__maybe_unused , +int range_num__maybe_unused ) +{ +} + +static inline +void itrace_synth_opts__clear_time_range (struct itrace_synth_opts *opts +__maybe_unused ) +{ +} +#endif #endif
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf auxtrace: Add perf time interval to itrace_synth_ops
perf auxtrace: Add perf time interval to itrace_synth_ops
Commit-ID: 33526f362b019f0a17c6b522eb3b07017dba98a7 Gitweb: https://git.kernel.org/tip/33526f362b019f0a17c6b522eb3b07017dba98a7 Author: Adrian Hunter <[email protected]> AuthorDate: Tue, 4 Jun 2019 15:59:59 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 10 Jun 2019 16:20:11 -0300
perf auxtrace: Add perf time interval to itrace_synth_ops
Instruction trace decoders can optimize output based on what time intervals will be filtered, so pass that information in itrace_synth_ops.
--- tools/perf/util/auxtrace.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
tools/perf/util/auxtrace.h +34 -0
@@ -83,6 +83,8 @@ enum itrace_period_type {* @period_type: 'instructions' events period type * @initial_skip: skip N events at the beginning. * @cpu_bitmap: CPUs for which to synthesize events, or NULL for all +* @ptime_range: time intervals to trace or NULL +* @range_num: number of time intervals to trace */ struct itrace_synth_opts {bool set;
@@ -107,6 +109,8 @@ struct itrace_synth_opts {enum itrace_period_type period_type;unsigned long initial_skip;unsigned long *cpu_bitmap; +struct perf_time_interval *ptime_range; +int range_num; };/**
@@ -599,6 +603,21 @@ static inline void auxtrace__free(struct perf_session *session)" PERIOD[ns|us|ms|i|t]: specify period to sample stream\n" \" concatenate multiple options. Default is ibxwpe or cewp\n" +static inline +void itrace_synth_opts__set_time_range(struct itrace_synth_opts *opts, + struct perf_time_interval *ptime_range, + int range_num) +{ + opts->ptime_range = ptime_range; + opts->range_num = range_num; +} + +static inline +void itrace_synth_opts__clear_time_range (struct itrace_synth_opts *opts) +{ + opts->ptime_range =NULL ; + opts->range_num =0 ; +}#else
@@ -742,6 +761,21 @@ void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp,#define ITRACE_HELP "" +static inline +void itrace_synth_opts__set_time_range (struct itrace_synth_opts *opts +__maybe_unused , +struct perf_time_interval *ptime_range +__maybe_unused , +int range_num__maybe_unused ) +{ +} + +static inline +void itrace_synth_opts__clear_time_range (struct itrace_synth_opts *opts +__maybe_unused ) +{ +} +#endif #endif
Adrian Hunter
reviewerPATCH 2/19 perf script: Set perf time interval in itrace_synth_ops
In reply to Adrian HunterInstruction trace decoders can optimize output based on what time intervals will be filtered, so pass that information in itrace_synth_ops.
--- tools/perf/builtin-script.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/builtin-script.c +7 -1
@@ -3829,6 +3829,10 @@ int cmd_script(int argc, const char **argv) &script.range_num);if (err <0 ) goto out_delete; + +itrace_synth_opts__set_time_range (&itrace_synth_opts, + script.ptime_range, + script.range_num); } err =__cmd_script (&script);
@@ -3836,8 +3840,10 @@ int cmd_script(int argc, const char **argv)flush_scripting (); out_delete: -if (script.ptime_range) +if (script.ptime_range) { +itrace_synth_opts__clear_time_range (&itrace_synth_opts);zfree (&script.ptime_range); + }perf_evlist__free_stats (session->evlist);perf_session__delete (session);
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf script: Set perf time interval in itrace_synth_ops
perf script: Set perf time interval in itrace_synth_ops
Commit-ID: 400ae9818fe64899cea921a89c7078e0df9e41ea Gitweb: https://git.kernel.org/tip/400ae9818fe64899cea921a89c7078e0df9e41ea Author: Adrian Hunter <[email protected]> AuthorDate: Tue, 4 Jun 2019 16:00:00 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 10 Jun 2019 16:20:11 -0300
perf script: Set perf time interval in itrace_synth_ops
Instruction trace decoders can optimize output based on what time intervals will be filtered, so pass that information in itrace_synth_ops.
--- tools/perf/builtin-script.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/builtin-script.c +7 -1
@@ -3829,6 +3829,10 @@ int cmd_script(int argc, const char **argv) &script.range_num);if (err <0 ) goto out_delete; + +itrace_synth_opts__set_time_range (&itrace_synth_opts, + script.ptime_range, + script.range_num); } err =__cmd_script (&script);
@@ -3836,8 +3840,10 @@ int cmd_script(int argc, const char **argv)flush_scripting (); out_delete: -if (script.ptime_range) +if (script.ptime_range) { +itrace_synth_opts__clear_time_range (&itrace_synth_opts);zfree (&script.ptime_range); + }perf_evlist__free_stats (session->evlist);perf_session__delete (session);
Adrian Hunter
reviewerPATCH 3/19 perf report: Set perf time interval in itrace_synth_ops
In reply to Adrian HunterInstruction trace decoders can optimize output based on what time intervals will be filtered, so pass that information in itrace_synth_ops.
--- tools/perf/builtin-report.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/builtin-report.c +7 -1
@@ -1428,6 +1428,10 @@ int cmd_report(int argc, const char **argv) &report.range_num);if (ret <0 ) goto error; + +itrace_synth_opts__set_time_range (&itrace_synth_opts, + report.ptime_range, + report.range_num); } if (session->tevent.pevent &&
@@ -1449,8 +1453,10 @@ int cmd_report(int argc, const char **argv) ret =0 ; error: -if (report.ptime_range) +if (report.ptime_range) { +itrace_synth_opts__clear_time_range (&itrace_synth_opts);zfree (&report.ptime_range); + }zstd_fini (&(session->zstd_data));perf_session__delete (session);return ret;
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf report: Set perf time interval in itrace_synth_ops
perf report: Set perf time interval in itrace_synth_ops
Commit-ID: 4885c90c5e84926cfb083c58d8b6d70d1b1ac7cf Gitweb: https://git.kernel.org/tip/4885c90c5e84926cfb083c58d8b6d70d1b1ac7cf Author: Adrian Hunter <[email protected]> AuthorDate: Tue, 4 Jun 2019 16:00:01 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 10 Jun 2019 16:20:12 -0300
perf report: Set perf time interval in itrace_synth_ops
Instruction trace decoders can optimize output based on what time intervals will be filtered, so pass that information in itrace_synth_ops.
--- tools/perf/builtin-report.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/builtin-report.c +7 -1
@@ -1428,6 +1428,10 @@ repeat: &report.range_num);if (ret <0 ) goto error; + +itrace_synth_opts__set_time_range (&itrace_synth_opts, + report.ptime_range, + report.range_num); } if (session->tevent.pevent &&
@@ -1449,8 +1453,10 @@ repeat: ret =0 ; error: -if (report.ptime_range) +if (report.ptime_range) { +itrace_synth_opts__clear_time_range (&itrace_synth_opts);zfree (&report.ptime_range); + }zstd_fini (&(session->zstd_data));perf_session__delete (session);return ret;
Adrian Hunter
reviewerPATCH 4/19 perf intel-pt: Add lookahead callback
In reply to Adrian HunterAdd a callback function to enable the decoder to lookahead at subsequent trace buffers. This will be used to implement a "fast forward" facility which will be needed to support efficient time interval filtering.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 2 ++ tools/perf/util/intel-pt-decoder/intel-pt-decoder.h | 3 +++ 2 files changed, 5 insertions(+)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +2 -0
@@ -104,6 +104,7 @@ struct intel_pt_decoder { uint64_t *insn_cnt_ptr, uint64_t *ip, uint64_t to_ip, uint64_t max_insn_cnt, void *data);bool (*pgd_ip)(uint64_t ip,void *data); +int (*lookahead)(void *data,intel_pt_lookahead_cb_t cb,void *cb_data);void *data;struct intel_pt_state state;const unsigned char *buf;
@@ -233,6 +234,7 @@ struct intel_pt_decoder *intel_pt_decoder_new(struct intel_pt_params *params) decoder->get_trace = params->get_trace; decoder->walk_insn = params->walk_insn; decoder->pgd_ip = params->pgd_ip; + decoder->lookahead = params->lookahead; decoder->data = params->data; decoder->return_compression = params->return_compression; decoder->branch_enable = params->branch_enable;
tools/perf/util/intel-pt-decoder/intel-pt-decoder.h +3 -0
@@ -102,12 +102,15 @@ struct intel_pt_buffer {uint64_t trace_nr; }; +typedef int (*intel_pt_lookahead_cb_t )(struct intel_pt_buffer *,void *); +struct intel_pt_params {int (*get_trace)(struct intel_pt_buffer *buffer,void *data);int (*walk_insn)(struct intel_pt_insn *intel_pt_insn,uint64_t *insn_cnt_ptr,uint64_t *ip,uint64_t to_ip,uint64_t max_insn_cnt,void *data);bool (*pgd_ip)(uint64_t ip,void *data); +int (*lookahead)(void *data,intel_pt_lookahead_cb_t cb,void *cb_data);void *data;bool return_compression;bool branch_enable;
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Add lookahead callback
perf intel-pt: Add lookahead callback
Commit-ID: 4d678e9039b075f9418600dc87ec5e61cfb57115 Gitweb: https://git.kernel.org/tip/4d678e9039b075f9418600dc87ec5e61cfb57115 Author: Adrian Hunter <[email protected]> AuthorDate: Tue, 4 Jun 2019 16:00:02 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 10 Jun 2019 16:20:12 -0300
perf intel-pt: Add lookahead callback
Add a callback function to enable the decoder to lookahead at subsequent trace buffers. This will be used to implement a "fast forward" facility which will be needed to support efficient time interval filtering.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 2 ++ tools/perf/util/intel-pt-decoder/intel-pt-decoder.h | 3 +++ 2 files changed, 5 insertions(+)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +2 -0
@@ -104,6 +104,7 @@ struct intel_pt_decoder { uint64_t *insn_cnt_ptr, uint64_t *ip, uint64_t to_ip, uint64_t max_insn_cnt, void *data);bool (*pgd_ip)(uint64_t ip,void *data); +int (*lookahead)(void *data,intel_pt_lookahead_cb_t cb,void *cb_data);void *data;struct intel_pt_state state;const unsigned char *buf;
@@ -233,6 +234,7 @@ struct intel_pt_decoder *intel_pt_decoder_new(struct intel_pt_params *params) decoder->get_trace = params->get_trace; decoder->walk_insn = params->walk_insn; decoder->pgd_ip = params->pgd_ip; + decoder->lookahead = params->lookahead; decoder->data = params->data; decoder->return_compression = params->return_compression; decoder->branch_enable = params->branch_enable;
tools/perf/util/intel-pt-decoder/intel-pt-decoder.h +3 -0
@@ -102,12 +102,15 @@ struct intel_pt_buffer {uint64_t trace_nr; }; +typedef int (*intel_pt_lookahead_cb_t )(struct intel_pt_buffer *,void *); +struct intel_pt_params {int (*get_trace)(struct intel_pt_buffer *buffer,void *data);int (*walk_insn)(struct intel_pt_insn *intel_pt_insn,uint64_t *insn_cnt_ptr,uint64_t *ip,uint64_t to_ip,uint64_t max_insn_cnt,void *data);bool (*pgd_ip)(uint64_t ip,void *data); +int (*lookahead)(void *data,intel_pt_lookahead_cb_t cb,void *cb_data);void *data;bool return_compression;bool branch_enable;
Adrian Hunter
reviewerPATCH 5/19 perf intel-pt: Factor out intel_pt_8b_tsc()
In reply to Adrian HunterFactor out intel_pt_8b_tsc() so it can be reused.
--- .../util/intel-pt-decoder/intel-pt-decoder.c | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +17 -9
@@ -1369,6 +1369,21 @@ static int intel_pt_mode_tsx(struct intel_pt_decoder *decoder, bool *no_tip)return 0 ; } +static uint64_t intel_pt_8b_tsc (uint64_t timestamp,uint64_t ref_timestamp) +{ + timestamp |= (ref_timestamp & (0xffULL <<56 )); + +if (timestamp < ref_timestamp) { +if (ref_timestamp - timestamp > (1ULL <<55 )) + timestamp += (1ULL <<56 ); + }else { +if (timestamp - ref_timestamp > (1ULL <<55 )) + timestamp -= (1ULL <<56 ); + } + +return timestamp; +} +static void intel_pt_calc_tsc_timestamp (struct intel_pt_decoder *decoder) {uint64_t timestamp;
@@ -1376,15 +1391,8 @@ static void intel_pt_calc_tsc_timestamp(struct intel_pt_decoder *decoder) decoder->have_tma = false;if (decoder->ref_timestamp) { - timestamp = decoder->packet.payload | - (decoder->ref_timestamp & (0xffULL <<56 )); -if (timestamp < decoder->ref_timestamp) { -if (decoder->ref_timestamp - timestamp > (1ULL <<55 )) - timestamp += (1ULL <<56 ); - }else { -if (timestamp - decoder->ref_timestamp > (1ULL <<55 )) - timestamp -= (1ULL <<56 ); - } + timestamp =intel_pt_8b_tsc (decoder->packet.payload, + decoder->ref_timestamp); decoder->tsc_timestamp = timestamp; decoder->timestamp = timestamp; decoder->ref_timestamp =0 ;
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Factor out intel_pt_8b_tsc()
perf intel-pt: Factor out intel_pt_8b_tsc()
Commit-ID: e72b52a2cfdea5cb0279b2d63a36d78b8c2134de Gitweb: https://git.kernel.org/tip/e72b52a2cfdea5cb0279b2d63a36d78b8c2134de Author: Adrian Hunter <[email protected]> AuthorDate: Tue, 4 Jun 2019 16:00:03 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 10 Jun 2019 16:20:12 -0300
perf intel-pt: Factor out intel_pt_8b_tsc()
Factor out intel_pt_8b_tsc() so it can be reused.
--- .../perf/util/intel-pt-decoder/intel-pt-decoder.c | 26 ++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +17 -9
@@ -1369,6 +1369,21 @@ static int intel_pt_mode_tsx(struct intel_pt_decoder *decoder, bool *no_tip)return 0 ; } +static uint64_t intel_pt_8b_tsc (uint64_t timestamp,uint64_t ref_timestamp) +{ + timestamp |= (ref_timestamp & (0xffULL <<56 )); + +if (timestamp < ref_timestamp) { +if (ref_timestamp - timestamp > (1ULL <<55 )) + timestamp += (1ULL <<56 ); + }else { +if (timestamp - ref_timestamp > (1ULL <<55 )) + timestamp -= (1ULL <<56 ); + } + +return timestamp; +} +static void intel_pt_calc_tsc_timestamp (struct intel_pt_decoder *decoder) {uint64_t timestamp;
@@ -1376,15 +1391,8 @@ static void intel_pt_calc_tsc_timestamp(struct intel_pt_decoder *decoder) decoder->have_tma = false;if (decoder->ref_timestamp) { - timestamp = decoder->packet.payload | - (decoder->ref_timestamp & (0xffULL <<56 )); -if (timestamp < decoder->ref_timestamp) { -if (decoder->ref_timestamp - timestamp > (1ULL <<55 )) - timestamp += (1ULL <<56 ); - }else { -if (timestamp - decoder->ref_timestamp > (1ULL <<55 )) - timestamp -= (1ULL <<56 ); - } + timestamp =intel_pt_8b_tsc (decoder->packet.payload, + decoder->ref_timestamp); decoder->tsc_timestamp = timestamp; decoder->timestamp = timestamp; decoder->ref_timestamp =0 ;
Adrian Hunter
reviewerPATCH 6/19 perf intel-pt: Factor out intel_pt_reposition()
In reply to Adrian HunterFactor out intel_pt_reposition() so it can be reused.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +9 -4
@@ -494,6 +494,14 @@ static inline void intel_pt_update_sample_time(struct intel_pt_decoder *decoder) decoder->sample_insn_cnt = decoder->timestamp_insn_cnt; } +static void intel_pt_reposition (struct intel_pt_decoder *decoder) +{ + decoder->ip =0 ; + decoder->pkt_state =INTEL_PT_STATE_NO_PSB ; + decoder->timestamp =0 ; + decoder->have_tma = false; +} +static int intel_pt_get_data (struct intel_pt_decoder *decoder) {struct intel_pt_buffer buffer = { .buf =0 , };
@@ -512,11 +520,8 @@ static int intel_pt_get_data(struct intel_pt_decoder *decoder)return -ENODATA ; }if (!buffer.consecutive) { - decoder->ip =0 ; - decoder->pkt_state =INTEL_PT_STATE_NO_PSB ; +intel_pt_reposition (decoder); decoder->ref_timestamp = buffer.ref_timestamp; - decoder->timestamp =0 ; - decoder->have_tma = false; decoder->state.trace_nr = buffer.trace_nr;intel_pt_log ("Reference timestamp 0x%" PRIx64"\n" , decoder->ref_timestamp);
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Factor out intel_pt_reposition()
perf intel-pt: Factor out intel_pt_reposition()
Commit-ID: 6492e5f013d9975d68528150edadead91e97a78a Gitweb: https://git.kernel.org/tip/6492e5f013d9975d68528150edadead91e97a78a Author: Adrian Hunter <[email protected]> AuthorDate: Tue, 4 Jun 2019 16:00:04 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 10 Jun 2019 16:20:12 -0300
perf intel-pt: Factor out intel_pt_reposition()
Factor out intel_pt_reposition() so it can be reused.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +9 -4
@@ -494,6 +494,14 @@ static inline void intel_pt_update_sample_time(struct intel_pt_decoder *decoder) decoder->sample_insn_cnt = decoder->timestamp_insn_cnt; } +static void intel_pt_reposition (struct intel_pt_decoder *decoder) +{ + decoder->ip =0 ; + decoder->pkt_state =INTEL_PT_STATE_NO_PSB ; + decoder->timestamp =0 ; + decoder->have_tma = false; +} +static int intel_pt_get_data (struct intel_pt_decoder *decoder) {struct intel_pt_buffer buffer = { .buf =0 , };
@@ -512,11 +520,8 @@ static int intel_pt_get_data(struct intel_pt_decoder *decoder)return -ENODATA ; }if (!buffer.consecutive) { - decoder->ip =0 ; - decoder->pkt_state =INTEL_PT_STATE_NO_PSB ; +intel_pt_reposition (decoder); decoder->ref_timestamp = buffer.ref_timestamp; - decoder->timestamp =0 ; - decoder->have_tma = false; decoder->state.trace_nr = buffer.trace_nr;intel_pt_log ("Reference timestamp 0x%" PRIx64"\n" , decoder->ref_timestamp);
Adrian Hunter
reviewerPATCH 7/19 perf intel-pt: Add reposition parameter to intel_pt_get_data()
In reply to Adrian HunterWhen the decoder gets the next trace buffer, some state is reset if the buffer is not consecutive to the previous buffer. Add a parameter 'reposition' so that can be done also to support a "fast forward" facility.
--- .../util/intel-pt-decoder/intel-pt-decoder.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +9 -8
@@ -502,7 +502,7 @@ static void intel_pt_reposition(struct intel_pt_decoder *decoder) decoder->have_tma = false; } -static int intel_pt_get_data (struct intel_pt_decoder *decoder) +static int intel_pt_get_data (struct intel_pt_decoder *decoder,bool reposition) {struct intel_pt_buffer buffer = { .buf =0 , };int ret;
@@ -519,7 +519,7 @@ static int intel_pt_get_data(struct intel_pt_decoder *decoder)intel_pt_log ("No more data\n" );return -ENODATA ; } -if (!buffer.consecutive) { +if (!buffer.consecutive || reposition) {intel_pt_reposition (decoder); decoder->ref_timestamp = buffer.ref_timestamp; decoder->state.trace_nr = buffer.trace_nr;
@@ -531,10 +531,11 @@ static int intel_pt_get_data(struct intel_pt_decoder *decoder)return 0 ; } -static int intel_pt_get_next_data (struct intel_pt_decoder *decoder) +static int intel_pt_get_next_data (struct intel_pt_decoder *decoder, +bool reposition) {if (!decoder->next_buf) -return intel_pt_get_data (decoder); +return intel_pt_get_data (decoder, reposition); decoder->buf = decoder->next_buf; decoder->len = decoder->next_len;
@@ -553,7 +554,7 @@ static int intel_pt_get_split_packet(struct intel_pt_decoder *decoder) len = decoder->len;memcpy (buf, decoder->buf, len); - ret =intel_pt_get_data (decoder); + ret =intel_pt_get_data (decoder, false);if (ret) { decoder->pos += old_len;return ret <0 ? ret : -EINVAL ;
@@ -879,7 +880,7 @@ static int intel_pt_get_next_packet(struct intel_pt_decoder *decoder) decoder->len -= decoder->pkt_step;if (!decoder->len) { - ret =intel_pt_get_next_data (decoder); + ret =intel_pt_get_next_data (decoder, false);if (ret)return ret; }
@@ -2369,7 +2370,7 @@ static int intel_pt_get_split_psb(struct intel_pt_decoder *decoder, decoder->pos += decoder->len; decoder->len =0 ; - ret =intel_pt_get_next_data (decoder); + ret =intel_pt_get_next_data (decoder, false);if (ret)return ret;
@@ -2395,7 +2396,7 @@ static int intel_pt_scan_for_psb(struct intel_pt_decoder *decoder)intel_pt_log ("Scanning for PSB\n" );while (1 ) {if (!decoder->len) { - ret =intel_pt_get_next_data (decoder); + ret =intel_pt_get_next_data (decoder, false);if (ret)return ret; }
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Add reposition parameter to intel_pt_get_data()
perf intel-pt: Add reposition parameter to intel_pt_get_data()
Commit-ID: 6c1f0b18ac3361837dbe53e794e28096285fb4f0 Gitweb: https://git.kernel.org/tip/6c1f0b18ac3361837dbe53e794e28096285fb4f0 Author: Adrian Hunter <[email protected]> AuthorDate: Tue, 4 Jun 2019 16:00:05 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 10 Jun 2019 16:20:12 -0300
perf intel-pt: Add reposition parameter to intel_pt_get_data()
When the decoder gets the next trace buffer, some state is reset if the buffer is not consecutive to the previous buffer. Add a parameter 'reposition' so that can be done also to support a "fast forward" facility.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +9 -8
@@ -502,7 +502,7 @@ static void intel_pt_reposition(struct intel_pt_decoder *decoder) decoder->have_tma = false; } -static int intel_pt_get_data (struct intel_pt_decoder *decoder) +static int intel_pt_get_data (struct intel_pt_decoder *decoder,bool reposition) {struct intel_pt_buffer buffer = { .buf =0 , };int ret;
@@ -519,7 +519,7 @@ static int intel_pt_get_data(struct intel_pt_decoder *decoder)intel_pt_log ("No more data\n" );return -ENODATA ; } -if (!buffer.consecutive) { +if (!buffer.consecutive || reposition) {intel_pt_reposition (decoder); decoder->ref_timestamp = buffer.ref_timestamp; decoder->state.trace_nr = buffer.trace_nr;
@@ -531,10 +531,11 @@ static int intel_pt_get_data(struct intel_pt_decoder *decoder)return 0 ; } -static int intel_pt_get_next_data (struct intel_pt_decoder *decoder) +static int intel_pt_get_next_data (struct intel_pt_decoder *decoder, +bool reposition) {if (!decoder->next_buf) -return intel_pt_get_data (decoder); +return intel_pt_get_data (decoder, reposition); decoder->buf = decoder->next_buf; decoder->len = decoder->next_len;
@@ -553,7 +554,7 @@ static int intel_pt_get_split_packet(struct intel_pt_decoder *decoder) len = decoder->len;memcpy (buf, decoder->buf, len); - ret =intel_pt_get_data (decoder); + ret =intel_pt_get_data (decoder, false);if (ret) { decoder->pos += old_len;return ret <0 ? ret : -EINVAL ;
@@ -879,7 +880,7 @@ static int intel_pt_get_next_packet(struct intel_pt_decoder *decoder) decoder->len -= decoder->pkt_step;if (!decoder->len) { - ret =intel_pt_get_next_data (decoder); + ret =intel_pt_get_next_data (decoder, false);if (ret)return ret; }
@@ -2369,7 +2370,7 @@ static int intel_pt_get_split_psb(struct intel_pt_decoder *decoder, decoder->pos += decoder->len; decoder->len =0 ; - ret =intel_pt_get_next_data (decoder); + ret =intel_pt_get_next_data (decoder, false);if (ret)return ret;
@@ -2395,7 +2396,7 @@ static int intel_pt_scan_for_psb(struct intel_pt_decoder *decoder)intel_pt_log ("Scanning for PSB\n" );while (1 ) {if (!decoder->len) { - ret =intel_pt_get_next_data (decoder); + ret =intel_pt_get_next_data (decoder, false);if (ret)return ret; }
Adrian Hunter
reviewerPATCH 8/19 perf intel-pt: Add intel_pt_fast_forward()
In reply to Adrian HunterIntel PT decoding is done in time order. In order to support efficient time interval filtering, add a facility to "fast forward" towards a particular timestamp. That involves finding the right buffer, stepping to that buffer, and then stepping forward PSBs. Because decoding must begin at a PSB, "fast forward" stops at the last PSB that has a timestamp before the target timestamp.
--- .../util/intel-pt-decoder/intel-pt-decoder.c | 130 ++++++++++++++++++ .../util/intel-pt-decoder/intel-pt-decoder.h | 2 + 2 files changed, 132 insertions(+)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +130 -0
@@ -126,6 +126,7 @@ struct intel_pt_decoder {uint64_t timestamp;uint64_t tsc_timestamp;uint64_t ref_timestamp; +uint64_t buf_timestamp;uint64_t sample_timestamp;uint64_t ret_addr;uint64_t ctc_timestamp;
@@ -519,6 +520,7 @@ static int intel_pt_get_data(struct intel_pt_decoder *decoder, bool reposition)intel_pt_log ("No more data\n" );return -ENODATA ; } + decoder->buf_timestamp = buffer.ref_timestamp;if (!buffer.consecutive || reposition) {intel_pt_reposition (decoder); decoder->ref_timestamp = buffer.ref_timestamp;
@@ -2854,3 +2856,131 @@ unsigned char *intel_pt_find_overlap(unsigned char *buf_a, size_t len_a,return buf_b;/* No overlap */ } } + +/** +* struct fast_forward_data - data used by intel_pt_ff_cb(). +* @timestamp: timestamp to fast forward towards +* @buf_timestamp: buffer timestamp of last buffer with trace data earlier than +* the fast forward timestamp. +*/ +struct fast_forward_data { +uint64_t timestamp; +uint64_t buf_timestamp; +}; + +/** +* intel_pt_ff_cb - fast forward lookahead callback. +* @buffer: Intel PT trace buffer +* @data: opaque pointer to fast forward data (struct fast_forward_data) +* +* Determine if @buffer trace is past the fast forward timestamp. +* +* Return: 1 (stop lookahead) if @buffer trace is past the fast forward +* timestamp, and 0 otherwise. +*/ +static int intel_pt_ff_cb (struct intel_pt_buffer *buffer,void *data) +{ +struct fast_forward_data *d = data; +unsigned char *buf; +uint64_t tsc; +size_t rem; +size_t len; + + buf = (unsigned char *)buffer->buf; + len = buffer->len; + +if (!intel_pt_next_psb (&buf, &len) || + !intel_pt_next_tsc (buf, len, &tsc, &rem)) +return 0 ; + + tsc =intel_pt_8b_tsc (tsc, buffer->ref_timestamp); + +intel_pt_log ("Buffer 1st timestamp " x64_fmt" ref timestamp " x64_fmt"\n" , + tsc, buffer->ref_timestamp); + +/* +* If the buffer contains a timestamp earlier that the fast forward +* timestamp, then record it, else stop. +*/ +if (tsc < d->timestamp) + d->buf_timestamp = buffer->ref_timestamp; +else +return 1 ; + +return 0 ; +} + +/** +* intel_pt_fast_forward - reposition decoder forwards. +* @decoder: Intel PT decoder +* @timestamp: timestamp to fast forward towards +* +* Reposition decoder at the last PSB with a timestamp earlier than @timestamp. +* +* Return: 0 on success or negative error code on failure. +*/ +int intel_pt_fast_forward (struct intel_pt_decoder *decoder,uint64_t timestamp) +{ +struct fast_forward_data d = { .timestamp = timestamp }; +unsigned char *buf; +size_t len; +int err; + +intel_pt_log ("Fast forward towards timestamp " x64_fmt"\n" , timestamp); + +/* Find buffer timestamp of buffer to fast forward to */ + err = decoder->lookahead (decoder->data, intel_pt_ff_cb, &d); +if (err <0 ) +return err; + +/* Walk to buffer with same buffer timestamp */ +if (d.buf_timestamp) { +do { + decoder->pos += decoder->len; + decoder->len =0 ; + err =intel_pt_get_next_data (decoder, true); +/* -ENOLINK means non-consecutive trace */ +if (err && err != -ENOLINK ) +return err; + }while (decoder->buf_timestamp != d.buf_timestamp); + } + +if (!decoder->buf) +return 0 ; + + buf = (unsigned char *)decoder->buf; + len = decoder->len; + +if (!intel_pt_next_psb (&buf, &len)) +return 0 ; + +/* +* Walk PSBs while the PSB timestamp is less than the fast forward +* timestamp. +*/ +do { +uint64_t tsc; +size_t rem; + +if (!intel_pt_next_tsc (buf, len, &tsc, &rem)) +break ; + tsc =intel_pt_8b_tsc (tsc, decoder->buf_timestamp); +/* +* A TSC packet can slip past MTC packets but, after fast +* forward, decoding starts at the TSC timestamp. That means +* the timestamps may not be exactly the same as the timestamps +* that would have been decoded without fast forward. +*/ +if (tsc < timestamp) { +intel_pt_log ("Fast forward to next PSB timestamp " x64_fmt"\n" , tsc); + decoder->pos += decoder->len - len; + decoder->buf = buf; + decoder->len = len; +intel_pt_reposition (decoder); + }else { +break ; + } + }while (intel_pt_step_psb (&buf, &len)); + +return 0 ; +}
tools/perf/util/intel-pt-decoder/intel-pt-decoder.h +2 -0
@@ -130,6 +130,8 @@ void intel_pt_decoder_free(struct intel_pt_decoder *decoder);const struct intel_pt_state *intel_pt_decode (struct intel_pt_decoder *decoder); +int intel_pt_fast_forward (struct intel_pt_decoder *decoder,uint64_t timestamp); +unsigned char *intel_pt_find_overlap (unsigned char *buf_a,size_t len_a,unsigned char *buf_b,size_t len_b,bool have_tsc,bool *consecutive);
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Add intel_pt_fast_forward()
perf intel-pt: Add intel_pt_fast_forward()
Commit-ID: a7fa19f5a255cc8970202d5c54092089a01fc042 Gitweb: https://git.kernel.org/tip/a7fa19f5a255cc8970202d5c54092089a01fc042 Author: Adrian Hunter <[email protected]> AuthorDate: Tue, 4 Jun 2019 16:00:06 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 10 Jun 2019 16:20:12 -0300
perf intel-pt: Add intel_pt_fast_forward()
Intel PT decoding is done in time order. In order to support efficient time interval filtering, add a facility to "fast forward" towards a particular timestamp. That involves finding the right buffer, stepping to that buffer, and then stepping forward PSBs. Because decoding must begin at a PSB, "fast forward" stops at the last PSB that has a timestamp before the target timestamp.
--- .../perf/util/intel-pt-decoder/intel-pt-decoder.c | 130 +++++++++++++++++++++ .../perf/util/intel-pt-decoder/intel-pt-decoder.h | 2 + 2 files changed, 132 insertions(+)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +130 -0
@@ -126,6 +126,7 @@ struct intel_pt_decoder {uint64_t timestamp;uint64_t tsc_timestamp;uint64_t ref_timestamp; +uint64_t buf_timestamp;uint64_t sample_timestamp;uint64_t ret_addr;uint64_t ctc_timestamp;
@@ -519,6 +520,7 @@ static int intel_pt_get_data(struct intel_pt_decoder *decoder, bool reposition)intel_pt_log ("No more data\n" );return -ENODATA ; } + decoder->buf_timestamp = buffer.ref_timestamp;if (!buffer.consecutive || reposition) {intel_pt_reposition (decoder); decoder->ref_timestamp = buffer.ref_timestamp;
@@ -2854,3 +2856,131 @@ unsigned char *intel_pt_find_overlap(unsigned char *buf_a, size_t len_a,return buf_b;/* No overlap */ } } + +/** +* struct fast_forward_data - data used by intel_pt_ff_cb(). +* @timestamp: timestamp to fast forward towards +* @buf_timestamp: buffer timestamp of last buffer with trace data earlier than +* the fast forward timestamp. +*/ +struct fast_forward_data { +uint64_t timestamp; +uint64_t buf_timestamp; +}; + +/** +* intel_pt_ff_cb - fast forward lookahead callback. +* @buffer: Intel PT trace buffer +* @data: opaque pointer to fast forward data (struct fast_forward_data) +* +* Determine if @buffer trace is past the fast forward timestamp. +* +* Return: 1 (stop lookahead) if @buffer trace is past the fast forward +* timestamp, and 0 otherwise. +*/ +static int intel_pt_ff_cb (struct intel_pt_buffer *buffer,void *data) +{ +struct fast_forward_data *d = data; +unsigned char *buf; +uint64_t tsc; +size_t rem; +size_t len; + + buf = (unsigned char *)buffer->buf; + len = buffer->len; + +if (!intel_pt_next_psb (&buf, &len) || + !intel_pt_next_tsc (buf, len, &tsc, &rem)) +return 0 ; + + tsc =intel_pt_8b_tsc (tsc, buffer->ref_timestamp); + +intel_pt_log ("Buffer 1st timestamp " x64_fmt" ref timestamp " x64_fmt"\n" , + tsc, buffer->ref_timestamp); + +/* +* If the buffer contains a timestamp earlier that the fast forward +* timestamp, then record it, else stop. +*/ +if (tsc < d->timestamp) + d->buf_timestamp = buffer->ref_timestamp; +else +return 1 ; + +return 0 ; +} + +/** +* intel_pt_fast_forward - reposition decoder forwards. +* @decoder: Intel PT decoder +* @timestamp: timestamp to fast forward towards +* +* Reposition decoder at the last PSB with a timestamp earlier than @timestamp. +* +* Return: 0 on success or negative error code on failure. +*/ +int intel_pt_fast_forward (struct intel_pt_decoder *decoder,uint64_t timestamp) +{ +struct fast_forward_data d = { .timestamp = timestamp }; +unsigned char *buf; +size_t len; +int err; + +intel_pt_log ("Fast forward towards timestamp " x64_fmt"\n" , timestamp); + +/* Find buffer timestamp of buffer to fast forward to */ + err = decoder->lookahead (decoder->data, intel_pt_ff_cb, &d); +if (err <0 ) +return err; + +/* Walk to buffer with same buffer timestamp */ +if (d.buf_timestamp) { +do { + decoder->pos += decoder->len; + decoder->len =0 ; + err =intel_pt_get_next_data (decoder, true); +/* -ENOLINK means non-consecutive trace */ +if (err && err != -ENOLINK ) +return err; + }while (decoder->buf_timestamp != d.buf_timestamp); + } + +if (!decoder->buf) +return 0 ; + + buf = (unsigned char *)decoder->buf; + len = decoder->len; + +if (!intel_pt_next_psb (&buf, &len)) +return 0 ; + +/* +* Walk PSBs while the PSB timestamp is less than the fast forward +* timestamp. +*/ +do { +uint64_t tsc; +size_t rem; + +if (!intel_pt_next_tsc (buf, len, &tsc, &rem)) +break ; + tsc =intel_pt_8b_tsc (tsc, decoder->buf_timestamp); +/* +* A TSC packet can slip past MTC packets but, after fast +* forward, decoding starts at the TSC timestamp. That means +* the timestamps may not be exactly the same as the timestamps +* that would have been decoded without fast forward. +*/ +if (tsc < timestamp) { +intel_pt_log ("Fast forward to next PSB timestamp " x64_fmt"\n" , tsc); + decoder->pos += decoder->len - len; + decoder->buf = buf; + decoder->len = len; +intel_pt_reposition (decoder); + }else { +break ; + } + }while (intel_pt_step_psb (&buf, &len)); + +return 0 ; +}
tools/perf/util/intel-pt-decoder/intel-pt-decoder.h +2 -0
@@ -130,6 +130,8 @@ void intel_pt_decoder_free(struct intel_pt_decoder *decoder);const struct intel_pt_state *intel_pt_decode (struct intel_pt_decoder *decoder); +int intel_pt_fast_forward (struct intel_pt_decoder *decoder,uint64_t timestamp); +unsigned char *intel_pt_find_overlap (unsigned char *buf_a,size_t len_a,unsigned char *buf_b,size_t len_b,bool have_tsc,bool *consecutive);
Adrian Hunter
reviewerPATCH 9/19 perf intel-pt: Factor out intel_pt_get_buffer()
In reply to Adrian HunterFactor out intel_pt_get_buffer() so it can be reused.
--- tools/perf/util/intel-pt.c | 60 +++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 23 deletions(-)
tools/perf/util/intel-pt.c +37 -23
@@ -239,32 +239,13 @@ static int intel_pt_do_fix_overlap(struct intel_pt *pt, struct auxtrace_buffer *return 0 ; } -/* This function assumes data is processed sequentially only */ -static int intel_pt_get_trace (struct intel_pt_buffer *b,void *data) +static int intel_pt_get_buffer (struct intel_pt_queue *ptq, +struct auxtrace_buffer *buffer, +struct auxtrace_buffer *old_buffer, +struct intel_pt_buffer *b) { -struct intel_pt_queue *ptq = data; -struct auxtrace_buffer *buffer = ptq->buffer; -struct auxtrace_buffer *old_buffer = ptq->old_buffer; -struct auxtrace_queue *queue;bool might_overlap; -if (ptq->stop) { - b->len =0 ; -return 0 ; - } - - queue = &ptq->pt->queues.queue_array[ptq->queue_nr]; - - buffer =auxtrace_buffer__next (queue, buffer); -if (!buffer) { -if (old_buffer) -auxtrace_buffer__drop_data (old_buffer); - b->len =0 ; -return 0 ; - } - - ptq->buffer = buffer; -if (!buffer->data) {int fd =perf_data__fd (ptq->pt->session->data);
@@ -294,6 +275,39 @@ static int intel_pt_get_trace(struct intel_pt_buffer *b, void *data) b->consecutive = true; } +return 0 ; +} + +/* This function assumes data is processed sequentially only */ +static int intel_pt_get_trace (struct intel_pt_buffer *b,void *data) +{ +struct intel_pt_queue *ptq = data; +struct auxtrace_buffer *buffer = ptq->buffer; +struct auxtrace_buffer *old_buffer = ptq->old_buffer; +struct auxtrace_queue *queue; +int err; + +if (ptq->stop) { + b->len =0 ; +return 0 ; + } + + queue = &ptq->pt->queues.queue_array[ptq->queue_nr]; + + buffer =auxtrace_buffer__next (queue, buffer); +if (!buffer) { +if (old_buffer) +auxtrace_buffer__drop_data (old_buffer); + b->len =0 ; +return 0 ; + } + + ptq->buffer = buffer; + + err =intel_pt_get_buffer (ptq, buffer, old_buffer, b); +if (err) +return err; +if (ptq->step_through_buffers) ptq->stop = true;
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Factor out intel_pt_get_buffer()
perf intel-pt: Factor out intel_pt_get_buffer()
Commit-ID: e96f7df8807615b96af59f8f8bc6263a7adc27b7 Gitweb: https://git.kernel.org/tip/e96f7df8807615b96af59f8f8bc6263a7adc27b7 Author: Adrian Hunter <[email protected]> AuthorDate: Tue, 4 Jun 2019 16:00:07 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 10 Jun 2019 16:20:12 -0300
perf intel-pt: Factor out intel_pt_get_buffer()
Factor out intel_pt_get_buffer() so it can be reused.
--- tools/perf/util/intel-pt.c | 60 ++++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 23 deletions(-)
tools/perf/util/intel-pt.c +37 -23
@@ -239,32 +239,13 @@ static int intel_pt_do_fix_overlap(struct intel_pt *pt, struct auxtrace_buffer *return 0 ; } -/* This function assumes data is processed sequentially only */ -static int intel_pt_get_trace (struct intel_pt_buffer *b,void *data) +static int intel_pt_get_buffer (struct intel_pt_queue *ptq, +struct auxtrace_buffer *buffer, +struct auxtrace_buffer *old_buffer, +struct intel_pt_buffer *b) { -struct intel_pt_queue *ptq = data; -struct auxtrace_buffer *buffer = ptq->buffer; -struct auxtrace_buffer *old_buffer = ptq->old_buffer; -struct auxtrace_queue *queue;bool might_overlap; -if (ptq->stop) { - b->len =0 ; -return 0 ; - } - - queue = &ptq->pt->queues.queue_array[ptq->queue_nr]; - - buffer =auxtrace_buffer__next (queue, buffer); -if (!buffer) { -if (old_buffer) -auxtrace_buffer__drop_data (old_buffer); - b->len =0 ; -return 0 ; - } - - ptq->buffer = buffer; -if (!buffer->data) {int fd =perf_data__fd (ptq->pt->session->data);
@@ -294,6 +275,39 @@ static int intel_pt_get_trace(struct intel_pt_buffer *b, void *data) b->consecutive = true; } +return 0 ; +} + +/* This function assumes data is processed sequentially only */ +static int intel_pt_get_trace (struct intel_pt_buffer *b,void *data) +{ +struct intel_pt_queue *ptq = data; +struct auxtrace_buffer *buffer = ptq->buffer; +struct auxtrace_buffer *old_buffer = ptq->old_buffer; +struct auxtrace_queue *queue; +int err; + +if (ptq->stop) { + b->len =0 ; +return 0 ; + } + + queue = &ptq->pt->queues.queue_array[ptq->queue_nr]; + + buffer =auxtrace_buffer__next (queue, buffer); +if (!buffer) { +if (old_buffer) +auxtrace_buffer__drop_data (old_buffer); + b->len =0 ; +return 0 ; + } + + ptq->buffer = buffer; + + err =intel_pt_get_buffer (ptq, buffer, old_buffer, b); +if (err) +return err; +if (ptq->step_through_buffers) ptq->stop = true;
Adrian Hunter
reviewerPATCH 10/19 perf intel-pt: Add support for lookahead
In reply to Adrian HunterImplement the lookahead callback to let the decoder access subsequent buffers. intel_pt_lookahead() manages the buffer lifetime and calls the decoder for each buffer until the decoder returns a non-zero value.
--- tools/perf/util/intel-pt.c | 59 +++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-)
tools/perf/util/intel-pt.c +58 -1
@@ -278,7 +278,63 @@ static int intel_pt_get_buffer(struct intel_pt_queue *ptq,return 0 ; } -/* This function assumes data is processed sequentially only */ +/* Do not drop buffers with references - refer intel_pt_get_trace() */ +static void intel_pt_lookahead_drop_buffer (struct intel_pt_queue *ptq, +struct auxtrace_buffer *buffer) +{ +if (!buffer || buffer == ptq->buffer || buffer == ptq->old_buffer) +return ; + +auxtrace_buffer__drop_data (buffer); +} + +/* Must be serialized with respect to intel_pt_get_trace() */ +static int intel_pt_lookahead (void *data,intel_pt_lookahead_cb_t cb, +void *cb_data) +{ +struct intel_pt_queue *ptq = data; +struct auxtrace_buffer *buffer = ptq->buffer; +struct auxtrace_buffer *old_buffer = ptq->old_buffer; +struct auxtrace_queue *queue; +int err =0 ; + + queue = &ptq->pt->queues.queue_array[ptq->queue_nr]; + +while (1 ) { +struct intel_pt_buffer b = { .len =0 }; + + buffer =auxtrace_buffer__next (queue, buffer); +if (!buffer) +break ; + + err =intel_pt_get_buffer (ptq, buffer, old_buffer, &b); +if (err) +break ; + +if (b.len) { +intel_pt_lookahead_drop_buffer (ptq, old_buffer); + old_buffer = buffer; + }else { +intel_pt_lookahead_drop_buffer (ptq, buffer); +continue ; + } + + err =cb (&b, cb_data); +if (err) +break ; + } + +if (buffer != old_buffer) +intel_pt_lookahead_drop_buffer (ptq, buffer); +intel_pt_lookahead_drop_buffer (ptq, old_buffer); + +return err; +} + +/* +* This function assumes data is processed sequentially only. +* Must be serialized with respect to intel_pt_lookahead() +*/ static int intel_pt_get_trace (struct intel_pt_buffer *b,void *data) {struct intel_pt_queue *ptq = data;
@@ -827,6 +883,7 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt, params.get_trace = intel_pt_get_trace; params.walk_insn = intel_pt_walk_next_insn; + params.lookahead = intel_pt_lookahead; params.data = ptq; params.return_compression =intel_pt_return_compression (pt); params.branch_enable =intel_pt_branch_enable (pt);
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Add support for lookahead
perf intel-pt: Add support for lookahead
Commit-ID: da9000ae35027fb7305b8cad0b37df71937ad578 Gitweb: https://git.kernel.org/tip/da9000ae35027fb7305b8cad0b37df71937ad578 Author: Adrian Hunter <[email protected]> AuthorDate: Tue, 4 Jun 2019 16:00:08 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 10 Jun 2019 16:20:12 -0300
perf intel-pt: Add support for lookahead
Implement the lookahead callback to let the decoder access subsequent buffers. intel_pt_lookahead() manages the buffer lifetime and calls the decoder for each buffer until the decoder returns a non-zero value.
--- tools/perf/util/intel-pt.c | 59 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-)
tools/perf/util/intel-pt.c +58 -1
@@ -278,7 +278,63 @@ static int intel_pt_get_buffer(struct intel_pt_queue *ptq,return 0 ; } -/* This function assumes data is processed sequentially only */ +/* Do not drop buffers with references - refer intel_pt_get_trace() */ +static void intel_pt_lookahead_drop_buffer (struct intel_pt_queue *ptq, +struct auxtrace_buffer *buffer) +{ +if (!buffer || buffer == ptq->buffer || buffer == ptq->old_buffer) +return ; + +auxtrace_buffer__drop_data (buffer); +} + +/* Must be serialized with respect to intel_pt_get_trace() */ +static int intel_pt_lookahead (void *data,intel_pt_lookahead_cb_t cb, +void *cb_data) +{ +struct intel_pt_queue *ptq = data; +struct auxtrace_buffer *buffer = ptq->buffer; +struct auxtrace_buffer *old_buffer = ptq->old_buffer; +struct auxtrace_queue *queue; +int err =0 ; + + queue = &ptq->pt->queues.queue_array[ptq->queue_nr]; + +while (1 ) { +struct intel_pt_buffer b = { .len =0 }; + + buffer =auxtrace_buffer__next (queue, buffer); +if (!buffer) +break ; + + err =intel_pt_get_buffer (ptq, buffer, old_buffer, &b); +if (err) +break ; + +if (b.len) { +intel_pt_lookahead_drop_buffer (ptq, old_buffer); + old_buffer = buffer; + }else { +intel_pt_lookahead_drop_buffer (ptq, buffer); +continue ; + } + + err =cb (&b, cb_data); +if (err) +break ; + } + +if (buffer != old_buffer) +intel_pt_lookahead_drop_buffer (ptq, buffer); +intel_pt_lookahead_drop_buffer (ptq, old_buffer); + +return err; +} + +/* +* This function assumes data is processed sequentially only. +* Must be serialized with respect to intel_pt_lookahead() +*/ static int intel_pt_get_trace (struct intel_pt_buffer *b,void *data) {struct intel_pt_queue *ptq = data;
@@ -827,6 +883,7 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt, params.get_trace = intel_pt_get_trace; params.walk_insn = intel_pt_walk_next_insn; + params.lookahead = intel_pt_lookahead; params.data = ptq; params.return_compression =intel_pt_return_compression (pt); params.branch_enable =intel_pt_branch_enable (pt);
Adrian Hunter
reviewerPATCH 11/19 perf intel-pt: Add support for efficient time interval filtering
In reply to Adrian HunterSet up time ranges for efficient time interval filtering using the new "fast forward" facility.
Because decoding is done in time order, intel_pt_time_filter() needs to look only at the next start or end timestamp - refer intel_pt_next_time().
--- tools/perf/util/intel-pt.c | 208 +++++++++++++++++++++++++++++++++++++ 1 file changed, 208 insertions(+)
tools/perf/util/intel-pt.c +208 -0
@@ -42,6 +42,7 @@#include "tsc.h" #include "intel-pt.h" #include "config.h" +#include "time-utils.h" #include "intel-pt-decoder/intel-pt-log.h" #include "intel-pt-decoder/intel-pt-decoder.h"
@@ -50,6 +51,11 @@#define MAX_TIMESTAMP (~0ULL) +struct range { +u64 start; +u64 end; +}; +struct intel_pt {struct auxtrace auxtrace;struct auxtrace_queues queues;
@@ -118,6 +124,9 @@ struct intel_pt {char *filter;struct addr_filters filts; + +struct range *time_ranges; +unsigned int range_cnt; };enum switch_state {
@@ -154,6 +163,9 @@ struct intel_pt_queue {bool have_sample;u64 time;u64 timestamp; +u64 sel_timestamp; +bool sel_start; +unsigned int sel_idx;u32 flags;u16 insn_len;u64 last_insn_cnt;
@@ -1007,6 +1019,23 @@ static void intel_pt_sample_flags(struct intel_pt_queue *ptq) ptq->flags |=PERF_IP_FLAG_TRACE_END ; } +static void intel_pt_setup_time_range (struct intel_pt *pt, +struct intel_pt_queue *ptq) +{ +if (!pt->range_cnt) +return ; + + ptq->sel_timestamp = pt->time_ranges[0 ].start; + ptq->sel_idx =0 ; + +if (ptq->sel_timestamp) { + ptq->sel_start = true; + }else { + ptq->sel_timestamp = pt->time_ranges[0 ].end; + ptq->sel_start = false; + } +} +static int intel_pt_setup_queue (struct intel_pt *pt,struct auxtrace_queue *queue,unsigned int queue_nr)
@@ -1031,6 +1060,8 @@ static int intel_pt_setup_queue(struct intel_pt *pt, ptq->step_through_buffers = true; ptq->sync_switch = pt->sync_switch; + +intel_pt_setup_time_range (pt, ptq); } if (!ptq->on_heap &&
@@ -1045,6 +1076,14 @@ static int intel_pt_setup_queue(struct intel_pt *pt,intel_pt_log ("queue %u getting timestamp\n" , queue_nr);intel_pt_log ("queue %u decoding cpu %d pid %d tid %d\n" , queue_nr, ptq->cpu, ptq->pid, ptq->tid); + +if (ptq->sel_start && ptq->sel_timestamp) { + ret =intel_pt_fast_forward (ptq->decoder, + ptq->sel_timestamp); +if (ret) +return ret; + } +while (1 ) { state =intel_pt_decode (ptq->decoder);if (state->err) {
@@ -1064,6 +1103,9 @@ static int intel_pt_setup_queue(struct intel_pt *pt, queue_nr, ptq->timestamp); ptq->state = state; ptq->have_sample = true; +if (ptq->sel_start && ptq->sel_timestamp && + ptq->timestamp < ptq->sel_timestamp) + ptq->have_sample = false;intel_pt_sample_flags (ptq); ret =auxtrace_heap__add (&pt->heap, queue_nr, ptq->timestamp);if (ret)
@@ -1750,10 +1792,83 @@ static void intel_pt_enable_sync_switch(struct intel_pt *pt) } } +/* +* To filter against time ranges, it is only necessary to look at the next start +* or end time. +*/ +static bool intel_pt_next_time (struct intel_pt_queue *ptq) +{ +struct intel_pt *pt = ptq->pt; + +if (ptq->sel_start) { +/* Next time is an end time */ + ptq->sel_start = false; + ptq->sel_timestamp = pt->time_ranges[ptq->sel_idx].end; +return true; + }else if (ptq->sel_idx +1 < pt->range_cnt) { +/* Next time is a start time */ + ptq->sel_start = true; + ptq->sel_idx +=1 ; + ptq->sel_timestamp = pt->time_ranges[ptq->sel_idx].start; +return true; + } + +/* No next time */ +return false; +} + +static int intel_pt_time_filter (struct intel_pt_queue *ptq,u64 *ff_timestamp) +{ +int err; + +while (1 ) { +if (ptq->sel_start) { +if (ptq->timestamp >= ptq->sel_timestamp) { +/* After start time, so consider next time */ +intel_pt_next_time (ptq); +if (!ptq->sel_timestamp) { +/* No end time */ +return 0 ; + } +/* Check against end time */ +continue ; + } +/* Before start time, so fast forward */ + ptq->have_sample = false; +if (ptq->sel_timestamp > *ff_timestamp) { +if (ptq->sync_switch) { +intel_pt_next_tid (ptq->pt, ptq); + ptq->switch_state =INTEL_PT_SS_UNKNOWN ; + } + *ff_timestamp = ptq->sel_timestamp; + err =intel_pt_fast_forward (ptq->decoder, + ptq->sel_timestamp); +if (err) +return err; + } +return 0 ; + }else if (ptq->timestamp > ptq->sel_timestamp) { +/* After end time, so consider next time */ +if (!intel_pt_next_time (ptq)) { +/* No next time range, so stop decoding */ + ptq->have_sample = false; + ptq->switch_state =INTEL_PT_SS_NOT_TRACING ; +return 1 ; + } +/* Check against next start time */ +continue ; + }else { +/* Before end time */ +return 0 ; + } + } +} +static int intel_pt_run_decoder (struct intel_pt_queue *ptq,u64 *timestamp) {const struct intel_pt_state *state = ptq->state;struct intel_pt *pt = ptq->pt; +u64 ff_timestamp =0 ;int err;if (!pt->kernel_start) {
@@ -1818,6 +1933,12 @@ static int intel_pt_run_decoder(struct intel_pt_queue *ptq, u64 *timestamp) ptq->timestamp = state->timestamp; } +if (ptq->sel_timestamp) { + err =intel_pt_time_filter (ptq, &ff_timestamp); +if (err) +return err; + } +if (!pt->timeless_decoding && ptq->timestamp >= *timestamp) { *timestamp = ptq->timestamp;return 0 ;
@@ -2223,6 +2344,7 @@ static void intel_pt_free(struct perf_session *session)thread__put (pt->unknown_thread);addr_filters__exit (&pt->filts);zfree (&pt->filter); +zfree (&pt->time_ranges);free (pt); }
@@ -2520,6 +2642,85 @@ static int intel_pt_perf_config(const char *var, const char *value, void *data)return 0 ; } +/* Find least TSC which converts to ns or later */ +static u64 intel_pt_tsc_start (u64 ns,struct intel_pt *pt) +{ +u64 tsc, tm; + + tsc =perf_time_to_tsc (ns, &pt->tc); + +while (1 ) { + tm =tsc_to_perf_time (tsc, &pt->tc); +if (tm < ns) +break ; + tsc -=1 ; + } + +while (tm < ns) + tm =tsc_to_perf_time (++tsc, &pt->tc); + +return tsc; +} + +/* Find greatest TSC which converts to ns or earlier */ +static u64 intel_pt_tsc_end (u64 ns,struct intel_pt *pt) +{ +u64 tsc, tm; + + tsc =perf_time_to_tsc (ns, &pt->tc); + +while (1 ) { + tm =tsc_to_perf_time (tsc, &pt->tc); +if (tm > ns) +break ; + tsc +=1 ; + } + +while (tm > ns) + tm =tsc_to_perf_time (--tsc, &pt->tc); + +return tsc; +} + +static int intel_pt_setup_time_ranges (struct intel_pt *pt, +struct itrace_synth_opts *opts) +{ +struct perf_time_interval *p = opts->ptime_range; +int n = opts->range_num; +int i; + +if (!n || !p || pt->timeless_decoding) +return 0 ; + + pt->time_ranges =calloc (n,sizeof (struct range )); +if (!pt->time_ranges) +return -ENOMEM ; + + pt->range_cnt = n; + +intel_pt_log ("%s: %u range(s)\n" , __func__, n); + +for (i =0 ; i < n; i++) { +struct range *r = &pt->time_ranges[i]; +u64 ts = p[i].start; +u64 te = p[i].end; + +/* +* Take care to ensure the TSC range matches the perf-time range +* when converted back to perf-time. +*/ + r->start = ts ?intel_pt_tsc_start (ts, pt) :0 ; + r->end = te ?intel_pt_tsc_end (te, pt) :0 ; + +intel_pt_log ("range %d: perf time interval: %" PRIu64" to %" PRIu64"\n" , + i, ts, te); +intel_pt_log ("range %d: TSC time interval: %#" PRIx64" to %#" PRIx64"\n" , + i, r->start, r->end); + } + +return 0 ; +} +static const char *const intel_pt_info_fmts[] = { [INTEL_PT_PMU_TYPE ] =" PMU Type %" PRId64"\n" , [INTEL_PT_TIME_SHIFT ] =" Time Shift %" PRIu64"\n" ,
@@ -2752,6 +2953,12 @@ int intel_pt_process_auxtrace_info(union perf_event *event, pt->cbr2khz = tsc_freq / pt->max_non_turbo_ratio /1000 ; } +if (session->itrace_synth_opts) { + err =intel_pt_setup_time_ranges (pt, session->itrace_synth_opts); +if (err) + goto err_delete_thread; + } +if (pt->synth_opts.calls) pt->branches_filter |=PERF_IP_FLAG_CALL |PERF_IP_FLAG_ASYNC |PERF_IP_FLAG_TRACE_END ;
@@ -2792,6 +2999,7 @@ int intel_pt_process_auxtrace_info(union perf_event *event, err_free:addr_filters__exit (&pt->filts);zfree (&pt->filter); +zfree (&pt->time_ranges);free (pt);return err; }
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge botperf intel-pt: Add support for efficient time interval filtering
Commit-ID: 2c47db90ed71af9c12d5600dbcef864761d76b3d Gitweb: https://git.kernel.org/tip/2c47db90ed71af9c12d5600dbcef864761d76b3d Author: Adrian Hunter <[email protected]> AuthorDate: Tue, 4 Jun 2019 16:00:09 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 10 Jun 2019 16:20:12 -0300
perf intel-pt: Add support for efficient time interval filtering
Set up time ranges for efficient time interval filtering using the new "fast forward" facility.
Because decoding is done in time order, intel_pt_time_filter() needs to look only at the next start or end timestamp - refer intel_pt_next_time().
--- tools/perf/util/intel-pt.c | 208 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 208 insertions(+)
tools/perf/util/intel-pt.c +208 -0
@@ -42,6 +42,7 @@#include "tsc.h" #include "intel-pt.h" #include "config.h" +#include "time-utils.h" #include "intel-pt-decoder/intel-pt-log.h" #include "intel-pt-decoder/intel-pt-decoder.h"
@@ -50,6 +51,11 @@#define MAX_TIMESTAMP (~0ULL) +struct range { +u64 start; +u64 end; +}; +struct intel_pt {struct auxtrace auxtrace;struct auxtrace_queues queues;
@@ -118,6 +124,9 @@ struct intel_pt {char *filter;struct addr_filters filts; + +struct range *time_ranges; +unsigned int range_cnt; };enum switch_state {
@@ -154,6 +163,9 @@ struct intel_pt_queue {bool have_sample;u64 time;u64 timestamp; +u64 sel_timestamp; +bool sel_start; +unsigned int sel_idx;u32 flags;u16 insn_len;u64 last_insn_cnt;
@@ -1007,6 +1019,23 @@ static void intel_pt_sample_flags(struct intel_pt_queue *ptq) ptq->flags |=PERF_IP_FLAG_TRACE_END ; } +static void intel_pt_setup_time_range (struct intel_pt *pt, +struct intel_pt_queue *ptq) +{ +if (!pt->range_cnt) +return ; + + ptq->sel_timestamp = pt->time_ranges[0 ].start; + ptq->sel_idx =0 ; + +if (ptq->sel_timestamp) { + ptq->sel_start = true; + }else { + ptq->sel_timestamp = pt->time_ranges[0 ].end; + ptq->sel_start = false; + } +} +static int intel_pt_setup_queue (struct intel_pt *pt,struct auxtrace_queue *queue,unsigned int queue_nr)
@@ -1031,6 +1060,8 @@ static int intel_pt_setup_queue(struct intel_pt *pt, ptq->step_through_buffers = true; ptq->sync_switch = pt->sync_switch; + +intel_pt_setup_time_range (pt, ptq); } if (!ptq->on_heap &&
@@ -1045,6 +1076,14 @@ static int intel_pt_setup_queue(struct intel_pt *pt,intel_pt_log ("queue %u getting timestamp\n" , queue_nr);intel_pt_log ("queue %u decoding cpu %d pid %d tid %d\n" , queue_nr, ptq->cpu, ptq->pid, ptq->tid); + +if (ptq->sel_start && ptq->sel_timestamp) { + ret =intel_pt_fast_forward (ptq->decoder, + ptq->sel_timestamp); +if (ret) +return ret; + } +while (1 ) { state =intel_pt_decode (ptq->decoder);if (state->err) {
@@ -1064,6 +1103,9 @@ static int intel_pt_setup_queue(struct intel_pt *pt, queue_nr, ptq->timestamp); ptq->state = state; ptq->have_sample = true; +if (ptq->sel_start && ptq->sel_timestamp && + ptq->timestamp < ptq->sel_timestamp) + ptq->have_sample = false;intel_pt_sample_flags (ptq); ret =auxtrace_heap__add (&pt->heap, queue_nr, ptq->timestamp);if (ret)
@@ -1750,10 +1792,83 @@ static void intel_pt_enable_sync_switch(struct intel_pt *pt) } } +/* +* To filter against time ranges, it is only necessary to look at the next start +* or end time. +*/ +static bool intel_pt_next_time (struct intel_pt_queue *ptq) +{ +struct intel_pt *pt = ptq->pt; + +if (ptq->sel_start) { +/* Next time is an end time */ + ptq->sel_start = false; + ptq->sel_timestamp = pt->time_ranges[ptq->sel_idx].end; +return true; + }else if (ptq->sel_idx +1 < pt->range_cnt) { +/* Next time is a start time */ + ptq->sel_start = true; + ptq->sel_idx +=1 ; + ptq->sel_timestamp = pt->time_ranges[ptq->sel_idx].start; +return true; + } + +/* No next time */ +return false; +} + +static int intel_pt_time_filter (struct intel_pt_queue *ptq,u64 *ff_timestamp) +{ +int err; + +while (1 ) { +if (ptq->sel_start) { +if (ptq->timestamp >= ptq->sel_timestamp) { +/* After start time, so consider next time */ +intel_pt_next_time (ptq); +if (!ptq->sel_timestamp) { +/* No end time */ +return 0 ; + } +/* Check against end time */ +continue ; + } +/* Before start time, so fast forward */ + ptq->have_sample = false; +if (ptq->sel_timestamp > *ff_timestamp) { +if (ptq->sync_switch) { +intel_pt_next_tid (ptq->pt, ptq); + ptq->switch_state =INTEL_PT_SS_UNKNOWN ; + } + *ff_timestamp = ptq->sel_timestamp; + err =intel_pt_fast_forward (ptq->decoder, + ptq->sel_timestamp); +if (err) +return err; + } +return 0 ; + }else if (ptq->timestamp > ptq->sel_timestamp) { +/* After end time, so consider next time */ +if (!intel_pt_next_time (ptq)) { +/* No next time range, so stop decoding */ + ptq->have_sample = false; + ptq->switch_state =INTEL_PT_SS_NOT_TRACING ; +return 1 ; + } +/* Check against next start time */ +continue ; + }else { +/* Before end time */ +return 0 ; + } + } +} +static int intel_pt_run_decoder (struct intel_pt_queue *ptq,u64 *timestamp) {const struct intel_pt_state *state = ptq->state;struct intel_pt *pt = ptq->pt; +u64 ff_timestamp =0 ;int err;if (!pt->kernel_start) {
@@ -1818,6 +1933,12 @@ static int intel_pt_run_decoder(struct intel_pt_queue *ptq, u64 *timestamp) ptq->timestamp = state->timestamp; } +if (ptq->sel_timestamp) { + err =intel_pt_time_filter (ptq, &ff_timestamp); +if (err) +return err; + } +if (!pt->timeless_decoding && ptq->timestamp >= *timestamp) { *timestamp = ptq->timestamp;return 0 ;
@@ -2223,6 +2344,7 @@ static void intel_pt_free(struct perf_session *session)thread__put (pt->unknown_thread);addr_filters__exit (&pt->filts);zfree (&pt->filter); +zfree (&pt->time_ranges);free (pt); }
@@ -2520,6 +2642,85 @@ static int intel_pt_perf_config(const char *var, const char *value, void *data)return 0 ; } +/* Find least TSC which converts to ns or later */ +static u64 intel_pt_tsc_start (u64 ns,struct intel_pt *pt) +{ +u64 tsc, tm; + + tsc =perf_time_to_tsc (ns, &pt->tc); + +while (1 ) { + tm =tsc_to_perf_time (tsc, &pt->tc); +if (tm < ns) +break ; + tsc -=1 ; + } + +while (tm < ns) + tm =tsc_to_perf_time (++tsc, &pt->tc); + +return tsc; +} + +/* Find greatest TSC which converts to ns or earlier */ +static u64 intel_pt_tsc_end (u64 ns,struct intel_pt *pt) +{ +u64 tsc, tm; + + tsc =perf_time_to_tsc (ns, &pt->tc); + +while (1 ) { + tm =tsc_to_perf_time (tsc, &pt->tc); +if (tm > ns) +break ; + tsc +=1 ; + } + +while (tm > ns) + tm =tsc_to_perf_time (--tsc, &pt->tc); + +return tsc; +} + +static int intel_pt_setup_time_ranges (struct intel_pt *pt, +struct itrace_synth_opts *opts) +{ +struct perf_time_interval *p = opts->ptime_range; +int n = opts->range_num; +int i; + +if (!n || !p || pt->timeless_decoding) +return 0 ; + + pt->time_ranges =calloc (n,sizeof (struct range )); +if (!pt->time_ranges) +return -ENOMEM ; + + pt->range_cnt = n; + +intel_pt_log ("%s: %u range(s)\n" , __func__, n); + +for (i =0 ; i < n; i++) { +struct range *r = &pt->time_ranges[i]; +u64 ts = p[i].start; +u64 te = p[i].end; + +/* +* Take care to ensure the TSC range matches the perf-time range +* when converted back to perf-time. +*/ + r->start = ts ?intel_pt_tsc_start (ts, pt) :0 ; + r->end = te ?intel_pt_tsc_end (te, pt) :0 ; + +intel_pt_log ("range %d: perf time interval: %" PRIu64" to %" PRIu64"\n" , + i, ts, te); +intel_pt_log ("range %d: TSC time interval: %#" PRIx64" to %#" PRIx64"\n" , + i, r->start, r->end); + } + +return 0 ; +} +static const char *const intel_pt_info_fmts[] = { [INTEL_PT_PMU_TYPE ] =" PMU Type %" PRId64"\n" , [INTEL_PT_TIME_SHIFT ] =" Time Shift %" PRIu64"\n" ,
@@ -2752,6 +2953,12 @@ int intel_pt_process_auxtrace_info(union perf_event *event, pt->cbr2khz = tsc_freq / pt->max_non_turbo_ratio /1000 ; } +if (session->itrace_synth_opts) { + err =intel_pt_setup_time_ranges (pt, session->itrace_synth_opts); +if (err) + goto err_delete_thread; + } +if (pt->synth_opts.calls) pt->branches_filter |=PERF_IP_FLAG_CALL |PERF_IP_FLAG_ASYNC |PERF_IP_FLAG_TRACE_END ;
@@ -2792,6 +2999,7 @@ err_free_queues: err_free:addr_filters__exit (&pt->filts);zfree (&pt->filter); +zfree (&pt->time_ranges);free (pt);return err; }
Adrian Hunter
reviewerPATCH 12/19 perf time-utils: Treat time ranges consistently
In reply to Adrian HunterCurrently, options allow only 1 explicit (non-percentage) time range. In preparation for adding support for multiple explicit time ranges, treat time ranges consistently.
Instead of treating some time ranges as inclusive and some as excluding the end time, treat all time ranges as inclusive. This is only a 1 nanosecond change but is necessary to treat multiple explicit time ranges in a consistent manner.
Note, there is a later patch that adds a test for time-utils.
--- tools/perf/util/time-utils.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
tools/perf/util/time-utils.c +3 -4
@@ -389,13 +389,12 @@ bool perf_time__ranges_skip_sample(struct perf_time_interval *ptime_buf, ptime = &ptime_buf[i];if (timestamp >= ptime->start && - ((timestamp < ptime->end && i < num -1 ) || - (timestamp <= ptime->end && i == num -1 ))) { -break ; + (timestamp <= ptime->end || !ptime->end)) { +return false; } } -return (i == num) ? true : false; +return true; } int perf_time__parse_for_ranges(const char *time_str,
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf time-utils: Treat time ranges consistently
perf time-utils: Treat time ranges consistently
Commit-ID: f79a7689d99366aee9f89d785bca6c52ed6b76eb Gitweb: https://git.kernel.org/tip/f79a7689d99366aee9f89d785bca6c52ed6b76eb Author: Adrian Hunter <[email protected]> AuthorDate: Tue, 4 Jun 2019 16:00:10 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 10 Jun 2019 16:20:12 -0300
perf time-utils: Treat time ranges consistently
Currently, options allow only 1 explicit (non-percentage) time range. In preparation for adding support for multiple explicit time ranges, treat time ranges consistently.
Instead of treating some time ranges as inclusive and some as excluding the end time, treat all time ranges as inclusive. This is only a 1 nanosecond change but is necessary to treat multiple explicit time ranges in a consistent manner.
Note, there is a later patch that adds a test for time-utils.
--- tools/perf/util/time-utils.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
tools/perf/util/time-utils.c +3 -4
@@ -389,13 +389,12 @@ bool perf_time__ranges_skip_sample(struct perf_time_interval *ptime_buf, ptime = &ptime_buf[i];if (timestamp >= ptime->start && - ((timestamp < ptime->end && i < num -1 ) || - (timestamp <= ptime->end && i == num -1 ))) { -break ; + (timestamp <= ptime->end || !ptime->end)) { +return false; } } -return (i == num) ? true : false; +return true; } int perf_time__parse_for_ranges(const char *time_str,
Adrian Hunter
reviewerPATCH 13/19 perf time-utils: Factor out set_percent_time()
In reply to Adrian HunterFactor out set_percent_time() so it can be reused.
--- tools/perf/util/time-utils.c | 39 +++++++++++++++++------------------- 1 file changed, 18 insertions(+), 21 deletions(-)
tools/perf/util/time-utils.c +18 -21
@@ -135,12 +135,27 @@ static int parse_percent(double *pcnt, char *str)return 0 ; } +static int set_percent_time (struct perf_time_interval *ptime,double start_pcnt, +double end_pcnt,u64 start,u64 end) +{ +u64 total = end - start; + +if (start_pcnt <0.0 || start_pcnt >1.0 || + end_pcnt <0.0 || end_pcnt >1.0 ) { +return -1 ; + } + + ptime->start = start +round (start_pcnt * total); + ptime->end = start +round (end_pcnt * total); + +return 0 ; +} +static int percent_slash_split (char *str,struct perf_time_interval *ptime,u64 start,u64 end) {char *p, *end_str;double pcnt, start_pcnt, end_pcnt; -u64 total = end - start;int i;/*
@@ -168,15 +183,7 @@ static int percent_slash_split(char *str, struct perf_time_interval *ptime, start_pcnt = pcnt * (i -1 ); end_pcnt = pcnt * i; -if (start_pcnt <0.0 || start_pcnt >1.0 || - end_pcnt <0.0 || end_pcnt >1.0 ) { -return -1 ; - } - - ptime->start = start +round (start_pcnt * total); - ptime->end = start +round (end_pcnt * total); - -return 0 ; +return set_percent_time (ptime, start_pcnt, end_pcnt, start, end); } static int percent_dash_split(char *str, struct perf_time_interval *ptime,
@@ -184,7 +191,6 @@ static int percent_dash_split(char *str, struct perf_time_interval *ptime, {char *start_str =NULL , *end_str;double start_pcnt, end_pcnt; -u64 total = end - start;int ret;/*
@@ -203,16 +209,7 @@ static int percent_dash_split(char *str, struct perf_time_interval *ptime,free (start_str); -if (start_pcnt <0.0 || start_pcnt >1.0 || - end_pcnt <0.0 || end_pcnt >1.0 || - start_pcnt > end_pcnt) { -return -1 ; - } - - ptime->start = start +round (start_pcnt * total); - ptime->end = start +round (end_pcnt * total); - -return 0 ; +return set_percent_time (ptime, start_pcnt, end_pcnt, start, end); } typedef int (*time_pecent_split)(char *, struct perf_time_interval *,
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf time-utils: Factor out set_percent_time()
perf time-utils: Factor out set_percent_time()
Commit-ID: c763242a5e742f8fefda0bb6cfdf6a5a34ae5e10 Gitweb: https://git.kernel.org/tip/c763242a5e742f8fefda0bb6cfdf6a5a34ae5e10 Author: Adrian Hunter <[email protected]> AuthorDate: Tue, 4 Jun 2019 16:00:11 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 10 Jun 2019 16:20:12 -0300
perf time-utils: Factor out set_percent_time()
Factor out set_percent_time() so it can be reused.
--- tools/perf/util/time-utils.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-)
tools/perf/util/time-utils.c +18 -21
@@ -135,12 +135,27 @@ static int parse_percent(double *pcnt, char *str)return 0 ; } +static int set_percent_time (struct perf_time_interval *ptime,double start_pcnt, +double end_pcnt,u64 start,u64 end) +{ +u64 total = end - start; + +if (start_pcnt <0.0 || start_pcnt >1.0 || + end_pcnt <0.0 || end_pcnt >1.0 ) { +return -1 ; + } + + ptime->start = start +round (start_pcnt * total); + ptime->end = start +round (end_pcnt * total); + +return 0 ; +} +static int percent_slash_split (char *str,struct perf_time_interval *ptime,u64 start,u64 end) {char *p, *end_str;double pcnt, start_pcnt, end_pcnt; -u64 total = end - start;int i;/*
@@ -168,15 +183,7 @@ static int percent_slash_split(char *str, struct perf_time_interval *ptime, start_pcnt = pcnt * (i -1 ); end_pcnt = pcnt * i; -if (start_pcnt <0.0 || start_pcnt >1.0 || - end_pcnt <0.0 || end_pcnt >1.0 ) { -return -1 ; - } - - ptime->start = start +round (start_pcnt * total); - ptime->end = start +round (end_pcnt * total); - -return 0 ; +return set_percent_time (ptime, start_pcnt, end_pcnt, start, end); } static int percent_dash_split(char *str, struct perf_time_interval *ptime,
@@ -184,7 +191,6 @@ static int percent_dash_split(char *str, struct perf_time_interval *ptime, {char *start_str =NULL , *end_str;double start_pcnt, end_pcnt; -u64 total = end - start;int ret;/*
@@ -203,16 +209,7 @@ static int percent_dash_split(char *str, struct perf_time_interval *ptime,free (start_str); -if (start_pcnt <0.0 || start_pcnt >1.0 || - end_pcnt <0.0 || end_pcnt >1.0 || - start_pcnt > end_pcnt) { -return -1 ; - } - - ptime->start = start +round (start_pcnt * total); - ptime->end = start +round (end_pcnt * total); - -return 0 ; +return set_percent_time (ptime, start_pcnt, end_pcnt, start, end); } typedef int (*time_pecent_split)(char *, struct perf_time_interval *,
Adrian Hunter
reviewerPATCH 14/19 perf time-utils: Prevent percentage time range overlap
In reply to Adrian HunterPrevent percentage time range overlap. This is only a 1 nanosecond change but makes the results more logical e.g. a sample cannot be in both the first 10% and the second 20%.
Note, there is a later patch that adds a test for time-utils.
--- tools/perf/util/time-utils.c | 3 +++ 1 file changed, 3 insertions(+)
tools/perf/util/time-utils.c +3 -0
@@ -148,6 +148,9 @@ static int set_percent_time(struct perf_time_interval *ptime, double start_pcnt, ptime->start = start +round (start_pcnt * total); ptime->end = start +round (end_pcnt * total); +if (ptime->end > ptime->start && ptime->end != end) + ptime->end -=1 ; +return 0 ; }
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf time-utils: Prevent percentage time range overlap
perf time-utils: Prevent percentage time range overlap
Commit-ID: b16bfeb3db1b50273e95f539953c337be759500d Gitweb: https://git.kernel.org/tip/b16bfeb3db1b50273e95f539953c337be759500d Author: Adrian Hunter <[email protected]> AuthorDate: Tue, 4 Jun 2019 16:00:12 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 10 Jun 2019 16:20:12 -0300
perf time-utils: Prevent percentage time range overlap
Prevent percentage time range overlap. This is only a 1 nanosecond change but makes the results more logical e.g. a sample cannot be in both the first 10% and the second 20%.
Note, there is a later patch that adds a test for time-utils.
--- tools/perf/util/time-utils.c | 3 +++ 1 file changed, 3 insertions(+)
tools/perf/util/time-utils.c +3 -0
@@ -148,6 +148,9 @@ static int set_percent_time(struct perf_time_interval *ptime, double start_pcnt, ptime->start = start +round (start_pcnt * total); ptime->end = start +round (end_pcnt * total); +if (ptime->end > ptime->start && ptime->end != end) + ptime->end -=1 ; +return 0 ; }
Adrian Hunter
reviewerPATCH 15/19 perf time-utils: Fix --time documentation
In reply to Adrian HunterCorrect some punctuation and spelling and correct the format to show that the time resolution is nanoseconds not microseconds.
--- tools/perf/Documentation/perf-diff.txt | 6 +++--- tools/perf/Documentation/perf-report.txt | 6 +++--- tools/perf/Documentation/perf-script.txt | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-)
tools/perf/Documentation/perf-diff.txt +3 -3
@@ -142,9 +142,9 @@ OPTIONS perf diff --time 0%-10%,30%-40% It also supports analyzing samples within a given time window - <start>,<stop>. Times have the format seconds.microseconds. If 'start' - is not given (i.e., time string is ',x.y') then analysis starts at - the beginning of the file. If stop time is not given (i.e, time + <start>,<stop>. Times have the format seconds.nanoseconds. If 'start' + is not given (i.e. time string is ',x.y') then analysis starts at + the beginning of the file. If stop time is not given (i.e. time string is 'x.y,') then analysis goes to the end of the file. Time string is 'a1.b1,c1.d1:a2.b2,c2.d2'. Use ':' to separate timestamps for different perf.data files.
tools/perf/Documentation/perf-report.txt +3 -3
@@ -412,12 +412,12 @@ OPTIONS --time:: Only analyze samples within given time window: <start>,<stop>. Times - have the format seconds.microseconds. If start is not given (i.e., time + have the format seconds.nanoseconds. If start is not given (i.e. time string is ',x.y') then analysis starts at the beginning of the file. If - stop time is not given (i.e, time string is 'x.y,') then analysis goes + stop time is not given (i.e. time string is 'x.y,') then analysis goes to end of file. - Also support time percent with multiple time range. Time string is + Also support time percent with multiple time ranges. Time string is 'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'. For example:
tools/perf/Documentation/perf-script.txt +3 -3
@@ -361,12 +361,12 @@ include::itrace.txt[] --time:: Only analyze samples within given time window: <start>,<stop>. Times - have the format seconds.microseconds. If start is not given (i.e., time + have the format seconds.nanoseconds. If start is not given (i.e. time string is ',x.y') then analysis starts at the beginning of the file. If - stop time is not given (i.e, time string is 'x.y,') then analysis goes + stop time is not given (i.e. time string is 'x.y,') then analysis goes to end of file. - Also support time percent with multipe time range. Time string is + Also support time percent with multiple time ranges. Time string is 'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'. For example:
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf time-utils: Fix --time documentation
perf time-utils: Fix --time documentation
Commit-ID: 0ccc69ba0af46e3371c8cefb506aaf9f0e4f554c Gitweb: https://git.kernel.org/tip/0ccc69ba0af46e3371c8cefb506aaf9f0e4f554c Author: Adrian Hunter <[email protected]> AuthorDate: Tue, 4 Jun 2019 16:00:13 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 10 Jun 2019 16:20:12 -0300
perf time-utils: Fix --time documentation
Correct some punctuation and spelling and correct the format to show that the time resolution is nanoseconds not microseconds.
--- tools/perf/Documentation/perf-diff.txt | 6 +++--- tools/perf/Documentation/perf-report.txt | 6 +++--- tools/perf/Documentation/perf-script.txt | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-)
tools/perf/Documentation/perf-diff.txt +3 -3
@@ -142,9 +142,9 @@ OPTIONS perf diff --time 0%-10%,30%-40% It also supports analyzing samples within a given time window - <start>,<stop>. Times have the format seconds.microseconds. If 'start' - is not given (i.e., time string is ',x.y') then analysis starts at - the beginning of the file. If stop time is not given (i.e, time + <start>,<stop>. Times have the format seconds.nanoseconds. If 'start' + is not given (i.e. time string is ',x.y') then analysis starts at + the beginning of the file. If stop time is not given (i.e. time string is 'x.y,') then analysis goes to the end of the file. Time string is 'a1.b1,c1.d1:a2.b2,c2.d2'. Use ':' to separate timestamps for different perf.data files.
tools/perf/Documentation/perf-report.txt +3 -3
@@ -412,12 +412,12 @@ OPTIONS --time:: Only analyze samples within given time window: <start>,<stop>. Times - have the format seconds.microseconds. If start is not given (i.e., time + have the format seconds.nanoseconds. If start is not given (i.e. time string is ',x.y') then analysis starts at the beginning of the file. If - stop time is not given (i.e, time string is 'x.y,') then analysis goes + stop time is not given (i.e. time string is 'x.y,') then analysis goes to end of file. - Also support time percent with multiple time range. Time string is + Also support time percent with multiple time ranges. Time string is 'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'. For example:
tools/perf/Documentation/perf-script.txt +3 -3
@@ -361,12 +361,12 @@ include::itrace.txt[] --time:: Only analyze samples within given time window: <start>,<stop>. Times - have the format seconds.microseconds. If start is not given (i.e., time + have the format seconds.nanoseconds. If start is not given (i.e. time string is ',x.y') then analysis starts at the beginning of the file. If - stop time is not given (i.e, time string is 'x.y,') then analysis goes + stop time is not given (i.e. time string is 'x.y,') then analysis goes to end of file. - Also support time percent with multipe time range. Time string is + Also support time percent with multiple time ranges. Time string is 'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'. For example:
Adrian Hunter
reviewerPATCH 16/19 perf time-utils: Simplify perf_time__parse_for_ranges() error paths slightly
In reply to Adrian HunterSimplify perf_time__parse_for_ranges() error paths slightly.
--- tools/perf/util/time-utils.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
tools/perf/util/time-utils.c +5 -7
@@ -403,7 +403,7 @@ int perf_time__parse_for_ranges(const char *time_str, int *range_size, int *range_num) { struct perf_time_interval *ptime_range; -int size, num, ret; +int size, num, ret = -EINVAL ; ptime_range =perf_time__range_alloc (time_str, &size);if (!ptime_range)
@@ -415,7 +415,6 @@ int perf_time__parse_for_ranges(const char *time_str,pr_err ("HINT: no first/last sample time found in perf data.\n" "Please use latest perf binary to execute 'perf record'\n" "(if '--buildid-all' is enabled, please set '--timestamp-boundary').\n" ); - ret = -EINVAL ; goto error; }
@@ -425,11 +424,8 @@ int perf_time__parse_for_ranges(const char *time_str, session->evlist->first_sample_time, session->evlist->last_sample_time); -if (num <0 ) { -pr_err ("Invalid time string\n" ); - ret = -EINVAL ; - goto error; - } +if (num <0 ) + goto error_invalid; }else { num =1 ; }
@@ -439,6 +435,8 @@ int perf_time__parse_for_ranges(const char *time_str, *ranges = ptime_range;return 0 ; +error_invalid: +pr_err ("Invalid time string\n" ); error:free (ptime_range);return ret;
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf time-utils: Simplify perf_time__parse_for_ranges() error paths slightly
perf time-utils: Simplify perf_time__parse_for_ranges() error paths slightly
Commit-ID: 2a8afddc084a5f5f933382758dd2767ed8a69f77 Gitweb: https://git.kernel.org/tip/2a8afddc084a5f5f933382758dd2767ed8a69f77 Author: Adrian Hunter <[email protected]> AuthorDate: Tue, 4 Jun 2019 16:00:14 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 10 Jun 2019 16:20:12 -0300
perf time-utils: Simplify perf_time__parse_for_ranges() error paths slightly
Simplify perf_time__parse_for_ranges() error paths slightly.
--- tools/perf/util/time-utils.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
tools/perf/util/time-utils.c +5 -7
@@ -403,7 +403,7 @@ int perf_time__parse_for_ranges(const char *time_str, int *range_size, int *range_num) { struct perf_time_interval *ptime_range; -int size, num, ret; +int size, num, ret = -EINVAL ; ptime_range =perf_time__range_alloc (time_str, &size);if (!ptime_range)
@@ -415,7 +415,6 @@ int perf_time__parse_for_ranges(const char *time_str,pr_err ("HINT: no first/last sample time found in perf data.\n" "Please use latest perf binary to execute 'perf record'\n" "(if '--buildid-all' is enabled, please set '--timestamp-boundary').\n" ); - ret = -EINVAL ; goto error; }
@@ -425,11 +424,8 @@ int perf_time__parse_for_ranges(const char *time_str, session->evlist->first_sample_time, session->evlist->last_sample_time); -if (num <0 ) { -pr_err ("Invalid time string\n" ); - ret = -EINVAL ; - goto error; - } +if (num <0 ) + goto error_invalid; }else { num =1 ; }
@@ -439,6 +435,8 @@ int perf_time__parse_for_ranges(const char *time_str, *ranges = ptime_range;return 0 ; +error_invalid: +pr_err ("Invalid time string\n" ); error:free (ptime_range);return ret;
Adrian Hunter
reviewerPATCH 17/19 perf time-utils: Make perf_time__parse_for_ranges() more logical
In reply to Adrian HunterExplicit time ranges never contain a percent sign whereas percentage ranges always do, so it is possible to call the correct parser.
--- tools/perf/util/time-utils.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/time-utils.c +4 -1
@@ -402,6 +402,7 @@ int perf_time__parse_for_ranges(const char *time_str,struct perf_time_interval **ranges, int *range_size, int *range_num) { + bool has_percent = strchr(time_str, '%');struct perf_time_interval *ptime_range;int size, num, ret = -EINVAL ;
@@ -409,7 +410,7 @@ int perf_time__parse_for_ranges(const char *time_str,if (!ptime_range)return -ENOMEM ; -if (perf_time__parse_str (ptime_range, time_str) !=0 ) { +if (has_percent) {if (session->evlist->first_sample_time ==0 && session->evlist->last_sample_time ==0 ) { pr_err("HINT: no first/last sample time found in perf data.\n"
@@ -427,6 +428,8 @@ int perf_time__parse_for_ranges(const char *time_str,if (num <0 ) goto error_invalid; }else { +if (perf_time__parse_str (ptime_range, time_str)) + goto error_invalid; num =1 ; }
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf time-utils: Make perf_time__parse_for_ranges() more logical
perf time-utils: Make perf_time__parse_for_ranges() more logical
Commit-ID: 929afa0092d0ea6be2fbd0ac087319092595eba6 Gitweb: https://git.kernel.org/tip/929afa0092d0ea6be2fbd0ac087319092595eba6 Author: Adrian Hunter <[email protected]> AuthorDate: Tue, 4 Jun 2019 16:00:15 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 10 Jun 2019 16:20:12 -0300
perf time-utils: Make perf_time__parse_for_ranges() more logical
Explicit time ranges never contain a percent sign whereas percentage ranges always do, so it is possible to call the correct parser.
--- tools/perf/util/time-utils.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/time-utils.c +4 -1
@@ -402,6 +402,7 @@ int perf_time__parse_for_ranges(const char *time_str,struct perf_time_interval **ranges, int *range_size, int *range_num) { + bool has_percent = strchr(time_str, '%');struct perf_time_interval *ptime_range;int size, num, ret = -EINVAL ;
@@ -409,7 +410,7 @@ int perf_time__parse_for_ranges(const char *time_str,if (!ptime_range)return -ENOMEM ; -if (perf_time__parse_str (ptime_range, time_str) !=0 ) { +if (has_percent) {if (session->evlist->first_sample_time ==0 && session->evlist->last_sample_time ==0 ) { pr_err("HINT: no first/last sample time found in perf data.\n"
@@ -427,6 +428,8 @@ int perf_time__parse_for_ranges(const char *time_str,if (num <0 ) goto error_invalid; }else { +if (perf_time__parse_str (ptime_range, time_str)) + goto error_invalid; num =1 ; }
Adrian Hunter
reviewerPATCH 18/19 perf tests: Add a test for time-utils
In reply to Adrian HunterTest time ranges work as expected.
--- tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 4 + tools/perf/tests/tests.h | 1 + tools/perf/tests/time-utils-test.c | 234 +++++++++++++++++++++++++++++ 4 files changed, 240 insertions(+) create mode 100644 tools/perf/tests/time-utils-test.c
tools/perf/tests/Build +1 -0
@@ -51,6 +51,7 @@ perf-y += clang.o perf-y += unit_number__scnprintf.o perf-y += mem2node.o perf-y += map_groups.o +perf-y += time-utils-test.o $(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c tests/Build $(call rule_mkdir)
tools/perf/tests/builtin-test.c +4 -0
@@ -289,6 +289,10 @@ static struct test generic_tests[] = { .desc = "mem2node", .func = test__mem2node, }, + { + .desc = "time utils", + .func = test__time_utils, + }, { .desc = "map_groups__merge_in", .func = test__map_groups__merge_in,
tools/perf/tests/tests.h +1 -0
@@ -108,6 +108,7 @@ int test__clang_subtest_get_nr(void);int test__unit_number__scnprint (struct test *test,int subtest);int test__mem2node (struct test *t,int subtest);int test__map_groups__merge_in (struct test *t,int subtest); +int test__time_utils (struct test *t,int subtest);bool test__bp_signal_is_supported (void );bool test__wp_is_supported (void );
tools/perf/tests/time-utils-test.c new file +234 -0
234 lines not on this page · raw message
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf tests: Add a test for time-utils
perf tests: Add a test for time-utils
Commit-ID: e39a12cbd2496edb4cab0f99efb0d217c55ba273 Gitweb: https://git.kernel.org/tip/e39a12cbd2496edb4cab0f99efb0d217c55ba273 Author: Adrian Hunter <[email protected]> AuthorDate: Tue, 4 Jun 2019 16:00:16 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 10 Jun 2019 16:20:12 -0300
perf tests: Add a test for time-utils
Test time ranges work as expected.
Committer testing:
$ perf test "time utils" 59: time utils : Ok $ perf test -v "time utils" 59: time utils : --- start --- test child forked, pid 31711
parse_nsec_time("0")
0
parse_nsec_time("1")
1000000000
parse_nsec_time("0.000000001")
1
parse_nsec_time("1.000000001")
1000000001
parse_nsec_time("123456.123456")
123456123456000
parse_nsec_time("1234567.123456789")
1234567123456789
parse_nsec_time("18446744073.709551615")
18446744073709551615
perf_time__parse_str("1234567.123456789,1234567.123456789") start time 1234567123456789, end time 1234567123456789
perf_time__parse_str("1234567.123456789,1234567.123456790") start time 1234567123456789, end time 1234567123456790
perf_time__parse_str("1234567.123456789,")
start time 1234567123456789, end time 0
perf_time__parse_str(",1234567.123456789")
start time 0, end time 1234567123456789
perf_time__parse_str("0,1234567.123456789")
start time 0, end time 1234567123456789
perf_time__parse_for_ranges("1234567.123456789,1234567.123456790") start time 1234567123456789, end time 1234567123456790
perf_time__parse_for_ranges("10%/1")
first_sample_time 7654321000000000 last_sample_time 7654321000000100 start time 0: 7654321000000000, end time 0: 7654321000000009
perf_time__parse_for_ranges("10%/2")
first_sample_time 7654321000000000 last_sample_time 7654321000000100 start time 0: 7654321000000010, end time 0: 7654321000000019
perf_time__parse_for_ranges("10%/1,10%/2") first_sample_time 11223344000000000 last_sample_time 11223344000000100 start time 0: 11223344000000000, end time 0: 11223344000000009 start time 1: 11223344000000010, end time 1: 11223344000000019
perf_time__parse_for_ranges("10%/1,10%/3,10%/10") first_sample_time 11223344000000000 last_sample_time 11223344000000100 start time 0: 11223344000000000, end time 0: 11223344000000009 start time 1: 11223344000000020, end time 1: 11223344000000029 start time 2: 11223344000000090, end time 2: 11223344000000100
test child finished with 0
---- end ----
time utils: Ok
$
--- tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 4 + tools/perf/tests/tests.h | 1 + tools/perf/tests/time-utils-test.c | 234 +++++++++++++++++++++++++++++++++++++ 4 files changed, 240 insertions(+)
tools/perf/tests/Build +1 -0
@@ -51,6 +51,7 @@ perf-y += clang.o perf-y += unit_number__scnprintf.o perf-y += mem2node.o perf-y += map_groups.o +perf-y += time-utils-test.o $(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c tests/Build $(call rule_mkdir)
tools/perf/tests/builtin-test.c +4 -0
@@ -289,6 +289,10 @@ static struct test generic_tests[] = { .desc = "mem2node", .func = test__mem2node, }, + { + .desc = "time utils", + .func = test__time_utils, + }, { .desc = "map_groups__merge_in", .func = test__map_groups__merge_in,
tools/perf/tests/tests.h +1 -0
@@ -108,6 +108,7 @@ int test__clang_subtest_get_nr(void);int test__unit_number__scnprint (struct test *test,int subtest);int test__mem2node (struct test *t,int subtest);int test__map_groups__merge_in (struct test *t,int subtest); +int test__time_utils (struct test *t,int subtest);bool test__bp_signal_is_supported (void );bool test__wp_is_supported (void );
tools/perf/tests/time-utils-test.c new file +234 -0
234 lines not on this page · raw message
Adrian Hunter
reviewerPATCH 19/19 perf time-utils: Add support for multiple explicit time intervals
In reply to Adrian HunterCurrently only a single explicit time range is accepted. Add support for multiple ranges separated by spaces, which requires the string to be quoted. Update the time utils test accordingly.
--- tools/perf/Documentation/perf-diff.txt | 8 ++- tools/perf/Documentation/perf-report.txt | 3 +- tools/perf/Documentation/perf-script.txt | 3 +- tools/perf/tests/time-utils-test.c | 17 ++++++ tools/perf/util/time-utils.c | 74 ++++++++++++++++++++++-- 5 files changed, 94 insertions(+), 11 deletions(-)
tools/perf/Documentation/perf-diff.txt +5 -3
@@ -145,9 +145,11 @@ OPTIONS <start>,<stop>. Times have the format seconds.nanoseconds. If 'start' is not given (i.e. time string is ',x.y') then analysis starts at the beginning of the file. If stop time is not given (i.e. time - string is 'x.y,') then analysis goes to the end of the file. Time string is - 'a1.b1,c1.d1:a2.b2,c2.d2'. Use ':' to separate timestamps for different - perf.data files. + string is 'x.y,') then analysis goes to the end of the file. + Multiple ranges can be separated by spaces, which requires the argument + to be quoted e.g. --time "1234.567,1234.789 1235," + Time string is'a1.b1,c1.d1:a2.b2,c2.d2'. Use ':' to separate timestamps + for different perf.data files. For example, we get the timestamp information from 'perf script'.
tools/perf/Documentation/perf-report.txt +2 -1
@@ -415,7 +415,8 @@ OPTIONS have the format seconds.nanoseconds. If start is not given (i.e. time string is ',x.y') then analysis starts at the beginning of the file. If stop time is not given (i.e. time string is 'x.y,') then analysis goes - to end of file. + to end of file. Multiple ranges can be separated by spaces, which + requires the argument to be quoted e.g. --time "1234.567,1234.789 1235," Also support time percent with multiple time ranges. Time string is 'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'.
tools/perf/Documentation/perf-script.txt +2 -1
@@ -364,7 +364,8 @@ include::itrace.txt[] have the format seconds.nanoseconds. If start is not given (i.e. time string is ',x.y') then analysis starts at the beginning of the file. If stop time is not given (i.e. time string is 'x.y,') then analysis goes - to end of file. + to end of file. Multiple ranges can be separated by spaces, which + requires the argument to be quoted e.g. --time "1234.567,1234.789 1235," Also support time percent with multiple time ranges. Time string is 'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'.
tools/perf/tests/time-utils-test.c +17 -0
@@ -168,6 +168,23 @@ int test__time_utils(struct test *t __maybe_unused, int subtest __maybe_unused) pass &=test__perf_time__parse_for_ranges (&d); } + { +u64 b =1234567123456789ULL ; +u64 c =7654321987654321ULL ; +u64 e =8000000000000000ULL ; +struct test_data d = { + .str ="1234567.123456789,1234567.123456790 " +"7654321.987654321,7654321.987654444 " +"8000000,8000000.000000005" , + .ptime = { {b, b +1 }, {c, c +123 }, {e, e +5 }, }, + .num =3 , + .skip = { b -1 , b +2 , c -1 , c +124 , e -1 , e +6 }, + .noskip = { b, b +1 , c, c +123 , e, e +5 }, + }; + + pass &=test__perf_time__parse_for_ranges (&d); + } + {u64 b =7654321ULL *NSEC_PER_SEC ;struct test_data d = {
tools/perf/util/time-utils.c +68 -6
95 lines not on this page · raw message
Signature · 1 line
2.17.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf time-utils: Add support for multiple explicit time intervals
perf time-utils: Add support for multiple explicit time intervals
Commit-ID: a77a05e2337df1347f4de96bfa313db7008fe8bd Gitweb: https://git.kernel.org/tip/a77a05e2337df1347f4de96bfa313db7008fe8bd Author: Adrian Hunter <[email protected]> AuthorDate: Tue, 4 Jun 2019 16:00:17 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 10 Jun 2019 16:20:13 -0300
perf time-utils: Add support for multiple explicit time intervals
Currently only a single explicit time range is accepted. Add support for multiple ranges separated by spaces, which requires the string to be quoted. Update the time utils test accordingly.
--- tools/perf/Documentation/perf-diff.txt | 8 ++-- tools/perf/Documentation/perf-report.txt | 3 +- tools/perf/Documentation/perf-script.txt | 3 +- tools/perf/tests/time-utils-test.c | 17 ++++++++ tools/perf/util/time-utils.c | 74 +++++++++++++++++++++++++++++--- 5 files changed, 94 insertions(+), 11 deletions(-)
tools/perf/Documentation/perf-diff.txt +5 -3
@@ -145,9 +145,11 @@ OPTIONS <start>,<stop>. Times have the format seconds.nanoseconds. If 'start' is not given (i.e. time string is ',x.y') then analysis starts at the beginning of the file. If stop time is not given (i.e. time - string is 'x.y,') then analysis goes to the end of the file. Time string is - 'a1.b1,c1.d1:a2.b2,c2.d2'. Use ':' to separate timestamps for different - perf.data files. + string is 'x.y,') then analysis goes to the end of the file. + Multiple ranges can be separated by spaces, which requires the argument + to be quoted e.g. --time "1234.567,1234.789 1235," + Time string is'a1.b1,c1.d1:a2.b2,c2.d2'. Use ':' to separate timestamps + for different perf.data files. For example, we get the timestamp information from 'perf script'.
tools/perf/Documentation/perf-report.txt +2 -1
@@ -415,7 +415,8 @@ OPTIONS have the format seconds.nanoseconds. If start is not given (i.e. time string is ',x.y') then analysis starts at the beginning of the file. If stop time is not given (i.e. time string is 'x.y,') then analysis goes - to end of file. + to end of file. Multiple ranges can be separated by spaces, which + requires the argument to be quoted e.g. --time "1234.567,1234.789 1235," Also support time percent with multiple time ranges. Time string is 'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'.
tools/perf/Documentation/perf-script.txt +2 -1
@@ -364,7 +364,8 @@ include::itrace.txt[] have the format seconds.nanoseconds. If start is not given (i.e. time string is ',x.y') then analysis starts at the beginning of the file. If stop time is not given (i.e. time string is 'x.y,') then analysis goes - to end of file. + to end of file. Multiple ranges can be separated by spaces, which + requires the argument to be quoted e.g. --time "1234.567,1234.789 1235," Also support time percent with multiple time ranges. Time string is 'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'.
tools/perf/tests/time-utils-test.c +17 -0
@@ -168,6 +168,23 @@ int test__time_utils(struct test *t __maybe_unused, int subtest __maybe_unused) pass &=test__perf_time__parse_for_ranges (&d); } + { +u64 b =1234567123456789ULL ; +u64 c =7654321987654321ULL ; +u64 e =8000000000000000ULL ; +struct test_data d = { + .str ="1234567.123456789,1234567.123456790 " +"7654321.987654321,7654321.987654444 " +"8000000,8000000.000000005" , + .ptime = { {b, b +1 }, {c, c +123 }, {e, e +5 }, }, + .num =3 , + .skip = { b -1 , b +2 , c -1 , c +124 , e -1 , e +6 }, + .noskip = { b, b +1 , c, c +123 , e, e +5 }, + }; + + pass &=test__perf_time__parse_for_ranges (&d); + } + {u64 b =7654321ULL *NSEC_PER_SEC ;struct test_data d = {
tools/perf/util/time-utils.c +68 -6
95 lines not on this page · raw message
Arnaldo Carvalho de Melo
AppliedEm Tue, Jun 04, 2019 at 03:59:58PM +0300, Adrian Hunter escreveu:
Quoted 10 lines
Hi
Here are some patches to add support for efficient time interval filtering. First there are 3 patches to add perf time interval to the itrace options structure. Then changes to Intel PT to support "fast forwarding" to a particular timestamp. The filtering is added in patch "perf intel-pt: Add support for efficient time interval filtering". After that there are patches to time-utils, leading up to adding a new test and adding support multiple explicit time intervals.
Quoted 2 lines
The Intel PT changes make time filtering much faster because decoding is limited to the minimal time ranges needed to support the time intervals.
Thanks, applied!
Will now go with the other patches in this batch to the container tests, hopefully should hit Ingo's mail box soon :-)
- Arnaldo
- Arnaldo
Quoted 42 lines
Adrian Hunter (19):
perf auxtrace: Add perf time interval toitrace_synth_ops
perf script: Set perf time interval initrace_synth_ops
perf report: Set perf time interval initrace_synth_ops
perf intel-pt: Add lookahead callback
perf intel-pt: Factor outintel_pt_8b_tsc()
perf intel-pt: Factor outintel_pt_reposition()
perf intel-pt: Add reposition parameter tointel_pt_get_data()perf intel-pt: Addintel_pt_fast_forward()
perf intel-pt: Factor outintel_pt_get_buffer()
perf intel-pt: Add support for lookahead
perf intel-pt: Add support for efficient time interval filtering perf time-utils: Treat time ranges consistently
perf time-utils: Factor outset_percent_time()
perf time-utils: Prevent percentage time range overlap
perf time-utils: Fix --time documentation
perf time-utils: Simplifyperf_time__parse_for_ranges()error paths slightly perf time-utils: Makeperf_time__parse_for_ranges()more logical perf tests: Add a test for time-utils
perf time-utils: Add support for multiple explicit time intervalstools/perf/Documentation/perf-diff.txt | 14 +- tools/perf/Documentation/perf-report.txt | 9 +- tools/perf/Documentation/perf-script.txt | 9 +- tools/perf/builtin-report.c | 8 +- tools/perf/builtin-script.c | 8 +- tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 4 + tools/perf/tests/tests.h | 1 + tools/perf/tests/time-utils-test.c | 251 ++++++++++++++++ tools/perf/util/auxtrace.h | 34 +++ .../perf/util/intel-pt-decoder/intel-pt-decoder.c | 188 ++++++++++-- .../perf/util/intel-pt-decoder/intel-pt-decoder.h | 5 + tools/perf/util/intel-pt.c | 325 +++++++++++++++++++-- tools/perf/util/time-utils.c | 132 ++++++--- 14 files changed, 894 insertions(+), 95 deletions(-) create mode 100644 tools/perf/tests/time-utils-test.cRegards
Adrian
Signature · 1 line
- Arnaldo