diff options
author | Adrian Hunter <adrian.hunter@intel.com> | 2019-05-10 08:41:41 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-05-16 13:17:23 -0400 |
commit | 7ba8fa20e26eb3c0c04d747f7fd2223694eac4d5 (patch) | |
tree | 50ae8c6322f69a8c9b18f82846a9552d127351a8 | |
parent | 6466ec14aaf44ff14a05369dcf0929d0f01171c6 (diff) |
perf intel-pt: Fix instructions sampling rate
The timestamp used to determine if an instruction sample is made, is an
estimate based on the number of instructions since the last known
timestamp. A consequence is that it might go backwards, which results in
extra samples. Change it so that a sample is only made when the
timestamp goes forwards.
Note this does not affect a sampling period of 0 or sampling periods
specified as a count of instructions.
Example:
Before:
$ perf script --itrace=i10us
ls 13812 [003] 2167315.222583: 3270 instructions:u: 7fac71e2e494 __GI___tunables_init+0xf4 (/lib/x86_64-linux-gnu/ld-2.28.so)
ls 13812 [003] 2167315.222667: 30902 instructions:u: 7fac71e2da0f _dl_cache_libcmp+0x2f (/lib/x86_64-linux-gnu/ld-2.28.so)
ls 13812 [003] 2167315.222667: 10 instructions:u: 7fac71e2d9ff _dl_cache_libcmp+0x1f (/lib/x86_64-linux-gnu/ld-2.28.so)
ls 13812 [003] 2167315.222667: 8 instructions:u: 7fac71e2d9ea _dl_cache_libcmp+0xa (/lib/x86_64-linux-gnu/ld-2.28.so)
ls 13812 [003] 2167315.222667: 14 instructions:u: 7fac71e2d9ea _dl_cache_libcmp+0xa (/lib/x86_64-linux-gnu/ld-2.28.so)
ls 13812 [003] 2167315.222667: 6 instructions:u: 7fac71e2d9ff _dl_cache_libcmp+0x1f (/lib/x86_64-linux-gnu/ld-2.28.so)
ls 13812 [003] 2167315.222667: 14 instructions:u: 7fac71e2d9ff _dl_cache_libcmp+0x1f (/lib/x86_64-linux-gnu/ld-2.28.so)
ls 13812 [003] 2167315.222667: 4 instructions:u: 7fac71e2dab2 _dl_cache_libcmp+0xd2 (/lib/x86_64-linux-gnu/ld-2.28.so)
ls 13812 [003] 2167315.222728: 16423 instructions:u: 7fac71e2477a _dl_map_object_deps+0x1ba (/lib/x86_64-linux-gnu/ld-2.28.so)
ls 13812 [003] 2167315.222734: 12731 instructions:u: 7fac71e27938 _dl_name_match_p+0x68 (/lib/x86_64-linux-gnu/ld-2.28.so)
...
After:
$ perf script --itrace=i10us
ls 13812 [003] 2167315.222583: 3270 instructions:u: 7fac71e2e494 __GI___tunables_init+0xf4 (/lib/x86_64-linux-gnu/ld-2.28.so)
ls 13812 [003] 2167315.222667: 30902 instructions:u: 7fac71e2da0f _dl_cache_libcmp+0x2f (/lib/x86_64-linux-gnu/ld-2.28.so)
ls 13812 [003] 2167315.222728: 16479 instructions:u: 7fac71e2477a _dl_map_object_deps+0x1ba (/lib/x86_64-linux-gnu/ld-2.28.so)
...
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: stable@vger.kernel.org
Fixes: f4aa081949e7b ("perf tools: Add Intel PT decoder")
Link: http://lkml.kernel.org/r/20190510124143.27054-2-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c index 872fab163585..26dbf11e071a 100644 --- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | |||
@@ -888,16 +888,20 @@ static uint64_t intel_pt_next_period(struct intel_pt_decoder *decoder) | |||
888 | timestamp = decoder->timestamp + decoder->timestamp_insn_cnt; | 888 | timestamp = decoder->timestamp + decoder->timestamp_insn_cnt; |
889 | masked_timestamp = timestamp & decoder->period_mask; | 889 | masked_timestamp = timestamp & decoder->period_mask; |
890 | if (decoder->continuous_period) { | 890 | if (decoder->continuous_period) { |
891 | if (masked_timestamp != decoder->last_masked_timestamp) | 891 | if (masked_timestamp > decoder->last_masked_timestamp) |
892 | return 1; | 892 | return 1; |
893 | } else { | 893 | } else { |
894 | timestamp += 1; | 894 | timestamp += 1; |
895 | masked_timestamp = timestamp & decoder->period_mask; | 895 | masked_timestamp = timestamp & decoder->period_mask; |
896 | if (masked_timestamp != decoder->last_masked_timestamp) { | 896 | if (masked_timestamp > decoder->last_masked_timestamp) { |
897 | decoder->last_masked_timestamp = masked_timestamp; | 897 | decoder->last_masked_timestamp = masked_timestamp; |
898 | decoder->continuous_period = true; | 898 | decoder->continuous_period = true; |
899 | } | 899 | } |
900 | } | 900 | } |
901 | |||
902 | if (masked_timestamp < decoder->last_masked_timestamp) | ||
903 | return decoder->period_ticks; | ||
904 | |||
901 | return decoder->period_ticks - (timestamp - masked_timestamp); | 905 | return decoder->period_ticks - (timestamp - masked_timestamp); |
902 | } | 906 | } |
903 | 907 | ||
@@ -926,7 +930,10 @@ static void intel_pt_sample_insn(struct intel_pt_decoder *decoder) | |||
926 | case INTEL_PT_PERIOD_TICKS: | 930 | case INTEL_PT_PERIOD_TICKS: |
927 | timestamp = decoder->timestamp + decoder->timestamp_insn_cnt; | 931 | timestamp = decoder->timestamp + decoder->timestamp_insn_cnt; |
928 | masked_timestamp = timestamp & decoder->period_mask; | 932 | masked_timestamp = timestamp & decoder->period_mask; |
929 | decoder->last_masked_timestamp = masked_timestamp; | 933 | if (masked_timestamp > decoder->last_masked_timestamp) |
934 | decoder->last_masked_timestamp = masked_timestamp; | ||
935 | else | ||
936 | decoder->last_masked_timestamp += decoder->period_ticks; | ||
930 | break; | 937 | break; |
931 | case INTEL_PT_PERIOD_NONE: | 938 | case INTEL_PT_PERIOD_NONE: |
932 | case INTEL_PT_PERIOD_MTC: | 939 | case INTEL_PT_PERIOD_MTC: |