* [PATCH 1/2] perf intel-pt: Fix estimated timestamps for cycle-accurate mode @ 2016-09-28 11:41 Adrian Hunter 2016-09-28 11:41 ` [PATCH 2/2] perf intel-pt: Fix MTC timestamp calculation for large MTC periods Adrian Hunter ` (2 more replies) 0 siblings, 3 replies; 6+ messages in thread From: Adrian Hunter @ 2016-09-28 11:41 UTC (permalink / raw) To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel In cycle-accurate mode, timestamps can be calculated from CYC packets. The decoder also estimates timestamps based on the number of instructions since the last timestamp. For that to work in cycle-accurate mode, the instruction count needs to be reset to zero when a timestamp is calculated from a CYC packet, but that wasn't happening, so fix it. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Cc: stable@vger.kernel.org # v4.3+ --- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 2 ++ 1 file changed, 2 insertions(+) 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 7591a0c37473..3d1d446f037f 100644 --- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c @@ -1353,6 +1353,8 @@ static void intel_pt_calc_cyc_timestamp(struct intel_pt_decoder *decoder) timestamp, decoder->timestamp); else decoder->timestamp = timestamp; + + decoder->timestamp_insn_cnt = 0; } /* Walk PSB+ packets when already in sync. */ -- 1.9.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] perf intel-pt: Fix MTC timestamp calculation for large MTC periods 2016-09-28 11:41 [PATCH 1/2] perf intel-pt: Fix estimated timestamps for cycle-accurate mode Adrian Hunter @ 2016-09-28 11:41 ` Adrian Hunter 2016-10-06 22:40 ` [tip:perf/urgent] " tip-bot for Adrian Hunter 2016-10-05 7:33 ` [PATCH 1/2] perf intel-pt: Fix estimated timestamps for cycle-accurate mode Adrian Hunter 2016-10-06 22:40 ` [tip:perf/urgent] " tip-bot for Adrian Hunter 2 siblings, 1 reply; 6+ messages in thread From: Adrian Hunter @ 2016-09-28 11:41 UTC (permalink / raw) To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel The MTC packet provides a 8-bit slice of CTC which is related to TSC by the TMA packet, however the TMA packet only provides the lower 16 bits of CTC. If mtc_shift > 8 then some of the MTC bits are not in the CTC provided by the TMA packet. Fix-up the last_mtc calculated from the TMA packet by copying the missing bits from the current MTC assuming the least difference between the two, and that the current MTC comes after last_mtc. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Cc: stable@vger.kernel.org # v4.3+ --- .../perf/util/intel-pt-decoder/intel-pt-decoder.c | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) 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 3d1d446f037f..16c06d3ae577 100644 --- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c @@ -90,6 +90,7 @@ struct intel_pt_decoder { bool pge; bool have_tma; bool have_cyc; + bool fixup_last_mtc; uint64_t pos; uint64_t last_ip; uint64_t ip; @@ -586,10 +587,31 @@ struct intel_pt_calc_cyc_to_tsc_info { uint64_t tsc_timestamp; uint64_t timestamp; bool have_tma; + bool fixup_last_mtc; bool from_mtc; double cbr_cyc_to_tsc; }; +/* + * MTC provides a 8-bit slice of CTC but the TMA packet only provides the lower + * 16 bits of CTC. If mtc_shift > 8 then some of the MTC bits are not in the CTC + * provided by the TMA packet. Fix-up the last_mtc calculated from the TMA + * packet by copying the missing bits from the current MTC assuming the least + * difference between the two, and that the current MTC comes after last_mtc. + */ +static void intel_pt_fixup_last_mtc(uint32_t mtc, int mtc_shift, + uint32_t *last_mtc) +{ + uint32_t first_missing_bit = 1U << (16 - mtc_shift); + uint32_t mask = ~(first_missing_bit - 1); + + *last_mtc |= mtc & mask; + if (*last_mtc >= mtc) { + *last_mtc -= first_missing_bit; + *last_mtc &= 0xff; + } +} + static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info) { struct intel_pt_decoder *decoder = pkt_info->decoder; @@ -619,6 +641,11 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info) return 0; mtc = pkt_info->packet.payload; + if (decoder->mtc_shift > 8 && data->fixup_last_mtc) { + data->fixup_last_mtc = false; + intel_pt_fixup_last_mtc(mtc, decoder->mtc_shift, + &data->last_mtc); + } if (mtc > data->last_mtc) mtc_delta = mtc - data->last_mtc; else @@ -687,6 +714,7 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info) data->ctc_delta = 0; data->have_tma = true; + data->fixup_last_mtc = true; return 0; @@ -753,6 +781,7 @@ static void intel_pt_calc_cyc_to_tsc(struct intel_pt_decoder *decoder, .tsc_timestamp = decoder->tsc_timestamp, .timestamp = decoder->timestamp, .have_tma = decoder->have_tma, + .fixup_last_mtc = decoder->fixup_last_mtc, .from_mtc = from_mtc, .cbr_cyc_to_tsc = 0, }; @@ -1271,6 +1300,7 @@ static void intel_pt_calc_tma(struct intel_pt_decoder *decoder) } decoder->ctc_delta = 0; decoder->have_tma = true; + decoder->fixup_last_mtc = true; intel_pt_log("CTC timestamp " x64_fmt " last MTC %#x CTC rem %#x\n", decoder->ctc_timestamp, decoder->last_mtc, ctc_rem); } @@ -1285,6 +1315,12 @@ static void intel_pt_calc_mtc_timestamp(struct intel_pt_decoder *decoder) mtc = decoder->packet.payload; + if (decoder->mtc_shift > 8 && decoder->fixup_last_mtc) { + decoder->fixup_last_mtc = false; + intel_pt_fixup_last_mtc(mtc, decoder->mtc_shift, + &decoder->last_mtc); + } + if (mtc > decoder->last_mtc) mtc_delta = mtc - decoder->last_mtc; else -- 1.9.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [tip:perf/urgent] perf intel-pt: Fix MTC timestamp calculation for large MTC periods 2016-09-28 11:41 ` [PATCH 2/2] perf intel-pt: Fix MTC timestamp calculation for large MTC periods Adrian Hunter @ 2016-10-06 22:40 ` tip-bot for Adrian Hunter 0 siblings, 0 replies; 6+ messages in thread From: tip-bot for Adrian Hunter @ 2016-10-06 22:40 UTC (permalink / raw) To: linux-tip-commits Cc: tglx, mingo, jolsa, adrian.hunter, linux-kernel, acme, hpa Commit-ID: 3bccbe20f6d188ce7b00326e776b745cfd35b10a Gitweb: http://git.kernel.org/tip/3bccbe20f6d188ce7b00326e776b745cfd35b10a Author: Adrian Hunter <adrian.hunter@intel.com> AuthorDate: Wed, 28 Sep 2016 14:41:36 +0300 Committer: Arnaldo Carvalho de Melo <acme@redhat.com> CommitDate: Wed, 5 Oct 2016 08:15:58 -0300 perf intel-pt: Fix MTC timestamp calculation for large MTC periods The MTC packet provides a 8-bit slice of CTC which is related to TSC by the TMA packet, however the TMA packet only provides the lower 16 bits of CTC. If mtc_shift > 8 then some of the MTC bits are not in the CTC provided by the TMA packet. Fix-up the last_mtc calculated from the TMA packet by copying the missing bits from the current MTC assuming the least difference between the two, and that the current MTC comes after last_mtc. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: stable@vger.kernel.org # v4.3+ Link: http://lkml.kernel.org/r/1475062896-22274-2-git-send-email-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> --- .../perf/util/intel-pt-decoder/intel-pt-decoder.c | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) 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 3d1d446..16c06d3 100644 --- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c @@ -90,6 +90,7 @@ struct intel_pt_decoder { bool pge; bool have_tma; bool have_cyc; + bool fixup_last_mtc; uint64_t pos; uint64_t last_ip; uint64_t ip; @@ -586,10 +587,31 @@ struct intel_pt_calc_cyc_to_tsc_info { uint64_t tsc_timestamp; uint64_t timestamp; bool have_tma; + bool fixup_last_mtc; bool from_mtc; double cbr_cyc_to_tsc; }; +/* + * MTC provides a 8-bit slice of CTC but the TMA packet only provides the lower + * 16 bits of CTC. If mtc_shift > 8 then some of the MTC bits are not in the CTC + * provided by the TMA packet. Fix-up the last_mtc calculated from the TMA + * packet by copying the missing bits from the current MTC assuming the least + * difference between the two, and that the current MTC comes after last_mtc. + */ +static void intel_pt_fixup_last_mtc(uint32_t mtc, int mtc_shift, + uint32_t *last_mtc) +{ + uint32_t first_missing_bit = 1U << (16 - mtc_shift); + uint32_t mask = ~(first_missing_bit - 1); + + *last_mtc |= mtc & mask; + if (*last_mtc >= mtc) { + *last_mtc -= first_missing_bit; + *last_mtc &= 0xff; + } +} + static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info) { struct intel_pt_decoder *decoder = pkt_info->decoder; @@ -619,6 +641,11 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info) return 0; mtc = pkt_info->packet.payload; + if (decoder->mtc_shift > 8 && data->fixup_last_mtc) { + data->fixup_last_mtc = false; + intel_pt_fixup_last_mtc(mtc, decoder->mtc_shift, + &data->last_mtc); + } if (mtc > data->last_mtc) mtc_delta = mtc - data->last_mtc; else @@ -687,6 +714,7 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info) data->ctc_delta = 0; data->have_tma = true; + data->fixup_last_mtc = true; return 0; @@ -753,6 +781,7 @@ static void intel_pt_calc_cyc_to_tsc(struct intel_pt_decoder *decoder, .tsc_timestamp = decoder->tsc_timestamp, .timestamp = decoder->timestamp, .have_tma = decoder->have_tma, + .fixup_last_mtc = decoder->fixup_last_mtc, .from_mtc = from_mtc, .cbr_cyc_to_tsc = 0, }; @@ -1271,6 +1300,7 @@ static void intel_pt_calc_tma(struct intel_pt_decoder *decoder) } decoder->ctc_delta = 0; decoder->have_tma = true; + decoder->fixup_last_mtc = true; intel_pt_log("CTC timestamp " x64_fmt " last MTC %#x CTC rem %#x\n", decoder->ctc_timestamp, decoder->last_mtc, ctc_rem); } @@ -1285,6 +1315,12 @@ static void intel_pt_calc_mtc_timestamp(struct intel_pt_decoder *decoder) mtc = decoder->packet.payload; + if (decoder->mtc_shift > 8 && decoder->fixup_last_mtc) { + decoder->fixup_last_mtc = false; + intel_pt_fixup_last_mtc(mtc, decoder->mtc_shift, + &decoder->last_mtc); + } + if (mtc > decoder->last_mtc) mtc_delta = mtc - decoder->last_mtc; else ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] perf intel-pt: Fix estimated timestamps for cycle-accurate mode 2016-09-28 11:41 [PATCH 1/2] perf intel-pt: Fix estimated timestamps for cycle-accurate mode Adrian Hunter 2016-09-28 11:41 ` [PATCH 2/2] perf intel-pt: Fix MTC timestamp calculation for large MTC periods Adrian Hunter @ 2016-10-05 7:33 ` Adrian Hunter 2016-10-05 11:16 ` Arnaldo Carvalho de Melo 2016-10-06 22:40 ` [tip:perf/urgent] " tip-bot for Adrian Hunter 2 siblings, 1 reply; 6+ messages in thread From: Adrian Hunter @ 2016-10-05 7:33 UTC (permalink / raw) To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel On 28/09/16 14:41, Adrian Hunter wrote: > In cycle-accurate mode, timestamps can be calculated from CYC packets. The > decoder also estimates timestamps based on the number of instructions since > the last timestamp. For that to work in cycle-accurate mode, the > instruction count needs to be reset to zero when a timestamp is calculated > from a CYC packet, but that wasn't happening, so fix it. > > Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> > Cc: stable@vger.kernel.org # v4.3+ Hi These 2 patches are still outstanding when you have time. Regards Adrian > --- > tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 2 ++ > 1 file changed, 2 insertions(+) > > 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 7591a0c37473..3d1d446f037f 100644 > --- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c > +++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c > @@ -1353,6 +1353,8 @@ static void intel_pt_calc_cyc_timestamp(struct intel_pt_decoder *decoder) > timestamp, decoder->timestamp); > else > decoder->timestamp = timestamp; > + > + decoder->timestamp_insn_cnt = 0; > } > > /* Walk PSB+ packets when already in sync. */ > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] perf intel-pt: Fix estimated timestamps for cycle-accurate mode 2016-10-05 7:33 ` [PATCH 1/2] perf intel-pt: Fix estimated timestamps for cycle-accurate mode Adrian Hunter @ 2016-10-05 11:16 ` Arnaldo Carvalho de Melo 0 siblings, 0 replies; 6+ messages in thread From: Arnaldo Carvalho de Melo @ 2016-10-05 11:16 UTC (permalink / raw) To: Adrian Hunter; +Cc: Jiri Olsa, linux-kernel Em Wed, Oct 05, 2016 at 10:33:14AM +0300, Adrian Hunter escreveu: > On 28/09/16 14:41, Adrian Hunter wrote: > > In cycle-accurate mode, timestamps can be calculated from CYC packets. The > > decoder also estimates timestamps based on the number of instructions since > > the last timestamp. For that to work in cycle-accurate mode, the > > instruction count needs to be reset to zero when a timestamp is calculated > > from a CYC packet, but that wasn't happening, so fix it. > > > > Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> > > Cc: stable@vger.kernel.org # v4.3+ > > Hi > > These 2 patches are still outstanding when you have time. Thanks for the reminder, applied. > Regards > Adrian > > > --- > > tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > > 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 7591a0c37473..3d1d446f037f 100644 > > --- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c > > +++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c > > @@ -1353,6 +1353,8 @@ static void intel_pt_calc_cyc_timestamp(struct intel_pt_decoder *decoder) > > timestamp, decoder->timestamp); > > else > > decoder->timestamp = timestamp; > > + > > + decoder->timestamp_insn_cnt = 0; > > } > > > > /* Walk PSB+ packets when already in sync. */ > > ^ permalink raw reply [flat|nested] 6+ messages in thread
* [tip:perf/urgent] perf intel-pt: Fix estimated timestamps for cycle-accurate mode 2016-09-28 11:41 [PATCH 1/2] perf intel-pt: Fix estimated timestamps for cycle-accurate mode Adrian Hunter 2016-09-28 11:41 ` [PATCH 2/2] perf intel-pt: Fix MTC timestamp calculation for large MTC periods Adrian Hunter 2016-10-05 7:33 ` [PATCH 1/2] perf intel-pt: Fix estimated timestamps for cycle-accurate mode Adrian Hunter @ 2016-10-06 22:40 ` tip-bot for Adrian Hunter 2 siblings, 0 replies; 6+ messages in thread From: tip-bot for Adrian Hunter @ 2016-10-06 22:40 UTC (permalink / raw) To: linux-tip-commits Cc: tglx, acme, mingo, hpa, adrian.hunter, jolsa, linux-kernel Commit-ID: 51ee6481fa8e879cc942bcc1b0af713e158b7a98 Gitweb: http://git.kernel.org/tip/51ee6481fa8e879cc942bcc1b0af713e158b7a98 Author: Adrian Hunter <adrian.hunter@intel.com> AuthorDate: Wed, 28 Sep 2016 14:41:35 +0300 Committer: Arnaldo Carvalho de Melo <acme@redhat.com> CommitDate: Wed, 5 Oct 2016 08:15:29 -0300 perf intel-pt: Fix estimated timestamps for cycle-accurate mode In cycle-accurate mode, timestamps can be calculated from CYC packets. The decoder also estimates timestamps based on the number of instructions since the last timestamp. For that to work in cycle-accurate mode, the instruction count needs to be reset to zero when a timestamp is calculated from a CYC packet, but that wasn't happening, so fix it. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: stable@vger.kernel.org # v4.3+ Link: http://lkml.kernel.org/r/1475062896-22274-1-git-send-email-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> --- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 2 ++ 1 file changed, 2 insertions(+) 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 7591a0c..3d1d446 100644 --- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c @@ -1353,6 +1353,8 @@ static void intel_pt_calc_cyc_timestamp(struct intel_pt_decoder *decoder) timestamp, decoder->timestamp); else decoder->timestamp = timestamp; + + decoder->timestamp_insn_cnt = 0; } /* Walk PSB+ packets when already in sync. */ ^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2016-10-06 22:41 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2016-09-28 11:41 [PATCH 1/2] perf intel-pt: Fix estimated timestamps for cycle-accurate mode Adrian Hunter 2016-09-28 11:41 ` [PATCH 2/2] perf intel-pt: Fix MTC timestamp calculation for large MTC periods Adrian Hunter 2016-10-06 22:40 ` [tip:perf/urgent] " tip-bot for Adrian Hunter 2016-10-05 7:33 ` [PATCH 1/2] perf intel-pt: Fix estimated timestamps for cycle-accurate mode Adrian Hunter 2016-10-05 11:16 ` Arnaldo Carvalho de Melo 2016-10-06 22:40 ` [tip:perf/urgent] " tip-bot for Adrian Hunter
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.