perf intel-pt: Power events and PTWRITE
Adrian Hunter
reviewerv2 cover perf intel-pt: Power events and PTWRITE
Hi
Here are some patches to support Intel PT Power events and PTWRITE. Power events report changes to C-state but I have also added support for the existing CBR (core-to-bus ratio) packet and included that when outputting power events. The PTWRITE packet is associated with the new ptwrite instruction, which is essentially just a way to stuff a 32 or 64 bit value into the PT trace. More details can be found in the patches that add documentation and in the Intel SDM.
As far as I know, there isn't any hardware released that supports the new packets, however the CBR packet is not new and will now be visible by default.
There are also some miscellaneous improvements to Intel PT.
There are 3 patches that introduce a new way to define synthesized events that carry arbitrary raw_data. I sent an RFC about that earlier. The 3 patches are:
perf script: Add 'synth' event type for synthesized events perf script: Add 'synth' field for synthesized event payloads perf script: Add synthesized Intel PT power and ptwrite events
Changes in V2:
Reorder patches and add stable tags to fixes.
Adrian Hunter (37):
perf intel-pt: Move decoder error setting into one condition perf intel-pt: Improve sample timestamp
perf intel-pt: Fix missing stack clear
perf intel-pt: Ensure IP is zero when state is INTEL_PT_STATE_NO_IP perf intel-pt: Fix last_ip usage
perf intel-pt: Ensure never to set 'last_ip' when packet 'count' is zero perf intel-pt: Use FUP always when scanning for an IP
perf intel-pt: Clear FUP flag on error
perf intel-pt: Add missing __fallthrough
perf intel-pt: Allow decoding with branch tracing disabled
perf intel-pt: Add default config for pass-through branch enable perf intel-pt: Add documentation for new config terms
perf intel-pt: Add decoder support for ptwrite and power event packets perf intel-pt: Add reserved byte to CBR packet payload
perf intel-pt: Add decoder support for CBR events
perf intel-pt: Remove redundant initial_skip checks
perf intel-pt: Fix transactions_sample_type
perf tools: Fix message because cpu list option is -C not -c perf script: Fix message because field list option is -F not -f perf script: Add 'synth' event type for synthesized events
perf script: Add 'synth' field for synthesized event payloads tools include: Add byte-swapping macros to kernel.h
perf auxtrace: Add itrace option to output ptwrite events
perf auxtrace: Add itrace option to output power events
perf script: Add synthesized Intel PT power and ptwrite events perf intel-pt: Factor out common code synthesizing event samples perf intel-pt: Remove unused instructions_sample_period
perf intel-pt: Join needlessly wrapped lines
perf intel-pt: Tidy Intel PT evsel lookup into separate function perf intel-pt: Tidy messages into called function intel_pt_synth_event() perf intel-pt: Factor out intel_pt_set_event_name()
perf intel-pt: Move code in intel_pt_synth_events() to simplify attr setting perf intel-pt: Synthesize new power and ptwrite events
perf intel-pt: Add example script for power events and PTWRITE perf intel-pt: Update documentation to include new ptwrite and power events perf intel-pt: Do not use TSC packets for calculating CPU cycles to TSC perf auxtrace: Add CPU filter support
tools/include/linux/kernel.h | 35 +- tools/perf/Documentation/intel-pt.txt | 78 ++- tools/perf/Documentation/itrace.txt | 8 +- tools/perf/Documentation/perf-script.txt | 6 +- tools/perf/arch/x86/util/intel-pt.c | 5 + tools/perf/builtin-report.c | 1 + tools/perf/builtin-script.c | 207 ++++++- .../perf/scripts/python/bin/intel-pt-events-record | 13 + .../perf/scripts/python/bin/intel-pt-events-report | 3 + tools/perf/scripts/python/intel-pt-events.py | 128 ++++ tools/perf/util/auxtrace.c | 18 + tools/perf/util/auxtrace.h | 6 + tools/perf/util/event.h | 93 +++ .../perf/util/intel-pt-decoder/intel-pt-decoder.c | 304 +++++++++- .../perf/util/intel-pt-decoder/intel-pt-decoder.h | 13 + .../util/intel-pt-decoder/intel-pt-pkt-decoder.c | 110 +++- .../util/intel-pt-decoder/intel-pt-pkt-decoder.h | 7 + tools/perf/util/intel-pt.c | 642 +++++++++++++++------ tools/perf/util/session.c | 2 +- 19 files changed, 1435 insertions(+), 244 deletions(-) create mode 100644 tools/perf/scripts/python/bin/intel-pt-events-record create mode 100644 tools/perf/scripts/python/bin/intel-pt-events-report create mode 100644 tools/perf/scripts/python/intel-pt-events.py
Regards
Adrian
Adrian Hunter
reviewerPATCH v2 1/37 perf intel-pt: Move decoder error setting into one condition
Move decoder error setting into one condition.
Cc'ed to stable because later fixes depend on it.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +7 -4
@@ -2130,15 +2130,18 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder) } }while (err == -ENOLINK ); - decoder->state.err = err ?intel_pt_ext_err (err) :0 ; +if (err) { + decoder->state.err =intel_pt_ext_err (err); + decoder->state.from_ip = decoder->ip; + }else { + decoder->state.err =0 ; + } + decoder->state.timestamp = decoder->timestamp; decoder->state.est_timestamp =intel_pt_est_timestamp (decoder); decoder->state.cr3 = decoder->cr3; decoder->state.tot_insn_cnt = decoder->tot_insn_cnt; -if (err) - decoder->state.from_ip = decoder->ip; -return &decoder->state; }
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Move decoder error setting into one condition
perf intel-pt: Move decoder error setting into one condition
Commit-ID: 22c06892332d8916115525145b78e606e9cc6492 Gitweb: http://git.kernel.org/tip/22c06892332d8916115525145b78e606e9cc6492 Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:02 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 21 Jun 2017 11:35:43 -0300
perf intel-pt: Move decoder error setting into one condition
Move decoder error setting into one condition.
Cc'ed to stable because later fixes depend on it.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +7 -4
@@ -2130,15 +2130,18 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder) } }while (err == -ENOLINK ); - decoder->state.err = err ?intel_pt_ext_err (err) :0 ; +if (err) { + decoder->state.err =intel_pt_ext_err (err); + decoder->state.from_ip = decoder->ip; + }else { + decoder->state.err =0 ; + } + decoder->state.timestamp = decoder->timestamp; decoder->state.est_timestamp =intel_pt_est_timestamp (decoder); decoder->state.cr3 = decoder->cr3; decoder->state.tot_insn_cnt = decoder->tot_insn_cnt; -if (err) - decoder->state.from_ip = decoder->ip; -return &decoder->state; }
Adrian Hunter
reviewerPATCH v2 2/37 perf intel-pt: Improve sample timestamp
In reply to Adrian HunterThe decoder uses its current timestamp in samples. Usually that is a timestamp that has already passed, but in some cases it is a timestamp for a branch that the decoder is walking towards, and consequently hasn't reached. Improve that situation by using the pkt_state to determine when to use the current or previous timestamp.
--- .../perf/util/intel-pt-decoder/intel-pt-decoder.c | 34 ++++++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +31 -3
@@ -64,6 +64,25 @@ enum intel_pt_pkt_state { INTEL_PT_STATE_FUP_NO_TIP, }; +static inline bool intel_pt_sample_time (enum intel_pt_pkt_state pkt_state) +{ +switch (pkt_state) { +case INTEL_PT_STATE_NO_PSB : +case INTEL_PT_STATE_NO_IP : +case INTEL_PT_STATE_ERR_RESYNC : +case INTEL_PT_STATE_IN_SYNC : +case INTEL_PT_STATE_TNT : +return true; +case INTEL_PT_STATE_TIP : +case INTEL_PT_STATE_TIP_PGD : +case INTEL_PT_STATE_FUP : +case INTEL_PT_STATE_FUP_NO_TIP : +return false; +default : +return true; + }; +} +#ifdef INTEL_PT_STRICT #define INTEL_PT_STATE_ERR1 INTEL_PT_STATE_NO_PSB#define INTEL_PT_STATE_ERR2 INTEL_PT_STATE_NO_PSB
@@ -99,6 +118,7 @@ struct intel_pt_decoder {uint64_t timestamp;uint64_t tsc_timestamp;uint64_t ref_timestamp; +uint64_t sample_timestamp;uint64_t ret_addr;uint64_t ctc_timestamp;uint64_t ctc_delta;
@@ -139,6 +159,7 @@ struct intel_pt_decoder {unsigned int fup_tx_flags;unsigned int tx_flags;uint64_t timestamp_insn_cnt; +uint64_t sample_insn_cnt;uint64_t stuck_ip;int no_progress;int stuck_ip_prd;
@@ -898,6 +919,7 @@ static int intel_pt_walk_insn(struct intel_pt_decoder *decoder, decoder->tot_insn_cnt += insn_cnt; decoder->timestamp_insn_cnt += insn_cnt; + decoder->sample_insn_cnt += insn_cnt; decoder->period_insn_cnt += insn_cnt;if (err) {
@@ -2069,7 +2091,7 @@ static int intel_pt_sync(struct intel_pt_decoder *decoder)static uint64_t intel_pt_est_timestamp (struct intel_pt_decoder *decoder) { -uint64_t est = decoder->timestamp_insn_cnt <<1 ; +uint64_t est = decoder->sample_insn_cnt <<1 ;if (!decoder->cbr || !decoder->max_non_turbo_ratio) goto out;
@@ -2077,7 +2099,7 @@ static uint64_t intel_pt_est_timestamp(struct intel_pt_decoder *decoder) est *= decoder->max_non_turbo_ratio; est /= decoder->cbr; out: -return decoder->timestamp + est; +return decoder->sample_timestamp + est; }const struct intel_pt_state *intel_pt_decode (struct intel_pt_decoder *decoder)
@@ -2133,11 +2155,17 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder)if (err) { decoder->state.err =intel_pt_ext_err (err); decoder->state.from_ip = decoder->ip; + decoder->sample_timestamp = decoder->timestamp; + decoder->sample_insn_cnt = decoder->timestamp_insn_cnt; }else { decoder->state.err =0 ; +if (intel_pt_sample_time (decoder->pkt_state)) { + decoder->sample_timestamp = decoder->timestamp; + decoder->sample_insn_cnt = decoder->timestamp_insn_cnt; + } } - decoder->state.timestamp = decoder->timestamp; + decoder->state.timestamp = decoder->sample_timestamp; decoder->state.est_timestamp =intel_pt_est_timestamp (decoder); decoder->state.cr3 = decoder->cr3; decoder->state.tot_insn_cnt = decoder->tot_insn_cnt;
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Improve sample timestamp
perf intel-pt: Improve sample timestamp
Commit-ID: 3f04d98e972b59706bd43d6cc75efac91f8fba50 Gitweb: http://git.kernel.org/tip/3f04d98e972b59706bd43d6cc75efac91f8fba50 Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:03 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 21 Jun 2017 11:35:43 -0300
perf intel-pt: Improve sample timestamp
The decoder uses its current timestamp in samples. Usually that is a timestamp that has already passed, but in some cases it is a timestamp for a branch that the decoder is walking towards, and consequently hasn't reached. Improve that situation by using the pkt_state to determine when to use the current or previous timestamp.
--- .../perf/util/intel-pt-decoder/intel-pt-decoder.c | 34 ++++++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +31 -3
@@ -64,6 +64,25 @@ enum intel_pt_pkt_state { INTEL_PT_STATE_FUP_NO_TIP, }; +static inline bool intel_pt_sample_time (enum intel_pt_pkt_state pkt_state) +{ +switch (pkt_state) { +case INTEL_PT_STATE_NO_PSB : +case INTEL_PT_STATE_NO_IP : +case INTEL_PT_STATE_ERR_RESYNC : +case INTEL_PT_STATE_IN_SYNC : +case INTEL_PT_STATE_TNT : +return true; +case INTEL_PT_STATE_TIP : +case INTEL_PT_STATE_TIP_PGD : +case INTEL_PT_STATE_FUP : +case INTEL_PT_STATE_FUP_NO_TIP : +return false; +default : +return true; + }; +} +#ifdef INTEL_PT_STRICT #define INTEL_PT_STATE_ERR1 INTEL_PT_STATE_NO_PSB#define INTEL_PT_STATE_ERR2 INTEL_PT_STATE_NO_PSB
@@ -99,6 +118,7 @@ struct intel_pt_decoder {uint64_t timestamp;uint64_t tsc_timestamp;uint64_t ref_timestamp; +uint64_t sample_timestamp;uint64_t ret_addr;uint64_t ctc_timestamp;uint64_t ctc_delta;
@@ -139,6 +159,7 @@ struct intel_pt_decoder {unsigned int fup_tx_flags;unsigned int tx_flags;uint64_t timestamp_insn_cnt; +uint64_t sample_insn_cnt;uint64_t stuck_ip;int no_progress;int stuck_ip_prd;
@@ -898,6 +919,7 @@ static int intel_pt_walk_insn(struct intel_pt_decoder *decoder, decoder->tot_insn_cnt += insn_cnt; decoder->timestamp_insn_cnt += insn_cnt; + decoder->sample_insn_cnt += insn_cnt; decoder->period_insn_cnt += insn_cnt;if (err) {
@@ -2069,7 +2091,7 @@ static int intel_pt_sync(struct intel_pt_decoder *decoder)static uint64_t intel_pt_est_timestamp (struct intel_pt_decoder *decoder) { -uint64_t est = decoder->timestamp_insn_cnt <<1 ; +uint64_t est = decoder->sample_insn_cnt <<1 ;if (!decoder->cbr || !decoder->max_non_turbo_ratio) goto out;
@@ -2077,7 +2099,7 @@ static uint64_t intel_pt_est_timestamp(struct intel_pt_decoder *decoder) est *= decoder->max_non_turbo_ratio; est /= decoder->cbr; out: -return decoder->timestamp + est; +return decoder->sample_timestamp + est; }const struct intel_pt_state *intel_pt_decode (struct intel_pt_decoder *decoder)
@@ -2133,11 +2155,17 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder)if (err) { decoder->state.err =intel_pt_ext_err (err); decoder->state.from_ip = decoder->ip; + decoder->sample_timestamp = decoder->timestamp; + decoder->sample_insn_cnt = decoder->timestamp_insn_cnt; }else { decoder->state.err =0 ; +if (intel_pt_sample_time (decoder->pkt_state)) { + decoder->sample_timestamp = decoder->timestamp; + decoder->sample_insn_cnt = decoder->timestamp_insn_cnt; + } } - decoder->state.timestamp = decoder->timestamp; + decoder->state.timestamp = decoder->sample_timestamp; decoder->state.est_timestamp =intel_pt_est_timestamp (decoder); decoder->state.cr3 = decoder->cr3; decoder->state.tot_insn_cnt = decoder->tot_insn_cnt;
Adrian Hunter
reviewerPATCH v2 3/37 perf intel-pt: Fix missing stack clear
In reply to Adrian HunterThe return compression stack must be cleared whenever there is a PSB. Fix one case where that was not happening.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +1 -0
@@ -1932,6 +1932,7 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder)break ;case INTEL_PT_PSB : +intel_pt_clear_stack (&decoder->stack); err =intel_pt_walk_psb (decoder);if (err)return err;
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Fix missing stack clear
perf intel-pt: Fix missing stack clear
Commit-ID: 12b7080609097753fd8198cc1daf589be3ec1cca Gitweb: http://git.kernel.org/tip/12b7080609097753fd8198cc1daf589be3ec1cca Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:04 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 21 Jun 2017 11:35:44 -0300
perf intel-pt: Fix missing stack clear
The return compression stack must be cleared whenever there is a PSB. Fix one case where that was not happening.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +1 -0
@@ -1932,6 +1932,7 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder)break ;case INTEL_PT_PSB : +intel_pt_clear_stack (&decoder->stack); err =intel_pt_walk_psb (decoder);if (err)return err;
Adrian Hunter
reviewerPATCH v2 4/37 perf intel-pt: Ensure IP is zero when state is INTEL_PT_STATE_NO_IP
In reply to Adrian HunterA value of zero is used to indicate that there is no IP. Ensure the value is zero when the state is INTEL_PT_STATE_NO_IP.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +1 -0
@@ -2117,6 +2117,7 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder)break ;case INTEL_PT_STATE_NO_IP : decoder->last_ip =0 ; + decoder->ip =0 ;/* Fall through */ case INTEL_PT_STATE_ERR_RESYNC : err =intel_pt_sync_ip (decoder);
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Ensure IP is zero when state is INTEL_PT_STATE_NO_IP
perf intel-pt: Ensure IP is zero when state is INTEL_PT_STATE_NO_IP
Commit-ID: ad7167a8cd174ba7d8c0d0ed8d8410521206d104 Gitweb: http://git.kernel.org/tip/ad7167a8cd174ba7d8c0d0ed8d8410521206d104 Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:05 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 21 Jun 2017 11:35:44 -0300
perf intel-pt: Ensure IP is zero when state is INTEL_PT_STATE_NO_IP
A value of zero is used to indicate that there is no IP. Ensure the value is zero when the state is INTEL_PT_STATE_NO_IP.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +1 -0
@@ -2117,6 +2117,7 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder)break ;case INTEL_PT_STATE_NO_IP : decoder->last_ip =0 ; + decoder->ip =0 ;/* Fall through */ case INTEL_PT_STATE_ERR_RESYNC : err =intel_pt_sync_ip (decoder);
Adrian Hunter
reviewerPATCH v2 5/37 perf intel-pt: Fix last_ip usage
In reply to Adrian HunterIntel PT uses IP compression based on the last IP. For decoding purposes, 'last IP' is considered to be reset to zero whenever there is a synchronization packet (PSB). The decoder wasn't doing that, and was treating the zero value to mean that there was no last IP, whereas compression can be done against the zero value. Fix by setting last_ip to zero when a PSB is received and keep track of have_last_ip.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +11 -2
@@ -111,6 +111,7 @@ struct intel_pt_decoder {bool have_tma;bool have_cyc;bool fixup_last_mtc; +bool have_last_ip;uint64_t pos;uint64_t last_ip;uint64_t ip;
@@ -419,6 +420,7 @@ static uint64_t intel_pt_calc_ip(const struct intel_pt_pkt *packet,static inline void intel_pt_set_last_ip (struct intel_pt_decoder *decoder) { decoder->last_ip =intel_pt_calc_ip (&decoder->packet, decoder->last_ip); + decoder->have_last_ip = true; }static inline void intel_pt_set_ip (struct intel_pt_decoder *decoder)
@@ -1672,6 +1674,8 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder)break ;case INTEL_PT_PSB : + decoder->last_ip =0 ; + decoder->have_last_ip = true;intel_pt_clear_stack (&decoder->stack); err =intel_pt_walk_psbend (decoder);if (err == -EAGAIN )
@@ -1752,7 +1756,7 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder)static inline bool intel_pt_have_ip (struct intel_pt_decoder *decoder) { -return decoder->last_ip || decoder->packet.count ==0 || +return decoder->have_last_ip || decoder->packet.count ==0 || decoder->packet.count ==3 || decoder->packet.count ==6 ; }
@@ -1882,7 +1886,7 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder)if (decoder->ip)return 0 ; } -if (decoder->packet.count) +if (decoder->packet.count && decoder->have_last_ip)intel_pt_set_last_ip (decoder);break ;
@@ -1932,6 +1936,8 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder)break ;case INTEL_PT_PSB : + decoder->last_ip =0 ; + decoder->have_last_ip = true;intel_pt_clear_stack (&decoder->stack); err =intel_pt_walk_psb (decoder);if (err)
@@ -2066,6 +2072,7 @@ static int intel_pt_sync(struct intel_pt_decoder *decoder) decoder->pge = false; decoder->continuous_period = false; + decoder->have_last_ip = false; decoder->last_ip =0 ; decoder->ip =0 ;intel_pt_clear_stack (&decoder->stack);
@@ -2074,6 +2081,7 @@ static int intel_pt_sync(struct intel_pt_decoder *decoder)if (err)return err; + decoder->have_last_ip = true; decoder->pkt_state =INTEL_PT_STATE_NO_IP ; err =intel_pt_walk_psb (decoder);
@@ -2116,6 +2124,7 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder) err =intel_pt_sync (decoder);break ;case INTEL_PT_STATE_NO_IP : + decoder->have_last_ip = false; decoder->last_ip =0 ; decoder->ip =0 ;/* Fall through */
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Fix last_ip usage
perf intel-pt: Fix last_ip usage
Commit-ID: ee14ac0ef6827cd6f9a572cc83dd0191ea17812c Gitweb: http://git.kernel.org/tip/ee14ac0ef6827cd6f9a572cc83dd0191ea17812c Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:06 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 21 Jun 2017 11:35:45 -0300
perf intel-pt: Fix last_ip usage
Intel PT uses IP compression based on the last IP. For decoding purposes, 'last IP' is considered to be reset to zero whenever there is a synchronization packet (PSB). The decoder wasn't doing that, and was treating the zero value to mean that there was no last IP, whereas compression can be done against the zero value. Fix by setting last_ip to zero when a PSB is received and keep track of have_last_ip.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +11 -2
@@ -111,6 +111,7 @@ struct intel_pt_decoder {bool have_tma;bool have_cyc;bool fixup_last_mtc; +bool have_last_ip;uint64_t pos;uint64_t last_ip;uint64_t ip;
@@ -419,6 +420,7 @@ static uint64_t intel_pt_calc_ip(const struct intel_pt_pkt *packet,static inline void intel_pt_set_last_ip (struct intel_pt_decoder *decoder) { decoder->last_ip =intel_pt_calc_ip (&decoder->packet, decoder->last_ip); + decoder->have_last_ip = true; }static inline void intel_pt_set_ip (struct intel_pt_decoder *decoder)
@@ -1672,6 +1674,8 @@ next:break ;case INTEL_PT_PSB : + decoder->last_ip =0 ; + decoder->have_last_ip = true;intel_pt_clear_stack (&decoder->stack); err =intel_pt_walk_psbend (decoder);if (err == -EAGAIN )
@@ -1752,7 +1756,7 @@ next:static inline bool intel_pt_have_ip (struct intel_pt_decoder *decoder) { -return decoder->last_ip || decoder->packet.count ==0 || +return decoder->have_last_ip || decoder->packet.count ==0 || decoder->packet.count ==3 || decoder->packet.count ==6 ; }
@@ -1882,7 +1886,7 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder)if (decoder->ip)return 0 ; } -if (decoder->packet.count) +if (decoder->packet.count && decoder->have_last_ip)intel_pt_set_last_ip (decoder);break ;
@@ -1932,6 +1936,8 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder)break ;case INTEL_PT_PSB : + decoder->last_ip =0 ; + decoder->have_last_ip = true;intel_pt_clear_stack (&decoder->stack); err =intel_pt_walk_psb (decoder);if (err)
@@ -2066,6 +2072,7 @@ static int intel_pt_sync(struct intel_pt_decoder *decoder) decoder->pge = false; decoder->continuous_period = false; + decoder->have_last_ip = false; decoder->last_ip =0 ; decoder->ip =0 ;intel_pt_clear_stack (&decoder->stack);
@@ -2074,6 +2081,7 @@ static int intel_pt_sync(struct intel_pt_decoder *decoder)if (err)return err; + decoder->have_last_ip = true; decoder->pkt_state =INTEL_PT_STATE_NO_IP ; err =intel_pt_walk_psb (decoder);
@@ -2116,6 +2124,7 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder) err =intel_pt_sync (decoder);break ;case INTEL_PT_STATE_NO_IP : + decoder->have_last_ip = false; decoder->last_ip =0 ; decoder->ip =0 ;/* Fall through */
Adrian Hunter
reviewerPATCH v2 6/37 perf intel-pt: Ensure never to set 'last_ip' when packet 'count' is zero
In reply to Adrian HunterIntel PT uses IP compression based on the last IP. For decoding purposes, 'last IP' is not updated when a branch target has been suppressed, which is indicated by IPBytes == 0. IPBytes is stored in the packet 'count', so ensure never to set 'last_ip' when packet 'count' is zero.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +5 -3
@@ -1470,7 +1470,8 @@ static int intel_pt_walk_psbend(struct intel_pt_decoder *decoder)case INTEL_PT_FUP : decoder->pge = true; -intel_pt_set_last_ip (decoder); +if (decoder->packet.count) +intel_pt_set_last_ip (decoder);break ;case INTEL_PT_MODE_TSX :
@@ -1756,8 +1757,9 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder)static inline bool intel_pt_have_ip (struct intel_pt_decoder *decoder) { -return decoder->have_last_ip || decoder->packet.count ==0 || - decoder->packet.count ==3 || decoder->packet.count ==6 ; +return decoder->packet.count && + (decoder->have_last_ip || decoder->packet.count ==3 || + decoder->packet.count ==6 ); }/* Walk PSB+ packets to get in sync. */
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Ensure never to set 'last_ip' when packet 'count' is zero
perf intel-pt: Ensure never to set 'last_ip' when packet 'count' is zero
Commit-ID: f952eaceb089b691eba7c4e13686e742a8f26bf5 Gitweb: http://git.kernel.org/tip/f952eaceb089b691eba7c4e13686e742a8f26bf5 Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:07 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 21 Jun 2017 11:35:46 -0300
perf intel-pt: Ensure never to set 'last_ip' when packet 'count' is zero
Intel PT uses IP compression based on the last IP. For decoding purposes, 'last IP' is not updated when a branch target has been suppressed, which is indicated by IPBytes == 0. IPBytes is stored in the packet 'count', so ensure never to set 'last_ip' when packet 'count' is zero.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +5 -3
@@ -1470,7 +1470,8 @@ static int intel_pt_walk_psbend(struct intel_pt_decoder *decoder)case INTEL_PT_FUP : decoder->pge = true; -intel_pt_set_last_ip (decoder); +if (decoder->packet.count) +intel_pt_set_last_ip (decoder);break ;case INTEL_PT_MODE_TSX :
@@ -1756,8 +1757,9 @@ next:static inline bool intel_pt_have_ip (struct intel_pt_decoder *decoder) { -return decoder->have_last_ip || decoder->packet.count ==0 || - decoder->packet.count ==3 || decoder->packet.count ==6 ; +return decoder->packet.count && + (decoder->have_last_ip || decoder->packet.count ==3 || + decoder->packet.count ==6 ); }/* Walk PSB+ packets to get in sync. */
Adrian Hunter
reviewerPATCH v2 7/37 perf intel-pt: Use FUP always when scanning for an IP
In reply to Adrian HunterThe decoder will try to use branch packets to find an IP to start decoding or to recover from errors. Currently the FUP packet is used only in the case of an overflow, however there is no reason for that to be a special case. So just use FUP always when scanning for an IP.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +4 -8
@@ -1882,14 +1882,10 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder)break ;case INTEL_PT_FUP : -if (decoder->overflow) { -if (intel_pt_have_ip (decoder)) -intel_pt_set_ip (decoder); -if (decoder->ip) -return 0 ; - } -if (decoder->packet.count && decoder->have_last_ip) -intel_pt_set_last_ip (decoder); +if (intel_pt_have_ip (decoder)) +intel_pt_set_ip (decoder); +if (decoder->ip) +return 0 ;break ;case INTEL_PT_MTC :
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Use FUP always when scanning for an IP
perf intel-pt: Use FUP always when scanning for an IP
Commit-ID: 622b7a47b843c78626f40c1d1aeef8483383fba2 Gitweb: http://git.kernel.org/tip/622b7a47b843c78626f40c1d1aeef8483383fba2 Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:08 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 21 Jun 2017 11:35:46 -0300
perf intel-pt: Use FUP always when scanning for an IP
The decoder will try to use branch packets to find an IP to start decoding or to recover from errors. Currently the FUP packet is used only in the case of an overflow, however there is no reason for that to be a special case. So just use FUP always when scanning for an IP.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +4 -8
@@ -1882,14 +1882,10 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder)break ;case INTEL_PT_FUP : -if (decoder->overflow) { -if (intel_pt_have_ip (decoder)) -intel_pt_set_ip (decoder); -if (decoder->ip) -return 0 ; - } -if (decoder->packet.count && decoder->have_last_ip) -intel_pt_set_last_ip (decoder); +if (intel_pt_have_ip (decoder)) +intel_pt_set_ip (decoder); +if (decoder->ip) +return 0 ;break ;case INTEL_PT_MTC :
Adrian Hunter
reviewerPATCH v2 8/37 perf intel-pt: Clear FUP flag on error
In reply to Adrian HunterSometimes a FUP packet is associated with a TSX transaction and a flag is set to indicate that. Ensure that flag is cleared on any error condition because at that point the decoder can no longer assume it is correct.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 2 ++ 1 file changed, 2 insertions(+)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +2 -0
@@ -1962,6 +1962,8 @@ static int intel_pt_sync_ip(struct intel_pt_decoder *decoder) {int err; + decoder->set_fup_tx_flags = false; +intel_pt_log ("Scanning for full IP\n" ); err =intel_pt_walk_to_ip (decoder);if (err)
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Clear FUP flag on error
perf intel-pt: Clear FUP flag on error
Commit-ID: 6a558f12dbe85437acbdec5e149ea07b5554eced Gitweb: http://git.kernel.org/tip/6a558f12dbe85437acbdec5e149ea07b5554eced Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:09 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 21 Jun 2017 11:35:47 -0300
perf intel-pt: Clear FUP flag on error
Sometimes a FUP packet is associated with a TSX transaction and a flag is set to indicate that. Ensure that flag is cleared on any error condition because at that point the decoder can no longer assume it is correct.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 2 ++ 1 file changed, 2 insertions(+)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +2 -0
@@ -1962,6 +1962,8 @@ static int intel_pt_sync_ip(struct intel_pt_decoder *decoder) {int err; + decoder->set_fup_tx_flags = false; +intel_pt_log ("Scanning for full IP\n" ); err =intel_pt_walk_to_ip (decoder);if (err)
Adrian Hunter
reviewerPATCH v2 9/37 perf intel-pt: Add missing __fallthrough
In reply to Adrian Hunterperf tools uses __fallthrough. Add missing __fallthrough to a switch statement.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +1 -1
@@ -2127,7 +2127,7 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder) decoder->have_last_ip = false; decoder->last_ip =0 ; decoder->ip =0 ; -/* Fall through */ + __fallthrough;case INTEL_PT_STATE_ERR_RESYNC : err =intel_pt_sync_ip (decoder);break ;
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Add missing __fallthrough
perf intel-pt: Add missing __fallthrough
Commit-ID: 04194207fe6424c7a1bfd6f43ef7deb90cdf716f Gitweb: http://git.kernel.org/tip/04194207fe6424c7a1bfd6f43ef7deb90cdf716f Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:10 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 21 Jun 2017 11:35:47 -0300
perf intel-pt: Add missing __fallthrough
perf tools uses __fallthrough. Add missing __fallthrough to a switch statement.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +1 -1
@@ -2127,7 +2127,7 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder) decoder->have_last_ip = false; decoder->last_ip =0 ; decoder->ip =0 ; -/* Fall through */ + __fallthrough;case INTEL_PT_STATE_ERR_RESYNC : err =intel_pt_sync_ip (decoder);break ;
Adrian Hunter
reviewerPATCH v2 10/37 perf intel-pt: Allow decoding with branch tracing disabled
In reply to Adrian HunterThe kernel now supports the disabling of branch tracing, however the decoder assumes branch tracing is always enabled. Pass through a parameter to indicate whether branch tracing is enabled and use it to avoid cases when the decoder is expecting branch packets. There are 2 such cases. First, FUP packets which can bind to an IP even when there is no branch tracing. Secondly, the decoder will try to use branch packets to find an IP to start decoding or to recover from errors.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 13 +++++++++++++ tools/perf/util/intel-pt-decoder/intel-pt-decoder.h | 1 + tools/perf/util/intel-pt.c | 14 ++++++++++++++ 3 files changed, 28 insertions(+)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +13 -0
@@ -106,6 +106,7 @@ struct intel_pt_decoder {const unsigned char *buf;size_t len;bool return_compression; +bool branch_enable;bool mtc_insn;bool pge;bool have_tma;
@@ -214,6 +215,7 @@ struct intel_pt_decoder *intel_pt_decoder_new(struct intel_pt_params *params) decoder->pgd_ip = params->pgd_ip; decoder->data = params->data; decoder->return_compression = params->return_compression; + decoder->branch_enable = params->branch_enable; decoder->period = params->period; decoder->period_type = params->period_type;
@@ -1650,6 +1652,10 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder)break ; }intel_pt_set_last_ip (decoder); +if (!decoder->branch_enable) { + decoder->ip = decoder->last_ip; +break ; + } err =intel_pt_walk_fup (decoder);if (err != -EAGAIN ) {if (err)
@@ -1964,6 +1970,13 @@ static int intel_pt_sync_ip(struct intel_pt_decoder *decoder) decoder->set_fup_tx_flags = false; +if (!decoder->branch_enable) { + decoder->pkt_state =INTEL_PT_STATE_IN_SYNC ; + decoder->overflow = false; + decoder->state.type =0 ;/* Do not have a sample */ +return 0 ; + } +intel_pt_log ("Scanning for full IP\n" ); err =intel_pt_walk_to_ip (decoder);if (err)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.h +1 -0
@@ -87,6 +87,7 @@ struct intel_pt_params {bool (*pgd_ip)(uint64_t ip,void *data);void *data;bool return_compression; +bool branch_enable;uint64_t period;enum intel_pt_period_type period_type;unsigned max_non_turbo_ratio;
tools/perf/util/intel-pt.c +14 -0
@@ -668,6 +668,19 @@ static bool intel_pt_return_compression(struct intel_pt *pt)return true; } +static bool intel_pt_branch_enable (struct intel_pt *pt) +{ +struct perf_evsel *evsel; +u64 config; + +evlist__for_each_entry (pt->session->evlist, evsel) { +if (intel_pt_get_config (pt, &evsel->attr, &config) && + (config &1 ) && !(config &0x2000 )) +return false; + } +return true; +} +static unsigned int intel_pt_mtc_period (struct intel_pt *pt) {struct perf_evsel *evsel;
@@ -799,6 +812,7 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt, params.walk_insn = intel_pt_walk_next_insn; params.data = ptq; params.return_compression =intel_pt_return_compression (pt); + params.branch_enable =intel_pt_branch_enable (pt); params.max_non_turbo_ratio = pt->max_non_turbo_ratio; params.mtc_period =intel_pt_mtc_period (pt); params.tsc_ctc_ratio_n = pt->tsc_ctc_ratio_n;
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Allow decoding with branch tracing disabled
perf intel-pt: Allow decoding with branch tracing disabled
Commit-ID: 839598176b0554967238234e1e92c7d1e3f0d53d Gitweb: http://git.kernel.org/tip/839598176b0554967238234e1e92c7d1e3f0d53d Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:11 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 21 Jun 2017 11:35:48 -0300
perf intel-pt: Allow decoding with branch tracing disabled
The kernel now supports the disabling of branch tracing, however the decoder assumes branch tracing is always enabled. Pass through a parameter to indicate whether branch tracing is enabled and use it to avoid cases when the decoder is expecting branch packets. There are 2 such cases. First, FUP packets which can bind to an IP even when there is no branch tracing. Secondly, the decoder will try to use branch packets to find an IP to start decoding or to recover from errors.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 13 +++++++++++++ tools/perf/util/intel-pt-decoder/intel-pt-decoder.h | 1 + tools/perf/util/intel-pt.c | 14 ++++++++++++++ 3 files changed, 28 insertions(+)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +13 -0
@@ -106,6 +106,7 @@ struct intel_pt_decoder {const unsigned char *buf;size_t len;bool return_compression; +bool branch_enable;bool mtc_insn;bool pge;bool have_tma;
@@ -214,6 +215,7 @@ struct intel_pt_decoder *intel_pt_decoder_new(struct intel_pt_params *params) decoder->pgd_ip = params->pgd_ip; decoder->data = params->data; decoder->return_compression = params->return_compression; + decoder->branch_enable = params->branch_enable; decoder->period = params->period; decoder->period_type = params->period_type;
@@ -1650,6 +1652,10 @@ next:break ; }intel_pt_set_last_ip (decoder); +if (!decoder->branch_enable) { + decoder->ip = decoder->last_ip; +break ; + } err =intel_pt_walk_fup (decoder);if (err != -EAGAIN ) {if (err)
@@ -1964,6 +1970,13 @@ static int intel_pt_sync_ip(struct intel_pt_decoder *decoder) decoder->set_fup_tx_flags = false; +if (!decoder->branch_enable) { + decoder->pkt_state =INTEL_PT_STATE_IN_SYNC ; + decoder->overflow = false; + decoder->state.type =0 ;/* Do not have a sample */ +return 0 ; + } +intel_pt_log ("Scanning for full IP\n" ); err =intel_pt_walk_to_ip (decoder);if (err)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.h +1 -0
@@ -87,6 +87,7 @@ struct intel_pt_params {bool (*pgd_ip)(uint64_t ip,void *data);void *data;bool return_compression; +bool branch_enable;uint64_t period;enum intel_pt_period_type period_type;unsigned max_non_turbo_ratio;
tools/perf/util/intel-pt.c +14 -0
@@ -668,6 +668,19 @@ static bool intel_pt_return_compression(struct intel_pt *pt)return true; } +static bool intel_pt_branch_enable (struct intel_pt *pt) +{ +struct perf_evsel *evsel; +u64 config; + +evlist__for_each_entry (pt->session->evlist, evsel) { +if (intel_pt_get_config (pt, &evsel->attr, &config) && + (config &1 ) && !(config &0x2000 )) +return false; + } +return true; +} +static unsigned int intel_pt_mtc_period (struct intel_pt *pt) {struct perf_evsel *evsel;
@@ -799,6 +812,7 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt, params.walk_insn = intel_pt_walk_next_insn; params.data = ptq; params.return_compression =intel_pt_return_compression (pt); + params.branch_enable =intel_pt_branch_enable (pt); params.max_non_turbo_ratio = pt->max_non_turbo_ratio; params.mtc_period =intel_pt_mtc_period (pt); params.tsc_ctc_ratio_n = pt->tsc_ctc_ratio_n;
Adrian Hunter
reviewerPATCH v2 11/37 perf intel-pt: Add default config for pass-through branch enable
In reply to Adrian HunterBranch tracing is enabled by default, so a fake config bit called 'pt' (pass-through) was added to allow the 'branch enable' bit to have affect. Add default config 'pt,branch' which will allow users to disable branch tracing using 'branch=0' instead of having to specify 'pt,branch=0'.
--- tools/perf/arch/x86/util/intel-pt.c | 5 +++++ 1 file changed, 5 insertions(+)
tools/perf/arch/x86/util/intel-pt.c +5 -0
@@ -196,6 +196,7 @@ static u64 intel_pt_default_config(struct perf_pmu *intel_pt_pmu)int psb_cyc, psb_periods, psb_period;int pos =0 ;u64 config; +char c; pos +=scnprintf (buf + pos,sizeof (buf) - pos,"tsc" );
@@ -229,6 +230,10 @@ static u64 intel_pt_default_config(struct perf_pmu *intel_pt_pmu) } } +if (perf_pmu__scan_file (intel_pt_pmu,"format/pt" ,"%c" , &c) ==1 && +perf_pmu__scan_file (intel_pt_pmu,"format/branch" ,"%c" , &c) ==1 ) + pos +=scnprintf (buf + pos,sizeof (buf) - pos,",pt,branch" ); +pr_debug2 ("%s default config: %s\n" , intel_pt_pmu->name, buf);intel_pt_parse_terms (&intel_pt_pmu->format, buf, &config);
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Add default config for pass-through branch enable
perf intel-pt: Add default config for pass-through branch enable
Commit-ID: 9fd629f9a6d0eded133f5f9866226f6bbfe5f50d Gitweb: http://git.kernel.org/tip/9fd629f9a6d0eded133f5f9866226f6bbfe5f50d Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:12 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 21 Jun 2017 11:35:48 -0300
perf intel-pt: Add default config for pass-through branch enable
Branch tracing is enabled by default, so a fake config bit called 'pt' (pass-through) was added to allow the 'branch enable' bit to have affect. Add default config 'pt,branch' which will allow users to disable branch tracing using 'branch=0' instead of having to specify 'pt,branch=0'.
--- tools/perf/arch/x86/util/intel-pt.c | 5 +++++ 1 file changed, 5 insertions(+)
tools/perf/arch/x86/util/intel-pt.c +5 -0
@@ -192,6 +192,7 @@ static u64 intel_pt_default_config(struct perf_pmu *intel_pt_pmu)int psb_cyc, psb_periods, psb_period;int pos =0 ;u64 config; +char c; pos +=scnprintf (buf + pos,sizeof (buf) - pos,"tsc" );
@@ -225,6 +226,10 @@ static u64 intel_pt_default_config(struct perf_pmu *intel_pt_pmu) } } +if (perf_pmu__scan_file (intel_pt_pmu,"format/pt" ,"%c" , &c) ==1 && +perf_pmu__scan_file (intel_pt_pmu,"format/branch" ,"%c" , &c) ==1 ) + pos +=scnprintf (buf + pos,sizeof (buf) - pos,",pt,branch" ); +pr_debug2 ("%s default config: %s\n" , intel_pt_pmu->name, buf);intel_pt_parse_terms (&intel_pt_pmu->format, buf, &config);
Adrian Hunter
reviewerPATCH v2 12/37 perf intel-pt: Add documentation for new config terms
In reply to Adrian HunterAdd documentation for new config terms.
--- tools/perf/Documentation/intel-pt.txt | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
tools/perf/Documentation/intel-pt.txt +36 -0
@@ -364,6 +364,42 @@ cyc_thresh Specifies how frequently CYC packets are produced - see cyc CYC packets are not requested by default. +pt Specifies pass-through which enables the 'branch' config term. + + The default config selects 'pt' if it is available, so a user will + never need to specify this term. + +branch Enable branch tracing. Branch tracing is enabled by default so to + disable branch tracing use 'branch=0'. + + The default config selects 'branch' if it is available. + +ptw Enable PTWRITE packets which are produced when a ptwrite instruction + is executed. + + Support for this feature is indicated by: + + /sys/bus/event_source/devices/intel_pt/caps/ptwrite + + which contains "1" if the feature is supported and + "0" otherwise. + +fup_on_ptw Enable a FUP packet to follow the PTWRITE packet. The FUP packet + provides the address of the ptwrite instruction. In the absence of + fup_on_ptw, the decoder will use the address of the previous branch + if branch tracing is enabled, otherwise the address will be zero. + Note that fup_on_ptw will work even when branch tracing is disabled. + +pwr_evt Enable power events. The power events provide information about + changes to the CPU C-state. + + Support for this feature is indicated by: + + /sys/bus/event_source/devices/intel_pt/caps/power_event_trace + + which contains "1" if the feature is supported and + "0" otherwise. + new snapshot option -------------------
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Add documentation for new config terms
perf intel-pt: Add documentation for new config terms
Commit-ID: 2bc60ffd663fc706ba70e603c369ae8ba0523b25 Gitweb: http://git.kernel.org/tip/2bc60ffd663fc706ba70e603c369ae8ba0523b25 Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:13 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 21 Jun 2017 11:35:49 -0300
perf intel-pt: Add documentation for new config terms
Add documentation for new config terms.
--- tools/perf/Documentation/intel-pt.txt | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
tools/perf/Documentation/intel-pt.txt +36 -0
@@ -364,6 +364,42 @@ cyc_thresh Specifies how frequently CYC packets are produced - see cyc CYC packets are not requested by default. +pt Specifies pass-through which enables the 'branch' config term. + + The default config selects 'pt' if it is available, so a user will + never need to specify this term. + +branch Enable branch tracing. Branch tracing is enabled by default so to + disable branch tracing use 'branch=0'. + + The default config selects 'branch' if it is available. + +ptw Enable PTWRITE packets which are produced when a ptwrite instruction + is executed. + + Support for this feature is indicated by: + + /sys/bus/event_source/devices/intel_pt/caps/ptwrite + + which contains "1" if the feature is supported and + "0" otherwise. + +fup_on_ptw Enable a FUP packet to follow the PTWRITE packet. The FUP packet + provides the address of the ptwrite instruction. In the absence of + fup_on_ptw, the decoder will use the address of the previous branch + if branch tracing is enabled, otherwise the address will be zero. + Note that fup_on_ptw will work even when branch tracing is disabled. + +pwr_evt Enable power events. The power events provide information about + changes to the CPU C-state. + + Support for this feature is indicated by: + + /sys/bus/event_source/devices/intel_pt/caps/power_event_trace + + which contains "1" if the feature is supported and + "0" otherwise. + new snapshot option -------------------
Adrian Hunter
reviewerPATCH v2 13/37 perf intel-pt: Add decoder support for ptwrite and power event packets
In reply to Adrian HunterAdd decoder support for PTWRITE, MWAIT, PWRE, PWRX and EXSTOP packets. This patch only affects the decoder, so the tools still do not select or consume the new information. That is added in subsequent patches.
--- .../perf/util/intel-pt-decoder/intel-pt-decoder.c | 176 ++++++++++++++++++++- .../perf/util/intel-pt-decoder/intel-pt-decoder.h | 10 ++ .../util/intel-pt-decoder/intel-pt-pkt-decoder.c | 108 +++++++++++++ .../util/intel-pt-decoder/intel-pt-pkt-decoder.h | 7 + 4 files changed, 293 insertions(+), 8 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +168 -8
@@ -158,8 +158,15 @@ struct intel_pt_decoder {bool continuous_period;bool overflow;bool set_fup_tx_flags; +bool set_fup_ptw; +bool set_fup_mwait; +bool set_fup_pwre; +bool set_fup_exstop;unsigned int fup_tx_flags;unsigned int tx_flags; +uint64_t fup_ptw_payload; +uint64_t fup_mwait_payload; +uint64_t fup_pwre_payload;uint64_t timestamp_insn_cnt;uint64_t sample_insn_cnt;uint64_t stuck_ip;
@@ -660,6 +667,8 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info)case INTEL_PT_PAD :case INTEL_PT_VMCS :case INTEL_PT_MNT : +case INTEL_PT_PTWRITE : +case INTEL_PT_PTWRITE_IP :return 0 ;case INTEL_PT_MTC :
@@ -758,6 +767,11 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info)case INTEL_PT_TIP_PGD :case INTEL_PT_TRACESTOP : +case INTEL_PT_EXSTOP : +case INTEL_PT_EXSTOP_IP : +case INTEL_PT_MWAIT : +case INTEL_PT_PWRE : +case INTEL_PT_PWRX :case INTEL_PT_OVF :case INTEL_PT_BAD :/* Does not happen */ default :
@@ -1016,6 +1030,57 @@ static int intel_pt_walk_insn(struct intel_pt_decoder *decoder,return err; } +static bool intel_pt_fup_event (struct intel_pt_decoder *decoder) +{ +bool ret = false; + +if (decoder->set_fup_tx_flags) { + decoder->set_fup_tx_flags = false; + decoder->tx_flags = decoder->fup_tx_flags; + decoder->state.type =INTEL_PT_TRANSACTION ; + decoder->state.from_ip = decoder->ip; + decoder->state.to_ip =0 ; + decoder->state.flags = decoder->fup_tx_flags; +return true; + } +if (decoder->set_fup_ptw) { + decoder->set_fup_ptw = false; + decoder->state.type =INTEL_PT_PTW ; + decoder->state.flags |=INTEL_PT_FUP_IP ; + decoder->state.from_ip = decoder->ip; + decoder->state.to_ip =0 ; + decoder->state.ptw_payload = decoder->fup_ptw_payload; +return true; + } +if (decoder->set_fup_mwait) { + decoder->set_fup_mwait = false; + decoder->state.type =INTEL_PT_MWAIT_OP ; + decoder->state.from_ip = decoder->ip; + decoder->state.to_ip =0 ; + decoder->state.mwait_payload = decoder->fup_mwait_payload; + ret = true; + } +if (decoder->set_fup_pwre) { + decoder->set_fup_pwre = false; + decoder->state.type |=INTEL_PT_PWR_ENTRY ; + decoder->state.type &= ~INTEL_PT_BRANCH ; + decoder->state.from_ip = decoder->ip; + decoder->state.to_ip =0 ; + decoder->state.pwre_payload = decoder->fup_pwre_payload; + ret = true; + } +if (decoder->set_fup_exstop) { + decoder->set_fup_exstop = false; + decoder->state.type |=INTEL_PT_EX_STOP ; + decoder->state.type &= ~INTEL_PT_BRANCH ; + decoder->state.flags |=INTEL_PT_FUP_IP ; + decoder->state.from_ip = decoder->ip; + decoder->state.to_ip =0 ; + ret = true; + } +return ret; +} +static int intel_pt_walk_fup (struct intel_pt_decoder *decoder) {struct intel_pt_insn intel_pt_insn;
@@ -1029,15 +1094,8 @@ static int intel_pt_walk_fup(struct intel_pt_decoder *decoder)if (err ==INTEL_PT_RETURN )return 0 ;if (err == -EAGAIN ) { -if (decoder->set_fup_tx_flags) { - decoder->set_fup_tx_flags = false; - decoder->tx_flags = decoder->fup_tx_flags; - decoder->state.type =INTEL_PT_TRANSACTION ; - decoder->state.from_ip = decoder->ip; - decoder->state.to_ip =0 ; - decoder->state.flags = decoder->fup_tx_flags; +if (intel_pt_fup_event (decoder))return 0 ; - }return err; } decoder->set_fup_tx_flags = false;
@@ -1443,6 +1501,13 @@ static int intel_pt_walk_psbend(struct intel_pt_decoder *decoder)case INTEL_PT_TRACESTOP :case INTEL_PT_BAD :case INTEL_PT_PSB : +case INTEL_PT_PTWRITE : +case INTEL_PT_PTWRITE_IP : +case INTEL_PT_EXSTOP : +case INTEL_PT_EXSTOP_IP : +case INTEL_PT_MWAIT : +case INTEL_PT_PWRE : +case INTEL_PT_PWRX : decoder->have_tma = false;intel_pt_log ("ERROR: Unexpected packet\n" );return -EAGAIN ;
@@ -1524,6 +1589,13 @@ static int intel_pt_walk_fup_tip(struct intel_pt_decoder *decoder)case INTEL_PT_MODE_TSX :case INTEL_PT_BAD :case INTEL_PT_PSBEND : +case INTEL_PT_PTWRITE : +case INTEL_PT_PTWRITE_IP : +case INTEL_PT_EXSTOP : +case INTEL_PT_EXSTOP_IP : +case INTEL_PT_MWAIT : +case INTEL_PT_PWRE : +case INTEL_PT_PWRX :intel_pt_log ("ERROR: Missing TIP after FUP\n" ); decoder->pkt_state =INTEL_PT_STATE_ERR3 ;return -ENOENT ;
@@ -1654,8 +1726,13 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder)intel_pt_set_last_ip (decoder);if (!decoder->branch_enable) { decoder->ip = decoder->last_ip; +if (intel_pt_fup_event (decoder)) +return 0 ; + no_tip = false;break ; } +if (decoder->set_fup_mwait) + no_tip = true; err =intel_pt_walk_fup (decoder);if (err != -EAGAIN ) {if (err)
@@ -1755,6 +1832,71 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder)case INTEL_PT_PAD :break ; +case INTEL_PT_PTWRITE_IP : + decoder->fup_ptw_payload = decoder->packet.payload; + err =intel_pt_get_next_packet (decoder); +if (err) +return err; +if (decoder->packet.type ==INTEL_PT_FUP ) { + decoder->set_fup_ptw = true; + no_tip = true; + }else { +intel_pt_log_at ("ERROR: Missing FUP after PTWRITE" , + decoder->pos); + } + goto next; + +case INTEL_PT_PTWRITE : + decoder->state.type =INTEL_PT_PTW ; + decoder->state.from_ip = decoder->ip; + decoder->state.to_ip =0 ; + decoder->state.ptw_payload = decoder->packet.payload; +return 0 ; + +case INTEL_PT_MWAIT : + decoder->fup_mwait_payload = decoder->packet.payload; + decoder->set_fup_mwait = true; +break ; + +case INTEL_PT_PWRE : +if (decoder->set_fup_mwait) { + decoder->fup_pwre_payload = + decoder->packet.payload; + decoder->set_fup_pwre = true; +break ; + } + decoder->state.type =INTEL_PT_PWR_ENTRY ; + decoder->state.from_ip = decoder->ip; + decoder->state.to_ip =0 ; + decoder->state.pwrx_payload = decoder->packet.payload; +return 0 ; + +case INTEL_PT_EXSTOP_IP : + err =intel_pt_get_next_packet (decoder); +if (err) +return err; +if (decoder->packet.type ==INTEL_PT_FUP ) { + decoder->set_fup_exstop = true; + no_tip = true; + }else { +intel_pt_log_at ("ERROR: Missing FUP after EXSTOP" , + decoder->pos); + } + goto next; + +case INTEL_PT_EXSTOP : + decoder->state.type =INTEL_PT_EX_STOP ; + decoder->state.from_ip = decoder->ip; + decoder->state.to_ip =0 ; +return 0 ; + +case INTEL_PT_PWRX : + decoder->state.type =INTEL_PT_PWR_EXIT ; + decoder->state.from_ip = decoder->ip; + decoder->state.to_ip =0 ; + decoder->state.pwrx_payload = decoder->packet.payload; +return 0 ; +default :return intel_pt_bug (decoder); }
@@ -1784,6 +1926,13 @@ static int intel_pt_walk_psb(struct intel_pt_decoder *decoder) __fallthrough;case INTEL_PT_TIP_PGE :case INTEL_PT_TIP : +case INTEL_PT_PTWRITE : +case INTEL_PT_PTWRITE_IP : +case INTEL_PT_EXSTOP : +case INTEL_PT_EXSTOP_IP : +case INTEL_PT_MWAIT : +case INTEL_PT_PWRE : +case INTEL_PT_PWRX :intel_pt_log ("ERROR: Unexpected packet\n" );return -ENOENT ;
@@ -1958,6 +2107,13 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder)case INTEL_PT_VMCS :case INTEL_PT_MNT :case INTEL_PT_PAD : +case INTEL_PT_PTWRITE : +case INTEL_PT_PTWRITE_IP : +case INTEL_PT_EXSTOP : +case INTEL_PT_EXSTOP_IP : +case INTEL_PT_MWAIT : +case INTEL_PT_PWRE : +case INTEL_PT_PWRX :default :break ; }
@@ -1969,6 +2125,10 @@ static int intel_pt_sync_ip(struct intel_pt_decoder *decoder)int err; decoder->set_fup_tx_flags = false; + decoder->set_fup_ptw = false; + decoder->set_fup_mwait = false; + decoder->set_fup_pwre = false; + decoder->set_fup_exstop = false;if (!decoder->branch_enable) { decoder->pkt_state =INTEL_PT_STATE_IN_SYNC ;
tools/perf/util/intel-pt-decoder/intel-pt-decoder.h +10 -0
@@ -25,11 +25,17 @@#define INTEL_PT_IN_TX (1 << 0)#define INTEL_PT_ABORT_TX (1 << 1)#define INTEL_PT_ASYNC (1 << 2) +#define INTEL_PT_FUP_IP (1 << 3)enum intel_pt_sample_type {INTEL_PT_BRANCH =1 <<0 ,INTEL_PT_INSTRUCTION =1 <<1 ,INTEL_PT_TRANSACTION =1 <<2 , +INTEL_PT_PTW =1 <<3 , +INTEL_PT_MWAIT_OP =1 <<4 , +INTEL_PT_PWR_ENTRY =1 <<5 , +INTEL_PT_EX_STOP =1 <<6 , +INTEL_PT_PWR_EXIT =1 <<7 , };enum intel_pt_period_type {
@@ -63,6 +69,10 @@ struct intel_pt_state {uint64_t timestamp;uint64_t est_timestamp;uint64_t trace_nr; +uint64_t ptw_payload; +uint64_t mwait_payload; +uint64_t pwre_payload; +uint64_t pwrx_payload;uint32_t flags;enum intel_pt_insn_op insn_op;int insn_len;
tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c +108 -0
138 lines not on this page · raw message
tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.h +7 -0
@@ -52,6 +52,13 @@ enum intel_pt_pkt_type {INTEL_PT_PIP ,INTEL_PT_OVF ,INTEL_PT_MNT , +INTEL_PT_PTWRITE , +INTEL_PT_PTWRITE_IP , +INTEL_PT_EXSTOP , +INTEL_PT_EXSTOP_IP , +INTEL_PT_MWAIT , +INTEL_PT_PWRE , + INTEL_PT_PWRX, }; struct intel_pt_pkt {
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Add decoder support for ptwrite and power event packets
perf intel-pt: Add decoder support for ptwrite and power event packets
Commit-ID: a472e65fc490ab87e30b7fecb8981f02dbb2b865 Gitweb: http://git.kernel.org/tip/a472e65fc490ab87e30b7fecb8981f02dbb2b865 Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:14 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 21 Jun 2017 11:35:50 -0300
perf intel-pt: Add decoder support for ptwrite and power event packets
Add decoder support for PTWRITE, MWAIT, PWRE, PWRX and EXSTOP packets. This patch only affects the decoder, so the tools still do not select or consume the new information. That is added in subsequent patches.
--- .../perf/util/intel-pt-decoder/intel-pt-decoder.c | 176 ++++++++++++++++++++- .../perf/util/intel-pt-decoder/intel-pt-decoder.h | 10 ++ .../util/intel-pt-decoder/intel-pt-pkt-decoder.c | 108 +++++++++++++ .../util/intel-pt-decoder/intel-pt-pkt-decoder.h | 7 + 4 files changed, 293 insertions(+), 8 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +168 -8
@@ -158,8 +158,15 @@ struct intel_pt_decoder {bool continuous_period;bool overflow;bool set_fup_tx_flags; +bool set_fup_ptw; +bool set_fup_mwait; +bool set_fup_pwre; +bool set_fup_exstop;unsigned int fup_tx_flags;unsigned int tx_flags; +uint64_t fup_ptw_payload; +uint64_t fup_mwait_payload; +uint64_t fup_pwre_payload;uint64_t timestamp_insn_cnt;uint64_t sample_insn_cnt;uint64_t stuck_ip;
@@ -660,6 +667,8 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info)case INTEL_PT_PAD :case INTEL_PT_VMCS :case INTEL_PT_MNT : +case INTEL_PT_PTWRITE : +case INTEL_PT_PTWRITE_IP :return 0 ;case INTEL_PT_MTC :
@@ -758,6 +767,11 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info)case INTEL_PT_TIP_PGD :case INTEL_PT_TRACESTOP : +case INTEL_PT_EXSTOP : +case INTEL_PT_EXSTOP_IP : +case INTEL_PT_MWAIT : +case INTEL_PT_PWRE : +case INTEL_PT_PWRX :case INTEL_PT_OVF :case INTEL_PT_BAD :/* Does not happen */ default :
@@ -1016,6 +1030,57 @@ out_no_progress:return err; } +static bool intel_pt_fup_event (struct intel_pt_decoder *decoder) +{ +bool ret = false; + +if (decoder->set_fup_tx_flags) { + decoder->set_fup_tx_flags = false; + decoder->tx_flags = decoder->fup_tx_flags; + decoder->state.type =INTEL_PT_TRANSACTION ; + decoder->state.from_ip = decoder->ip; + decoder->state.to_ip =0 ; + decoder->state.flags = decoder->fup_tx_flags; +return true; + } +if (decoder->set_fup_ptw) { + decoder->set_fup_ptw = false; + decoder->state.type =INTEL_PT_PTW ; + decoder->state.flags |=INTEL_PT_FUP_IP ; + decoder->state.from_ip = decoder->ip; + decoder->state.to_ip =0 ; + decoder->state.ptw_payload = decoder->fup_ptw_payload; +return true; + } +if (decoder->set_fup_mwait) { + decoder->set_fup_mwait = false; + decoder->state.type =INTEL_PT_MWAIT_OP ; + decoder->state.from_ip = decoder->ip; + decoder->state.to_ip =0 ; + decoder->state.mwait_payload = decoder->fup_mwait_payload; + ret = true; + } +if (decoder->set_fup_pwre) { + decoder->set_fup_pwre = false; + decoder->state.type |=INTEL_PT_PWR_ENTRY ; + decoder->state.type &= ~INTEL_PT_BRANCH ; + decoder->state.from_ip = decoder->ip; + decoder->state.to_ip =0 ; + decoder->state.pwre_payload = decoder->fup_pwre_payload; + ret = true; + } +if (decoder->set_fup_exstop) { + decoder->set_fup_exstop = false; + decoder->state.type |=INTEL_PT_EX_STOP ; + decoder->state.type &= ~INTEL_PT_BRANCH ; + decoder->state.flags |=INTEL_PT_FUP_IP ; + decoder->state.from_ip = decoder->ip; + decoder->state.to_ip =0 ; + ret = true; + } +return ret; +} +static int intel_pt_walk_fup (struct intel_pt_decoder *decoder) {struct intel_pt_insn intel_pt_insn;
@@ -1029,15 +1094,8 @@ static int intel_pt_walk_fup(struct intel_pt_decoder *decoder)if (err ==INTEL_PT_RETURN )return 0 ;if (err == -EAGAIN ) { -if (decoder->set_fup_tx_flags) { - decoder->set_fup_tx_flags = false; - decoder->tx_flags = decoder->fup_tx_flags; - decoder->state.type =INTEL_PT_TRANSACTION ; - decoder->state.from_ip = decoder->ip; - decoder->state.to_ip =0 ; - decoder->state.flags = decoder->fup_tx_flags; +if (intel_pt_fup_event (decoder))return 0 ; - }return err; } decoder->set_fup_tx_flags = false;
@@ -1443,6 +1501,13 @@ static int intel_pt_walk_psbend(struct intel_pt_decoder *decoder)case INTEL_PT_TRACESTOP :case INTEL_PT_BAD :case INTEL_PT_PSB : +case INTEL_PT_PTWRITE : +case INTEL_PT_PTWRITE_IP : +case INTEL_PT_EXSTOP : +case INTEL_PT_EXSTOP_IP : +case INTEL_PT_MWAIT : +case INTEL_PT_PWRE : +case INTEL_PT_PWRX : decoder->have_tma = false;intel_pt_log ("ERROR: Unexpected packet\n" );return -EAGAIN ;
@@ -1524,6 +1589,13 @@ static int intel_pt_walk_fup_tip(struct intel_pt_decoder *decoder)case INTEL_PT_MODE_TSX :case INTEL_PT_BAD :case INTEL_PT_PSBEND : +case INTEL_PT_PTWRITE : +case INTEL_PT_PTWRITE_IP : +case INTEL_PT_EXSTOP : +case INTEL_PT_EXSTOP_IP : +case INTEL_PT_MWAIT : +case INTEL_PT_PWRE : +case INTEL_PT_PWRX :intel_pt_log ("ERROR: Missing TIP after FUP\n" ); decoder->pkt_state =INTEL_PT_STATE_ERR3 ;return -ENOENT ;
@@ -1654,8 +1726,13 @@ next:intel_pt_set_last_ip (decoder);if (!decoder->branch_enable) { decoder->ip = decoder->last_ip; +if (intel_pt_fup_event (decoder)) +return 0 ; + no_tip = false;break ; } +if (decoder->set_fup_mwait) + no_tip = true; err =intel_pt_walk_fup (decoder);if (err != -EAGAIN ) {if (err)
@@ -1755,6 +1832,71 @@ next:case INTEL_PT_PAD :break ; +case INTEL_PT_PTWRITE_IP : + decoder->fup_ptw_payload = decoder->packet.payload; + err =intel_pt_get_next_packet (decoder); +if (err) +return err; +if (decoder->packet.type ==INTEL_PT_FUP ) { + decoder->set_fup_ptw = true; + no_tip = true; + }else { +intel_pt_log_at ("ERROR: Missing FUP after PTWRITE" , + decoder->pos); + } + goto next; + +case INTEL_PT_PTWRITE : + decoder->state.type =INTEL_PT_PTW ; + decoder->state.from_ip = decoder->ip; + decoder->state.to_ip =0 ; + decoder->state.ptw_payload = decoder->packet.payload; +return 0 ; + +case INTEL_PT_MWAIT : + decoder->fup_mwait_payload = decoder->packet.payload; + decoder->set_fup_mwait = true; +break ; + +case INTEL_PT_PWRE : +if (decoder->set_fup_mwait) { + decoder->fup_pwre_payload = + decoder->packet.payload; + decoder->set_fup_pwre = true; +break ; + } + decoder->state.type =INTEL_PT_PWR_ENTRY ; + decoder->state.from_ip = decoder->ip; + decoder->state.to_ip =0 ; + decoder->state.pwrx_payload = decoder->packet.payload; +return 0 ; + +case INTEL_PT_EXSTOP_IP : + err =intel_pt_get_next_packet (decoder); +if (err) +return err; +if (decoder->packet.type ==INTEL_PT_FUP ) { + decoder->set_fup_exstop = true; + no_tip = true; + }else { +intel_pt_log_at ("ERROR: Missing FUP after EXSTOP" , + decoder->pos); + } + goto next; + +case INTEL_PT_EXSTOP : + decoder->state.type =INTEL_PT_EX_STOP ; + decoder->state.from_ip = decoder->ip; + decoder->state.to_ip =0 ; +return 0 ; + +case INTEL_PT_PWRX : + decoder->state.type =INTEL_PT_PWR_EXIT ; + decoder->state.from_ip = decoder->ip; + decoder->state.to_ip =0 ; + decoder->state.pwrx_payload = decoder->packet.payload; +return 0 ; +default :return intel_pt_bug (decoder); }
@@ -1784,6 +1926,13 @@ static int intel_pt_walk_psb(struct intel_pt_decoder *decoder) __fallthrough;case INTEL_PT_TIP_PGE :case INTEL_PT_TIP : +case INTEL_PT_PTWRITE : +case INTEL_PT_PTWRITE_IP : +case INTEL_PT_EXSTOP : +case INTEL_PT_EXSTOP_IP : +case INTEL_PT_MWAIT : +case INTEL_PT_PWRE : +case INTEL_PT_PWRX :intel_pt_log ("ERROR: Unexpected packet\n" );return -ENOENT ;
@@ -1958,6 +2107,13 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder)case INTEL_PT_VMCS :case INTEL_PT_MNT :case INTEL_PT_PAD : +case INTEL_PT_PTWRITE : +case INTEL_PT_PTWRITE_IP : +case INTEL_PT_EXSTOP : +case INTEL_PT_EXSTOP_IP : +case INTEL_PT_MWAIT : +case INTEL_PT_PWRE : +case INTEL_PT_PWRX :default :break ; }
@@ -1969,6 +2125,10 @@ static int intel_pt_sync_ip(struct intel_pt_decoder *decoder)int err; decoder->set_fup_tx_flags = false; + decoder->set_fup_ptw = false; + decoder->set_fup_mwait = false; + decoder->set_fup_pwre = false; + decoder->set_fup_exstop = false;if (!decoder->branch_enable) { decoder->pkt_state =INTEL_PT_STATE_IN_SYNC ;
tools/perf/util/intel-pt-decoder/intel-pt-decoder.h +10 -0
@@ -25,11 +25,17 @@#define INTEL_PT_IN_TX (1 << 0)#define INTEL_PT_ABORT_TX (1 << 1)#define INTEL_PT_ASYNC (1 << 2) +#define INTEL_PT_FUP_IP (1 << 3)enum intel_pt_sample_type {INTEL_PT_BRANCH =1 <<0 ,INTEL_PT_INSTRUCTION =1 <<1 ,INTEL_PT_TRANSACTION =1 <<2 , +INTEL_PT_PTW =1 <<3 , +INTEL_PT_MWAIT_OP =1 <<4 , +INTEL_PT_PWR_ENTRY =1 <<5 , +INTEL_PT_EX_STOP =1 <<6 , +INTEL_PT_PWR_EXIT =1 <<7 , };enum intel_pt_period_type {
@@ -63,6 +69,10 @@ struct intel_pt_state {uint64_t timestamp;uint64_t est_timestamp;uint64_t trace_nr; +uint64_t ptw_payload; +uint64_t mwait_payload; +uint64_t pwre_payload; +uint64_t pwrx_payload;uint32_t flags;enum intel_pt_insn_op insn_op;int insn_len;
tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c +108 -0
138 lines not on this page · raw message
tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.h +7 -0
@@ -52,6 +52,13 @@ enum intel_pt_pkt_type {INTEL_PT_PIP ,INTEL_PT_OVF ,INTEL_PT_MNT , +INTEL_PT_PTWRITE , +INTEL_PT_PTWRITE_IP , +INTEL_PT_EXSTOP , +INTEL_PT_EXSTOP_IP , +INTEL_PT_MWAIT , +INTEL_PT_PWRE , + INTEL_PT_PWRX, }; struct intel_pt_pkt {
Adrian Hunter
reviewerPATCH v2 14/37 perf intel-pt: Add reserved byte to CBR packet payload
In reply to Adrian HunterFuture proof CBR packet decoding by passing through also the undefined 'reserved' byte in the packet payload.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 2 +- tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +1 -1
@@ -1444,7 +1444,7 @@ static void intel_pt_calc_mtc_timestamp(struct intel_pt_decoder *decoder)static void intel_pt_calc_cbr (struct intel_pt_decoder *decoder) { -unsigned int cbr = decoder->packet.payload; +unsigned int cbr = decoder->packet.payload &0xff ;if (decoder->cbr == cbr)return ;
tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c +1 -1
@@ -130,7 +130,7 @@ static int intel_pt_get_cbr(const unsigned char *buf, size_t len,if (len <4 )return INTEL_PT_NEED_MORE_BYTES ; packet->type =INTEL_PT_CBR ; - packet->payload = buf[2 ]; + packet->payload =le16_to_cpu (*(uint16_t *)(buf +2 ));return 4 ; }
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Add reserved byte to CBR packet payload
perf intel-pt: Add reserved byte to CBR packet payload
Commit-ID: 26fb2fb19c28ec692d6604bb01cbb4f03a4ee009 Gitweb: http://git.kernel.org/tip/26fb2fb19c28ec692d6604bb01cbb4f03a4ee009 Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:15 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 21 Jun 2017 11:35:50 -0300
perf intel-pt: Add reserved byte to CBR packet payload
Future proof CBR packet decoding by passing through also the undefined 'reserved' byte in the packet payload.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 2 +- tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +1 -1
@@ -1444,7 +1444,7 @@ static void intel_pt_calc_mtc_timestamp(struct intel_pt_decoder *decoder)static void intel_pt_calc_cbr (struct intel_pt_decoder *decoder) { -unsigned int cbr = decoder->packet.payload; +unsigned int cbr = decoder->packet.payload &0xff ;if (decoder->cbr == cbr)return ;
tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c +1 -1
@@ -130,7 +130,7 @@ static int intel_pt_get_cbr(const unsigned char *buf, size_t len,if (len <4 )return INTEL_PT_NEED_MORE_BYTES ; packet->type =INTEL_PT_CBR ; - packet->payload = buf[2 ]; + packet->payload =le16_to_cpu (*(uint16_t *)(buf +2 ));return 4 ; }
Adrian Hunter
reviewerPATCH v2 15/37 perf intel-pt: Add decoder support for CBR events
In reply to Adrian HunterAdd decoder support for informing the tools of changes to the core-to-bus ratio (CBR).
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 19 +++++++++++++++++++ tools/perf/util/intel-pt-decoder/intel-pt-decoder.h | 2 ++ 2 files changed, 21 insertions(+)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +19 -0
@@ -141,6 +141,7 @@ struct intel_pt_decoder {int pkt_len;int last_packet_type;unsigned int cbr; +unsigned int cbr_seen;unsigned int max_non_turbo_ratio;double max_non_turbo_ratio_fp;double cbr_cyc_to_tsc;
@@ -167,6 +168,7 @@ struct intel_pt_decoder {uint64_t fup_ptw_payload;uint64_t fup_mwait_payload;uint64_t fup_pwre_payload; +uint64_t cbr_payload;uint64_t timestamp_insn_cnt;uint64_t sample_insn_cnt;uint64_t stuck_ip;
@@ -1446,6 +1448,8 @@ static void intel_pt_calc_cbr(struct intel_pt_decoder *decoder) {unsigned int cbr = decoder->packet.payload &0xff ; + decoder->cbr_payload = decoder->packet.payload; +if (decoder->cbr == cbr)return ;
@@ -1806,6 +1810,16 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder)case INTEL_PT_CBR :intel_pt_calc_cbr (decoder); +if (!decoder->branch_enable && + decoder->cbr != decoder->cbr_seen) { + decoder->cbr_seen = decoder->cbr; + decoder->state.type =INTEL_PT_CBR_CHG ; + decoder->state.from_ip = decoder->ip; + decoder->state.to_ip =0 ; + decoder->state.cbr_payload = + decoder->packet.payload; +return 0 ; + }break ;case INTEL_PT_MODE_EXEC :
@@ -2343,6 +2357,11 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder) decoder->sample_insn_cnt = decoder->timestamp_insn_cnt; }else { decoder->state.err =0 ; +if (decoder->cbr != decoder->cbr_seen && decoder->state.type) { + decoder->cbr_seen = decoder->cbr; + decoder->state.type |=INTEL_PT_CBR_CHG ; + decoder->state.cbr_payload = decoder->cbr_payload; + }if (intel_pt_sample_time (decoder->pkt_state)) { decoder->sample_timestamp = decoder->timestamp; decoder->sample_insn_cnt = decoder->timestamp_insn_cnt;
tools/perf/util/intel-pt-decoder/intel-pt-decoder.h +2 -0
@@ -36,6 +36,7 @@ enum intel_pt_sample_type {INTEL_PT_PWR_ENTRY =1 <<5 ,INTEL_PT_EX_STOP =1 <<6 ,INTEL_PT_PWR_EXIT =1 <<7 , + INTEL_PT_CBR_CHG = 1 << 8, }; enum intel_pt_period_type {
@@ -73,6 +74,7 @@ struct intel_pt_state {uint64_t mwait_payload;uint64_t pwre_payload;uint64_t pwrx_payload; +uint64_t cbr_payload;uint32_t flags;enum intel_pt_insn_op insn_op;int insn_len;
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Add decoder support for CBR events
perf intel-pt: Add decoder support for CBR events
Commit-ID: 0a7c700d23450bd4467855d5162920d5edf314b0 Gitweb: http://git.kernel.org/tip/0a7c700d23450bd4467855d5162920d5edf314b0 Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:16 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 21 Jun 2017 11:35:51 -0300
perf intel-pt: Add decoder support for CBR events
Add decoder support for informing the tools of changes to the core-to-bus ratio (CBR).
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 19 +++++++++++++++++++ tools/perf/util/intel-pt-decoder/intel-pt-decoder.h | 2 ++ 2 files changed, 21 insertions(+)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +19 -0
@@ -141,6 +141,7 @@ struct intel_pt_decoder {int pkt_len;int last_packet_type;unsigned int cbr; +unsigned int cbr_seen;unsigned int max_non_turbo_ratio;double max_non_turbo_ratio_fp;double cbr_cyc_to_tsc;
@@ -167,6 +168,7 @@ struct intel_pt_decoder {uint64_t fup_ptw_payload;uint64_t fup_mwait_payload;uint64_t fup_pwre_payload; +uint64_t cbr_payload;uint64_t timestamp_insn_cnt;uint64_t sample_insn_cnt;uint64_t stuck_ip;
@@ -1446,6 +1448,8 @@ static void intel_pt_calc_cbr(struct intel_pt_decoder *decoder) {unsigned int cbr = decoder->packet.payload &0xff ; + decoder->cbr_payload = decoder->packet.payload; +if (decoder->cbr == cbr)return ;
@@ -1806,6 +1810,16 @@ next:case INTEL_PT_CBR :intel_pt_calc_cbr (decoder); +if (!decoder->branch_enable && + decoder->cbr != decoder->cbr_seen) { + decoder->cbr_seen = decoder->cbr; + decoder->state.type =INTEL_PT_CBR_CHG ; + decoder->state.from_ip = decoder->ip; + decoder->state.to_ip =0 ; + decoder->state.cbr_payload = + decoder->packet.payload; +return 0 ; + }break ;case INTEL_PT_MODE_EXEC :
@@ -2343,6 +2357,11 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder) decoder->sample_insn_cnt = decoder->timestamp_insn_cnt; }else { decoder->state.err =0 ; +if (decoder->cbr != decoder->cbr_seen && decoder->state.type) { + decoder->cbr_seen = decoder->cbr; + decoder->state.type |=INTEL_PT_CBR_CHG ; + decoder->state.cbr_payload = decoder->cbr_payload; + }if (intel_pt_sample_time (decoder->pkt_state)) { decoder->sample_timestamp = decoder->timestamp; decoder->sample_insn_cnt = decoder->timestamp_insn_cnt;
tools/perf/util/intel-pt-decoder/intel-pt-decoder.h +2 -0
@@ -36,6 +36,7 @@ enum intel_pt_sample_type {INTEL_PT_PWR_ENTRY =1 <<5 ,INTEL_PT_EX_STOP =1 <<6 ,INTEL_PT_PWR_EXIT =1 <<7 , + INTEL_PT_CBR_CHG = 1 << 8, }; enum intel_pt_period_type {
@@ -73,6 +74,7 @@ struct intel_pt_state {uint64_t mwait_payload;uint64_t pwre_payload;uint64_t pwrx_payload; +uint64_t cbr_payload;uint32_t flags;enum intel_pt_insn_op insn_op;int insn_len;
Adrian Hunter
reviewerPATCH v2 16/37 perf intel-pt: Remove redundant initial_skip checks
In reply to Adrian Hunter'initial_skip' is checked inside the sample synthesis functions which means it is actually being done twice for 'instructions' and 'transactions' samples. Remove the redundant checks.
--- tools/perf/util/intel-pt.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
tools/perf/util/intel-pt.c +2 -6
@@ -1322,18 +1322,14 @@ static int intel_pt_sample(struct intel_pt_queue *ptq) ptq->have_sample = false;if (pt->sample_instructions && - (state->type &INTEL_PT_INSTRUCTION ) && - (!pt->synth_opts.initial_skip || - pt->num_events++ >= pt->synth_opts.initial_skip)) { + (state->type &INTEL_PT_INSTRUCTION )) { err =intel_pt_synth_instruction_sample (ptq);if (err)return err; }if (pt->sample_transactions && - (state->type &INTEL_PT_TRANSACTION ) && - (!pt->synth_opts.initial_skip || - pt->num_events++ >= pt->synth_opts.initial_skip)) { + (state->type &INTEL_PT_TRANSACTION )) { err =intel_pt_synth_transaction_sample (ptq);if (err)return err;
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Remove redundant initial_skip checks
perf intel-pt: Remove redundant initial_skip checks
Commit-ID: 5da3b23b3b03d34fbb8cb9947c1a99ea77c2203f Gitweb: http://git.kernel.org/tip/5da3b23b3b03d34fbb8cb9947c1a99ea77c2203f Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:17 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 21 Jun 2017 11:35:51 -0300
perf intel-pt: Remove redundant initial_skip checks
'initial_skip' is checked inside the sample synthesis functions which means it is actually being done twice for 'instructions' and 'transactions' samples. Remove the redundant checks.
--- tools/perf/util/intel-pt.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
tools/perf/util/intel-pt.c +2 -6
@@ -1322,18 +1322,14 @@ static int intel_pt_sample(struct intel_pt_queue *ptq) ptq->have_sample = false;if (pt->sample_instructions && - (state->type &INTEL_PT_INSTRUCTION ) && - (!pt->synth_opts.initial_skip || - pt->num_events++ >= pt->synth_opts.initial_skip)) { + (state->type &INTEL_PT_INSTRUCTION )) { err =intel_pt_synth_instruction_sample (ptq);if (err)return err; }if (pt->sample_transactions && - (state->type &INTEL_PT_TRANSACTION ) && - (!pt->synth_opts.initial_skip || - pt->num_events++ >= pt->synth_opts.initial_skip)) { + (state->type &INTEL_PT_TRANSACTION )) { err =intel_pt_synth_transaction_sample (ptq);if (err)return err;
Adrian Hunter
reviewerPATCH v2 17/37 perf intel-pt: Fix transactions_sample_type
In reply to Adrian Hunter'transactions_sample_type' is needed to correctly inject transactions samples but it was not being set. Set it from the event sample type.
--- tools/perf/util/intel-pt.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/util/intel-pt.c +1 -0
@@ -2035,6 +2035,7 @@ static int intel_pt_synth_events(struct intel_pt *pt,return err; } pt->sample_transactions = true; + pt->transactions_sample_type = attr.sample_type; pt->transactions_id = id; id +=1 ;evlist__for_each_entry (evlist, evsel) {
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Fix transactions_sample_type
perf intel-pt: Fix transactions_sample_type
Commit-ID: 2116074898ff9ff093963adc0fefcabbbbd7ec41 Gitweb: http://git.kernel.org/tip/2116074898ff9ff093963adc0fefcabbbbd7ec41 Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:18 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 21 Jun 2017 11:35:52 -0300
perf intel-pt: Fix transactions_sample_type
'transactions_sample_type' is needed to correctly inject transactions samples but it was not being set. Set it from the event sample type.
--- tools/perf/util/intel-pt.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/util/intel-pt.c +1 -0
@@ -2035,6 +2035,7 @@ static int intel_pt_synth_events(struct intel_pt *pt,return err; } pt->sample_transactions = true; + pt->transactions_sample_type = attr.sample_type; pt->transactions_id = id; id +=1 ;evlist__for_each_entry (evlist, evsel) {
Adrian Hunter
reviewerPATCH v2 18/37 perf tools: Fix message because cpu list option is -C not -c
In reply to Adrian HunterFix message because cpu list option is -C not -c
--- tools/perf/util/session.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/session.c +1 -1
@@ -2035,7 +2035,7 @@ int perf_session__cpu_bitmap(struct perf_session *session,if (!(evsel->attr.sample_type &PERF_SAMPLE_CPU )) {pr_err ("File does not contain CPU events. " -"Remove -c option to proceed.\n" ); +"Remove -C option to proceed.\n" );return -1 ; } }
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf tools: Fix message because cpu list option is -C not -c
perf tools: Fix message because cpu list option is -C not -c
Commit-ID: 30795467e54f3fe0d00f2dba4e58e6475b8fd2e7 Gitweb: http://git.kernel.org/tip/30795467e54f3fe0d00f2dba4e58e6475b8fd2e7 Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:19 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 21 Jun 2017 11:35:53 -0300
perf tools: Fix message because cpu list option is -C not -c
Fix message because cpu list option is -C not -c
--- tools/perf/util/session.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/session.c +1 -1
@@ -2035,7 +2035,7 @@ int perf_session__cpu_bitmap(struct perf_session *session,if (!(evsel->attr.sample_type &PERF_SAMPLE_CPU )) {pr_err ("File does not contain CPU events. " -"Remove -c option to proceed.\n" ); +"Remove -C option to proceed.\n" );return -1 ; } }
Adrian Hunter
reviewerPATCH v2 19/37 perf script: Fix message because field list option is -F not -f
In reply to Adrian HunterFix message because field list option is -F not -f.
--- tools/perf/builtin-script.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-script.c +1 -1
@@ -383,7 +383,7 @@ static int perf_session__check_output_opt(struct perf_session *session)*/ if (!evsel && output[j].user_set && !output[j].wildcard_set) {pr_err ("%s events do not exist. " -"Remove corresponding -f option to proceed.\n" , +"Remove corresponding -F option to proceed.\n" ,event_type (j));return -1 ; }
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf script: Fix message because field list option is -F not -f
perf script: Fix message because field list option is -F not -f
Commit-ID: 701516ae3dec801084bc913d21e03fce15c61a0b Gitweb: http://git.kernel.org/tip/701516ae3dec801084bc913d21e03fce15c61a0b Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:20 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 21 Jun 2017 11:35:53 -0300
perf script: Fix message because field list option is -F not -f
Fix message because field list option is -F not -f.
--- tools/perf/builtin-script.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-script.c +1 -1
@@ -385,7 +385,7 @@ static int perf_session__check_output_opt(struct perf_session *session)*/ if (!evsel && output[j].user_set && !output[j].wildcard_set) {pr_err ("%s events do not exist. " -"Remove corresponding -f option to proceed.\n" , +"Remove corresponding -F option to proceed.\n" ,event_type (j));return -1 ; }
Adrian Hunter
reviewerPATCH v2 20/37 perf script: Add 'synth' event type for synthesized events
In reply to Adrian HunterInstruction trace decoders such as Intel PT may have additional information recorded in the trace. For example, Intel PT has power information and a there is a new instruction 'ptwrite' that can write a value into a PTWRITE trace packet. Such information may be associated with an IP and so can be treated as a sample (PERF_RECORD_SAMPLE). Custom data can be incorporated in the sample as raw_data (PERF_SAMPLE_RAW). However a means of identifying the raw data format is needed. That will be done by synthesizing an attribute for it. So add an attribute type for custom synthesized events. Different synthesized events will be identified by the attribute 'config'.
--- tools/perf/builtin-script.c | 74 +++++++++++++++++++++++++++++++++++---------- tools/perf/util/event.h | 3 ++ 2 files changed, 61 insertions(+), 16 deletions(-)
tools/perf/builtin-script.c +58 -16
@@ -117,6 +117,11 @@ struct output_option { {.str = "brstackinsn", .field = PERF_OUTPUT_BRSTACKINSN}, }; +enum { + OUTPUT_TYPE_SYNTH = PERF_TYPE_MAX, + OUTPUT_TYPE_MAX +}; + /* default set to maintain compatibility with current format */ static struct { bool user_set;
@@ -124,7 +129,7 @@ struct output_option {unsigned int print_ip_opts;u64 fields;u64 invalid_fields; -} output[PERF_TYPE_MAX] = { +} output[OUTPUT_TYPE_MAX] = { [PERF_TYPE_HARDWARE] = { .user_set = false,
@@ -182,12 +187,43 @@ struct output_option { .invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT, }, + + [OUTPUT_TYPE_SYNTH] = { + .user_set = false, + + .fields =PERF_OUTPUT_COMM |PERF_OUTPUT_TID | +PERF_OUTPUT_CPU |PERF_OUTPUT_TIME | +PERF_OUTPUT_EVNAME |PERF_OUTPUT_IP | + PERF_OUTPUT_SYM | PERF_OUTPUT_DSO, + + .invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT, + }, }; +static inline int output_type (unsigned int type) +{ +switch (type) { +case PERF_TYPE_SYNTH : +return OUTPUT_TYPE_SYNTH ; +default : +return type; + } +} + +static inline unsigned int attr_type (unsigned int type) +{ +switch (type) { +case OUTPUT_TYPE_SYNTH : +return PERF_TYPE_SYNTH ; +default : +return type; + } +} +static bool output_set_by_user (void ) {int j; -for (j =0 ; j <PERF_TYPE_MAX ; ++j) { +for (j =0 ; j <OUTPUT_TYPE_MAX ; ++j) {if (output[j].user_set)return true; }
@@ -208,7 +244,7 @@ static const char *output_field2str(enum perf_output_field field)return str; } -#define PRINT_FIELD (x) (output[attr->type].fields & PERF_OUTPUT_##x) +#define PRINT_FIELD (x) (output[output_type(attr->type)].fields & PERF_OUTPUT_##x) static int perf_evsel__do_check_stype(struct perf_evsel *evsel, u64 sample_type, const char *sample_msg,
@@ -216,7 +252,7 @@ static int perf_evsel__do_check_stype(struct perf_evsel *evsel, bool allow_user_set) {struct perf_event_attr *attr = &evsel->attr; -int type = attr->type; +int type =output_type (attr->type);const char *evname;if (attr->sample_type & sample_type)
@@ -346,7 +382,7 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel,static void set_print_ip_opts (struct perf_event_attr *attr) { -unsigned int type = attr->type; +unsigned int type =output_type (attr->type); output[type].print_ip_opts =0 ;if (PRINT_FIELD (IP ))
@@ -374,14 +410,15 @@ static int perf_session__check_output_opt(struct perf_session *session)unsigned int j;struct perf_evsel *evsel; -for (j =0 ; j <PERF_TYPE_MAX ; ++j) { - evsel =perf_session__find_first_evtype (session, j); +for (j =0 ; j <OUTPUT_TYPE_MAX ; ++j) { + evsel =perf_session__find_first_evtype (session,attr_type (j));/* * even if fields is set to 0 (ie., show nothing) event must * exist if user explicitly includes it on the command line */ -if (!evsel && output[j].user_set && !output[j].wildcard_set) { +if (!evsel && output[j].user_set && !output[j].wildcard_set && + j !=OUTPUT_TYPE_SYNTH ) {pr_err ("%s events do not exist. " "Remove corresponding -F option to proceed.\n" ,event_type (j));
@@ -906,6 +943,7 @@ static void print_sample_bts(struct perf_sample *sample, struct machine *machine) {struct perf_event_attr *attr = &evsel->attr; +unsigned int type =output_type (attr->type);bool print_srcline_last = false;if (PRINT_FIELD (CALLINDENT ))
@@ -913,7 +951,7 @@ static void print_sample_bts(struct perf_sample *sample,/* print branch_from information */ if (PRINT_FIELD (IP )) { -unsigned int print_opts = output[attr->type].print_ip_opts; +unsigned int print_opts = output[type].print_ip_opts;struct callchain_cursor *cursor =NULL ; if (symbol_conf.use_callchain && sample->callchain &&
@@ -936,7 +974,7 @@ static void print_sample_bts(struct perf_sample *sample,/* print branch_to information */ if (PRINT_FIELD (ADDR ) || ((evsel->attr.sample_type &PERF_SAMPLE_ADDR ) && - !output[attr->type].user_set)) { + !output[type].user_set)) {printf (" => " );print_sample_addr (sample, thread, attr); }
@@ -1132,8 +1170,9 @@ static void process_event(struct perf_script *script, {struct thread *thread = al->thread;struct perf_event_attr *attr = &evsel->attr; +unsigned int type =output_type (attr->type); -if (output[attr->type].fields ==0 ) +if (output[type].fields ==0 )return ;print_sample_start (sample, thread, evsel);
@@ -1180,7 +1219,7 @@ static void process_event(struct perf_script *script, cursor = &callchain_cursor;putchar (cursor ?'\n' :' ' ); -sample__fprintf_sym (sample, al,0 , output[attr->type].print_ip_opts, cursor, stdout); +sample__fprintf_sym (sample, al,0 , output[type].print_ip_opts, cursor, stdout); }if (PRINT_FIELD (IREGS ))
@@ -1325,7 +1364,8 @@ static int process_attr(struct perf_tool *tool, union perf_event *event, evlist = *pevlist; evsel =perf_evlist__last (*pevlist); -if (evsel->attr.type >=PERF_TYPE_MAX ) +if (evsel->attr.type >=PERF_TYPE_MAX && + evsel->attr.type !=PERF_TYPE_SYNTH )return 0 ;evlist__for_each_entry (evlist, pos) {
@@ -1749,6 +1789,8 @@ static int parse_output_fields(const struct option *opt __maybe_unused, type =PERF_TYPE_RAW ; else if (!strcmp(str, "break")) type =PERF_TYPE_BREAKPOINT ; + else if (!strcmp(str, "synth")) + type =OUTPUT_TYPE_SYNTH ; else {fprintf (stderr,"Invalid event type in field string.\n" ); rc = -EINVAL ;
@@ -1775,7 +1817,7 @@ static int parse_output_fields(const struct option *opt __maybe_unused,if (output_set_by_user ())pr_warning ("Overriding previous field request for all events.\n" ); -for (j =0 ; j <PERF_TYPE_MAX ; ++j) { +for (j =0 ; j <OUTPUT_TYPE_MAX ; ++j) { output[j].fields =0 ; output[j].user_set = true; output[j].wildcard_set = true;
@@ -1801,7 +1843,7 @@ static int parse_output_fields(const struct option *opt __maybe_unused,/* add user option to all events types for * which it is valid */ -for (j =0 ; j <PERF_TYPE_MAX ; ++j) { +for (j =0 ; j <OUTPUT_TYPE_MAX ; ++j) {if (output[j].invalid_fields & all_output_options[i].field) {pr_warning ("\'%s\' not valid for %s events. Ignoring.\n" , all_output_options[i].str,event_type (j));
@@ -2444,7 +2486,7 @@ int cmd_script(int argc, const char **argv) symbol__config_symfs), OPT_CALLBACK('F', "fields", NULL, "str","comma separated output fields prepend with 'type:'. " -"Valid types: hw,sw,trace,raw. " +"Valid types: hw,sw,trace,raw,synth. " "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso," "addr,symoff,period,iregs,brstack,brstacksym,flags," "bpf-output,callindent,insn,insnlen,brstackinsn",
tools/perf/util/event.h +3 -0
@@ -252,6 +252,9 @@ enum auxtrace_error_type { PERF_AUXTRACE_ERROR_MAX }; +/* Attribute type for custom synthesized events */ +#define PERF_TYPE_SYNTH 3000000000 +/* * The kernel collects the number of events it couldn't send in a stretch and * when possible sends this number in a PERF_RECORD_LOST event. The number of
Signature · 1 line
1.9.1
Adrian Hunter
reviewerPATCH v3 20/37 perf script: Add 'synth' event type for synthesized events
Instruction trace decoders such as Intel PT may have additional information recorded in the trace. For example, Intel PT has power information and a there is a new instruction 'ptwrite' that can write a value into a PTWRITE trace packet. Such information may be associated with an IP and so can be treated as a sample (PERF_RECORD_SAMPLE). Custom data can be incorporated in the sample as raw_data (PERF_SAMPLE_RAW). However a means of identifying the raw data format is needed. That will be done by synthesizing an attribute for it. So add an attribute type for custom synthesized events. Different synthesized events will be identified by the attribute 'config'.
---
Changes in V3:
Re-base on Arnaldo's perf/core branch
tools/perf/builtin-script.c | 74 +++++++++++++++++++++++++++++++++++---------- tools/perf/util/event.h | 3 ++ 2 files changed, 61 insertions(+), 16 deletions(-)
tools/perf/builtin-script.c +58 -16
@@ -119,6 +119,11 @@ struct output_option { {.str = "brstackoff", .field = PERF_OUTPUT_BRSTACKOFF}, }; +enum { + OUTPUT_TYPE_SYNTH = PERF_TYPE_MAX, + OUTPUT_TYPE_MAX +}; + /* default set to maintain compatibility with current format */ static struct { bool user_set;
@@ -126,7 +131,7 @@ struct output_option {unsigned int print_ip_opts;u64 fields;u64 invalid_fields; -} output[PERF_TYPE_MAX] = { +} output[OUTPUT_TYPE_MAX] = { [PERF_TYPE_HARDWARE] = { .user_set = false,
@@ -184,12 +189,43 @@ struct output_option { .invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT, }, + + [OUTPUT_TYPE_SYNTH] = { + .user_set = false, + + .fields =PERF_OUTPUT_COMM |PERF_OUTPUT_TID | +PERF_OUTPUT_CPU |PERF_OUTPUT_TIME | +PERF_OUTPUT_EVNAME |PERF_OUTPUT_IP | + PERF_OUTPUT_SYM | PERF_OUTPUT_DSO, + + .invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT, + }, }; +static inline int output_type (unsigned int type) +{ +switch (type) { +case PERF_TYPE_SYNTH : +return OUTPUT_TYPE_SYNTH ; +default : +return type; + } +} + +static inline unsigned int attr_type (unsigned int type) +{ +switch (type) { +case OUTPUT_TYPE_SYNTH : +return PERF_TYPE_SYNTH ; +default : +return type; + } +} +static bool output_set_by_user (void ) {int j; -for (j =0 ; j <PERF_TYPE_MAX ; ++j) { +for (j =0 ; j <OUTPUT_TYPE_MAX ; ++j) {if (output[j].user_set)return true; }
@@ -210,7 +246,7 @@ static const char *output_field2str(enum perf_output_field field)return str; } -#define PRINT_FIELD (x) (output[attr->type].fields & PERF_OUTPUT_##x) +#define PRINT_FIELD (x) (output[output_type(attr->type)].fields & PERF_OUTPUT_##x) static int perf_evsel__do_check_stype(struct perf_evsel *evsel, u64 sample_type, const char *sample_msg,
@@ -218,7 +254,7 @@ static int perf_evsel__do_check_stype(struct perf_evsel *evsel, bool allow_user_set) {struct perf_event_attr *attr = &evsel->attr; -int type = attr->type; +int type =output_type (attr->type);const char *evname;if (attr->sample_type & sample_type)
@@ -348,7 +384,7 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel,static void set_print_ip_opts (struct perf_event_attr *attr) { -unsigned int type = attr->type; +unsigned int type =output_type (attr->type); output[type].print_ip_opts =0 ;if (PRINT_FIELD (IP ))
@@ -376,14 +412,15 @@ static int perf_session__check_output_opt(struct perf_session *session)unsigned int j;struct perf_evsel *evsel; -for (j =0 ; j <PERF_TYPE_MAX ; ++j) { - evsel =perf_session__find_first_evtype (session, j); +for (j =0 ; j <OUTPUT_TYPE_MAX ; ++j) { + evsel =perf_session__find_first_evtype (session,attr_type (j));/* * even if fields is set to 0 (ie., show nothing) event must * exist if user explicitly includes it on the command line */ -if (!evsel && output[j].user_set && !output[j].wildcard_set) { +if (!evsel && output[j].user_set && !output[j].wildcard_set && + j !=OUTPUT_TYPE_SYNTH ) {pr_err ("%s events do not exist. " "Remove corresponding -F option to proceed.\n" ,event_type (j));
@@ -989,6 +1026,7 @@ static void print_sample_bts(struct perf_sample *sample, struct machine *machine) {struct perf_event_attr *attr = &evsel->attr; +unsigned int type =output_type (attr->type);bool print_srcline_last = false;if (PRINT_FIELD (CALLINDENT ))
@@ -996,7 +1034,7 @@ static void print_sample_bts(struct perf_sample *sample,/* print branch_from information */ if (PRINT_FIELD (IP )) { -unsigned int print_opts = output[attr->type].print_ip_opts; +unsigned int print_opts = output[type].print_ip_opts;struct callchain_cursor *cursor =NULL ; if (symbol_conf.use_callchain && sample->callchain &&
@@ -1019,7 +1057,7 @@ static void print_sample_bts(struct perf_sample *sample,/* print branch_to information */ if (PRINT_FIELD (ADDR ) || ((evsel->attr.sample_type &PERF_SAMPLE_ADDR ) && - !output[attr->type].user_set)) { + !output[type].user_set)) {printf (" => " );print_sample_addr (sample, thread, attr); }
@@ -1215,8 +1253,9 @@ static void process_event(struct perf_script *script, {struct thread *thread = al->thread;struct perf_event_attr *attr = &evsel->attr; +unsigned int type =output_type (attr->type); -if (output[attr->type].fields ==0 ) +if (output[type].fields ==0 )return ;print_sample_start (sample, thread, evsel);
@@ -1263,7 +1302,7 @@ static void process_event(struct perf_script *script, cursor = &callchain_cursor;putchar (cursor ?'\n' :' ' ); -sample__fprintf_sym (sample, al,0 , output[attr->type].print_ip_opts, cursor, stdout); +sample__fprintf_sym (sample, al,0 , output[type].print_ip_opts, cursor, stdout); }if (PRINT_FIELD (IREGS ))
@@ -1410,7 +1449,8 @@ static int process_attr(struct perf_tool *tool, union perf_event *event, evlist = *pevlist; evsel =perf_evlist__last (*pevlist); -if (evsel->attr.type >=PERF_TYPE_MAX ) +if (evsel->attr.type >=PERF_TYPE_MAX && + evsel->attr.type !=PERF_TYPE_SYNTH )return 0 ;evlist__for_each_entry (evlist, pos) {
@@ -1835,6 +1875,8 @@ static int parse_output_fields(const struct option *opt __maybe_unused, type =PERF_TYPE_RAW ; else if (!strcmp(str, "break")) type =PERF_TYPE_BREAKPOINT ; + else if (!strcmp(str, "synth")) + type =OUTPUT_TYPE_SYNTH ; else {fprintf (stderr,"Invalid event type in field string.\n" ); rc = -EINVAL ;
@@ -1865,7 +1907,7 @@ static int parse_output_fields(const struct option *opt __maybe_unused,if (output_set_by_user ())pr_warning ("Overriding previous field request for all events.\n" ); -for (j =0 ; j <PERF_TYPE_MAX ; ++j) { +for (j =0 ; j <OUTPUT_TYPE_MAX ; ++j) { output[j].fields =0 ; output[j].user_set = true; output[j].wildcard_set = true;
@@ -1908,7 +1950,7 @@ static int parse_output_fields(const struct option *opt __maybe_unused,/* add user option to all events types for * which it is valid */ -for (j =0 ; j <PERF_TYPE_MAX ; ++j) { +for (j =0 ; j <OUTPUT_TYPE_MAX ; ++j) {if (output[j].invalid_fields & all_output_options[i].field) {pr_warning ("\'%s\' not valid for %s events. Ignoring.\n" , all_output_options[i].str,event_type (j));
@@ -2560,7 +2602,7 @@ int cmd_script(int argc, const char **argv) OPT_CALLBACK('F', "fields", NULL, "str", "comma separated output fields prepend with 'type:'. " "+field to add and -field to remove." - "Valid types: hw,sw,trace,raw. " + "Valid types: hw,sw,trace,raw,synth. " "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso," "addr,symoff,period,iregs,brstack,brstacksym,flags," "bpf-output,callindent,insn,insnlen,brstackinsn",
tools/perf/util/event.h +3 -0
@@ -252,6 +252,9 @@ enum auxtrace_error_type { PERF_AUXTRACE_ERROR_MAX }; +/* Attribute type for custom synthesized events */ +#define PERF_TYPE_SYNTH 3000000000 +/* * The kernel collects the number of events it couldn't send in a stretch and * when possible sends this number in a PERF_RECORD_LOST event. The number of
Signature · 1 line
1.9.1
Arnaldo Carvalho de Melo
maintainerRe: [PATCH V3 20/37] perf script: Add 'synth' event type for synthesized events
Em Wed, Jun 21, 2017 at 01:17:19PM +0300, Adrian Hunter escreveu:
tools/perf/util/event.h enum auxtrace_error_type { · line 256
Quoted 7 lines
+++
b/tools/perf/util/event.htools/perf/util/event.h +2
-0@@ -252,6 +252,9 @@ enum auxtrace_error_type { PERF_AUXTRACE_ERROR_MAX }; +/* Attribute type for custom synthesized events */ +#define PERF_TYPE_SYNTH 3000000000
Why don't you make it PERF_TYPE_MAX and bump PERF_TYPE_MAX by one? I.e. this way we have what can be in attr.type in a nice enumeration, can validate it more easily (attr.type < PERF_TYPE_MAX) and will not need to do those conversions to/from OUTPUT_TYPE_/PERF_TYPE_).
Peter: now its not the PERF_RECORD_ namespace that userspaces want a chunk of, its PERF_TYPE_, which so far has been pretty stable, grabing _one_ for event synthesizing things like Intel PT (and ARM's coresight, I think) directly at include/uapi/linux/perf_event.h's perf_type_id enum looks cleaner, no?
- Arnaldo
Adrian Hunter
reviewerRe: [PATCH V3 20/37] perf script: Add 'synth' event type for synthesized events
Quoted 6 lines · Arnaldo Carvalho de Melo
Em Wed, Jun 21, 2017 at 01:17:19PM +0300, Adrian Hunter escreveu:
Quoted 4 lines
+++
b/tools/perf/util/event.htools/perf/util/event.h +0
-0@@ -252,6 +252,9 @@ enum auxtrace_error_type { PERF_AUXTRACE_ERROR_MAX };
Quoted 7 lines
tools/perf/util/event.h enum auxtrace_error_type { · line 256
Quoted 2 lines
tools/perf/util/event.h +2
-0+/* Attribute type for custom synthesized events */ +#define PERF_TYPE_SYNTH 3000000000Why don't you make it
PERF_TYPE_MAXand bumpPERF_TYPE_MAXby one? I.e. this way we have what can be in attr.type in a nice enumeration, can validate it more easily (attr.type <PERF_TYPE_MAX) and will not need to do those conversions to/from OUTPUT_TYPE_/PERF_TYPE_).
PERF_TYPE_ is dynamically allocated above PERF_TYPE_MAX for PMUs. Presently perf_pmu_register() calls idr_alloc() with end=0 which limits the allocation to INT_MAX.
Quoted 5 lines
Peter: now its not the
PERF_RECORD_namespace that userspaces want a chunk of, itsPERF_TYPE_, which so far has been pretty stable, grabing _one_ for event synthesizing things like Intel PT (and ARM's coresight, I think) directly at include/uapi/linux/perf_event.h'sperf_type_idenum looks cleaner, no?
Arnaldo Carvalho de Melo
maintainerRe: [PATCH V3 20/37] perf script: Add 'synth' event type for synthesized events
Em Wed, Jun 21, 2017 at 07:41:04PM +0300, Adrian Hunter escreveu:
Quoted 15 lines · Arnaldo Carvalho de Melo
Quoted 6 lines
Em Wed, Jun 21, 2017 at 01:17:19PM +0300, Adrian Hunter escreveu:
Quoted 4 lines
+++
b/tools/perf/util/event.htools/perf/util/event.h +0
-0@@ -252,6 +252,9 @@ enum auxtrace_error_type { PERF_AUXTRACE_ERROR_MAX };Quoted 7 lines
tools/perf/util/event.h enum auxtrace_error_type { · line 256
Quoted 2 lines
tools/perf/util/event.h +2
-0+/* Attribute type for custom synthesized events */ +#define PERF_TYPE_SYNTH 3000000000Why don't you make it
PERF_TYPE_MAXand bumpPERF_TYPE_MAXby one? I.e. this way we have what can be in attr.type in a nice enumeration, can validate it more easily (attr.type <PERF_TYPE_MAX) and will not need to do those conversions to/from OUTPUT_TYPE_/PERF_TYPE_).
Quoted 3 lines
PERF_TYPE_is dynamically allocated abovePERF_TYPE_MAXfor PMUs. Presentlyperf_pmu_register()callsidr_alloc()with end=0 which limits the allocation toINT_MAX.
Oh, forgot about that, guess a comment right beside PERF_TYPE_MAX is in demand :-\
So why not:
/*
* PERF_TYPE_ is dynamically allocated above PERF_TYPE_MAX for PMUs. Presently
* perf_pmu_register() calls idr_alloc() with end=0 which limits the allocation
* to INT_MAX.
*/
#define PERF_TYPE_SYNTH (INT_MAX + 1L)
I.e. wouldn't be some arbitrarily huge value, but one right after what was defined as the area for the dynamicly allocated PERF_TYPE_ "namespace" for PMUs, right?
Quoted 5 lines
Quoted 5 lines
Peter: now its not the
PERF_RECORD_namespace that userspaces want a chunk of, itsPERF_TYPE_, which so far has been pretty stable, grabing _one_ for event synthesizing things like Intel PT (and ARM's coresight, I think) directly at include/uapi/linux/perf_event.h'sperf_type_idenum looks cleaner, no?
- Arnaldo
Adrian Hunter
reviewerRe: [PATCH V3 20/37] perf script: Add 'synth' event type for synthesized events
Quoted 32 lines · Arnaldo Carvalho de Melo
Em Wed, Jun 21, 2017 at 07:41:04PM +0300, Adrian Hunter escreveu:
Quoted 15 lines · Arnaldo Carvalho de Melo
Quoted 6 lines
Em Wed, Jun 21, 2017 at 01:17:19PM +0300, Adrian Hunter escreveu:
Quoted 4 lines
+++
b/tools/perf/util/event.htools/perf/util/event.h +0
-0@@ -252,6 +252,9 @@ enum auxtrace_error_type { PERF_AUXTRACE_ERROR_MAX };Quoted 7 lines
tools/perf/util/event.h enum auxtrace_error_type { · line 256
Quoted 2 lines
tools/perf/util/event.h +2
-0+/* Attribute type for custom synthesized events */ +#define PERF_TYPE_SYNTH 3000000000Why don't you make it
PERF_TYPE_MAXand bumpPERF_TYPE_MAXby one? I.e. this way we have what can be in attr.type in a nice enumeration, can validate it more easily (attr.type <PERF_TYPE_MAX) and will not need to do those conversions to/from OUTPUT_TYPE_/PERF_TYPE_).Quoted 3 lines
PERF_TYPE_is dynamically allocated abovePERF_TYPE_MAXfor PMUs. Presentlyperf_pmu_register()callsidr_alloc()with end=0 which limits the allocation toINT_MAX.Oh, forgot about that, guess a comment right beside
PERF_TYPE_MAXis in demand :-\So why not:
/*
*PERF_TYPE_is dynamically allocated abovePERF_TYPE_MAXfor PMUs. Presently
*perf_pmu_register()callsidr_alloc()with end=0 which limits the allocation
* toINT_MAX.
*/
#definePERF_TYPE_SYNTH(INT_MAX+ 1L)
Quoted 3 lines
I.e. wouldn't be some arbitrarily huge value, but one right after what was defined as the area for the dynamicly allocated
PERF_TYPE_"namespace" for PMUs, right?
That seems fine. Pedantically it should be (INT_MAX + 1U) otherwise it will be negative on a 32-bit system.
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
Peter: now its not the
PERF_RECORD_namespace that userspaces want a chunk of, itsPERF_TYPE_, which so far has been pretty stable, grabing _one_ for event synthesizing things like Intel PT (and ARM's coresight, I think) directly at include/uapi/linux/perf_event.h'sperf_type_idenum looks cleaner, no?- Arnaldo
Arnaldo Carvalho de Melo
maintainerRe: [PATCH V3 20/37] perf script: Add 'synth' event type for synthesized events
Em Wed, Jun 21, 2017 at 11:20:03PM +0300, Adrian Hunter escreveu:
Quoted 18 lines · Arnaldo Carvalho de Melo
Quoted 16 lines
Em Wed, Jun 21, 2017 at 07:41:04PM +0300, Adrian Hunter escreveu:
Quoted 3 lines
PERF_TYPE_is dynamically allocated abovePERF_TYPE_MAXfor PMUs. Presentlyperf_pmu_register()callsidr_alloc()with end=0 which limits the allocation toINT_MAX.Oh, forgot about that, guess a comment right beside
PERF_TYPE_MAXis in demand :-\So why not:
/*
*PERF_TYPE_is dynamically allocated abovePERF_TYPE_MAXfor PMUs. Presently
*perf_pmu_register()callsidr_alloc()with end=0 which limits the allocation
* toINT_MAX.
*/
#definePERF_TYPE_SYNTH(INT_MAX+ 1L)
Quoted 6 lines
Quoted 3 lines
I.e. wouldn't be some arbitrarily huge value, but one right after what was defined as the area for the dynamicly allocated
PERF_TYPE_"namespace" for PMUs, right?That seems fine. Pedantically it should be (
INT_MAX+ 1U) otherwise it will be negative on a 32-bit system.
oh, not pedantic at all, thanks for the fix, will update your patch and continue from there, Ingo already pulled everything up to this point, btw.
- Arnaldo
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf script: Add 'synth' event type for synthesized events
In reply to Adrian Hunterperf script: Add 'synth' event type for synthesized events
Commit-ID: 1405720d4f2669e5ebaed192bd727aca74f64732 Gitweb: http://git.kernel.org/tip/1405720d4f2669e5ebaed192bd727aca74f64732 Author: Adrian Hunter <[email protected]> AuthorDate: Wed, 21 Jun 2017 13:17:19 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 27 Jun 2017 12:03:09 -0300
perf script: Add 'synth' event type for synthesized events
Instruction trace decoders such as Intel PT may have additional information recorded in the trace. For example, Intel PT has power information and a there is a new instruction 'ptwrite' that can write a value into a PTWRITE trace packet.
Such information may be associated with an IP and so can be treated as a sample (PERF_RECORD_SAMPLE). Custom data can be incorporated in the sample as raw_data (PERF_SAMPLE_RAW).
However a means of identifying the raw data format is needed. That will be done by synthesizing an attribute for it.
So add an attribute type for custom synthesized events. Different synthesized events will be identified by the attribute 'config'.
Committer notes:
Start those PERF_TYPE_ after the PMU range, i.e. after (INT_MAX + 1U), i.e. after perf_pmu_register() -> idr_alloc(end=0).
--- tools/perf/builtin-script.c | 74 +++++++++++++++++++++++++++++++++++---------- tools/perf/util/event.h | 3 ++ 2 files changed, 61 insertions(+), 16 deletions(-)
tools/perf/builtin-script.c +58 -16
@@ -119,6 +119,11 @@ struct output_option { {.str = "brstackoff", .field = PERF_OUTPUT_BRSTACKOFF}, }; +enum { + OUTPUT_TYPE_SYNTH = PERF_TYPE_MAX, + OUTPUT_TYPE_MAX +}; + /* default set to maintain compatibility with current format */ static struct { bool user_set;
@@ -126,7 +131,7 @@ static struct {unsigned int print_ip_opts;u64 fields;u64 invalid_fields; -} output[PERF_TYPE_MAX] = { +} output[OUTPUT_TYPE_MAX] = { [PERF_TYPE_HARDWARE] = { .user_set = false,
@@ -184,12 +189,43 @@ static struct { .invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT, }, + + [OUTPUT_TYPE_SYNTH] = { + .user_set = false, + + .fields =PERF_OUTPUT_COMM |PERF_OUTPUT_TID | +PERF_OUTPUT_CPU |PERF_OUTPUT_TIME | +PERF_OUTPUT_EVNAME |PERF_OUTPUT_IP | + PERF_OUTPUT_SYM | PERF_OUTPUT_DSO, + + .invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT, + }, }; +static inline int output_type (unsigned int type) +{ +switch (type) { +case PERF_TYPE_SYNTH : +return OUTPUT_TYPE_SYNTH ; +default : +return type; + } +} + +static inline unsigned int attr_type (unsigned int type) +{ +switch (type) { +case OUTPUT_TYPE_SYNTH : +return PERF_TYPE_SYNTH ; +default : +return type; + } +} +static bool output_set_by_user (void ) {int j; -for (j =0 ; j <PERF_TYPE_MAX ; ++j) { +for (j =0 ; j <OUTPUT_TYPE_MAX ; ++j) {if (output[j].user_set)return true; }
@@ -210,7 +246,7 @@ static const char *output_field2str(enum perf_output_field field)return str; } -#define PRINT_FIELD (x) (output[attr->type].fields & PERF_OUTPUT_##x) +#define PRINT_FIELD (x) (output[output_type(attr->type)].fields & PERF_OUTPUT_##x) static int perf_evsel__do_check_stype(struct perf_evsel *evsel, u64 sample_type, const char *sample_msg,
@@ -218,7 +254,7 @@ static int perf_evsel__do_check_stype(struct perf_evsel *evsel, bool allow_user_set) {struct perf_event_attr *attr = &evsel->attr; -int type = attr->type; +int type =output_type (attr->type);const char *evname;if (attr->sample_type & sample_type)
@@ -348,7 +384,7 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel,static void set_print_ip_opts (struct perf_event_attr *attr) { -unsigned int type = attr->type; +unsigned int type =output_type (attr->type); output[type].print_ip_opts =0 ;if (PRINT_FIELD (IP ))
@@ -376,14 +412,15 @@ static int perf_session__check_output_opt(struct perf_session *session)unsigned int j;struct perf_evsel *evsel; -for (j =0 ; j <PERF_TYPE_MAX ; ++j) { - evsel =perf_session__find_first_evtype (session, j); +for (j =0 ; j <OUTPUT_TYPE_MAX ; ++j) { + evsel =perf_session__find_first_evtype (session,attr_type (j));/* * even if fields is set to 0 (ie., show nothing) event must * exist if user explicitly includes it on the command line */ -if (!evsel && output[j].user_set && !output[j].wildcard_set) { +if (!evsel && output[j].user_set && !output[j].wildcard_set && + j !=OUTPUT_TYPE_SYNTH ) {pr_err ("%s events do not exist. " "Remove corresponding -F option to proceed.\n" ,event_type (j));
@@ -989,6 +1026,7 @@ static void print_sample_bts(struct perf_sample *sample, struct machine *machine) {struct perf_event_attr *attr = &evsel->attr; +unsigned int type =output_type (attr->type);bool print_srcline_last = false;if (PRINT_FIELD (CALLINDENT ))
@@ -996,7 +1034,7 @@ static void print_sample_bts(struct perf_sample *sample,/* print branch_from information */ if (PRINT_FIELD (IP )) { -unsigned int print_opts = output[attr->type].print_ip_opts; +unsigned int print_opts = output[type].print_ip_opts;struct callchain_cursor *cursor =NULL ; if (symbol_conf.use_callchain && sample->callchain &&
@@ -1019,7 +1057,7 @@ static void print_sample_bts(struct perf_sample *sample,/* print branch_to information */ if (PRINT_FIELD (ADDR ) || ((evsel->attr.sample_type &PERF_SAMPLE_ADDR ) && - !output[attr->type].user_set)) { + !output[type].user_set)) {printf (" => " );print_sample_addr (sample, thread, attr); }
@@ -1215,8 +1253,9 @@ static void process_event(struct perf_script *script, {struct thread *thread = al->thread;struct perf_event_attr *attr = &evsel->attr; +unsigned int type =output_type (attr->type); -if (output[attr->type].fields ==0 ) +if (output[type].fields ==0 )return ;print_sample_start (sample, thread, evsel);
@@ -1263,7 +1302,7 @@ static void process_event(struct perf_script *script, cursor = &callchain_cursor;putchar (cursor ?'\n' :' ' ); -sample__fprintf_sym (sample, al,0 , output[attr->type].print_ip_opts, cursor, stdout); +sample__fprintf_sym (sample, al,0 , output[type].print_ip_opts, cursor, stdout); }if (PRINT_FIELD (IREGS ))
@@ -1410,7 +1449,8 @@ static int process_attr(struct perf_tool *tool, union perf_event *event, evlist = *pevlist; evsel =perf_evlist__last (*pevlist); -if (evsel->attr.type >=PERF_TYPE_MAX ) +if (evsel->attr.type >=PERF_TYPE_MAX && + evsel->attr.type !=PERF_TYPE_SYNTH )return 0 ;evlist__for_each_entry (evlist, pos) {
@@ -1835,6 +1875,8 @@ static int parse_output_fields(const struct option *opt __maybe_unused, type =PERF_TYPE_RAW ; else if (!strcmp(str, "break")) type =PERF_TYPE_BREAKPOINT ; + else if (!strcmp(str, "synth")) + type =OUTPUT_TYPE_SYNTH ; else {fprintf (stderr,"Invalid event type in field string.\n" ); rc = -EINVAL ;
@@ -1865,7 +1907,7 @@ static int parse_output_fields(const struct option *opt __maybe_unused,if (output_set_by_user ())pr_warning ("Overriding previous field request for all events.\n" ); -for (j =0 ; j <PERF_TYPE_MAX ; ++j) { +for (j =0 ; j <OUTPUT_TYPE_MAX ; ++j) { output[j].fields =0 ; output[j].user_set = true; output[j].wildcard_set = true;
@@ -1908,7 +1950,7 @@ parse:/* add user option to all events types for * which it is valid */ -for (j =0 ; j <PERF_TYPE_MAX ; ++j) { +for (j =0 ; j <OUTPUT_TYPE_MAX ; ++j) {if (output[j].invalid_fields & all_output_options[i].field) {pr_warning ("\'%s\' not valid for %s events. Ignoring.\n" , all_output_options[i].str,event_type (j));
@@ -2560,7 +2602,7 @@ int cmd_script(int argc, const char **argv) OPT_CALLBACK('F', "fields", NULL, "str", "comma separated output fields prepend with 'type:'. " "+field to add and -field to remove." - "Valid types: hw,sw,trace,raw. " + "Valid types: hw,sw,trace,raw,synth. " "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso," "addr,symoff,period,iregs,brstack,brstacksym,flags," "bpf-output,callindent,insn,insnlen,brstackinsn",
tools/perf/util/event.h +3 -0
@@ -252,6 +252,9 @@ enum auxtrace_error_type { PERF_AUXTRACE_ERROR_MAX }; +/* Attribute type for custom synthesized events */ +#define PERF_TYPE_SYNTH (INT_MAX + 1U) +/* * The kernel collects the number of events it couldn't send in a stretch and * when possible sends this number in a PERF_RECORD_LOST event. The number of
Adrian Hunter
reviewerPATCH v2 21/37 perf script: Add 'synth' field for synthesized event payloads
In reply to Adrian HunterAdd a field to display the content the raw_data of a synthesized event.
--- tools/perf/Documentation/perf-script.txt | 6 +++++- tools/perf/builtin-script.c | 20 ++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-script.txt +5 -1
@@ -117,7 +117,8 @@ OPTIONS Comma separated list of fields to print. Options are: comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff, srcline, period, iregs, brstack, brstacksym, flags, bpf-output, brstackinsn, - callindent, insn, insnlen. Field list can be prepended with the type, trace, sw or hw, + callindent, insn, insnlen, synth. + Field list can be prepended with the type, trace, sw or hw, to indicate to which event type the field list applies. e.g., -F sw:comm,tid,time,ip,sym and -F trace:time,cpu,trace
@@ -185,6 +186,9 @@ OPTIONS instruction bytes and the instruction length of the current instruction. + The synth field is used by synthesized events which may be created when + Instruction Trace decoding. + Finally, a user may not set fields to none for all event types. i.e., -F "" is not allowed.
tools/perf/builtin-script.c +18 -2
@@ -85,6 +85,7 @@ enum perf_output_field {PERF_OUTPUT_INSN =1U <<21 ,PERF_OUTPUT_INSNLEN =1U <<22 ,PERF_OUTPUT_BRSTACKINSN =1U <<23 , + PERF_OUTPUT_SYNTH = 1U << 24, }; struct output_option {
@@ -115,6 +116,7 @@ struct output_option { {.str = "insn", .field = PERF_OUTPUT_INSN}, {.str = "insnlen", .field = PERF_OUTPUT_INSNLEN}, {.str = "brstackinsn", .field = PERF_OUTPUT_BRSTACKINSN}, + {.str = "synth", .field = PERF_OUTPUT_SYNTH}, }; enum {
@@ -194,7 +196,8 @@ enum { .fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |PERF_OUTPUT_CPU |PERF_OUTPUT_TIME |PERF_OUTPUT_EVNAME |PERF_OUTPUT_IP | - PERF_OUTPUT_SYM | PERF_OUTPUT_DSO, +PERF_OUTPUT_SYM |PERF_OUTPUT_DSO | + PERF_OUTPUT_SYNTH, .invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT, },
@@ -1117,6 +1120,15 @@ static void print_sample_bpf_output(struct perf_sample *sample) (char *)(sample->raw_data)); } +static void print_sample_synth (struct perf_sample *sample__maybe_unused , +struct perf_evsel *evsel) +{ +switch (evsel->attr.config) { +default : +break ; + } +} +struct perf_script {struct perf_tool tool;struct perf_session *session;
@@ -1201,6 +1213,10 @@ static void process_event(struct perf_script *script,if (PRINT_FIELD (TRACE ))event_format__print (evsel->tp_format, sample->cpu, sample->raw_data, sample->raw_size); + +if (attr->type ==PERF_TYPE_SYNTH &&PRINT_FIELD (SYNTH )) +print_sample_synth (sample, evsel); +if (PRINT_FIELD (ADDR ))print_sample_addr (sample, thread, attr);
@@ -2489,7 +2505,7 @@ int cmd_script(int argc, const char **argv) "Valid types: hw,sw,trace,raw,synth. " "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso," "addr,symoff,period,iregs,brstack,brstacksym,flags," - "bpf-output,callindent,insn,insnlen,brstackinsn", + "bpf-output,callindent,insn,insnlen,brstackinsn,synth", parse_output_fields),OPT_BOOLEAN ('a' ,"all-cpus" , &system_wide, "system-wide collection from all CPUs"),
Signature · 1 line
1.9.1
Adrian Hunter
reviewerPATCH v3 21/37 perf script: Add 'synth' field for synthesized event payloads
Add a field to display the content the raw_data of a synthesized event.
---
Changes in V3:
Re-base on Arnaldo's perf/core branch
tools/perf/Documentation/perf-script.txt | 6 +++++- tools/perf/builtin-script.c | 20 ++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-script.txt +5 -1
@@ -117,7 +117,8 @@ OPTIONS Comma separated list of fields to print. Options are: comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff, srcline, period, iregs, brstack, brstacksym, flags, bpf-output, brstackinsn, brstackoff, - callindent, insn, insnlen. Field list can be prepended with the type, trace, sw or hw, + callindent, insn, insnlen, synth. + Field list can be prepended with the type, trace, sw or hw, to indicate to which event type the field list applies. e.g., -F sw:comm,tid,time,ip,sym and -F trace:time,cpu,trace
@@ -193,6 +194,9 @@ OPTIONS instruction bytes and the instruction length of the current instruction. + The synth field is used by synthesized events which may be created when + Instruction Trace decoding. + Finally, a user may not set fields to none for all event types. i.e., -F "" is not allowed.
tools/perf/builtin-script.c +18 -2
@@ -86,6 +86,7 @@ enum perf_output_field {PERF_OUTPUT_INSNLEN =1U <<22 ,PERF_OUTPUT_BRSTACKINSN =1U <<23 ,PERF_OUTPUT_BRSTACKOFF =1U <<24 , + PERF_OUTPUT_SYNTH = 1U << 25, }; struct output_option {
@@ -117,6 +118,7 @@ struct output_option { {.str = "insnlen", .field = PERF_OUTPUT_INSNLEN}, {.str = "brstackinsn", .field = PERF_OUTPUT_BRSTACKINSN}, {.str = "brstackoff", .field = PERF_OUTPUT_BRSTACKOFF}, + {.str = "synth", .field = PERF_OUTPUT_SYNTH}, }; enum {
@@ -196,7 +198,8 @@ enum { .fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |PERF_OUTPUT_CPU |PERF_OUTPUT_TIME |PERF_OUTPUT_EVNAME |PERF_OUTPUT_IP | - PERF_OUTPUT_SYM | PERF_OUTPUT_DSO, +PERF_OUTPUT_SYM |PERF_OUTPUT_DSO | + PERF_OUTPUT_SYNTH, .invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT, },
@@ -1200,6 +1203,15 @@ static void print_sample_bpf_output(struct perf_sample *sample) (char *)(sample->raw_data)); } +static void print_sample_synth (struct perf_sample *sample__maybe_unused , +struct perf_evsel *evsel) +{ +switch (evsel->attr.config) { +default : +break ; + } +} +struct perf_script {struct perf_tool tool;struct perf_session *session;
@@ -1284,6 +1296,10 @@ static void process_event(struct perf_script *script,if (PRINT_FIELD (TRACE ))event_format__print (evsel->tp_format, sample->cpu, sample->raw_data, sample->raw_size); + +if (attr->type ==PERF_TYPE_SYNTH &&PRINT_FIELD (SYNTH )) +print_sample_synth (sample, evsel); +if (PRINT_FIELD (ADDR ))print_sample_addr (sample, thread, attr);
@@ -2605,7 +2621,7 @@ int cmd_script(int argc, const char **argv) "Valid types: hw,sw,trace,raw,synth. " "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso," "addr,symoff,period,iregs,brstack,brstacksym,flags," - "bpf-output,callindent,insn,insnlen,brstackinsn", + "bpf-output,callindent,insn,insnlen,brstackinsn,synth", parse_output_fields),OPT_BOOLEAN ('a' ,"all-cpus" , &system_wide, "system-wide collection from all CPUs"),
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf script: Add 'synth' field for synthesized event payloads
In reply to Adrian Hunterperf script: Add 'synth' field for synthesized event payloads
Commit-ID: 47e780848e6229b102e601deeb1ce571dc69a84a Gitweb: http://git.kernel.org/tip/47e780848e6229b102e601deeb1ce571dc69a84a Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:22 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 27 Jun 2017 12:19:10 -0300
perf script: Add 'synth' field for synthesized event payloads
Add a field to display the content the raw_data of a synthesized event.
--- tools/perf/Documentation/perf-script.txt | 6 +++++- tools/perf/builtin-script.c | 20 ++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-script.txt +5 -1
@@ -117,7 +117,8 @@ OPTIONS Comma separated list of fields to print. Options are: comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff, srcline, period, iregs, brstack, brstacksym, flags, bpf-output, brstackinsn, brstackoff, - callindent, insn, insnlen. Field list can be prepended with the type, trace, sw or hw, + callindent, insn, insnlen, synth. + Field list can be prepended with the type, trace, sw or hw, to indicate to which event type the field list applies. e.g., -F sw:comm,tid,time,ip,sym and -F trace:time,cpu,trace
@@ -193,6 +194,9 @@ OPTIONS instruction bytes and the instruction length of the current instruction. + The synth field is used by synthesized events which may be created when + Instruction Trace decoding. + Finally, a user may not set fields to none for all event types. i.e., -F "" is not allowed.
tools/perf/builtin-script.c +18 -2
@@ -86,6 +86,7 @@ enum perf_output_field {PERF_OUTPUT_INSNLEN =1U <<22 ,PERF_OUTPUT_BRSTACKINSN =1U <<23 ,PERF_OUTPUT_BRSTACKOFF =1U <<24 , + PERF_OUTPUT_SYNTH = 1U << 25, }; struct output_option {
@@ -117,6 +118,7 @@ struct output_option { {.str = "insnlen", .field = PERF_OUTPUT_INSNLEN}, {.str = "brstackinsn", .field = PERF_OUTPUT_BRSTACKINSN}, {.str = "brstackoff", .field = PERF_OUTPUT_BRSTACKOFF}, + {.str = "synth", .field = PERF_OUTPUT_SYNTH}, }; enum {
@@ -196,7 +198,8 @@ static struct { .fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |PERF_OUTPUT_CPU |PERF_OUTPUT_TIME |PERF_OUTPUT_EVNAME |PERF_OUTPUT_IP | - PERF_OUTPUT_SYM | PERF_OUTPUT_DSO, +PERF_OUTPUT_SYM |PERF_OUTPUT_DSO | + PERF_OUTPUT_SYNTH, .invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT, },
@@ -1200,6 +1203,15 @@ static void print_sample_bpf_output(struct perf_sample *sample) (char *)(sample->raw_data)); } +static void print_sample_synth (struct perf_sample *sample__maybe_unused , +struct perf_evsel *evsel) +{ +switch (evsel->attr.config) { +default : +break ; + } +} +struct perf_script {struct perf_tool tool;struct perf_session *session;
@@ -1284,6 +1296,10 @@ static void process_event(struct perf_script *script,if (PRINT_FIELD (TRACE ))event_format__print (evsel->tp_format, sample->cpu, sample->raw_data, sample->raw_size); + +if (attr->type ==PERF_TYPE_SYNTH &&PRINT_FIELD (SYNTH )) +print_sample_synth (sample, evsel); +if (PRINT_FIELD (ADDR ))print_sample_addr (sample, thread, attr);
@@ -2605,7 +2621,7 @@ int cmd_script(int argc, const char **argv) "Valid types: hw,sw,trace,raw,synth. " "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso," "addr,symoff,period,iregs,brstack,brstacksym,flags," - "bpf-output,callindent,insn,insnlen,brstackinsn", + "bpf-output,callindent,insn,insnlen,brstackinsn,synth", parse_output_fields),OPT_BOOLEAN ('a' ,"all-cpus" , &system_wide, "system-wide collection from all CPUs"),
Adrian Hunter
reviewerPATCH v2 22/37 tools include: Add byte-swapping macros to kernel.h
In reply to Adrian HunterAdd byte-swapping macros to kernel.h
--- tools/include/linux/kernel.h | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-)
tools/include/linux/kernel.h +29 -6
@@ -5,6 +5,8 @@#include <stddef.h> #include <assert.h> #include <linux/compiler.h> +#include <endian.h> +#include <byteswap.h> #ifndef UINT_MAX #define UINT_MAX (~0U)
@@ -67,12 +69,33 @@#endif #endif -/* -* Both need more care to handle endianness -* (Don't use bitmap_copy_le() for now) -*/ -#define cpu_to_le64 (x) (x) -#define cpu_to_le32 (x) (x) +#if __BYTE_ORDER == __BIG_ENDIAN +#define cpu_to_le16 bswap_16 +#define cpu_to_le32 bswap_32 +#define cpu_to_le64 bswap_64 +#define le16_to_cpu bswap_16 +#define le32_to_cpu bswap_32 +#define le64_to_cpu bswap_64 +#define cpu_to_be16 +#define cpu_to_be32 +#define cpu_to_be64 +#define be16_to_cpu +#define be32_to_cpu +#define be64_to_cpu +#else +#define cpu_to_le16 +#define cpu_to_le32 +#define cpu_to_le64 +#define le16_to_cpu +#define le32_to_cpu +#define le64_to_cpu +#define cpu_to_be16 bswap_16 +#define cpu_to_be32 bswap_32 +#define cpu_to_be64 bswap_64 +#define be16_to_cpu bswap_16 +#define be32_to_cpu bswap_32 +#define be64_to_cpu bswap_64 +#endif int vscnprintf (char *buf,size_t size,const char *fmt,va_list args);int scnprintf (char * buf,size_t size,const char * fmt, ...);
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] tools include: Add byte-swapping macros to kernel.h
tools include: Add byte-swapping macros to kernel.h
Commit-ID: 07fda552f14830e71f0b5e8e4e31124369903aa3 Gitweb: http://git.kernel.org/tip/07fda552f14830e71f0b5e8e4e31124369903aa3 Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:23 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 27 Jun 2017 12:08:13 -0300
tools include: Add byte-swapping macros to kernel.h
Add byte-swapping macros to kernel.h
--- tools/include/linux/kernel.h | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-)
tools/include/linux/kernel.h +29 -6
@@ -5,6 +5,8 @@#include <stddef.h> #include <assert.h> #include <linux/compiler.h> +#include <endian.h> +#include <byteswap.h> #ifndef UINT_MAX #define UINT_MAX (~0U)
@@ -67,12 +69,33 @@#endif #endif -/* -* Both need more care to handle endianness -* (Don't use bitmap_copy_le() for now) -*/ -#define cpu_to_le64 (x) (x) -#define cpu_to_le32 (x) (x) +#if __BYTE_ORDER == __BIG_ENDIAN +#define cpu_to_le16 bswap_16 +#define cpu_to_le32 bswap_32 +#define cpu_to_le64 bswap_64 +#define le16_to_cpu bswap_16 +#define le32_to_cpu bswap_32 +#define le64_to_cpu bswap_64 +#define cpu_to_be16 +#define cpu_to_be32 +#define cpu_to_be64 +#define be16_to_cpu +#define be32_to_cpu +#define be64_to_cpu +#else +#define cpu_to_le16 +#define cpu_to_le32 +#define cpu_to_le64 +#define le16_to_cpu +#define le32_to_cpu +#define le64_to_cpu +#define cpu_to_be16 bswap_16 +#define cpu_to_be32 bswap_32 +#define cpu_to_be64 bswap_64 +#define be16_to_cpu bswap_16 +#define be32_to_cpu bswap_32 +#define be64_to_cpu bswap_64 +#endif int vscnprintf (char *buf,size_t size,const char *fmt,va_list args);int scnprintf (char * buf,size_t size,const char * fmt, ...);
Adrian Hunter
reviewerPATCH v2 23/37 perf auxtrace: Add itrace option to output ptwrite events
In reply to Adrian HunterAdd itrace option to output ptwrite events.
--- tools/perf/Documentation/itrace.txt | 7 ++++--- tools/perf/util/auxtrace.c | 4 ++++ tools/perf/util/auxtrace.h | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-)
tools/perf/Documentation/itrace.txt +4 -3
@@ -3,13 +3,14 @@ c synthesize branches events (calls only) r synthesize branches events (returns only) x synthesize transactions events + w synthesize ptwrite events e synthesize error events d create a debug log g synthesize a call chain (use with i or x) l synthesize last branch entries (use with i or x) s skip initial number of events - The default is all events i.e. the same as --itrace=ibxe + The default is all events i.e. the same as --itrace=ibxwe In addition, the period (default 100000) for instructions events can be specified in units of:
@@ -26,8 +27,8 @@ Also the number of last branch entries (default 64, max. 1024) for instructions or transactions events can be specified. - It is also possible to skip events generated (instructions, branches, transactions) - at the beginning. This is useful to ignore initialization code. + It is also possible to skip events generated (instructions, branches, transactions, + ptwrite) at the beginning. This is useful to ignore initialization code. --itrace=i0nss1000000
tools/perf/util/auxtrace.c +4 -0
@@ -947,6 +947,7 @@ void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts) synth_opts->instructions = true; synth_opts->branches = true; synth_opts->transactions = true; + synth_opts->ptwrites = true; synth_opts->errors = true; synth_opts->period_type =PERF_ITRACE_DEFAULT_PERIOD_TYPE ; synth_opts->period =PERF_ITRACE_DEFAULT_PERIOD ;
@@ -1030,6 +1031,9 @@ int itrace_parse_synth_opts(const struct option *opt, const char *str,case 'x' : synth_opts->transactions = true;break ; +case 'w' : + synth_opts->ptwrites = true; +break ;case 'e' : synth_opts->errors = true;break ;
tools/perf/util/auxtrace.h +2 -0
@@ -59,6 +59,7 @@ enum itrace_period_type {* @instructions: whether to synthesize 'instructions' events * @branches: whether to synthesize 'branches' events * @transactions: whether to synthesize events for transactions +* @ptwrites: whether to synthesize events for ptwrites * @errors: whether to synthesize decoder error events * @dont_decode: whether to skip decoding entirely * @log: write a decoding log
@@ -79,6 +80,7 @@ struct itrace_synth_opts {bool instructions;bool branches;bool transactions; +bool ptwrites;bool errors;bool dont_decode;bool log;
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf auxtrace: Add itrace option to output ptwrite events
perf auxtrace: Add itrace option to output ptwrite events
Commit-ID: 3bdafdffa9baf2b34aebad1c98bc17b50202cb78 Gitweb: http://git.kernel.org/tip/3bdafdffa9baf2b34aebad1c98bc17b50202cb78 Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:24 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 27 Jun 2017 12:09:20 -0300
perf auxtrace: Add itrace option to output ptwrite events
Add itrace option to output ptwrite events.
--- tools/perf/Documentation/itrace.txt | 7 ++++--- tools/perf/util/auxtrace.c | 4 ++++ tools/perf/util/auxtrace.h | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-)
tools/perf/Documentation/itrace.txt +4 -3
@@ -3,13 +3,14 @@ c synthesize branches events (calls only) r synthesize branches events (returns only) x synthesize transactions events + w synthesize ptwrite events e synthesize error events d create a debug log g synthesize a call chain (use with i or x) l synthesize last branch entries (use with i or x) s skip initial number of events - The default is all events i.e. the same as --itrace=ibxe + The default is all events i.e. the same as --itrace=ibxwe In addition, the period (default 100000) for instructions events can be specified in units of:
@@ -26,8 +27,8 @@ Also the number of last branch entries (default 64, max. 1024) for instructions or transactions events can be specified. - It is also possible to skip events generated (instructions, branches, transactions) - at the beginning. This is useful to ignore initialization code. + It is also possible to skip events generated (instructions, branches, transactions, + ptwrite) at the beginning. This is useful to ignore initialization code. --itrace=i0nss1000000
tools/perf/util/auxtrace.c +4 -0
@@ -947,6 +947,7 @@ void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts) synth_opts->instructions = true; synth_opts->branches = true; synth_opts->transactions = true; + synth_opts->ptwrites = true; synth_opts->errors = true; synth_opts->period_type =PERF_ITRACE_DEFAULT_PERIOD_TYPE ; synth_opts->period =PERF_ITRACE_DEFAULT_PERIOD ;
@@ -1030,6 +1031,9 @@ int itrace_parse_synth_opts(const struct option *opt, const char *str,case 'x' : synth_opts->transactions = true;break ; +case 'w' : + synth_opts->ptwrites = true; +break ;case 'e' : synth_opts->errors = true;break ;
tools/perf/util/auxtrace.h +2 -0
@@ -59,6 +59,7 @@ enum itrace_period_type {* @instructions: whether to synthesize 'instructions' events * @branches: whether to synthesize 'branches' events * @transactions: whether to synthesize events for transactions +* @ptwrites: whether to synthesize events for ptwrites * @errors: whether to synthesize decoder error events * @dont_decode: whether to skip decoding entirely * @log: write a decoding log
@@ -79,6 +80,7 @@ struct itrace_synth_opts {bool instructions;bool branches;bool transactions; +bool ptwrites;bool errors;bool dont_decode;bool log;
Adrian Hunter
reviewerPATCH v2 24/37 perf auxtrace: Add itrace option to output power events
In reply to Adrian HunterAdd itrace option to output power events.
--- tools/perf/Documentation/itrace.txt | 5 +++-- tools/perf/util/auxtrace.c | 4 ++++ tools/perf/util/auxtrace.h | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-)
tools/perf/Documentation/itrace.txt +3 -2
@@ -4,13 +4,14 @@ r synthesize branches events (returns only) x synthesize transactions events w synthesize ptwrite events + p synthesize power events e synthesize error events d create a debug log g synthesize a call chain (use with i or x) l synthesize last branch entries (use with i or x) s skip initial number of events - The default is all events i.e. the same as --itrace=ibxwe + The default is all events i.e. the same as --itrace=ibxwpe In addition, the period (default 100000) for instructions events can be specified in units of:
@@ -28,7 +29,7 @@ instructions or transactions events can be specified. It is also possible to skip events generated (instructions, branches, transactions, - ptwrite) at the beginning. This is useful to ignore initialization code. + ptwrite, power) at the beginning. This is useful to ignore initialization code. --itrace=i0nss1000000
tools/perf/util/auxtrace.c +4 -0
@@ -948,6 +948,7 @@ void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts) synth_opts->branches = true; synth_opts->transactions = true; synth_opts->ptwrites = true; + synth_opts->pwr_events = true; synth_opts->errors = true; synth_opts->period_type =PERF_ITRACE_DEFAULT_PERIOD_TYPE ; synth_opts->period =PERF_ITRACE_DEFAULT_PERIOD ;
@@ -1034,6 +1035,9 @@ int itrace_parse_synth_opts(const struct option *opt, const char *str,case 'w' : synth_opts->ptwrites = true;break ; +case 'p' : + synth_opts->pwr_events = true; +break ;case 'e' : synth_opts->errors = true;break ;
tools/perf/util/auxtrace.h +2 -0
@@ -60,6 +60,7 @@ enum itrace_period_type {* @branches: whether to synthesize 'branches' events * @transactions: whether to synthesize events for transactions * @ptwrites: whether to synthesize events for ptwrites +* @pwr_events: whether to synthesize power events * @errors: whether to synthesize decoder error events * @dont_decode: whether to skip decoding entirely * @log: write a decoding log
@@ -81,6 +82,7 @@ struct itrace_synth_opts {bool branches;bool transactions;bool ptwrites; +bool pwr_events;bool errors;bool dont_decode;bool log;
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf auxtrace: Add itrace option to output power events
perf auxtrace: Add itrace option to output power events
Commit-ID: 70d110d775993ff1f63905bbdbc70e3f6bd8da8a Gitweb: http://git.kernel.org/tip/70d110d775993ff1f63905bbdbc70e3f6bd8da8a Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:25 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 27 Jun 2017 12:09:58 -0300
perf auxtrace: Add itrace option to output power events
Add itrace option to output power events.
--- tools/perf/Documentation/itrace.txt | 5 +++-- tools/perf/util/auxtrace.c | 4 ++++ tools/perf/util/auxtrace.h | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-)
tools/perf/Documentation/itrace.txt +3 -2
@@ -4,13 +4,14 @@ r synthesize branches events (returns only) x synthesize transactions events w synthesize ptwrite events + p synthesize power events e synthesize error events d create a debug log g synthesize a call chain (use with i or x) l synthesize last branch entries (use with i or x) s skip initial number of events - The default is all events i.e. the same as --itrace=ibxwe + The default is all events i.e. the same as --itrace=ibxwpe In addition, the period (default 100000) for instructions events can be specified in units of:
@@ -28,7 +29,7 @@ instructions or transactions events can be specified. It is also possible to skip events generated (instructions, branches, transactions, - ptwrite) at the beginning. This is useful to ignore initialization code. + ptwrite, power) at the beginning. This is useful to ignore initialization code. --itrace=i0nss1000000
tools/perf/util/auxtrace.c +4 -0
@@ -948,6 +948,7 @@ void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts) synth_opts->branches = true; synth_opts->transactions = true; synth_opts->ptwrites = true; + synth_opts->pwr_events = true; synth_opts->errors = true; synth_opts->period_type =PERF_ITRACE_DEFAULT_PERIOD_TYPE ; synth_opts->period =PERF_ITRACE_DEFAULT_PERIOD ;
@@ -1034,6 +1035,9 @@ int itrace_parse_synth_opts(const struct option *opt, const char *str,case 'w' : synth_opts->ptwrites = true;break ; +case 'p' : + synth_opts->pwr_events = true; +break ;case 'e' : synth_opts->errors = true;break ;
tools/perf/util/auxtrace.h +2 -0
@@ -60,6 +60,7 @@ enum itrace_period_type {* @branches: whether to synthesize 'branches' events * @transactions: whether to synthesize events for transactions * @ptwrites: whether to synthesize events for ptwrites +* @pwr_events: whether to synthesize power events * @errors: whether to synthesize decoder error events * @dont_decode: whether to skip decoding entirely * @log: write a decoding log
@@ -81,6 +82,7 @@ struct itrace_synth_opts {bool branches;bool transactions;bool ptwrites; +bool pwr_events;bool errors;bool dont_decode;bool log;
Adrian Hunter
reviewerPATCH v2 25/37 perf script: Add synthesized Intel PT power and ptwrite events
In reply to Adrian HunterAdd definitions for synthesized Intel PT events for power and ptwrite.
--- tools/perf/builtin-script.c | 114 +++++++++++++++++++++++++++++++++++++++++++- tools/perf/util/event.h | 90 ++++++++++++++++++++++++++++++++++ 2 files changed, 203 insertions(+), 1 deletion(-)
tools/perf/builtin-script.c +113 -1
@@ -1120,10 +1120,122 @@ static void print_sample_bpf_output(struct perf_sample *sample) (char *)(sample->raw_data)); } -static void print_sample_synth (struct perf_sample *sample__maybe_unused , +static void print_sample_spacing (int len,int spacing) +{ +if (len >0 && len < spacing) +printf ("%*s" , spacing - len,"" ); +} + +static void print_sample_pt_spacing (int len) +{ +print_sample_spacing (len,34 ); +} + +static void print_sample_synth_ptwrite (struct perf_sample *sample) +{ +struct perf_synth_intel_ptwrite *data = sample->raw_data; +int len; + +if (sample->raw_size <sizeof (*data)) +return ; + + len =printf (" IP: %u payload: %#" PRIx64" " , + data->ip,le64_to_cpu (data->payload)); +print_sample_pt_spacing (len); +} + +static void print_sample_synth_mwait (struct perf_sample *sample) +{ +struct perf_synth_intel_mwait *data = sample->raw_data; +int len; + +if (sample->raw_size <sizeof (*data)) +return ; + + len =printf (" hints: %#x extensions: %#x " , + data->hints, data->extensions); +print_sample_pt_spacing (len); +} + +static void print_sample_synth_pwre (struct perf_sample *sample) +{ +struct perf_synth_intel_pwre *data = sample->raw_data; +int len; + +if (sample->raw_size <sizeof (*data)) +return ; + + len =printf (" hw: %u cstate: %u sub-cstate: %u " , + data->hw, data->cstate, data->subcstate); +print_sample_pt_spacing (len); +} + +static void print_sample_synth_exstop (struct perf_sample *sample) +{ +struct perf_synth_intel_exstop *data = sample->raw_data; +int len; + +if (sample->raw_size <sizeof (*data)) +return ; + + len =printf (" IP: %u " , data->ip); +print_sample_pt_spacing (len); +} + +static void print_sample_synth_pwrx (struct perf_sample *sample) +{ +struct perf_synth_intel_pwrx *data = sample->raw_data; +int len; + +if (sample->raw_size <sizeof (*data)) +return ; + + len =printf (" deepest cstate: %u last cstate: %u wake reason: %#x " , + data->deepest_cstate, data->last_cstate, + data->wake_reason); +print_sample_pt_spacing (len); +} + +static void print_sample_synth_cbr (struct perf_sample *sample) +{ +struct perf_synth_intel_cbr *data = sample->raw_data; +unsigned int percent, freq; +int len; + +if (sample->raw_size <sizeof (*data)) +return ; + + freq = (le32_to_cpu (data->freq) +500 ) /1000 ; + len =printf (" cbr: %2u freq: %4u MHz " , data->cbr, freq); +if (data->max_nonturbo) { + percent = (5 + (1000 * data->cbr) / data->max_nonturbo) /10 ; + len +=printf ("(%3u%%) " , percent); + } +print_sample_pt_spacing (len); +} + +static void print_sample_synth (struct perf_sample *sample,struct perf_evsel *evsel) {switch (evsel->attr.config) { +case PERF_SYNTH_INTEL_PTWRITE : +print_sample_synth_ptwrite (sample); +break ; +case PERF_SYNTH_INTEL_MWAIT : +print_sample_synth_mwait (sample); +break ; +case PERF_SYNTH_INTEL_PWRE : +print_sample_synth_pwre (sample); +break ; +case PERF_SYNTH_INTEL_EXSTOP : +print_sample_synth_exstop (sample); +break ; +case PERF_SYNTH_INTEL_PWRX : +print_sample_synth_pwrx (sample); +break ; +case PERF_SYNTH_INTEL_CBR : +print_sample_synth_cbr (sample); +break ;default :break ; }
tools/perf/util/event.h +90 -0
96 lines not on this page · raw message
Signature · 1 line
1.9.1
Arnaldo Carvalho de Melo
maintainerRe: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
Em Fri, May 26, 2017 at 11:17:26AM +0300, Adrian Hunter escreveu:
Quoted 8 lines
Add definitions for synthesized Intel PT events for power and ptwrite.
+++
b/tools/perf/util/event.htools/perf/util/event.h +5
-0+/* +* Raw data formats for synthesized events. Note that raw data plus the raw data +* size (4 bytes) must align to 8-bytes. +*/ +
tools/perf/util/event.h enum auxtrace_error_type { · line 282
Quoted 10 lines
tools/perf/util/event.h +10
-0+struct perf_synth_intel_ptwrite { +union { +struct { +u32 ip :1 , + reserved :31 ; + }; +u32 flags; + }; +u64 payload; +} __packed;
some versions of clang and gcc dislike this __packed here:
In file included from builtin-script.c:5:
In file included from /git/linux/tools/perf/util/debug.h:8:
/git/linux/tools/perf/util/event.h:274:2: error: packed attribute is unnecessary for (null) [-Werror,-Wpacked]
union {
^
/git/linux/tools/perf/util/event.h:285:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked]
u32 reserved;
^
/git/linux/tools/perf/util/event.h:298:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked]
u32 reserved;
^
/git/linux/tools/perf/util/event.h:322:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked]
u32 reserved;
^4 errors generated.
mv: can't rename '/tmp/build/perf/.builtin-script.o.tmp': No such file or directory
/git/linux/tools/build/Makefile.build:101: recipe for target '/tmp/build/perf/builtin-script.o' failed
Failing in various distros:
[root@jouet ~]# waitp 3940 ; time dm
1 92.3684147260 alpine:3.4: FAIL
2 95.9136365930 alpine:3.5: FAIL
3 104.8328303770 alpine:3.6: FAIL
4 121.6584964930 alpine:edge: FAIL
5 37.2536373490 android-ndk:r12b-arm: Ok
6 83.9077612370 archlinux:latest: Ok
7 14.7094639200 centos:5: FAIL
8 16.6371634320 centos:6: FAIL
Investigating...
Quoted 70 lines
tools/perf/util/event.h +65
-0+ +struct perf_synth_intel_mwait { +u32 reserved; +union { +struct { +u64 hints :8 , + reserved1 :24 , + extensions :2 , + reserved2 :30 ; + }; +u64 payload; + }; +} __packed; + +struct perf_synth_intel_pwre { +u32 reserved; +union { +struct { +u64 reserved1 :7 , + hw :1 , + subcstate :4 , + cstate :4 , + reserved2 :48 ; + }; +u64 payload; + }; +} __packed; + +struct perf_synth_intel_exstop { +union { +struct { +u32 ip :1 , + reserved :31 ; + }; +u32 flags; + }; +}; + +struct perf_synth_intel_pwrx { +u32 reserved; +union { +struct { +u64 deepest_cstate :4 , + last_cstate :4 , + wake_reason :4 , + reserved1 :52 ; + }; +u64 payload; + }; +} __packed; + +struct perf_synth_intel_cbr { +union { +struct { +u32 cbr :8 , + reserved1 :8 , + max_nonturbo :8 , + reserved2 :8 ; + }; +u32 flags; + }; +u32 freq; +u32 reserved3; +}; +/* * The kernel collects the number of events it couldn't send in a stretch and * when possible sends this number in a PERF_RECORD_LOST event. The number of Signature · 1 line
1.9.1
Adrian Hunter
reviewerRe: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
Quoted 54 lines · Arnaldo Carvalho de Melo
Em Fri, May 26, 2017 at 11:17:26AM +0300, Adrian Hunter escreveu:
Quoted 8 lines
Add definitions for synthesized Intel PT events for power and ptwrite.
+++
b/tools/perf/util/event.h(quoted diff) +5
-0+/* + * Raw data formats for synthesized events. Note that raw data plus the raw data + * size (4 bytes) must align to 8-bytes. + */ +Review
Quoted 10 lines
(quoted diff) +10
-0+struct perf_synth_intel_ptwrite { + union { + struct { + u32 ip : 1, + reserved : 31; + }; + u32 flags; + }; + u64 payload; +} __packed;some versions of clang and gcc dislike this
__packedhere:In file included from builtin-script.c:5:
In file included from /git/linux/tools/perf/util/debug.h:8:
/git/linux/tools/perf/util/event.h:274:2: error: packed attribute is unnecessary for (null) [-Werror,-Wpacked]union { ^ /git/linux/tools/perf/util/event.h:285:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked] u32 reserved; ^ /git/linux/tools/perf/util/event.h:298:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked] u32 reserved; ^ /git/linux/tools/perf/util/event.h:322:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked] u32 reserved; ^4 errors generated.
mv: can't rename '/tmp/build/perf/.builtin-script.o.tmp': No such file or directory/git/linux/tools/build/Makefile.build:101: recipe for target '
/tmp/build/perf/builtin-script.o' failedFailing in various distros:
[root@jouet ~]# waitp 3940 ; time dm
1 92.3684147260 alpine:3.4: FAIL
2 95.9136365930 alpine:3.5: FAIL
3 104.8328303770 alpine:3.6: FAIL
4 121.6584964930 alpine:edge: FAIL
5 37.2536373490 android-ndk:r12b-arm: Ok
6 83.9077612370 archlinux:latest: Ok
7 14.7094639200 centos:5: FAIL
8 16.6371634320 centos:6: FAIL
Quoted 1 line
Investigating...
Re-reading the documentation for __packed, it seems like the following might be better:
tools/perf/util/event.h +8 -8
@@ -278,8 +278,8 @@ struct perf_synth_intel_ptwrite { };u32 flags; }; -u64 payload; -} __packed; + u64 payload __packed; +};struct perf_synth_intel_mwait {u32 reserved;
@@ -291,8 +291,8 @@ struct perf_synth_intel_mwait { reserved2 :30 ; };u64 payload; - }; -} __packed; + } __packed; +};struct perf_synth_intel_pwre {u32 reserved;
@@ -305,8 +305,8 @@ struct perf_synth_intel_pwre { reserved2 :48 ; };u64 payload; - }; -} __packed; + } __packed; +}; struct perf_synth_intel_exstop { union {
@@ -328,8 +328,8 @@ struct perf_synth_intel_pwrx { reserved1 :52 ; };u64 payload; - }; -} __packed; + } __packed; +}; struct perf_synth_intel_cbr { union {
Arnaldo Carvalho de Melo
maintainerRe: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
Em Wed, Jun 28, 2017 at 08:40:25PM +0300, Adrian Hunter escreveu:
Quoted 55 lines · Arnaldo Carvalho de Melo
Quoted 54 lines
Em Fri, May 26, 2017 at 11:17:26AM +0300, Adrian Hunter escreveu:
Quoted 8 lines
Add definitions for synthesized Intel PT events for power and ptwrite.
+++
b/tools/perf/util/event.h(quoted diff) +5
-0+/* + * Raw data formats for synthesized events. Note that raw data plus the raw data + * size (4 bytes) must align to 8-bytes. + */ +Review
Quoted 10 lines
(quoted diff) +10
-0+struct perf_synth_intel_ptwrite { + union { + struct { + u32 ip : 1, + reserved : 31; + }; + u32 flags; + }; + u64 payload; +} __packed;some versions of clang and gcc dislike this
__packedhere:In file included from builtin-script.c:5:
In file included from /git/linux/tools/perf/util/debug.h:8:
/git/linux/tools/perf/util/event.h:274:2: error: packed attribute is unnecessary for (null) [-Werror,-Wpacked]union { ^ /git/linux/tools/perf/util/event.h:285:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked] u32 reserved; ^ /git/linux/tools/perf/util/event.h:298:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked] u32 reserved; ^ /git/linux/tools/perf/util/event.h:322:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked] u32 reserved; ^4 errors generated.
mv: can't rename '/tmp/build/perf/.builtin-script.o.tmp': No such file or directory/git/linux/tools/build/Makefile.build:101: recipe for target '
/tmp/build/perf/builtin-script.o' failedFailing in various distros:
[root@jouet ~]# waitp 3940 ; time dm
1 92.3684147260 alpine:3.4: FAIL
2 95.9136365930 alpine:3.5: FAIL
3 104.8328303770 alpine:3.6: FAIL
4 121.6584964930 alpine:edge: FAIL
5 37.2536373490 android-ndk:r12b-arm: Ok
6 83.9077612370 archlinux:latest: Ok
7 14.7094639200 centos:5: FAIL
8 16.6371634320 centos:6: FAIL
Quoted 4 lines
Quoted 1 line
Investigating...
Re-reading the documentation for
__packed, it seems like the following might be better:
Humm, can you provide the URL for such docs? I always saw packed as an attribute for a struct, not for a member... For members "aligned" is what I'm used to see:
__attribute__ ((aligned (8)))
In the kernel sources there are a few such cases as you suggest:
[acme@jouet linux]$ find include/ -name "*.h"| xargs grep -w __packed | grep -v } | grep -v "struct __packed" | wc -l 12
[acme@jouet linux]$
But most are the other way, i.e. tagging the packed attribute to the whole struct, as you originally did :-\
- Arnaldo
Quoted 48 lines
tools/perf/util/event.h +8
-8@@ -278,8 +278,8 @@ struct perf_synth_intel_ptwrite { };u32 flags; }; -u64 payload; -} __packed; + u64 payload __packed; +};struct perf_synth_intel_mwait {u32 reserved;@@ -291,8 +291,8 @@ struct perf_synth_intel_mwait { reserved2 :30 ; };u64 payload; - }; -} __packed; + } __packed; +};struct perf_synth_intel_pwre {u32 reserved;@@ -305,8 +305,8 @@ struct perf_synth_intel_pwre { reserved2 :48 ; };u64 payload; - }; -} __packed; + } __packed; +}; struct perf_synth_intel_exstop { union {@@ -328,8 +328,8 @@ struct perf_synth_intel_pwrx { reserved1 :52 ; };u64 payload; - }; -} __packed; + } __packed; +}; struct perf_synth_intel_cbr { union {
Hunter, Adrian
reviewerRE: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
Sorry for the top-post...
Yeah, I've now mixed up the variable attribute:
https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#Common-Variable-Attributes
with the type attribute:
https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#Common-Type-Attributes
Late here, so maybe it will make more sense tomorrow.
-----Original Message-----
From: Arnaldo Carvalho de Melo [mailto:[email protected]]
Sent: Wednesday, June 28, 2017 9:54 PM
To: Hunter, Adrian <[email protected]>
Cc: Andi Kleen <[email protected]>; [email protected]
Subject: Re: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
Em Wed, Jun 28, 2017 at 08:40:25PM +0300, Adrian Hunter escreveu:
Quoted 58 lines · Arnaldo Carvalho de Melo
Quoted 57 lines
Em Fri, May 26, 2017 at 11:17:26AM +0300, Adrian Hunter escreveu:
Quoted 9 lines
Add definitions for synthesized Intel PT events for power and ptwrite.
+++
b/tools/perf/util/event.h(quoted diff) +6
-0+/* + * Raw data formats for synthesized events. Note that raw data +plus the raw data + * size (4 bytes) must align to 8-bytes. + */ +Review
Quoted 10 lines
(quoted diff) +10
-0+struct perf_synth_intel_ptwrite { + union { + struct { + u32 ip : 1, + reserved : 31; + }; + u32 flags; + }; + u64 payload; +} __packed;some versions of clang and gcc dislike this
__packedhere:In file included from builtin-script.c:5:
In file included from /git/linux/tools/perf/util/debug.h:8:
/git/linux/tools/perf/util/event.h:274:2: error: packed attribute is unnecessary for (null) [-Werror,-Wpacked]union { ^ /git/linux/tools/perf/util/event.h:285:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked] u32 reserved; ^ /git/linux/tools/perf/util/event.h:298:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked] u32 reserved; ^ /git/linux/tools/perf/util/event.h:322:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked] u32 reserved; ^4 errors generated.
mv: can't rename '/tmp/build/perf/.builtin-script.o.tmp': No such file or directory/git/linux/tools/build/Makefile.build:101: recipe for target '
/tmp/build/perf/builtin-script.o' failedFailing in various distros:
[root@jouet ~]# waitp 3940 ; time dm
1 92.3684147260 alpine:3.4: FAIL
2 95.9136365930 alpine:3.5: FAIL
3 104.8328303770 alpine:3.6: FAIL
4 121.6584964930 alpine:edge: FAIL
5 37.2536373490 android-ndk:r12b-arm: Ok
6 83.9077612370 archlinux:latest: Ok
7 14.7094639200 centos:5: FAIL
8 16.6371634320 centos:6: FAIL
Quoted 4 lines
Quoted 1 line
Investigating...
Re-reading the documentation for
__packed, it seems like the following might be better:
Humm, can you provide the URL for such docs? I always saw packed as an attribute for a struct, not for a member... For members "aligned" is what I'm used to see:
__attribute__ ((aligned (8)))
In the kernel sources there are a few such cases as you suggest:
[acme@jouet linux]$ find include/ -name "*.h"| xargs grep -w __packed | grep -v } | grep -v "struct __packed" | wc -l 12
[acme@jouet linux]$
But most are the other way, i.e. tagging the packed attribute to the whole struct, as you originally did :-\
- Arnaldo
Quoted 48 lines
tools/perf/util/event.h index renamed from tools/perf/util/event.h +0
-0
c283603f59c7..a7547cb3b760100644tools/perf/util/event.h +8
-8@@ -278,8 +278,8 @@ struct perf_synth_intel_ptwrite { };u32 flags; }; -u64 payload; -} __packed; + u64 payload __packed; +};struct perf_synth_intel_mwait {u32 reserved;@@ -291,8 +291,8 @@ struct perf_synth_intel_mwait { reserved2 :30 ; };u64 payload; - }; -} __packed; + } __packed; +};struct perf_synth_intel_pwre {u32 reserved;@@ -305,8 +305,8 @@ struct perf_synth_intel_pwre { reserved2 :48 ; };u64 payload; - }; -} __packed; + } __packed; +}; struct perf_synth_intel_exstop { union {@@ -328,8 +328,8 @@ struct perf_synth_intel_pwrx { reserved1 :52 ; };u64 payload; - }; -} __packed; + } __packed; +}; struct perf_synth_intel_cbr { union {
Arnaldo Carvalho de Melo
maintainerRe: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
Em Wed, Jun 28, 2017 at 08:21:37PM +0000, Hunter, Adrian escreveu:
Quoted 11 lines
Sorry for the top-post...
Yeah, I've now mixed up the variable attribute:
https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#Common-Variable-Attributes
with the type attribute:
https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#Common-Type-Attributes
Late here, so maybe it will make more sense tomorrow.
Right, and I've not been able to focus on this, but I think the problem is with packed mixed with unnamed unions :-\
- Arnaldo
Quoted 133 lines
-----Original Message-----
From: Arnaldo Carvalho de Melo [mailto:[email protected]]
Sent: Wednesday, June 28, 2017 9:54 PM
To: Hunter, Adrian <[email protected]>
Cc: Andi Kleen <[email protected]>; [email protected]
Subject: Re: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite eventsEm Wed, Jun 28, 2017 at 08:40:25PM +0300, Adrian Hunter escreveu:
Quoted 58 lines · Arnaldo Carvalho de Melo
Quoted 57 lines
Em Fri, May 26, 2017 at 11:17:26AM +0300, Adrian Hunter escreveu:
Quoted 9 lines
Add definitions for synthesized Intel PT events for power and ptwrite.
+++
b/tools/perf/util/event.h(quoted diff) +6
-0+/* + * Raw data formats for synthesized events. Note that raw data +plus the raw data + * size (4 bytes) must align to 8-bytes. + */ +Review
Quoted 10 lines
(quoted diff) +10
-0+struct perf_synth_intel_ptwrite { + union { + struct { + u32 ip : 1, + reserved : 31; + }; + u32 flags; + }; + u64 payload; +} __packed;some versions of clang and gcc dislike this
__packedhere:In file included from builtin-script.c:5:
In file included from /git/linux/tools/perf/util/debug.h:8:
/git/linux/tools/perf/util/event.h:274:2: error: packed attribute is unnecessary for (null) [-Werror,-Wpacked]union { ^ /git/linux/tools/perf/util/event.h:285:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked] u32 reserved; ^ /git/linux/tools/perf/util/event.h:298:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked] u32 reserved; ^ /git/linux/tools/perf/util/event.h:322:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked] u32 reserved; ^4 errors generated.
mv: can't rename '/tmp/build/perf/.builtin-script.o.tmp': No such file or directory/git/linux/tools/build/Makefile.build:101: recipe for target '
/tmp/build/perf/builtin-script.o' failedFailing in various distros:
[root@jouet ~]# waitp 3940 ; time dm
1 92.3684147260 alpine:3.4: FAIL
2 95.9136365930 alpine:3.5: FAIL
3 104.8328303770 alpine:3.6: FAIL
4 121.6584964930 alpine:edge: FAIL
5 37.2536373490 android-ndk:r12b-arm: Ok
6 83.9077612370 archlinux:latest: Ok
7 14.7094639200 centos:5: FAIL
8 16.6371634320 centos:6: FAILQuoted 4 lines
Quoted 1 line
Investigating...
Re-reading the documentation for
__packed, it seems like the following might be better:Humm, can you provide the URL for such docs? I always saw packed as an attribute for a struct, not for a member... For members "aligned" is what I'm used to see:
__attribute__ ((aligned (8)))In the kernel sources there are a few such cases as you suggest:
[acme@jouet linux]$ find
include/-name "*.h"| xargs grep -w__packed| grep -v } | grep -v "struct__packed" | wc -l 12
[acme@jouet linux]$But most are the other way, i.e. tagging the packed attribute to the whole struct, as you originally did :-\
- Arnaldo
Quoted 48 lines
tools/perf/util/event.h index renamed from tools/perf/util/event.h +0
-0
c283603f59c7..a7547cb3b760100644tools/perf/util/event.h +8
-8@@ -278,8 +278,8 @@ struct perf_synth_intel_ptwrite { };u32 flags; }; -u64 payload; -} __packed; + u64 payload __packed; +};struct perf_synth_intel_mwait {u32 reserved;@@ -291,8 +291,8 @@ struct perf_synth_intel_mwait { reserved2 :30 ; };u64 payload; - }; -} __packed; + } __packed; +};struct perf_synth_intel_pwre {u32 reserved;@@ -305,8 +305,8 @@ struct perf_synth_intel_pwre { reserved2 :48 ; };u64 payload; - }; -} __packed; + } __packed; +}; struct perf_synth_intel_exstop { union {@@ -328,8 +328,8 @@ struct perf_synth_intel_pwrx { reserved1 :52 ; };u64 payload; - }; -} __packed; + } __packed; +}; struct perf_synth_intel_cbr { union {
Adrian Hunter
reviewerRe: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
Quoted 7 lines · Arnaldo Carvalho de Melo
Em Wed, Jun 28, 2017 at 08:21:37PM +0000, Hunter, Adrian escreveu:
Quoted 6 lines
Sorry for the top-post...
Yeah, I've now mixed up the variable attribute:
https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#Common-Variable-Attributes
Quoted 8 lines
Quoted 5 lines
with the type attribute:
https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#Common-Type-Attributes
Late here, so maybe it will make more sense tomorrow.
Right, and I've not been able to focus on this, but I think the problem is with packed mixed with unnamed unions :-\
Another possibility is to avoid packed altogether e.g.
tools/perf/builtin-script.c +12 -12
@@ -1216,10 +1216,10 @@ static void print_sample_pt_spacing(int len)static void print_sample_synth_ptwrite (struct perf_sample *sample) { -struct perf_synth_intel_ptwrite *data = sample->raw_data; +struct perf_synth_intel_ptwrite *data =perf_sample__synth_ptr (sample);int len; -if (sample->raw_size <sizeof (*data)) +if (perf_sample__bad_synth_size (sample, *data))return ; len = printf(" IP: %u payload: %#" PRIx64 " ",
@@ -1229,10 +1229,10 @@ static void print_sample_synth_ptwrite(struct perf_sample *sample)static void print_sample_synth_mwait (struct perf_sample *sample) { -struct perf_synth_intel_mwait *data = sample->raw_data; +struct perf_synth_intel_mwait *data =perf_sample__synth_ptr (sample);int len; -if (sample->raw_size <sizeof (*data)) +if (perf_sample__bad_synth_size (sample, *data))return ; len = printf(" hints: %#x extensions: %#x ",
@@ -1242,10 +1242,10 @@ static void print_sample_synth_mwait(struct perf_sample *sample)static void print_sample_synth_pwre (struct perf_sample *sample) { -struct perf_synth_intel_pwre *data = sample->raw_data; +struct perf_synth_intel_pwre *data =perf_sample__synth_ptr (sample);int len; -if (sample->raw_size <sizeof (*data)) +if (perf_sample__bad_synth_size (sample, *data))return ; len = printf(" hw: %u cstate: %u sub-cstate: %u ",
@@ -1255,10 +1255,10 @@ static void print_sample_synth_pwre(struct perf_sample *sample)static void print_sample_synth_exstop (struct perf_sample *sample) { -struct perf_synth_intel_exstop *data = sample->raw_data; +struct perf_synth_intel_exstop *data =perf_sample__synth_ptr (sample);int len; -if (sample->raw_size <sizeof (*data)) +if (perf_sample__bad_synth_size (sample, *data))return ; len =printf (" IP: %u " , data->ip);
@@ -1267,10 +1267,10 @@ static void print_sample_synth_exstop(struct perf_sample *sample)static void print_sample_synth_pwrx (struct perf_sample *sample) { -struct perf_synth_intel_pwrx *data = sample->raw_data; +struct perf_synth_intel_pwrx *data =perf_sample__synth_ptr (sample);int len; -if (sample->raw_size <sizeof (*data)) +if (perf_sample__bad_synth_size (sample, *data))return ; len = printf(" deepest cstate: %u last cstate: %u wake reason: %#x ",
@@ -1281,11 +1281,11 @@ static void print_sample_synth_pwrx(struct perf_sample *sample)static void print_sample_synth_cbr (struct perf_sample *sample) { -struct perf_synth_intel_cbr *data = sample->raw_data; +struct perf_synth_intel_cbr *data =perf_sample__synth_ptr (sample);unsigned int percent, freq;int len; -if (sample->raw_size <sizeof (*data)) +if (perf_sample__bad_synth_size (sample, *data))return ; freq = (le32_to_cpu (data->freq) +500 ) /1000 ;
tools/perf/util/event.h +34 -6
@@ -266,11 +266,16 @@ enum perf_synth_id { };/* -* Raw data formats for synthesized events. Note that raw data plus the raw data -* size (4 bytes) must align to 8-bytes. +* Raw data formats for synthesized events. Note that 4 bytes of padding are +* present to match the 'size' member of PERF_SAMPLE_RAW data which is always +* 8-byte aligned. That means we must dereference raw_data with an offset of 4. +* Refer perf_sample__synth_ptr() and perf_synth__raw_data(). It also means the +* structure sizes are 4 bytes bigger than the raw_size, refer +* perf_synth__raw_size(). */ struct perf_synth_intel_ptwrite { + u32 padding; union { struct { u32 ip : 1,
@@ -279,9 +284,10 @@ struct perf_synth_intel_ptwrite {u32 flags; };u64 payload; -} __packed; +}; struct perf_synth_intel_mwait { + u32 padding; u32 reserved; union { struct {
@@ -292,9 +298,10 @@ struct perf_synth_intel_mwait { };u64 payload; }; -} __packed; +}; struct perf_synth_intel_pwre { + u32 padding; u32 reserved; union { struct {
@@ -306,9 +313,10 @@ struct perf_synth_intel_pwre { };u64 payload; }; -} __packed; +}; struct perf_synth_intel_exstop { + u32 padding; union { struct { u32 ip : 1,
@@ -319,6 +327,7 @@ struct perf_synth_intel_exstop { }; struct perf_synth_intel_pwrx { + u32 padding; u32 reserved; union { struct {
@@ -329,9 +338,10 @@ struct perf_synth_intel_pwrx { };u64 payload; }; -} __packed; +}; struct perf_synth_intel_cbr { + u32 padding; union { struct { u32 cbr : 8,
@@ -346,6 +356,24 @@ struct perf_synth_intel_cbr { };/* +* raw_data is always 4 bytes from an 8-byte boundary, so subtract 4 to get +* 8-byte alignment. +*/ +static inline void *perf_sample__synth_ptr (struct perf_sample *sample) +{ +return sample->raw_data -4 ; +} + +static inline void *perf_synth__raw_data (void *p) +{ +return p +4 ; +} + +#define perf_synth__raw_size (d) (sizeof(d) - 4) + +#define perf_sample__bad_synth_size (s, d) ((s)->raw_size < sizeof(d) - 4) + +/* * The kernel collects the number of events it couldn't send in a stretch and * when possible sends this number in a PERF_RECORD_LOST event. The number of * such "chunks" of lost events is stored in .nr_events[PERF_EVENT_LOST] while
tools/perf/util/intel-pt.c +12 -12
@@ -1283,8 +1283,8 @@ static int intel_pt_synth_ptwrite_sample(struct intel_pt_queue *ptq) raw.ip = !!(ptq->state->flags &INTEL_PT_FUP_IP ); raw.payload =cpu_to_le64 (ptq->state->ptw_payload); - sample.raw_size =sizeof (raw); - sample.raw_data = &raw; + sample.raw_size =perf_synth__raw_size (raw); + sample.raw_data =perf_synth__raw_data (&raw);return intel_pt_deliver_synth_event (pt, ptq, event, &sample, pt->ptwrites_sample_type);
@@ -1311,8 +1311,8 @@ static int intel_pt_synth_cbr_sample(struct intel_pt_queue *ptq) raw.freq =cpu_to_le32 (raw.cbr * pt->cbr2khz); raw.reserved3 =0 ; - sample.raw_size =sizeof (raw); - sample.raw_data = &raw; + sample.raw_size =perf_synth__raw_size (raw); + sample.raw_data =perf_synth__raw_data (&raw);return intel_pt_deliver_synth_event (pt, ptq, event, &sample, pt->pwr_events_sample_type);
@@ -1336,8 +1336,8 @@ static int intel_pt_synth_mwait_sample(struct intel_pt_queue *ptq) raw.reserved =0 ; raw.payload =cpu_to_le64 (ptq->state->mwait_payload); - sample.raw_size =sizeof (raw); - sample.raw_data = &raw; + sample.raw_size =perf_synth__raw_size (raw); + sample.raw_data =perf_synth__raw_data (&raw);return intel_pt_deliver_synth_event (pt, ptq, event, &sample, pt->pwr_events_sample_type);
@@ -1361,8 +1361,8 @@ static int intel_pt_synth_pwre_sample(struct intel_pt_queue *ptq) raw.reserved =0 ; raw.payload =cpu_to_le64 (ptq->state->pwre_payload); - sample.raw_size =sizeof (raw); - sample.raw_data = &raw; + sample.raw_size =perf_synth__raw_size (raw); + sample.raw_data =perf_synth__raw_data (&raw);return intel_pt_deliver_synth_event (pt, ptq, event, &sample, pt->pwr_events_sample_type);
@@ -1386,8 +1386,8 @@ static int intel_pt_synth_exstop_sample(struct intel_pt_queue *ptq) raw.flags =0 ; raw.ip = !!(ptq->state->flags &INTEL_PT_FUP_IP ); - sample.raw_size =sizeof (raw); - sample.raw_data = &raw; + sample.raw_size =perf_synth__raw_size (raw); + sample.raw_data =perf_synth__raw_data (&raw);return intel_pt_deliver_synth_event (pt, ptq, event, &sample, pt->pwr_events_sample_type);
@@ -1411,8 +1411,8 @@ static int intel_pt_synth_pwrx_sample(struct intel_pt_queue *ptq) raw.reserved =0 ; raw.payload =cpu_to_le64 (ptq->state->pwrx_payload); - sample.raw_size =sizeof (raw); - sample.raw_data = &raw; + sample.raw_size =perf_synth__raw_size (raw); + sample.raw_data =perf_synth__raw_data (&raw);return intel_pt_deliver_synth_event (pt, ptq, event, &sample, pt->pwr_events_sample_type);
Quoted 135 lines
Quoted 134 lines
-----Original Message-----
From: Arnaldo Carvalho de Melo [mailto:[email protected]]
Sent: Wednesday, June 28, 2017 9:54 PM
To: Hunter, Adrian <[email protected]>
Cc: Andi Kleen <[email protected]>; [email protected]
Subject: Re: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite eventsEm Wed, Jun 28, 2017 at 08:40:25PM +0300, Adrian Hunter escreveu:
Quoted 58 lines · Arnaldo Carvalho de Melo
Quoted 57 lines
Em Fri, May 26, 2017 at 11:17:26AM +0300, Adrian Hunter escreveu:
Quoted 9 lines
Add definitions for synthesized Intel PT events for power and ptwrite.
+++
b/tools/perf/util/event.h(quoted diff) +6
-0+/* + * Raw data formats for synthesized events. Note that raw data +plus the raw data + * size (4 bytes) must align to 8-bytes. + */ +Review
Quoted 10 lines
(quoted diff) +10
-0+struct perf_synth_intel_ptwrite { + union { + struct { + u32 ip : 1, + reserved : 31; + }; + u32 flags; + }; + u64 payload; +} __packed;some versions of clang and gcc dislike this
__packedhere:In file included from builtin-script.c:5:
In file included from /git/linux/tools/perf/util/debug.h:8:
/git/linux/tools/perf/util/event.h:274:2: error: packed attribute is unnecessary for (null) [-Werror,-Wpacked]union { ^ /git/linux/tools/perf/util/event.h:285:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked] u32 reserved; ^ /git/linux/tools/perf/util/event.h:298:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked] u32 reserved; ^ /git/linux/tools/perf/util/event.h:322:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked] u32 reserved; ^4 errors generated.
mv: can't rename '/tmp/build/perf/.builtin-script.o.tmp': No such file or directory/git/linux/tools/build/Makefile.build:101: recipe for target '
/tmp/build/perf/builtin-script.o' failedFailing in various distros:
[root@jouet ~]# waitp 3940 ; time dm
1 92.3684147260 alpine:3.4: FAIL
2 95.9136365930 alpine:3.5: FAIL
3 104.8328303770 alpine:3.6: FAIL
4 121.6584964930 alpine:edge: FAIL
5 37.2536373490 android-ndk:r12b-arm: Ok
6 83.9077612370 archlinux:latest: Ok
7 14.7094639200 centos:5: FAIL
8 16.6371634320 centos:6: FAILQuoted 4 lines
Quoted 1 line
Investigating...
Re-reading the documentation for
__packed, it seems like the following might be better:Humm, can you provide the URL for such docs? I always saw packed as an attribute for a struct, not for a member... For members "aligned" is what I'm used to see:
__attribute__ ((aligned (8)))In the kernel sources there are a few such cases as you suggest:
[acme@jouet linux]$ find
include/-name "*.h"| xargs grep -w__packed| grep -v } | grep -v "struct__packed" | wc -l 12
[acme@jouet linux]$But most are the other way, i.e. tagging the packed attribute to the whole struct, as you originally did :-\
- Arnaldo
Quoted 48 lines
tools/perf/util/event.h index renamed from tools/perf/util/event.h +0
-0
c283603f59c7..a7547cb3b760100644tools/perf/util/event.h +8
-8@@ -278,8 +278,8 @@ struct perf_synth_intel_ptwrite { };u32 flags; }; -u64 payload; -} __packed; + u64 payload __packed; +};struct perf_synth_intel_mwait {u32 reserved;@@ -291,8 +291,8 @@ struct perf_synth_intel_mwait { reserved2 :30 ; };u64 payload; - }; -} __packed; + } __packed; +};struct perf_synth_intel_pwre {u32 reserved;@@ -305,8 +305,8 @@ struct perf_synth_intel_pwre { reserved2 :48 ; };u64 payload; - }; -} __packed; + } __packed; +}; struct perf_synth_intel_exstop { union {@@ -328,8 +328,8 @@ struct perf_synth_intel_pwrx { reserved1 :52 ; };u64 payload; - }; -} __packed; + } __packed; +}; struct perf_synth_intel_cbr { union {
Arnaldo Carvalho de Melo
maintainerRe: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
Em Thu, Jun 29, 2017 at 10:56:25PM +0300, Adrian Hunter escreveu:
Quoted 10 lines · Arnaldo Carvalho de Melo
Quoted 9 lines
Em Wed, Jun 28, 2017 at 08:21:37PM +0000, Hunter, Adrian escreveu:
Quoted 8 lines
Sorry for the top-post...
Yeah, I've now mixed up the variable attribute:
https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#Common-Variable-Attributes
with the type attribute:
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#Common-Type-Attributes
Late here, so maybe it will make more sense tomorrow.
Right, and I've not been able to focus on this, but I think the problem is with packed mixed with unnamed unions :-\
Another possibility is to avoid packed altogether e.g.
This one builds on centos:6, now running the full set of containers, will let you know the results.
- Arnaldo
Arnaldo Carvalho de Melo
maintainerRe: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
Em Thu, Jun 29, 2017 at 05:13:54PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 9 lines
Em Thu, Jun 29, 2017 at 10:56:25PM +0300, Adrian Hunter escreveu:
Quoted 5 lines · Arnaldo Carvalho de Melo
Quoted 2 lines
Right, and I've not been able to focus on this, but I think the problem is with packed mixed with unnamed unions :-\
Another possibility is to avoid packed altogether e.g.
This one builds on centos:6, now running the full set of containers, will let you know the results.
Ok, passes all tests (gcc, clang where available) on:
# dm 1 alpine:3.4: Ok 2 alpine:3.5: Ok 3 alpine:3.6: Ok 4 alpine:edge: Ok 5 android-ndk:r12b-arm: Ok 6 archlinux:latest: Ok 7 centos:5: Ok 8 centos:6: Ok 9 centos:7: Ok 10 debian:7: Ok 11 debian:8: Ok 12 debian:9: Ok 13 debian:experimental: Ok 14 debian:experimental-x-arm64: Ok 15 debian:experimental-x-mips: Ok 16 debian:experimental-x-mips64: Ok 17 debian:experimental-x-mipsel: Ok 18 fedora:20: Ok 19 fedora:21: Ok 20 fedora:22: Ok 21 fedora:23: Ok 22 fedora:24: Ok 23 fedora:24-x-ARC-uClibc: Ok 24 fedora:25: Ok 25 fedora:rawhide: Ok 26 mageia:5: Ok 27 opensuse:13.2: Ok 28 opensuse:42.1: Ok 29 opensuse:tumbleweed: Ok 30 ubuntu:12.04.5: Ok 31 ubuntu:14.04.4: Ok 32 ubuntu:14.04.4-x-linaro-arm64: Ok 33 ubuntu:15.10: Ok 34 ubuntu:16.04: Ok 35 ubuntu:16.04-x-arm: Ok 36 ubuntu:16.04-x-arm64: Ok 37 ubuntu:16.04-x-powerpc: Ok 38 ubuntu:16.04-x-powerpc64: Ok 39 ubuntu:16.04-x-powerpc64el: Ok 40 ubuntu:16.04-x-s390: Ok 41 ubuntu:16.10: Ok 42 ubuntu:17.04: Ok #
Can you provide new versions for the relevant patches?
Thanks,
- Arnaldo
Adrian Hunter
reviewerRe: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
Quoted 59 lines · Arnaldo Carvalho de Melo
Em Thu, Jun 29, 2017 at 05:13:54PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 9 lines
Em Thu, Jun 29, 2017 at 10:56:25PM +0300, Adrian Hunter escreveu:
Quoted 5 lines · Arnaldo Carvalho de Melo
Quoted 2 lines
Right, and I've not been able to focus on this, but I think the problem is with packed mixed with unnamed unions :-\
Another possibility is to avoid packed altogether e.g.
This one builds on centos:6, now running the full set of containers, will let you know the results.
Ok, passes all tests (gcc, clang where available) on:
# dm 1 alpine:3.4: Ok 2 alpine:3.5: Ok 3 alpine:3.6: Ok 4 alpine:edge: Ok 5 android-ndk:r12b-arm: Ok 6 archlinux:latest: Ok 7 centos:5: Ok 8 centos:6: Ok 9 centos:7: Ok 10 debian:7: Ok 11 debian:8: Ok 12 debian:9: Ok 13 debian:experimental: Ok 14 debian:experimental-x-arm64: Ok 15 debian:experimental-x-mips: Ok 16 debian:experimental-x-mips64: Ok 17 debian:experimental-x-mipsel: Ok 18 fedora:20: Ok 19 fedora:21: Ok 20 fedora:22: Ok 21 fedora:23: Ok 22 fedora:24: Ok 23 fedora:24-x-ARC-uClibc: Ok 24 fedora:25: Ok 25 fedora:rawhide: Ok 26 mageia:5: Ok 27 opensuse:13.2: Ok 28 opensuse:42.1: Ok 29 opensuse:tumbleweed: Ok 30 ubuntu:12.04.5: Ok 31 ubuntu:14.04.4: Ok 32 ubuntu:14.04.4-x-linaro-arm64: Ok 33 ubuntu:15.10: Ok 34 ubuntu:16.04: Ok 35 ubuntu:16.04-x-arm: Ok 36 ubuntu:16.04-x-arm64: Ok 37 ubuntu:16.04-x-powerpc: Ok 38 ubuntu:16.04-x-powerpc64: Ok 39 ubuntu:16.04-x-powerpc64el: Ok 40 ubuntu:16.04-x-s390: Ok 41 ubuntu:16.10: Ok 42 ubuntu:17.04: Ok #
Quoted 1 line
Can you provide new versions for the relevant patches?
I have sent new versions of the 2 patches affected.
Arnaldo Carvalho de Melo
maintainerRe: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
Em Fri, Jun 30, 2017 at 11:51:22AM +0300, Adrian Hunter escreveu:
Quoted 10 lines · Arnaldo Carvalho de Melo
Quoted 7 lines
Em Thu, Jun 29, 2017 at 05:13:54PM -0300, Arnaldo Carvalho de Melo escreveu:
Ok, passes all tests (gcc, clang where available) on:41 ubuntu:16.10: Ok
42 ubuntu:17.04: OkCan you provide new versions for the relevant patches?
I have sent new versions of the 2 patches affected.
Thanks, a grafted those in my branch, will perform the usual build tests, then try it on a kaby lake machine.
Have you thought about further "perf test" test cases to make sure this code stays working with all this infrastructure and details?
Things like running synthetic workloads and getting a short sequence known to have these new packet types, checking if the hardware performing the tests is capable of generating such traces, etc?
- Arnaldo
Hunter, Adrian
reviewerRE: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
-----Original Message-----
From: Arnaldo Carvalho de Melo [mailto:[email protected]]
Sent: Friday, June 30, 2017 5:54 PM
To: Hunter, Adrian <[email protected]>
Cc: Andi Kleen <[email protected]>; [email protected]
Subject: Re: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
Quoted 10 lines
Em Fri, Jun 30, 2017 at 11:51:22AM +0300, Adrian Hunter escreveu:
Quoted 8 lines · Arnaldo Carvalho de Melo
Quoted 7 lines
Em Thu, Jun 29, 2017 at 05:13:54PM -0300, Arnaldo Carvalho de Melo escreveu:
Ok, passes all tests (gcc, clang where available) on:41 ubuntu:16.10: Ok
42 ubuntu:17.04: OkCan you provide new versions for the relevant patches?
Quoted 7 lines
Quoted 1 line
I have sent new versions of the 2 patches affected.
Thanks, a grafted those in my branch, will perform the usual build tests, then try it on a kaby lake machine.
Have you thought about further "perf test" test cases to make sure this code stays working with all this infrastructure and details?
Things like running synthetic workloads and getting a short sequence known to have these new packet types, checking if the hardware performing the tests is capable of generating such traces, etc?
The power events might not occur. Ptwrite and cbr might be possible. Perhaps simpler to just synthesize and then parse the events back to check them.
Adrian Hunter
reviewerPATCH v3 25/37 perf script: Add synthesized Intel PT power and ptwrite events
In reply to Adrian HunterAdd definitions for synthesized Intel PT events for power and ptwrite.
---
Changes in V3:
Avoid using __packed
tools/perf/builtin-script.c | 114 +++++++++++++++++++++++++++++++++++++++++- tools/perf/util/event.h | 118 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 231 insertions(+), 1 deletion(-)
tools/perf/builtin-script.c +113 -1
@@ -1203,10 +1203,122 @@ static void print_sample_bpf_output(struct perf_sample *sample) (char *)(sample->raw_data)); } -static void print_sample_synth (struct perf_sample *sample__maybe_unused , +static void print_sample_spacing (int len,int spacing) +{ +if (len >0 && len < spacing) +printf ("%*s" , spacing - len,"" ); +} + +static void print_sample_pt_spacing (int len) +{ +print_sample_spacing (len,34 ); +} + +static void print_sample_synth_ptwrite (struct perf_sample *sample) +{ +struct perf_synth_intel_ptwrite *data =perf_sample__synth_ptr (sample); +int len; + +if (perf_sample__bad_synth_size (sample, *data)) +return ; + + len =printf (" IP: %u payload: %#" PRIx64" " , + data->ip,le64_to_cpu (data->payload)); +print_sample_pt_spacing (len); +} + +static void print_sample_synth_mwait (struct perf_sample *sample) +{ +struct perf_synth_intel_mwait *data =perf_sample__synth_ptr (sample); +int len; + +if (perf_sample__bad_synth_size (sample, *data)) +return ; + + len =printf (" hints: %#x extensions: %#x " , + data->hints, data->extensions); +print_sample_pt_spacing (len); +} + +static void print_sample_synth_pwre (struct perf_sample *sample) +{ +struct perf_synth_intel_pwre *data =perf_sample__synth_ptr (sample); +int len; + +if (perf_sample__bad_synth_size (sample, *data)) +return ; + + len =printf (" hw: %u cstate: %u sub-cstate: %u " , + data->hw, data->cstate, data->subcstate); +print_sample_pt_spacing (len); +} + +static void print_sample_synth_exstop (struct perf_sample *sample) +{ +struct perf_synth_intel_exstop *data =perf_sample__synth_ptr (sample); +int len; + +if (perf_sample__bad_synth_size (sample, *data)) +return ; + + len =printf (" IP: %u " , data->ip); +print_sample_pt_spacing (len); +} + +static void print_sample_synth_pwrx (struct perf_sample *sample) +{ +struct perf_synth_intel_pwrx *data =perf_sample__synth_ptr (sample); +int len; + +if (perf_sample__bad_synth_size (sample, *data)) +return ; + + len =printf (" deepest cstate: %u last cstate: %u wake reason: %#x " , + data->deepest_cstate, data->last_cstate, + data->wake_reason); +print_sample_pt_spacing (len); +} + +static void print_sample_synth_cbr (struct perf_sample *sample) +{ +struct perf_synth_intel_cbr *data =perf_sample__synth_ptr (sample); +unsigned int percent, freq; +int len; + +if (perf_sample__bad_synth_size (sample, *data)) +return ; + + freq = (le32_to_cpu (data->freq) +500 ) /1000 ; + len =printf (" cbr: %2u freq: %4u MHz " , data->cbr, freq); +if (data->max_nonturbo) { + percent = (5 + (1000 * data->cbr) / data->max_nonturbo) /10 ; + len +=printf ("(%3u%%) " , percent); + } +print_sample_pt_spacing (len); +} + +static void print_sample_synth (struct perf_sample *sample,struct perf_evsel *evsel) {switch (evsel->attr.config) { +case PERF_SYNTH_INTEL_PTWRITE : +print_sample_synth_ptwrite (sample); +break ; +case PERF_SYNTH_INTEL_MWAIT : +print_sample_synth_mwait (sample); +break ; +case PERF_SYNTH_INTEL_PWRE : +print_sample_synth_pwre (sample); +break ; +case PERF_SYNTH_INTEL_EXSTOP : +print_sample_synth_exstop (sample); +break ; +case PERF_SYNTH_INTEL_PWRX : +print_sample_synth_pwrx (sample); +break ; +case PERF_SYNTH_INTEL_CBR : +print_sample_synth_cbr (sample); +break ;default :break ; }
tools/perf/util/event.h +118 -0
124 lines not on this page · raw message
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf script: Add synthesized Intel PT power and ptwrite events
perf script: Add synthesized Intel PT power and ptwrite events
Commit-ID: 65c5e18f9df078f40abd22a3f6983eb9804b6d02 Gitweb: http://git.kernel.org/tip/65c5e18f9df078f40abd22a3f6983eb9804b6d02 Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 30 Jun 2017 11:36:42 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 30 Jun 2017 11:40:20 -0300
perf script: Add synthesized Intel PT power and ptwrite events
Add definitions for synthesized Intel PT events for power and ptwrite.
--- tools/perf/builtin-script.c | 114 +++++++++++++++++++++++++++++++++++++++++- tools/perf/util/event.h | 118 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 231 insertions(+), 1 deletion(-)
tools/perf/builtin-script.c +113 -1
@@ -1203,10 +1203,122 @@ static void print_sample_bpf_output(struct perf_sample *sample) (char *)(sample->raw_data)); } -static void print_sample_synth (struct perf_sample *sample__maybe_unused , +static void print_sample_spacing (int len,int spacing) +{ +if (len >0 && len < spacing) +printf ("%*s" , spacing - len,"" ); +} + +static void print_sample_pt_spacing (int len) +{ +print_sample_spacing (len,34 ); +} + +static void print_sample_synth_ptwrite (struct perf_sample *sample) +{ +struct perf_synth_intel_ptwrite *data =perf_sample__synth_ptr (sample); +int len; + +if (perf_sample__bad_synth_size (sample, *data)) +return ; + + len =printf (" IP: %u payload: %#" PRIx64" " , + data->ip,le64_to_cpu (data->payload)); +print_sample_pt_spacing (len); +} + +static void print_sample_synth_mwait (struct perf_sample *sample) +{ +struct perf_synth_intel_mwait *data =perf_sample__synth_ptr (sample); +int len; + +if (perf_sample__bad_synth_size (sample, *data)) +return ; + + len =printf (" hints: %#x extensions: %#x " , + data->hints, data->extensions); +print_sample_pt_spacing (len); +} + +static void print_sample_synth_pwre (struct perf_sample *sample) +{ +struct perf_synth_intel_pwre *data =perf_sample__synth_ptr (sample); +int len; + +if (perf_sample__bad_synth_size (sample, *data)) +return ; + + len =printf (" hw: %u cstate: %u sub-cstate: %u " , + data->hw, data->cstate, data->subcstate); +print_sample_pt_spacing (len); +} + +static void print_sample_synth_exstop (struct perf_sample *sample) +{ +struct perf_synth_intel_exstop *data =perf_sample__synth_ptr (sample); +int len; + +if (perf_sample__bad_synth_size (sample, *data)) +return ; + + len =printf (" IP: %u " , data->ip); +print_sample_pt_spacing (len); +} + +static void print_sample_synth_pwrx (struct perf_sample *sample) +{ +struct perf_synth_intel_pwrx *data =perf_sample__synth_ptr (sample); +int len; + +if (perf_sample__bad_synth_size (sample, *data)) +return ; + + len =printf (" deepest cstate: %u last cstate: %u wake reason: %#x " , + data->deepest_cstate, data->last_cstate, + data->wake_reason); +print_sample_pt_spacing (len); +} + +static void print_sample_synth_cbr (struct perf_sample *sample) +{ +struct perf_synth_intel_cbr *data =perf_sample__synth_ptr (sample); +unsigned int percent, freq; +int len; + +if (perf_sample__bad_synth_size (sample, *data)) +return ; + + freq = (le32_to_cpu (data->freq) +500 ) /1000 ; + len =printf (" cbr: %2u freq: %4u MHz " , data->cbr, freq); +if (data->max_nonturbo) { + percent = (5 + (1000 * data->cbr) / data->max_nonturbo) /10 ; + len +=printf ("(%3u%%) " , percent); + } +print_sample_pt_spacing (len); +} + +static void print_sample_synth (struct perf_sample *sample,struct perf_evsel *evsel) {switch (evsel->attr.config) { +case PERF_SYNTH_INTEL_PTWRITE : +print_sample_synth_ptwrite (sample); +break ; +case PERF_SYNTH_INTEL_MWAIT : +print_sample_synth_mwait (sample); +break ; +case PERF_SYNTH_INTEL_PWRE : +print_sample_synth_pwre (sample); +break ; +case PERF_SYNTH_INTEL_EXSTOP : +print_sample_synth_exstop (sample); +break ; +case PERF_SYNTH_INTEL_PWRX : +print_sample_synth_pwrx (sample); +break ; +case PERF_SYNTH_INTEL_CBR : +print_sample_synth_cbr (sample); +break ;default :break ; }
tools/perf/util/event.h +118 -0
124 lines not on this page · raw message
Adrian Hunter
reviewerPATCH v2 26/37 perf intel-pt: Factor out common code synthesizing event samples
In reply to Adrian HunterFactor out common code in functions synthesizing event samples i.e. intel_pt_synth_branch_sample(), intel_pt_synth_instruction_sample() and intel_pt_synth_transaction_sample().
--- tools/perf/util/intel-pt.c | 222 ++++++++++++++++++++------------------------- 1 file changed, 100 insertions(+), 122 deletions(-)
tools/perf/util/intel-pt.c +100 -122
@@ -1058,6 +1058,36 @@ static void intel_pt_update_last_branch_rb(struct intel_pt_queue *ptq) bs->nr +=1 ; } +static inline bool intel_pt_skip_event (struct intel_pt *pt) +{ +return pt->synth_opts.initial_skip && + pt->num_events++ < pt->synth_opts.initial_skip; +} + +static void intel_pt_prep_b_sample (struct intel_pt *pt, +struct intel_pt_queue *ptq, +union perf_event *event, +struct perf_sample *sample) +{ + event->sample.header.type =PERF_RECORD_SAMPLE ; + event->sample.header.misc =PERF_RECORD_MISC_USER ; + event->sample.header.size =sizeof (struct perf_event_header ); + +if (!pt->timeless_decoding) + sample->time =tsc_to_perf_time (ptq->timestamp, &pt->tc); + + sample->cpumode =PERF_RECORD_MISC_USER ; + sample->ip = ptq->state->from_ip; + sample->pid = ptq->pid; + sample->tid = ptq->tid; + sample->addr = ptq->state->to_ip; + sample->period =1 ; + sample->cpu = ptq->cpu; + sample->flags = ptq->flags; + sample->insn_len = ptq->insn_len; +memcpy (sample->insn, ptq->insn,INTEL_PT_INSN_BUF_SZ ); +} +static int intel_pt_inject_event (union perf_event *event,struct perf_sample *sample,u64 type,bool swapped)
@@ -1066,9 +1096,35 @@ static int intel_pt_inject_event(union perf_event *event,return perf_event__synthesize_sample (event, type,0 , sample, swapped); } -static int intel_pt_synth_branch_sample (struct intel_pt_queue *ptq) +static inline int intel_pt_opt_inject (struct intel_pt *pt, +union perf_event *event, +struct perf_sample *sample,u64 type) +{ +if (!pt->synth_opts.inject) +return 0 ; + +return intel_pt_inject_event (event, sample, type, pt->synth_needs_swap); +} + +static int intel_pt_deliver_synth_b_event (struct intel_pt *pt, +union perf_event *event, +struct perf_sample *sample,u64 type) {int ret; + + ret =intel_pt_opt_inject (pt, event, sample, type); +if (ret) +return ret; + + ret =perf_session__deliver_synth_event (pt->session, event, sample); +if (ret) +pr_err ("Intel PT: failed to deliver event, error %d\n" , ret); + +return ret; +} + +static int intel_pt_synth_branch_sample (struct intel_pt_queue *ptq) +{struct intel_pt *pt = ptq->pt;union perf_event *event = ptq->event_buf;struct perf_sample sample = { .ip =0 , };
@@ -1080,29 +1136,13 @@ static int intel_pt_synth_branch_sample(struct intel_pt_queue *ptq)if (pt->branches_filter && !(pt->branches_filter & ptq->flags))return 0 ; -if (pt->synth_opts.initial_skip && - pt->num_events++ < pt->synth_opts.initial_skip) +if (intel_pt_skip_event (pt))return 0 ; - event->sample.header.type =PERF_RECORD_SAMPLE ; - event->sample.header.misc =PERF_RECORD_MISC_USER ; - event->sample.header.size =sizeof (struct perf_event_header ); +intel_pt_prep_b_sample (pt, ptq, event, &sample); -if (!pt->timeless_decoding) - sample.time =tsc_to_perf_time (ptq->timestamp, &pt->tc); - - sample.cpumode =PERF_RECORD_MISC_USER ; - sample.ip = ptq->state->from_ip; - sample.pid = ptq->pid; - sample.tid = ptq->tid; - sample.addr = ptq->state->to_ip; sample.id = ptq->pt->branches_id; sample.stream_id = ptq->pt->branches_id; - sample.period =1 ; - sample.cpu = ptq->cpu; - sample.flags = ptq->flags; - sample.insn_len = ptq->insn_len; -memcpy (sample.insn, ptq->insn,INTEL_PT_INSN_BUF_SZ );/* * perf report cannot handle events without a branch stack when using
@@ -1119,78 +1159,38 @@ static int intel_pt_synth_branch_sample(struct intel_pt_queue *ptq) sample.branch_stack = (struct branch_stack *)&dummy_bs; } -if (pt->synth_opts.inject) { - ret =intel_pt_inject_event (event, &sample, - pt->branches_sample_type, - pt->synth_needs_swap); -if (ret) -return ret; - } - - ret =perf_session__deliver_synth_event (pt->session, event, &sample); -if (ret) -pr_err ("Intel Processor Trace: failed to deliver branch event, error %d\n" , - ret); - -return ret; +return intel_pt_deliver_synth_b_event (pt, event, &sample, + pt->branches_sample_type); } -static int intel_pt_synth_instruction_sample (struct intel_pt_queue *ptq) +static void intel_pt_prep_sample (struct intel_pt *pt, +struct intel_pt_queue *ptq, +union perf_event *event, +struct perf_sample *sample) { -int ret; -struct intel_pt *pt = ptq->pt; -union perf_event *event = ptq->event_buf; -struct perf_sample sample = { .ip =0 , }; - -if (pt->synth_opts.initial_skip && - pt->num_events++ < pt->synth_opts.initial_skip) -return 0 ; - - event->sample.header.type =PERF_RECORD_SAMPLE ; - event->sample.header.misc =PERF_RECORD_MISC_USER ; - event->sample.header.size =sizeof (struct perf_event_header ); - -if (!pt->timeless_decoding) - sample.time =tsc_to_perf_time (ptq->timestamp, &pt->tc); - - sample.cpumode =PERF_RECORD_MISC_USER ; - sample.ip = ptq->state->from_ip; - sample.pid = ptq->pid; - sample.tid = ptq->tid; - sample.addr = ptq->state->to_ip; - sample.id = ptq->pt->instructions_id; - sample.stream_id = ptq->pt->instructions_id; - sample.period = ptq->state->tot_insn_cnt - ptq->last_insn_cnt; - sample.cpu = ptq->cpu; - sample.flags = ptq->flags; - sample.insn_len = ptq->insn_len; -memcpy (sample.insn, ptq->insn,INTEL_PT_INSN_BUF_SZ ); - - ptq->last_insn_cnt = ptq->state->tot_insn_cnt; +intel_pt_prep_b_sample (pt, ptq, event, sample);if (pt->synth_opts.callchain) {thread_stack__sample (ptq->thread, ptq->chain, - pt->synth_opts.callchain_sz, sample.ip); - sample.callchain = ptq->chain; + pt->synth_opts.callchain_sz, sample->ip); + sample->callchain = ptq->chain; }if (pt->synth_opts.last_branch) {intel_pt_copy_last_branch_rb (ptq); - sample.branch_stack = ptq->last_branch; + sample->branch_stack = ptq->last_branch; } +} -if (pt->synth_opts.inject) { - ret =intel_pt_inject_event (event, &sample, - pt->instructions_sample_type, - pt->synth_needs_swap); -if (ret) -return ret; - } +static inline int intel_pt_deliver_synth_event (struct intel_pt *pt, +struct intel_pt_queue *ptq, +union perf_event *event, +struct perf_sample *sample, +u64 type) +{ +int ret; - ret =perf_session__deliver_synth_event (pt->session, event, &sample); -if (ret) -pr_err ("Intel Processor Trace: failed to deliver instruction event, error %d\n" , - ret); + ret =intel_pt_deliver_synth_b_event (pt, event, sample, type);if (pt->synth_opts.last_branch)intel_pt_reset_last_branch_rb (ptq);
@@ -1198,65 +1198,43 @@ static int intel_pt_synth_instruction_sample(struct intel_pt_queue *ptq)return ret; } -static int intel_pt_synth_transaction_sample (struct intel_pt_queue *ptq) +static int intel_pt_synth_instruction_sample (struct intel_pt_queue *ptq) { -int ret;struct intel_pt *pt = ptq->pt;union perf_event *event = ptq->event_buf;struct perf_sample sample = { .ip =0 , }; -if (pt->synth_opts.initial_skip && - pt->num_events++ < pt->synth_opts.initial_skip) +if (intel_pt_skip_event (pt))return 0 ; - event->sample.header.type =PERF_RECORD_SAMPLE ; - event->sample.header.misc =PERF_RECORD_MISC_USER ; - event->sample.header.size =sizeof (struct perf_event_header ); +intel_pt_prep_sample (pt, ptq, event, &sample); -if (!pt->timeless_decoding) - sample.time =tsc_to_perf_time (ptq->timestamp, &pt->tc); + sample.id = ptq->pt->instructions_id; + sample.stream_id = ptq->pt->instructions_id; + sample.period = ptq->state->tot_insn_cnt - ptq->last_insn_cnt; - sample.cpumode =PERF_RECORD_MISC_USER ; - sample.ip = ptq->state->from_ip; - sample.pid = ptq->pid; - sample.tid = ptq->tid; - sample.addr = ptq->state->to_ip; - sample.id = ptq->pt->transactions_id; - sample.stream_id = ptq->pt->transactions_id; - sample.period =1 ; - sample.cpu = ptq->cpu; - sample.flags = ptq->flags; - sample.insn_len = ptq->insn_len; -memcpy (sample.insn, ptq->insn,INTEL_PT_INSN_BUF_SZ ); + ptq->last_insn_cnt = ptq->state->tot_insn_cnt; -if (pt->synth_opts.callchain) { -thread_stack__sample (ptq->thread, ptq->chain, - pt->synth_opts.callchain_sz, sample.ip); - sample.callchain = ptq->chain; - } +return intel_pt_deliver_synth_event (pt, ptq, event, &sample, + pt->instructions_sample_type); +} -if (pt->synth_opts.last_branch) { -intel_pt_copy_last_branch_rb (ptq); - sample.branch_stack = ptq->last_branch; - } +static int intel_pt_synth_transaction_sample (struct intel_pt_queue *ptq) +{ +struct intel_pt *pt = ptq->pt; +union perf_event *event = ptq->event_buf; +struct perf_sample sample = { .ip =0 , }; -if (pt->synth_opts.inject) { - ret =intel_pt_inject_event (event, &sample, - pt->transactions_sample_type, - pt->synth_needs_swap); -if (ret) -return ret; - } +if (intel_pt_skip_event (pt)) +return 0 ; - ret =perf_session__deliver_synth_event (pt->session, event, &sample); -if (ret) -pr_err ("Intel Processor Trace: failed to deliver transaction event, error %d\n" , - ret); +intel_pt_prep_sample (pt, ptq, event, &sample); -if (pt->synth_opts.last_branch) -intel_pt_reset_last_branch_rb (ptq); + sample.id = ptq->pt->transactions_id; + sample.stream_id = ptq->pt->transactions_id; -return ret; +return intel_pt_deliver_synth_event (pt, ptq, event, &sample, + pt->transactions_sample_type); } static int intel_pt_synth_error(struct intel_pt *pt, int code, int cpu,
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Factor out common code synthesizing event samples
perf intel-pt: Factor out common code synthesizing event samples
Commit-ID: 0f3e53799cd5fad1dcc8c077a3d9cc260243328f Gitweb: http://git.kernel.org/tip/0f3e53799cd5fad1dcc8c077a3d9cc260243328f Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:27 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 30 Jun 2017 11:44:33 -0300
perf intel-pt: Factor out common code synthesizing event samples
Factor out common code in functions synthesizing event samples i.e. intel_pt_synth_branch_sample(), intel_pt_synth_instruction_sample() and intel_pt_synth_transaction_sample().
--- tools/perf/util/intel-pt.c | 222 ++++++++++++++++++++------------------------- 1 file changed, 100 insertions(+), 122 deletions(-)
tools/perf/util/intel-pt.c +100 -122
@@ -1058,6 +1058,36 @@ static void intel_pt_update_last_branch_rb(struct intel_pt_queue *ptq) bs->nr +=1 ; } +static inline bool intel_pt_skip_event (struct intel_pt *pt) +{ +return pt->synth_opts.initial_skip && + pt->num_events++ < pt->synth_opts.initial_skip; +} + +static void intel_pt_prep_b_sample (struct intel_pt *pt, +struct intel_pt_queue *ptq, +union perf_event *event, +struct perf_sample *sample) +{ + event->sample.header.type =PERF_RECORD_SAMPLE ; + event->sample.header.misc =PERF_RECORD_MISC_USER ; + event->sample.header.size =sizeof (struct perf_event_header ); + +if (!pt->timeless_decoding) + sample->time =tsc_to_perf_time (ptq->timestamp, &pt->tc); + + sample->cpumode =PERF_RECORD_MISC_USER ; + sample->ip = ptq->state->from_ip; + sample->pid = ptq->pid; + sample->tid = ptq->tid; + sample->addr = ptq->state->to_ip; + sample->period =1 ; + sample->cpu = ptq->cpu; + sample->flags = ptq->flags; + sample->insn_len = ptq->insn_len; +memcpy (sample->insn, ptq->insn,INTEL_PT_INSN_BUF_SZ ); +} +static int intel_pt_inject_event (union perf_event *event,struct perf_sample *sample,u64 type,bool swapped)
@@ -1066,9 +1096,35 @@ static int intel_pt_inject_event(union perf_event *event,return perf_event__synthesize_sample (event, type,0 , sample, swapped); } -static int intel_pt_synth_branch_sample (struct intel_pt_queue *ptq) +static inline int intel_pt_opt_inject (struct intel_pt *pt, +union perf_event *event, +struct perf_sample *sample,u64 type) +{ +if (!pt->synth_opts.inject) +return 0 ; + +return intel_pt_inject_event (event, sample, type, pt->synth_needs_swap); +} + +static int intel_pt_deliver_synth_b_event (struct intel_pt *pt, +union perf_event *event, +struct perf_sample *sample,u64 type) {int ret; + + ret =intel_pt_opt_inject (pt, event, sample, type); +if (ret) +return ret; + + ret =perf_session__deliver_synth_event (pt->session, event, sample); +if (ret) +pr_err ("Intel PT: failed to deliver event, error %d\n" , ret); + +return ret; +} + +static int intel_pt_synth_branch_sample (struct intel_pt_queue *ptq) +{struct intel_pt *pt = ptq->pt;union perf_event *event = ptq->event_buf;struct perf_sample sample = { .ip =0 , };
@@ -1080,29 +1136,13 @@ static int intel_pt_synth_branch_sample(struct intel_pt_queue *ptq)if (pt->branches_filter && !(pt->branches_filter & ptq->flags))return 0 ; -if (pt->synth_opts.initial_skip && - pt->num_events++ < pt->synth_opts.initial_skip) +if (intel_pt_skip_event (pt))return 0 ; - event->sample.header.type =PERF_RECORD_SAMPLE ; - event->sample.header.misc =PERF_RECORD_MISC_USER ; - event->sample.header.size =sizeof (struct perf_event_header ); +intel_pt_prep_b_sample (pt, ptq, event, &sample); -if (!pt->timeless_decoding) - sample.time =tsc_to_perf_time (ptq->timestamp, &pt->tc); - - sample.cpumode =PERF_RECORD_MISC_USER ; - sample.ip = ptq->state->from_ip; - sample.pid = ptq->pid; - sample.tid = ptq->tid; - sample.addr = ptq->state->to_ip; sample.id = ptq->pt->branches_id; sample.stream_id = ptq->pt->branches_id; - sample.period =1 ; - sample.cpu = ptq->cpu; - sample.flags = ptq->flags; - sample.insn_len = ptq->insn_len; -memcpy (sample.insn, ptq->insn,INTEL_PT_INSN_BUF_SZ );/* * perf report cannot handle events without a branch stack when using
@@ -1119,78 +1159,38 @@ static int intel_pt_synth_branch_sample(struct intel_pt_queue *ptq) sample.branch_stack = (struct branch_stack *)&dummy_bs; } -if (pt->synth_opts.inject) { - ret =intel_pt_inject_event (event, &sample, - pt->branches_sample_type, - pt->synth_needs_swap); -if (ret) -return ret; - } - - ret =perf_session__deliver_synth_event (pt->session, event, &sample); -if (ret) -pr_err ("Intel Processor Trace: failed to deliver branch event, error %d\n" , - ret); - -return ret; +return intel_pt_deliver_synth_b_event (pt, event, &sample, + pt->branches_sample_type); } -static int intel_pt_synth_instruction_sample (struct intel_pt_queue *ptq) +static void intel_pt_prep_sample (struct intel_pt *pt, +struct intel_pt_queue *ptq, +union perf_event *event, +struct perf_sample *sample) { -int ret; -struct intel_pt *pt = ptq->pt; -union perf_event *event = ptq->event_buf; -struct perf_sample sample = { .ip =0 , }; - -if (pt->synth_opts.initial_skip && - pt->num_events++ < pt->synth_opts.initial_skip) -return 0 ; - - event->sample.header.type =PERF_RECORD_SAMPLE ; - event->sample.header.misc =PERF_RECORD_MISC_USER ; - event->sample.header.size =sizeof (struct perf_event_header ); - -if (!pt->timeless_decoding) - sample.time =tsc_to_perf_time (ptq->timestamp, &pt->tc); - - sample.cpumode =PERF_RECORD_MISC_USER ; - sample.ip = ptq->state->from_ip; - sample.pid = ptq->pid; - sample.tid = ptq->tid; - sample.addr = ptq->state->to_ip; - sample.id = ptq->pt->instructions_id; - sample.stream_id = ptq->pt->instructions_id; - sample.period = ptq->state->tot_insn_cnt - ptq->last_insn_cnt; - sample.cpu = ptq->cpu; - sample.flags = ptq->flags; - sample.insn_len = ptq->insn_len; -memcpy (sample.insn, ptq->insn,INTEL_PT_INSN_BUF_SZ ); - - ptq->last_insn_cnt = ptq->state->tot_insn_cnt; +intel_pt_prep_b_sample (pt, ptq, event, sample);if (pt->synth_opts.callchain) {thread_stack__sample (ptq->thread, ptq->chain, - pt->synth_opts.callchain_sz, sample.ip); - sample.callchain = ptq->chain; + pt->synth_opts.callchain_sz, sample->ip); + sample->callchain = ptq->chain; }if (pt->synth_opts.last_branch) {intel_pt_copy_last_branch_rb (ptq); - sample.branch_stack = ptq->last_branch; + sample->branch_stack = ptq->last_branch; } +} -if (pt->synth_opts.inject) { - ret =intel_pt_inject_event (event, &sample, - pt->instructions_sample_type, - pt->synth_needs_swap); -if (ret) -return ret; - } +static inline int intel_pt_deliver_synth_event (struct intel_pt *pt, +struct intel_pt_queue *ptq, +union perf_event *event, +struct perf_sample *sample, +u64 type) +{ +int ret; - ret =perf_session__deliver_synth_event (pt->session, event, &sample); -if (ret) -pr_err ("Intel Processor Trace: failed to deliver instruction event, error %d\n" , - ret); + ret =intel_pt_deliver_synth_b_event (pt, event, sample, type);if (pt->synth_opts.last_branch)intel_pt_reset_last_branch_rb (ptq);
@@ -1198,65 +1198,43 @@ static int intel_pt_synth_instruction_sample(struct intel_pt_queue *ptq)return ret; } -static int intel_pt_synth_transaction_sample (struct intel_pt_queue *ptq) +static int intel_pt_synth_instruction_sample (struct intel_pt_queue *ptq) { -int ret;struct intel_pt *pt = ptq->pt;union perf_event *event = ptq->event_buf;struct perf_sample sample = { .ip =0 , }; -if (pt->synth_opts.initial_skip && - pt->num_events++ < pt->synth_opts.initial_skip) +if (intel_pt_skip_event (pt))return 0 ; - event->sample.header.type =PERF_RECORD_SAMPLE ; - event->sample.header.misc =PERF_RECORD_MISC_USER ; - event->sample.header.size =sizeof (struct perf_event_header ); +intel_pt_prep_sample (pt, ptq, event, &sample); -if (!pt->timeless_decoding) - sample.time =tsc_to_perf_time (ptq->timestamp, &pt->tc); + sample.id = ptq->pt->instructions_id; + sample.stream_id = ptq->pt->instructions_id; + sample.period = ptq->state->tot_insn_cnt - ptq->last_insn_cnt; - sample.cpumode =PERF_RECORD_MISC_USER ; - sample.ip = ptq->state->from_ip; - sample.pid = ptq->pid; - sample.tid = ptq->tid; - sample.addr = ptq->state->to_ip; - sample.id = ptq->pt->transactions_id; - sample.stream_id = ptq->pt->transactions_id; - sample.period =1 ; - sample.cpu = ptq->cpu; - sample.flags = ptq->flags; - sample.insn_len = ptq->insn_len; -memcpy (sample.insn, ptq->insn,INTEL_PT_INSN_BUF_SZ ); + ptq->last_insn_cnt = ptq->state->tot_insn_cnt; -if (pt->synth_opts.callchain) { -thread_stack__sample (ptq->thread, ptq->chain, - pt->synth_opts.callchain_sz, sample.ip); - sample.callchain = ptq->chain; - } +return intel_pt_deliver_synth_event (pt, ptq, event, &sample, + pt->instructions_sample_type); +} -if (pt->synth_opts.last_branch) { -intel_pt_copy_last_branch_rb (ptq); - sample.branch_stack = ptq->last_branch; - } +static int intel_pt_synth_transaction_sample (struct intel_pt_queue *ptq) +{ +struct intel_pt *pt = ptq->pt; +union perf_event *event = ptq->event_buf; +struct perf_sample sample = { .ip =0 , }; -if (pt->synth_opts.inject) { - ret =intel_pt_inject_event (event, &sample, - pt->transactions_sample_type, - pt->synth_needs_swap); -if (ret) -return ret; - } +if (intel_pt_skip_event (pt)) +return 0 ; - ret =perf_session__deliver_synth_event (pt->session, event, &sample); -if (ret) -pr_err ("Intel Processor Trace: failed to deliver transaction event, error %d\n" , - ret); +intel_pt_prep_sample (pt, ptq, event, &sample); -if (pt->synth_opts.last_branch) -intel_pt_reset_last_branch_rb (ptq); + sample.id = ptq->pt->transactions_id; + sample.stream_id = ptq->pt->transactions_id; -return ret; +return intel_pt_deliver_synth_event (pt, ptq, event, &sample, + pt->transactions_sample_type); } static int intel_pt_synth_error(struct intel_pt *pt, int code, int cpu,
Adrian Hunter
reviewerPATCH v2 27/37 perf intel-pt: Remove unused instructions_sample_period
In reply to Adrian HunterRemove unused struct intel_pt member instructions_sample_period.
--- tools/perf/util/intel-pt.c | 2 -- 1 file changed, 2 deletions(-)
tools/perf/util/intel-pt.c +0 -2
@@ -81,7 +81,6 @@ struct intel_pt {bool sample_instructions;u64 instructions_sample_type; -u64 instructions_sample_period;u64 instructions_id;bool sample_branches;
@@ -1978,7 +1977,6 @@ static int intel_pt_synth_events(struct intel_pt *pt,intel_pt_ns_to_ticks (pt, pt->synth_opts.period); else attr.sample_period = pt->synth_opts.period; - pt->instructions_sample_period = attr.sample_period;if (pt->synth_opts.callchain) attr.sample_type |=PERF_SAMPLE_CALLCHAIN ;if (pt->synth_opts.last_branch)
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Remove unused instructions_sample_period
perf intel-pt: Remove unused instructions_sample_period
Commit-ID: f90d07a9f6d76e46ed99b4103747031394b16dd7 Gitweb: http://git.kernel.org/tip/f90d07a9f6d76e46ed99b4103747031394b16dd7 Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:28 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 30 Jun 2017 11:44:33 -0300
perf intel-pt: Remove unused instructions_sample_period
Remove unused struct intel_pt member instructions_sample_period.
--- tools/perf/util/intel-pt.c | 2 -- 1 file changed, 2 deletions(-)
tools/perf/util/intel-pt.c +0 -2
@@ -81,7 +81,6 @@ struct intel_pt {bool sample_instructions;u64 instructions_sample_type; -u64 instructions_sample_period;u64 instructions_id;bool sample_branches;
@@ -1978,7 +1977,6 @@ static int intel_pt_synth_events(struct intel_pt *pt,intel_pt_ns_to_ticks (pt, pt->synth_opts.period); else attr.sample_period = pt->synth_opts.period; - pt->instructions_sample_period = attr.sample_period;if (pt->synth_opts.callchain) attr.sample_type |=PERF_SAMPLE_CALLCHAIN ;if (pt->synth_opts.last_branch)
Adrian Hunter
reviewerPATCH v2 28/37 perf intel-pt: Join needlessly wrapped lines
In reply to Adrian HunterJoin needlessly wrapped lines.
--- tools/perf/util/intel-pt.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
tools/perf/util/intel-pt.c +2 -4
@@ -1298,15 +1298,13 @@ static int intel_pt_sample(struct intel_pt_queue *ptq) ptq->have_sample = false; -if (pt->sample_instructions && - (state->type &INTEL_PT_INSTRUCTION )) { +if (pt->sample_instructions && (state->type &INTEL_PT_INSTRUCTION )) { err =intel_pt_synth_instruction_sample (ptq);if (err)return err; } -if (pt->sample_transactions && - (state->type &INTEL_PT_TRANSACTION )) { +if (pt->sample_transactions && (state->type &INTEL_PT_TRANSACTION )) { err =intel_pt_synth_transaction_sample (ptq);if (err)return err;
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Join needlessly wrapped lines
perf intel-pt: Join needlessly wrapped lines
Commit-ID: 406a180501f6d0d4e43d5acc5f580abfc95c742d Gitweb: http://git.kernel.org/tip/406a180501f6d0d4e43d5acc5f580abfc95c742d Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:29 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 30 Jun 2017 11:44:34 -0300
perf intel-pt: Join needlessly wrapped lines
Join needlessly wrapped lines.
--- tools/perf/util/intel-pt.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
tools/perf/util/intel-pt.c +2 -4
@@ -1298,15 +1298,13 @@ static int intel_pt_sample(struct intel_pt_queue *ptq) ptq->have_sample = false; -if (pt->sample_instructions && - (state->type &INTEL_PT_INSTRUCTION )) { +if (pt->sample_instructions && (state->type &INTEL_PT_INSTRUCTION )) { err =intel_pt_synth_instruction_sample (ptq);if (err)return err; } -if (pt->sample_transactions && - (state->type &INTEL_PT_TRANSACTION )) { +if (pt->sample_transactions && (state->type &INTEL_PT_TRANSACTION )) { err =intel_pt_synth_transaction_sample (ptq);if (err)return err;
Adrian Hunter
reviewerPATCH v2 29/37 perf intel-pt: Tidy Intel PT evsel lookup into separate function
In reply to Adrian HunterTidy the lookup of the Intel PT selected event (perf_evsel) into a separate function.
--- tools/perf/util/intel-pt.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
tools/perf/util/intel-pt.c +15 -10
@@ -1922,24 +1922,29 @@ static int intel_pt_synth_event(struct perf_session *session, &id, intel_pt_event_synth); } +static struct perf_evsel *intel_pt_evsel (struct intel_pt *pt, +struct perf_evlist *evlist) +{ +struct perf_evsel *evsel; + +evlist__for_each_entry (evlist, evsel) { +if (evsel->attr.type == pt->pmu_type && evsel->ids) +return evsel; + } + +return NULL ; +} +static int intel_pt_synth_events (struct intel_pt *pt,struct perf_session *session) {struct perf_evlist *evlist = session->evlist; -struct perf_evsel *evsel; +struct perf_evsel *evsel =intel_pt_evsel (pt, evlist);struct perf_event_attr attr; -bool found = false;u64 id;int err; -evlist__for_each_entry (evlist, evsel) { -if (evsel->attr.type == pt->pmu_type && evsel->ids) { - found = true; -break ; - } - } - -if (!found) { +if (!evsel) {pr_debug ("There are no selected events with Intel Processor Trace data\n" );return 0 ; }
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Tidy Intel PT evsel lookup into separate function
perf intel-pt: Tidy Intel PT evsel lookup into separate function
Commit-ID: 85a564d26dfb45bbf0c0095e0fcee3bdc4a49a85 Gitweb: http://git.kernel.org/tip/85a564d26dfb45bbf0c0095e0fcee3bdc4a49a85 Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:30 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 30 Jun 2017 11:44:35 -0300
perf intel-pt: Tidy Intel PT evsel lookup into separate function
Tidy the lookup of the Intel PT selected event (perf_evsel) into a separate function.
--- tools/perf/util/intel-pt.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
tools/perf/util/intel-pt.c +15 -10
@@ -1922,24 +1922,29 @@ static int intel_pt_synth_event(struct perf_session *session, &id, intel_pt_event_synth); } +static struct perf_evsel *intel_pt_evsel (struct intel_pt *pt, +struct perf_evlist *evlist) +{ +struct perf_evsel *evsel; + +evlist__for_each_entry (evlist, evsel) { +if (evsel->attr.type == pt->pmu_type && evsel->ids) +return evsel; + } + +return NULL ; +} +static int intel_pt_synth_events (struct intel_pt *pt,struct perf_session *session) {struct perf_evlist *evlist = session->evlist; -struct perf_evsel *evsel; +struct perf_evsel *evsel =intel_pt_evsel (pt, evlist);struct perf_event_attr attr; -bool found = false;u64 id;int err; -evlist__for_each_entry (evlist, evsel) { -if (evsel->attr.type == pt->pmu_type && evsel->ids) { - found = true; -break ; - } - } - -if (!found) { +if (!evsel) {pr_debug ("There are no selected events with Intel Processor Trace data\n" );return 0 ; }
Adrian Hunter
reviewerPATCH v2 30/37 perf intel-pt: Tidy messages into called function intel_pt_synth_event()
In reply to Adrian HunterTidy print messages into called function intel_pt_synth_event().
--- tools/perf/util/intel-pt.c | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-)
tools/perf/util/intel-pt.c +18 -24
@@ -1910,16 +1910,25 @@ static int intel_pt_event_synth(struct perf_tool *tool, NULL); } -static int intel_pt_synth_event (struct perf_session *session, +static int intel_pt_synth_event (struct perf_session *session,const char *name,struct perf_event_attr *attr,u64 id) {struct intel_pt_synth intel_pt_synth; +int err; + +pr_debug ("Synthesizing '%s' event with id %" PRIu64" sample type %#" PRIx64"\n" , + name, id, (u64 )attr->sample_type);memset (&intel_pt_synth,0 ,sizeof (struct intel_pt_synth )); intel_pt_synth.session = session; -return perf_event__synthesize_attr (&intel_pt_synth.dummy_tool, attr,1 , - &id, intel_pt_event_synth); + err =perf_event__synthesize_attr (&intel_pt_synth.dummy_tool, attr,1 , + &id, intel_pt_event_synth); +if (err) +pr_err ("%s: failed to synthesize '%s' event type\n" , + __func__, name); + +return err; } static struct perf_evsel *intel_pt_evsel(struct intel_pt *pt,
@@ -1984,14 +1993,9 @@ static int intel_pt_synth_events(struct intel_pt *pt, attr.sample_type |=PERF_SAMPLE_CALLCHAIN ;if (pt->synth_opts.last_branch) attr.sample_type |=PERF_SAMPLE_BRANCH_STACK ; -pr_debug ("Synthesizing 'instructions' event with id %" PRIu64" sample type %#" PRIx64"\n" , - id, (u64 )attr.sample_type); - err =intel_pt_synth_event (session, &attr, id); -if (err) { -pr_err ("%s: failed to synthesize 'instructions' event type\n" , - __func__); + err =intel_pt_synth_event (session,"instructions" , &attr, id); +if (err)return err; - } pt->sample_instructions = true; pt->instructions_sample_type = attr.sample_type; pt->instructions_id = id;
@@ -2005,14 +2009,9 @@ static int intel_pt_synth_events(struct intel_pt *pt, attr.sample_type |=PERF_SAMPLE_CALLCHAIN ;if (pt->synth_opts.last_branch) attr.sample_type |=PERF_SAMPLE_BRANCH_STACK ; -pr_debug ("Synthesizing 'transactions' event with id %" PRIu64" sample type %#" PRIx64"\n" , - id, (u64 )attr.sample_type); - err =intel_pt_synth_event (session, &attr, id); -if (err) { -pr_err ("%s: failed to synthesize 'transactions' event type\n" , - __func__); + err =intel_pt_synth_event (session,"transactions" , &attr, id); +if (err)return err; - } pt->sample_transactions = true; pt->transactions_sample_type = attr.sample_type; pt->transactions_id = id;
@@ -2033,14 +2032,9 @@ static int intel_pt_synth_events(struct intel_pt *pt, attr.sample_type |=PERF_SAMPLE_ADDR ; attr.sample_type &= ~(u64 )PERF_SAMPLE_CALLCHAIN ; attr.sample_type &= ~(u64 )PERF_SAMPLE_BRANCH_STACK ; -pr_debug ("Synthesizing 'branches' event with id %" PRIu64" sample type %#" PRIx64"\n" , - id, (u64 )attr.sample_type); - err =intel_pt_synth_event (session, &attr, id); -if (err) { -pr_err ("%s: failed to synthesize 'branches' event type\n" , - __func__); + err =intel_pt_synth_event (session,"branches" , &attr, id); +if (err)return err; - } pt->sample_branches = true; pt->branches_sample_type = attr.sample_type; pt->branches_id = id;
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Tidy messages into called function intel_pt_synth_event()
perf intel-pt: Tidy messages into called function intel_pt_synth_event()
Commit-ID: 63a22cd9f8400fe914ddc3d597d925594f212519 Gitweb: http://git.kernel.org/tip/63a22cd9f8400fe914ddc3d597d925594f212519 Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:31 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 30 Jun 2017 11:44:35 -0300
perf intel-pt: Tidy messages into called function intel_pt_synth_event()
Tidy print messages into called function intel_pt_synth_event().
--- tools/perf/util/intel-pt.c | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-)
tools/perf/util/intel-pt.c +18 -24
@@ -1910,16 +1910,25 @@ static int intel_pt_event_synth(struct perf_tool *tool, NULL); } -static int intel_pt_synth_event (struct perf_session *session, +static int intel_pt_synth_event (struct perf_session *session,const char *name,struct perf_event_attr *attr,u64 id) {struct intel_pt_synth intel_pt_synth; +int err; + +pr_debug ("Synthesizing '%s' event with id %" PRIu64" sample type %#" PRIx64"\n" , + name, id, (u64 )attr->sample_type);memset (&intel_pt_synth,0 ,sizeof (struct intel_pt_synth )); intel_pt_synth.session = session; -return perf_event__synthesize_attr (&intel_pt_synth.dummy_tool, attr,1 , - &id, intel_pt_event_synth); + err =perf_event__synthesize_attr (&intel_pt_synth.dummy_tool, attr,1 , + &id, intel_pt_event_synth); +if (err) +pr_err ("%s: failed to synthesize '%s' event type\n" , + __func__, name); + +return err; } static struct perf_evsel *intel_pt_evsel(struct intel_pt *pt,
@@ -1984,14 +1993,9 @@ static int intel_pt_synth_events(struct intel_pt *pt, attr.sample_type |=PERF_SAMPLE_CALLCHAIN ;if (pt->synth_opts.last_branch) attr.sample_type |=PERF_SAMPLE_BRANCH_STACK ; -pr_debug ("Synthesizing 'instructions' event with id %" PRIu64" sample type %#" PRIx64"\n" , - id, (u64 )attr.sample_type); - err =intel_pt_synth_event (session, &attr, id); -if (err) { -pr_err ("%s: failed to synthesize 'instructions' event type\n" , - __func__); + err =intel_pt_synth_event (session,"instructions" , &attr, id); +if (err)return err; - } pt->sample_instructions = true; pt->instructions_sample_type = attr.sample_type; pt->instructions_id = id;
@@ -2005,14 +2009,9 @@ static int intel_pt_synth_events(struct intel_pt *pt, attr.sample_type |=PERF_SAMPLE_CALLCHAIN ;if (pt->synth_opts.last_branch) attr.sample_type |=PERF_SAMPLE_BRANCH_STACK ; -pr_debug ("Synthesizing 'transactions' event with id %" PRIu64" sample type %#" PRIx64"\n" , - id, (u64 )attr.sample_type); - err =intel_pt_synth_event (session, &attr, id); -if (err) { -pr_err ("%s: failed to synthesize 'transactions' event type\n" , - __func__); + err =intel_pt_synth_event (session,"transactions" , &attr, id); +if (err)return err; - } pt->sample_transactions = true; pt->transactions_sample_type = attr.sample_type; pt->transactions_id = id;
@@ -2033,14 +2032,9 @@ static int intel_pt_synth_events(struct intel_pt *pt, attr.sample_type |=PERF_SAMPLE_ADDR ; attr.sample_type &= ~(u64 )PERF_SAMPLE_CALLCHAIN ; attr.sample_type &= ~(u64 )PERF_SAMPLE_BRANCH_STACK ; -pr_debug ("Synthesizing 'branches' event with id %" PRIu64" sample type %#" PRIx64"\n" , - id, (u64 )attr.sample_type); - err =intel_pt_synth_event (session, &attr, id); -if (err) { -pr_err ("%s: failed to synthesize 'branches' event type\n" , - __func__); + err =intel_pt_synth_event (session,"branches" , &attr, id); +if (err)return err; - } pt->sample_branches = true; pt->branches_sample_type = attr.sample_type; pt->branches_id = id;
Adrian Hunter
reviewerPATCH v2 31/37 perf intel-pt: Factor out intel_pt_set_event_name()
In reply to Adrian HunterFactor out intel_pt_set_event_name() so it can be reused.
--- tools/perf/util/intel-pt.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
tools/perf/util/intel-pt.c +16 -8
@@ -1931,6 +1931,21 @@ static int intel_pt_synth_event(struct perf_session *session, const char *name,return err; } +static void intel_pt_set_event_name (struct perf_evlist *evlist,u64 id, +const char *name) +{ +struct perf_evsel *evsel; + +evlist__for_each_entry (evlist, evsel) { +if (evsel->id && evsel->id[0 ] == id) { +if (evsel->name) +zfree (&evsel->name); + evsel->name =strdup (name); +break ; + } + } +} +static struct perf_evsel *intel_pt_evsel (struct intel_pt *pt,struct perf_evlist *evlist) {
@@ -2015,15 +2030,8 @@ static int intel_pt_synth_events(struct intel_pt *pt, pt->sample_transactions = true; pt->transactions_sample_type = attr.sample_type; pt->transactions_id = id; +intel_pt_set_event_name (evlist, id,"transactions" ); id +=1 ; -evlist__for_each_entry (evlist, evsel) { -if (evsel->id && evsel->id[0 ] == pt->transactions_id) { -if (evsel->name) -zfree (&evsel->name); - evsel->name =strdup ("transactions" ); -break ; - } - } }if (pt->synth_opts.branches) {
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Factor out intel_pt_set_event_name()
perf intel-pt: Factor out intel_pt_set_event_name()
Commit-ID: bbac88ed64436201d6b6f2b00177d58081d56707 Gitweb: http://git.kernel.org/tip/bbac88ed64436201d6b6f2b00177d58081d56707 Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:32 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 30 Jun 2017 11:44:36 -0300
perf intel-pt: Factor out intel_pt_set_event_name()
Factor out intel_pt_set_event_name() so it can be reused.
--- tools/perf/util/intel-pt.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
tools/perf/util/intel-pt.c +16 -8
@@ -1931,6 +1931,21 @@ static int intel_pt_synth_event(struct perf_session *session, const char *name,return err; } +static void intel_pt_set_event_name (struct perf_evlist *evlist,u64 id, +const char *name) +{ +struct perf_evsel *evsel; + +evlist__for_each_entry (evlist, evsel) { +if (evsel->id && evsel->id[0 ] == id) { +if (evsel->name) +zfree (&evsel->name); + evsel->name =strdup (name); +break ; + } + } +} +static struct perf_evsel *intel_pt_evsel (struct intel_pt *pt,struct perf_evlist *evlist) {
@@ -2015,15 +2030,8 @@ static int intel_pt_synth_events(struct intel_pt *pt, pt->sample_transactions = true; pt->transactions_sample_type = attr.sample_type; pt->transactions_id = id; +intel_pt_set_event_name (evlist, id,"transactions" ); id +=1 ; -evlist__for_each_entry (evlist, evsel) { -if (evsel->id && evsel->id[0 ] == pt->transactions_id) { -if (evsel->name) -zfree (&evsel->name); - evsel->name =strdup ("transactions" ); -break ; - } - } }if (pt->synth_opts.branches) {
Adrian Hunter
reviewerPATCH v2 32/37 perf intel-pt: Move code in intel_pt_synth_events() to simplify attr setting
In reply to Adrian Hunterintel_pt_synth_events() uses the same attr structure to create each event. Move the code around a bit to simplify that.
--- tools/perf/util/intel-pt.c | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-)
tools/perf/util/intel-pt.c +22 -23
@@ -1997,6 +1997,25 @@ static int intel_pt_synth_events(struct intel_pt *pt,if (!id) id =1 ; +if (pt->synth_opts.branches) { + attr.config =PERF_COUNT_HW_BRANCH_INSTRUCTIONS ; + attr.sample_period =1 ; + attr.sample_type |=PERF_SAMPLE_ADDR ; + err =intel_pt_synth_event (session,"branches" , &attr, id); +if (err) +return err; + pt->sample_branches = true; + pt->branches_sample_type = attr.sample_type; + pt->branches_id = id; + id +=1 ; + attr.sample_type &= ~(u64 )PERF_SAMPLE_ADDR ; + } + +if (pt->synth_opts.callchain) + attr.sample_type |=PERF_SAMPLE_CALLCHAIN ; +if (pt->synth_opts.last_branch) + attr.sample_type |=PERF_SAMPLE_BRANCH_STACK ; +if (pt->synth_opts.instructions) { attr.config =PERF_COUNT_HW_INSTRUCTIONS ;if (pt->synth_opts.period_type ==PERF_ITRACE_PERIOD_NANOSECS )
@@ -2004,10 +2023,6 @@ static int intel_pt_synth_events(struct intel_pt *pt,intel_pt_ns_to_ticks (pt, pt->synth_opts.period); else attr.sample_period = pt->synth_opts.period; -if (pt->synth_opts.callchain) - attr.sample_type |=PERF_SAMPLE_CALLCHAIN ; -if (pt->synth_opts.last_branch) - attr.sample_type |=PERF_SAMPLE_BRANCH_STACK ; err =intel_pt_synth_event (session,"instructions" , &attr, id);if (err)return err;
@@ -2017,13 +2032,11 @@ static int intel_pt_synth_events(struct intel_pt *pt, id +=1 ; } + attr.sample_type &= ~(u64 )PERF_SAMPLE_PERIOD ; + attr.sample_period =1 ; +if (pt->synth_opts.transactions) { attr.config =PERF_COUNT_HW_INSTRUCTIONS ; - attr.sample_period =1 ; -if (pt->synth_opts.callchain) - attr.sample_type |=PERF_SAMPLE_CALLCHAIN ; -if (pt->synth_opts.last_branch) - attr.sample_type |=PERF_SAMPLE_BRANCH_STACK ; err =intel_pt_synth_event (session,"transactions" , &attr, id);if (err)return err;
@@ -2034,20 +2047,6 @@ static int intel_pt_synth_events(struct intel_pt *pt, id +=1 ; } -if (pt->synth_opts.branches) { - attr.config =PERF_COUNT_HW_BRANCH_INSTRUCTIONS ; - attr.sample_period =1 ; - attr.sample_type |=PERF_SAMPLE_ADDR ; - attr.sample_type &= ~(u64 )PERF_SAMPLE_CALLCHAIN ; - attr.sample_type &= ~(u64 )PERF_SAMPLE_BRANCH_STACK ; - err =intel_pt_synth_event (session,"branches" , &attr, id); -if (err) -return err; - pt->sample_branches = true; - pt->branches_sample_type = attr.sample_type; - pt->branches_id = id; - } - pt->synth_needs_swap = evsel->needs_swap;return 0 ;
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Move code in intel_pt_synth_events() to simplify attr setting
perf intel-pt: Move code in intel_pt_synth_events() to simplify attr setting
Commit-ID: 4a9fd4e0effc94b9ec79250946a0054d4dd1a963 Gitweb: http://git.kernel.org/tip/4a9fd4e0effc94b9ec79250946a0054d4dd1a963 Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:33 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 30 Jun 2017 11:44:36 -0300
perf intel-pt: Move code in intel_pt_synth_events() to simplify attr setting
intel_pt_synth_events() uses the same attr structure to create each event. Move the code around a bit to simplify that.
--- tools/perf/util/intel-pt.c | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-)
tools/perf/util/intel-pt.c +22 -23
@@ -1997,6 +1997,25 @@ static int intel_pt_synth_events(struct intel_pt *pt,if (!id) id =1 ; +if (pt->synth_opts.branches) { + attr.config =PERF_COUNT_HW_BRANCH_INSTRUCTIONS ; + attr.sample_period =1 ; + attr.sample_type |=PERF_SAMPLE_ADDR ; + err =intel_pt_synth_event (session,"branches" , &attr, id); +if (err) +return err; + pt->sample_branches = true; + pt->branches_sample_type = attr.sample_type; + pt->branches_id = id; + id +=1 ; + attr.sample_type &= ~(u64 )PERF_SAMPLE_ADDR ; + } + +if (pt->synth_opts.callchain) + attr.sample_type |=PERF_SAMPLE_CALLCHAIN ; +if (pt->synth_opts.last_branch) + attr.sample_type |=PERF_SAMPLE_BRANCH_STACK ; +if (pt->synth_opts.instructions) { attr.config =PERF_COUNT_HW_INSTRUCTIONS ;if (pt->synth_opts.period_type ==PERF_ITRACE_PERIOD_NANOSECS )
@@ -2004,10 +2023,6 @@ static int intel_pt_synth_events(struct intel_pt *pt,intel_pt_ns_to_ticks (pt, pt->synth_opts.period); else attr.sample_period = pt->synth_opts.period; -if (pt->synth_opts.callchain) - attr.sample_type |=PERF_SAMPLE_CALLCHAIN ; -if (pt->synth_opts.last_branch) - attr.sample_type |=PERF_SAMPLE_BRANCH_STACK ; err =intel_pt_synth_event (session,"instructions" , &attr, id);if (err)return err;
@@ -2017,13 +2032,11 @@ static int intel_pt_synth_events(struct intel_pt *pt, id +=1 ; } + attr.sample_type &= ~(u64 )PERF_SAMPLE_PERIOD ; + attr.sample_period =1 ; +if (pt->synth_opts.transactions) { attr.config =PERF_COUNT_HW_INSTRUCTIONS ; - attr.sample_period =1 ; -if (pt->synth_opts.callchain) - attr.sample_type |=PERF_SAMPLE_CALLCHAIN ; -if (pt->synth_opts.last_branch) - attr.sample_type |=PERF_SAMPLE_BRANCH_STACK ; err =intel_pt_synth_event (session,"transactions" , &attr, id);if (err)return err;
@@ -2034,20 +2047,6 @@ static int intel_pt_synth_events(struct intel_pt *pt, id +=1 ; } -if (pt->synth_opts.branches) { - attr.config =PERF_COUNT_HW_BRANCH_INSTRUCTIONS ; - attr.sample_period =1 ; - attr.sample_type |=PERF_SAMPLE_ADDR ; - attr.sample_type &= ~(u64 )PERF_SAMPLE_CALLCHAIN ; - attr.sample_type &= ~(u64 )PERF_SAMPLE_BRANCH_STACK ; - err =intel_pt_synth_event (session,"branches" , &attr, id); -if (err) -return err; - pt->sample_branches = true; - pt->branches_sample_type = attr.sample_type; - pt->branches_id = id; - } - pt->synth_needs_swap = evsel->needs_swap;return 0 ;
Adrian Hunter
reviewerPATCH v2 33/37 perf intel-pt: Synthesize new power and ptwrite events
In reply to Adrian HunterSynthesize new power and ptwrite events.
--- tools/perf/util/intel-pt.c | 283 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 283 insertions(+)
tools/perf/util/intel-pt.c +283 -0
@@ -92,6 +92,18 @@ struct intel_pt {u64 transactions_sample_type;u64 transactions_id; +bool sample_ptwrites; +u64 ptwrites_sample_type; +u64 ptwrites_id; + +bool sample_pwr_events; +u64 pwr_events_sample_type; +u64 mwait_id; +u64 pwre_id; +u64 exstop_id; +u64 pwrx_id; +u64 cbr_id; +bool synth_needs_swap;u64 tsc_bit;
@@ -102,6 +114,7 @@ struct intel_pt {u64 cyc_bit;u64 noretcomp_bit;unsigned max_non_turbo_ratio; +unsigned cbr2khz;unsigned long num_events;
@@ -1236,6 +1249,175 @@ static int intel_pt_synth_transaction_sample(struct intel_pt_queue *ptq) pt->transactions_sample_type); } +static void intel_pt_prep_p_sample (struct intel_pt *pt, +struct intel_pt_queue *ptq, +union perf_event *event, +struct perf_sample *sample) +{ +intel_pt_prep_sample (pt, ptq, event, sample); + +/* +* Zero IP is used to mean "trace start" but that is not the case for +* power or PTWRITE events with no IP, so clear the flags. +*/ +if (!sample->ip) + sample->flags =0 ; +} + +static int intel_pt_synth_ptwrite_sample (struct intel_pt_queue *ptq) +{ +struct intel_pt *pt = ptq->pt; +union perf_event *event = ptq->event_buf; +struct perf_sample sample = { .ip =0 , }; +struct perf_synth_intel_ptwrite raw; + +if (intel_pt_skip_event (pt)) +return 0 ; + +intel_pt_prep_p_sample (pt, ptq, event, &sample); + + sample.id = ptq->pt->ptwrites_id; + sample.stream_id = ptq->pt->ptwrites_id; + + raw.flags =0 ; + raw.ip = !!(ptq->state->flags &INTEL_PT_FUP_IP ); + raw.payload =cpu_to_le64 (ptq->state->ptw_payload); + + sample.raw_size =sizeof (raw); + sample.raw_data = &raw; + +return intel_pt_deliver_synth_event (pt, ptq, event, &sample, + pt->ptwrites_sample_type); +} + +static int intel_pt_synth_cbr_sample (struct intel_pt_queue *ptq) +{ +struct intel_pt *pt = ptq->pt; +union perf_event *event = ptq->event_buf; +struct perf_sample sample = { .ip =0 , }; +struct perf_synth_intel_cbr raw; +u32 flags; + +if (intel_pt_skip_event (pt)) +return 0 ; + +intel_pt_prep_p_sample (pt, ptq, event, &sample); + + sample.id = ptq->pt->cbr_id; + sample.stream_id = ptq->pt->cbr_id; + + flags = (u16 )ptq->state->cbr_payload | (pt->max_non_turbo_ratio <<16 ); + raw.flags =cpu_to_le32 (flags); + raw.freq =cpu_to_le32 (raw.cbr * pt->cbr2khz); + raw.reserved3 =0 ; + + sample.raw_size =sizeof (raw); + sample.raw_data = &raw; + +return intel_pt_deliver_synth_event (pt, ptq, event, &sample, + pt->pwr_events_sample_type); +} + +static int intel_pt_synth_mwait_sample (struct intel_pt_queue *ptq) +{ +struct intel_pt *pt = ptq->pt; +union perf_event *event = ptq->event_buf; +struct perf_sample sample = { .ip =0 , }; +struct perf_synth_intel_mwait raw; + +if (intel_pt_skip_event (pt)) +return 0 ; + +intel_pt_prep_p_sample (pt, ptq, event, &sample); + + sample.id = ptq->pt->mwait_id; + sample.stream_id = ptq->pt->mwait_id; + + raw.reserved =0 ; + raw.payload =cpu_to_le64 (ptq->state->mwait_payload); + + sample.raw_size =sizeof (raw); + sample.raw_data = &raw; + +return intel_pt_deliver_synth_event (pt, ptq, event, &sample, + pt->pwr_events_sample_type); +} + +static int intel_pt_synth_pwre_sample (struct intel_pt_queue *ptq) +{ +struct intel_pt *pt = ptq->pt; +union perf_event *event = ptq->event_buf; +struct perf_sample sample = { .ip =0 , }; +struct perf_synth_intel_pwre raw; + +if (intel_pt_skip_event (pt)) +return 0 ; + +intel_pt_prep_p_sample (pt, ptq, event, &sample); + + sample.id = ptq->pt->pwre_id; + sample.stream_id = ptq->pt->pwre_id; + + raw.reserved =0 ; + raw.payload =cpu_to_le64 (ptq->state->pwre_payload); + + sample.raw_size =sizeof (raw); + sample.raw_data = &raw; + +return intel_pt_deliver_synth_event (pt, ptq, event, &sample, + pt->pwr_events_sample_type); +} + +static int intel_pt_synth_exstop_sample (struct intel_pt_queue *ptq) +{ +struct intel_pt *pt = ptq->pt; +union perf_event *event = ptq->event_buf; +struct perf_sample sample = { .ip =0 , }; +struct perf_synth_intel_exstop raw; + +if (intel_pt_skip_event (pt)) +return 0 ; + +intel_pt_prep_p_sample (pt, ptq, event, &sample); + + sample.id = ptq->pt->exstop_id; + sample.stream_id = ptq->pt->exstop_id; + + raw.flags =0 ; + raw.ip = !!(ptq->state->flags &INTEL_PT_FUP_IP ); + + sample.raw_size =sizeof (raw); + sample.raw_data = &raw; + +return intel_pt_deliver_synth_event (pt, ptq, event, &sample, + pt->pwr_events_sample_type); +} + +static int intel_pt_synth_pwrx_sample (struct intel_pt_queue *ptq) +{ +struct intel_pt *pt = ptq->pt; +union perf_event *event = ptq->event_buf; +struct perf_sample sample = { .ip =0 , }; +struct perf_synth_intel_pwrx raw; + +if (intel_pt_skip_event (pt)) +return 0 ; + +intel_pt_prep_p_sample (pt, ptq, event, &sample); + + sample.id = ptq->pt->pwrx_id; + sample.stream_id = ptq->pt->pwrx_id; + + raw.reserved =0 ; + raw.payload =cpu_to_le64 (ptq->state->pwrx_payload); + + sample.raw_size =sizeof (raw); + sample.raw_data = &raw; + +return intel_pt_deliver_synth_event (pt, ptq, event, &sample, + pt->pwr_events_sample_type); +} +static int intel_pt_synth_error (struct intel_pt *pt,int code,int cpu,pid_t pid,pid_t tid,u64 ip) {
@@ -1287,6 +1469,10 @@ static inline bool intel_pt_is_switch_ip(struct intel_pt_queue *ptq, u64 ip) PERF_IP_FLAG_INTERRUPT | PERF_IP_FLAG_TX_ABORT)); } +#define INTEL_PT_PWR_EVT (INTEL_PT_MWAIT_OP | INTEL_PT_PWR_ENTRY | \ + INTEL_PT_EX_STOP | INTEL_PT_PWR_EXIT | \ + INTEL_PT_CBR_CHG) +static int intel_pt_sample (struct intel_pt_queue *ptq) {const struct intel_pt_state *state = ptq->state;
@@ -1298,6 +1484,34 @@ static int intel_pt_sample(struct intel_pt_queue *ptq) ptq->have_sample = false; +if (pt->sample_pwr_events && (state->type &INTEL_PT_PWR_EVT )) { +if (state->type &INTEL_PT_CBR_CHG ) { + err =intel_pt_synth_cbr_sample (ptq); +if (err) +return err; + } +if (state->type &INTEL_PT_MWAIT_OP ) { + err =intel_pt_synth_mwait_sample (ptq); +if (err) +return err; + } +if (state->type &INTEL_PT_PWR_ENTRY ) { + err =intel_pt_synth_pwre_sample (ptq); +if (err) +return err; + } +if (state->type &INTEL_PT_EX_STOP ) { + err =intel_pt_synth_exstop_sample (ptq); +if (err) +return err; + } +if (state->type &INTEL_PT_PWR_EXIT ) { + err =intel_pt_synth_pwrx_sample (ptq); +if (err) +return err; + } + } +if (pt->sample_instructions && (state->type &INTEL_PT_INSTRUCTION )) { err =intel_pt_synth_instruction_sample (ptq);if (err)
@@ -1310,6 +1524,12 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)return err; } +if (pt->sample_ptwrites && (state->type &INTEL_PT_PTW )) { + err =intel_pt_synth_ptwrite_sample (ptq); +if (err) +return err; + } +if (!(state->type &INTEL_PT_BRANCH ))return 0 ;
@@ -2047,6 +2267,68 @@ static int intel_pt_synth_events(struct intel_pt *pt, id +=1 ; } + attr.type =PERF_TYPE_SYNTH ; + attr.sample_type |=PERF_SAMPLE_RAW ; + +if (pt->synth_opts.ptwrites) { + attr.config =PERF_SYNTH_INTEL_PTWRITE ; + err =intel_pt_synth_event (session,"ptwrite" , &attr, id); +if (err) +return err; + pt->sample_ptwrites = true; + pt->ptwrites_sample_type = attr.sample_type; + pt->ptwrites_id = id; +intel_pt_set_event_name (evlist, id,"ptwrite" ); + id +=1 ; + } + +if (pt->synth_opts.pwr_events) { + pt->sample_pwr_events = true; + pt->pwr_events_sample_type = attr.sample_type; + + attr.config =PERF_SYNTH_INTEL_CBR ; + err =intel_pt_synth_event (session,"cbr" , &attr, id); +if (err) +return err; + pt->cbr_id = id; +intel_pt_set_event_name (evlist, id,"cbr" ); + id +=1 ; + } + +if (pt->synth_opts.pwr_events && (evsel->attr.config &0x10 )) { + attr.config =PERF_SYNTH_INTEL_MWAIT ; + err =intel_pt_synth_event (session,"mwait" , &attr, id); +if (err) +return err; + pt->mwait_id = id; +intel_pt_set_event_name (evlist, id,"mwait" ); + id +=1 ; + + attr.config =PERF_SYNTH_INTEL_PWRE ; + err =intel_pt_synth_event (session,"pwre" , &attr, id); +if (err) +return err; + pt->pwre_id = id; +intel_pt_set_event_name (evlist, id,"pwre" ); + id +=1 ; + + attr.config =PERF_SYNTH_INTEL_EXSTOP ; + err =intel_pt_synth_event (session,"exstop" , &attr, id); +if (err) +return err; + pt->exstop_id = id; +intel_pt_set_event_name (evlist, id,"exstop" ); + id +=1 ; + + attr.config =PERF_SYNTH_INTEL_PWRX ; + err =intel_pt_synth_event (session,"pwrx" , &attr, id); +if (err) +return err; + pt->pwrx_id = id; +intel_pt_set_event_name (evlist, id,"pwrx" ); + id +=1 ; + } + pt->synth_needs_swap = evsel->needs_swap;return 0 ;
@@ -2313,6 +2595,7 @@ int intel_pt_process_auxtrace_info(union perf_event *event,intel_pt_log ("TSC frequency %" PRIu64"\n" , tsc_freq);intel_pt_log ("Maximum non-turbo ratio %u\n" , pt->max_non_turbo_ratio); + pt->cbr2khz = tsc_freq / pt->max_non_turbo_ratio /1000 ; }if (pt->synth_opts.calls)
Signature · 1 line
1.9.1
Adrian Hunter
reviewerPATCH v3 33/37 perf intel-pt: Synthesize new power and ptwrite events
Synthesize new power and ptwrite events.
---
Changes in V3:
Use perf_synth__raw_size() and perf_synth__raw_data() as a result of avoiding __packed
tools/perf/util/intel-pt.c | 283 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 283 insertions(+)
tools/perf/util/intel-pt.c +283 -0
@@ -92,6 +92,18 @@ struct intel_pt {u64 transactions_sample_type;u64 transactions_id; +bool sample_ptwrites; +u64 ptwrites_sample_type; +u64 ptwrites_id; + +bool sample_pwr_events; +u64 pwr_events_sample_type; +u64 mwait_id; +u64 pwre_id; +u64 exstop_id; +u64 pwrx_id; +u64 cbr_id; +bool synth_needs_swap;u64 tsc_bit;
@@ -102,6 +114,7 @@ struct intel_pt {u64 cyc_bit;u64 noretcomp_bit;unsigned max_non_turbo_ratio; +unsigned cbr2khz;unsigned long num_events;
@@ -1236,6 +1249,175 @@ static int intel_pt_synth_transaction_sample(struct intel_pt_queue *ptq) pt->transactions_sample_type); } +static void intel_pt_prep_p_sample (struct intel_pt *pt, +struct intel_pt_queue *ptq, +union perf_event *event, +struct perf_sample *sample) +{ +intel_pt_prep_sample (pt, ptq, event, sample); + +/* +* Zero IP is used to mean "trace start" but that is not the case for +* power or PTWRITE events with no IP, so clear the flags. +*/ +if (!sample->ip) + sample->flags =0 ; +} + +static int intel_pt_synth_ptwrite_sample (struct intel_pt_queue *ptq) +{ +struct intel_pt *pt = ptq->pt; +union perf_event *event = ptq->event_buf; +struct perf_sample sample = { .ip =0 , }; +struct perf_synth_intel_ptwrite raw; + +if (intel_pt_skip_event (pt)) +return 0 ; + +intel_pt_prep_p_sample (pt, ptq, event, &sample); + + sample.id = ptq->pt->ptwrites_id; + sample.stream_id = ptq->pt->ptwrites_id; + + raw.flags =0 ; + raw.ip = !!(ptq->state->flags &INTEL_PT_FUP_IP ); + raw.payload =cpu_to_le64 (ptq->state->ptw_payload); + + sample.raw_size =perf_synth__raw_size (raw); + sample.raw_data =perf_synth__raw_data (&raw); + +return intel_pt_deliver_synth_event (pt, ptq, event, &sample, + pt->ptwrites_sample_type); +} + +static int intel_pt_synth_cbr_sample (struct intel_pt_queue *ptq) +{ +struct intel_pt *pt = ptq->pt; +union perf_event *event = ptq->event_buf; +struct perf_sample sample = { .ip =0 , }; +struct perf_synth_intel_cbr raw; +u32 flags; + +if (intel_pt_skip_event (pt)) +return 0 ; + +intel_pt_prep_p_sample (pt, ptq, event, &sample); + + sample.id = ptq->pt->cbr_id; + sample.stream_id = ptq->pt->cbr_id; + + flags = (u16 )ptq->state->cbr_payload | (pt->max_non_turbo_ratio <<16 ); + raw.flags =cpu_to_le32 (flags); + raw.freq =cpu_to_le32 (raw.cbr * pt->cbr2khz); + raw.reserved3 =0 ; + + sample.raw_size =perf_synth__raw_size (raw); + sample.raw_data =perf_synth__raw_data (&raw); + +return intel_pt_deliver_synth_event (pt, ptq, event, &sample, + pt->pwr_events_sample_type); +} + +static int intel_pt_synth_mwait_sample (struct intel_pt_queue *ptq) +{ +struct intel_pt *pt = ptq->pt; +union perf_event *event = ptq->event_buf; +struct perf_sample sample = { .ip =0 , }; +struct perf_synth_intel_mwait raw; + +if (intel_pt_skip_event (pt)) +return 0 ; + +intel_pt_prep_p_sample (pt, ptq, event, &sample); + + sample.id = ptq->pt->mwait_id; + sample.stream_id = ptq->pt->mwait_id; + + raw.reserved =0 ; + raw.payload =cpu_to_le64 (ptq->state->mwait_payload); + + sample.raw_size =perf_synth__raw_size (raw); + sample.raw_data =perf_synth__raw_data (&raw); + +return intel_pt_deliver_synth_event (pt, ptq, event, &sample, + pt->pwr_events_sample_type); +} + +static int intel_pt_synth_pwre_sample (struct intel_pt_queue *ptq) +{ +struct intel_pt *pt = ptq->pt; +union perf_event *event = ptq->event_buf; +struct perf_sample sample = { .ip =0 , }; +struct perf_synth_intel_pwre raw; + +if (intel_pt_skip_event (pt)) +return 0 ; + +intel_pt_prep_p_sample (pt, ptq, event, &sample); + + sample.id = ptq->pt->pwre_id; + sample.stream_id = ptq->pt->pwre_id; + + raw.reserved =0 ; + raw.payload =cpu_to_le64 (ptq->state->pwre_payload); + + sample.raw_size =perf_synth__raw_size (raw); + sample.raw_data =perf_synth__raw_data (&raw); + +return intel_pt_deliver_synth_event (pt, ptq, event, &sample, + pt->pwr_events_sample_type); +} + +static int intel_pt_synth_exstop_sample (struct intel_pt_queue *ptq) +{ +struct intel_pt *pt = ptq->pt; +union perf_event *event = ptq->event_buf; +struct perf_sample sample = { .ip =0 , }; +struct perf_synth_intel_exstop raw; + +if (intel_pt_skip_event (pt)) +return 0 ; + +intel_pt_prep_p_sample (pt, ptq, event, &sample); + + sample.id = ptq->pt->exstop_id; + sample.stream_id = ptq->pt->exstop_id; + + raw.flags =0 ; + raw.ip = !!(ptq->state->flags &INTEL_PT_FUP_IP ); + + sample.raw_size =perf_synth__raw_size (raw); + sample.raw_data =perf_synth__raw_data (&raw); + +return intel_pt_deliver_synth_event (pt, ptq, event, &sample, + pt->pwr_events_sample_type); +} + +static int intel_pt_synth_pwrx_sample (struct intel_pt_queue *ptq) +{ +struct intel_pt *pt = ptq->pt; +union perf_event *event = ptq->event_buf; +struct perf_sample sample = { .ip =0 , }; +struct perf_synth_intel_pwrx raw; + +if (intel_pt_skip_event (pt)) +return 0 ; + +intel_pt_prep_p_sample (pt, ptq, event, &sample); + + sample.id = ptq->pt->pwrx_id; + sample.stream_id = ptq->pt->pwrx_id; + + raw.reserved =0 ; + raw.payload =cpu_to_le64 (ptq->state->pwrx_payload); + + sample.raw_size =perf_synth__raw_size (raw); + sample.raw_data =perf_synth__raw_data (&raw); + +return intel_pt_deliver_synth_event (pt, ptq, event, &sample, + pt->pwr_events_sample_type); +} +static int intel_pt_synth_error (struct intel_pt *pt,int code,int cpu,pid_t pid,pid_t tid,u64 ip) {
@@ -1287,6 +1469,10 @@ static inline bool intel_pt_is_switch_ip(struct intel_pt_queue *ptq, u64 ip) PERF_IP_FLAG_INTERRUPT | PERF_IP_FLAG_TX_ABORT)); } +#define INTEL_PT_PWR_EVT (INTEL_PT_MWAIT_OP | INTEL_PT_PWR_ENTRY | \ + INTEL_PT_EX_STOP | INTEL_PT_PWR_EXIT | \ + INTEL_PT_CBR_CHG) +static int intel_pt_sample (struct intel_pt_queue *ptq) {const struct intel_pt_state *state = ptq->state;
@@ -1298,6 +1484,34 @@ static int intel_pt_sample(struct intel_pt_queue *ptq) ptq->have_sample = false; +if (pt->sample_pwr_events && (state->type &INTEL_PT_PWR_EVT )) { +if (state->type &INTEL_PT_CBR_CHG ) { + err =intel_pt_synth_cbr_sample (ptq); +if (err) +return err; + } +if (state->type &INTEL_PT_MWAIT_OP ) { + err =intel_pt_synth_mwait_sample (ptq); +if (err) +return err; + } +if (state->type &INTEL_PT_PWR_ENTRY ) { + err =intel_pt_synth_pwre_sample (ptq); +if (err) +return err; + } +if (state->type &INTEL_PT_EX_STOP ) { + err =intel_pt_synth_exstop_sample (ptq); +if (err) +return err; + } +if (state->type &INTEL_PT_PWR_EXIT ) { + err =intel_pt_synth_pwrx_sample (ptq); +if (err) +return err; + } + } +if (pt->sample_instructions && (state->type &INTEL_PT_INSTRUCTION )) { err =intel_pt_synth_instruction_sample (ptq);if (err)
@@ -1310,6 +1524,12 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)return err; } +if (pt->sample_ptwrites && (state->type &INTEL_PT_PTW )) { + err =intel_pt_synth_ptwrite_sample (ptq); +if (err) +return err; + } +if (!(state->type &INTEL_PT_BRANCH ))return 0 ;
@@ -2047,6 +2267,68 @@ static int intel_pt_synth_events(struct intel_pt *pt, id +=1 ; } + attr.type =PERF_TYPE_SYNTH ; + attr.sample_type |=PERF_SAMPLE_RAW ; + +if (pt->synth_opts.ptwrites) { + attr.config =PERF_SYNTH_INTEL_PTWRITE ; + err =intel_pt_synth_event (session,"ptwrite" , &attr, id); +if (err) +return err; + pt->sample_ptwrites = true; + pt->ptwrites_sample_type = attr.sample_type; + pt->ptwrites_id = id; +intel_pt_set_event_name (evlist, id,"ptwrite" ); + id +=1 ; + } + +if (pt->synth_opts.pwr_events) { + pt->sample_pwr_events = true; + pt->pwr_events_sample_type = attr.sample_type; + + attr.config =PERF_SYNTH_INTEL_CBR ; + err =intel_pt_synth_event (session,"cbr" , &attr, id); +if (err) +return err; + pt->cbr_id = id; +intel_pt_set_event_name (evlist, id,"cbr" ); + id +=1 ; + } + +if (pt->synth_opts.pwr_events && (evsel->attr.config &0x10 )) { + attr.config =PERF_SYNTH_INTEL_MWAIT ; + err =intel_pt_synth_event (session,"mwait" , &attr, id); +if (err) +return err; + pt->mwait_id = id; +intel_pt_set_event_name (evlist, id,"mwait" ); + id +=1 ; + + attr.config =PERF_SYNTH_INTEL_PWRE ; + err =intel_pt_synth_event (session,"pwre" , &attr, id); +if (err) +return err; + pt->pwre_id = id; +intel_pt_set_event_name (evlist, id,"pwre" ); + id +=1 ; + + attr.config =PERF_SYNTH_INTEL_EXSTOP ; + err =intel_pt_synth_event (session,"exstop" , &attr, id); +if (err) +return err; + pt->exstop_id = id; +intel_pt_set_event_name (evlist, id,"exstop" ); + id +=1 ; + + attr.config =PERF_SYNTH_INTEL_PWRX ; + err =intel_pt_synth_event (session,"pwrx" , &attr, id); +if (err) +return err; + pt->pwrx_id = id; +intel_pt_set_event_name (evlist, id,"pwrx" ); + id +=1 ; + } + pt->synth_needs_swap = evsel->needs_swap;return 0 ;
@@ -2313,6 +2595,7 @@ int intel_pt_process_auxtrace_info(union perf_event *event,intel_pt_log ("TSC frequency %" PRIu64"\n" , tsc_freq);intel_pt_log ("Maximum non-turbo ratio %u\n" , pt->max_non_turbo_ratio); + pt->cbr2khz = tsc_freq / pt->max_non_turbo_ratio /1000 ; }if (pt->synth_opts.calls)
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Synthesize new power and "ptwrite" events
perf intel-pt: Synthesize new power and "ptwrite" events
Commit-ID: 3797307576191d7fb4c974cd461188162ac36f33 Gitweb: http://git.kernel.org/tip/3797307576191d7fb4c974cd461188162ac36f33 Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 30 Jun 2017 11:36:45 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 30 Jun 2017 11:48:28 -0300
perf intel-pt: Synthesize new power and "ptwrite" events
Synthesize new power and ptwrite events.
Power events report changes to C-state but I have also added support for the existing CBR (core-to-bus ratio) packet and included that when outputting power events.
The PTWRITE packet is associated with the new "ptwrite" instruction, which is essentially just a way to stuff a 32 or 64 bit value into the PT trace.
More details can be found in the patches that add documentation and in the Intel SDM.
--- tools/perf/util/intel-pt.c | 283 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 283 insertions(+)
tools/perf/util/intel-pt.c +283 -0
@@ -92,6 +92,18 @@ struct intel_pt {u64 transactions_sample_type;u64 transactions_id; +bool sample_ptwrites; +u64 ptwrites_sample_type; +u64 ptwrites_id; + +bool sample_pwr_events; +u64 pwr_events_sample_type; +u64 mwait_id; +u64 pwre_id; +u64 exstop_id; +u64 pwrx_id; +u64 cbr_id; +bool synth_needs_swap;u64 tsc_bit;
@@ -102,6 +114,7 @@ struct intel_pt {u64 cyc_bit;u64 noretcomp_bit;unsigned max_non_turbo_ratio; +unsigned cbr2khz;unsigned long num_events;
@@ -1236,6 +1249,175 @@ static int intel_pt_synth_transaction_sample(struct intel_pt_queue *ptq) pt->transactions_sample_type); } +static void intel_pt_prep_p_sample (struct intel_pt *pt, +struct intel_pt_queue *ptq, +union perf_event *event, +struct perf_sample *sample) +{ +intel_pt_prep_sample (pt, ptq, event, sample); + +/* +* Zero IP is used to mean "trace start" but that is not the case for +* power or PTWRITE events with no IP, so clear the flags. +*/ +if (!sample->ip) + sample->flags =0 ; +} + +static int intel_pt_synth_ptwrite_sample (struct intel_pt_queue *ptq) +{ +struct intel_pt *pt = ptq->pt; +union perf_event *event = ptq->event_buf; +struct perf_sample sample = { .ip =0 , }; +struct perf_synth_intel_ptwrite raw; + +if (intel_pt_skip_event (pt)) +return 0 ; + +intel_pt_prep_p_sample (pt, ptq, event, &sample); + + sample.id = ptq->pt->ptwrites_id; + sample.stream_id = ptq->pt->ptwrites_id; + + raw.flags =0 ; + raw.ip = !!(ptq->state->flags &INTEL_PT_FUP_IP ); + raw.payload =cpu_to_le64 (ptq->state->ptw_payload); + + sample.raw_size =perf_synth__raw_size (raw); + sample.raw_data =perf_synth__raw_data (&raw); + +return intel_pt_deliver_synth_event (pt, ptq, event, &sample, + pt->ptwrites_sample_type); +} + +static int intel_pt_synth_cbr_sample (struct intel_pt_queue *ptq) +{ +struct intel_pt *pt = ptq->pt; +union perf_event *event = ptq->event_buf; +struct perf_sample sample = { .ip =0 , }; +struct perf_synth_intel_cbr raw; +u32 flags; + +if (intel_pt_skip_event (pt)) +return 0 ; + +intel_pt_prep_p_sample (pt, ptq, event, &sample); + + sample.id = ptq->pt->cbr_id; + sample.stream_id = ptq->pt->cbr_id; + + flags = (u16 )ptq->state->cbr_payload | (pt->max_non_turbo_ratio <<16 ); + raw.flags =cpu_to_le32 (flags); + raw.freq =cpu_to_le32 (raw.cbr * pt->cbr2khz); + raw.reserved3 =0 ; + + sample.raw_size =perf_synth__raw_size (raw); + sample.raw_data =perf_synth__raw_data (&raw); + +return intel_pt_deliver_synth_event (pt, ptq, event, &sample, + pt->pwr_events_sample_type); +} + +static int intel_pt_synth_mwait_sample (struct intel_pt_queue *ptq) +{ +struct intel_pt *pt = ptq->pt; +union perf_event *event = ptq->event_buf; +struct perf_sample sample = { .ip =0 , }; +struct perf_synth_intel_mwait raw; + +if (intel_pt_skip_event (pt)) +return 0 ; + +intel_pt_prep_p_sample (pt, ptq, event, &sample); + + sample.id = ptq->pt->mwait_id; + sample.stream_id = ptq->pt->mwait_id; + + raw.reserved =0 ; + raw.payload =cpu_to_le64 (ptq->state->mwait_payload); + + sample.raw_size =perf_synth__raw_size (raw); + sample.raw_data =perf_synth__raw_data (&raw); + +return intel_pt_deliver_synth_event (pt, ptq, event, &sample, + pt->pwr_events_sample_type); +} + +static int intel_pt_synth_pwre_sample (struct intel_pt_queue *ptq) +{ +struct intel_pt *pt = ptq->pt; +union perf_event *event = ptq->event_buf; +struct perf_sample sample = { .ip =0 , }; +struct perf_synth_intel_pwre raw; + +if (intel_pt_skip_event (pt)) +return 0 ; + +intel_pt_prep_p_sample (pt, ptq, event, &sample); + + sample.id = ptq->pt->pwre_id; + sample.stream_id = ptq->pt->pwre_id; + + raw.reserved =0 ; + raw.payload =cpu_to_le64 (ptq->state->pwre_payload); + + sample.raw_size =perf_synth__raw_size (raw); + sample.raw_data =perf_synth__raw_data (&raw); + +return intel_pt_deliver_synth_event (pt, ptq, event, &sample, + pt->pwr_events_sample_type); +} + +static int intel_pt_synth_exstop_sample (struct intel_pt_queue *ptq) +{ +struct intel_pt *pt = ptq->pt; +union perf_event *event = ptq->event_buf; +struct perf_sample sample = { .ip =0 , }; +struct perf_synth_intel_exstop raw; + +if (intel_pt_skip_event (pt)) +return 0 ; + +intel_pt_prep_p_sample (pt, ptq, event, &sample); + + sample.id = ptq->pt->exstop_id; + sample.stream_id = ptq->pt->exstop_id; + + raw.flags =0 ; + raw.ip = !!(ptq->state->flags &INTEL_PT_FUP_IP ); + + sample.raw_size =perf_synth__raw_size (raw); + sample.raw_data =perf_synth__raw_data (&raw); + +return intel_pt_deliver_synth_event (pt, ptq, event, &sample, + pt->pwr_events_sample_type); +} + +static int intel_pt_synth_pwrx_sample (struct intel_pt_queue *ptq) +{ +struct intel_pt *pt = ptq->pt; +union perf_event *event = ptq->event_buf; +struct perf_sample sample = { .ip =0 , }; +struct perf_synth_intel_pwrx raw; + +if (intel_pt_skip_event (pt)) +return 0 ; + +intel_pt_prep_p_sample (pt, ptq, event, &sample); + + sample.id = ptq->pt->pwrx_id; + sample.stream_id = ptq->pt->pwrx_id; + + raw.reserved =0 ; + raw.payload =cpu_to_le64 (ptq->state->pwrx_payload); + + sample.raw_size =perf_synth__raw_size (raw); + sample.raw_data =perf_synth__raw_data (&raw); + +return intel_pt_deliver_synth_event (pt, ptq, event, &sample, + pt->pwr_events_sample_type); +} +static int intel_pt_synth_error (struct intel_pt *pt,int code,int cpu,pid_t pid,pid_t tid,u64 ip) {
@@ -1287,6 +1469,10 @@ static inline bool intel_pt_is_switch_ip(struct intel_pt_queue *ptq, u64 ip) PERF_IP_FLAG_INTERRUPT | PERF_IP_FLAG_TX_ABORT)); } +#define INTEL_PT_PWR_EVT (INTEL_PT_MWAIT_OP | INTEL_PT_PWR_ENTRY | \ + INTEL_PT_EX_STOP | INTEL_PT_PWR_EXIT | \ + INTEL_PT_CBR_CHG) +static int intel_pt_sample (struct intel_pt_queue *ptq) {const struct intel_pt_state *state = ptq->state;
@@ -1298,6 +1484,34 @@ static int intel_pt_sample(struct intel_pt_queue *ptq) ptq->have_sample = false; +if (pt->sample_pwr_events && (state->type &INTEL_PT_PWR_EVT )) { +if (state->type &INTEL_PT_CBR_CHG ) { + err =intel_pt_synth_cbr_sample (ptq); +if (err) +return err; + } +if (state->type &INTEL_PT_MWAIT_OP ) { + err =intel_pt_synth_mwait_sample (ptq); +if (err) +return err; + } +if (state->type &INTEL_PT_PWR_ENTRY ) { + err =intel_pt_synth_pwre_sample (ptq); +if (err) +return err; + } +if (state->type &INTEL_PT_EX_STOP ) { + err =intel_pt_synth_exstop_sample (ptq); +if (err) +return err; + } +if (state->type &INTEL_PT_PWR_EXIT ) { + err =intel_pt_synth_pwrx_sample (ptq); +if (err) +return err; + } + } +if (pt->sample_instructions && (state->type &INTEL_PT_INSTRUCTION )) { err =intel_pt_synth_instruction_sample (ptq);if (err)
@@ -1310,6 +1524,12 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)return err; } +if (pt->sample_ptwrites && (state->type &INTEL_PT_PTW )) { + err =intel_pt_synth_ptwrite_sample (ptq); +if (err) +return err; + } +if (!(state->type &INTEL_PT_BRANCH ))return 0 ;
@@ -2047,6 +2267,68 @@ static int intel_pt_synth_events(struct intel_pt *pt, id +=1 ; } + attr.type =PERF_TYPE_SYNTH ; + attr.sample_type |=PERF_SAMPLE_RAW ; + +if (pt->synth_opts.ptwrites) { + attr.config =PERF_SYNTH_INTEL_PTWRITE ; + err =intel_pt_synth_event (session,"ptwrite" , &attr, id); +if (err) +return err; + pt->sample_ptwrites = true; + pt->ptwrites_sample_type = attr.sample_type; + pt->ptwrites_id = id; +intel_pt_set_event_name (evlist, id,"ptwrite" ); + id +=1 ; + } + +if (pt->synth_opts.pwr_events) { + pt->sample_pwr_events = true; + pt->pwr_events_sample_type = attr.sample_type; + + attr.config =PERF_SYNTH_INTEL_CBR ; + err =intel_pt_synth_event (session,"cbr" , &attr, id); +if (err) +return err; + pt->cbr_id = id; +intel_pt_set_event_name (evlist, id,"cbr" ); + id +=1 ; + } + +if (pt->synth_opts.pwr_events && (evsel->attr.config &0x10 )) { + attr.config =PERF_SYNTH_INTEL_MWAIT ; + err =intel_pt_synth_event (session,"mwait" , &attr, id); +if (err) +return err; + pt->mwait_id = id; +intel_pt_set_event_name (evlist, id,"mwait" ); + id +=1 ; + + attr.config =PERF_SYNTH_INTEL_PWRE ; + err =intel_pt_synth_event (session,"pwre" , &attr, id); +if (err) +return err; + pt->pwre_id = id; +intel_pt_set_event_name (evlist, id,"pwre" ); + id +=1 ; + + attr.config =PERF_SYNTH_INTEL_EXSTOP ; + err =intel_pt_synth_event (session,"exstop" , &attr, id); +if (err) +return err; + pt->exstop_id = id; +intel_pt_set_event_name (evlist, id,"exstop" ); + id +=1 ; + + attr.config =PERF_SYNTH_INTEL_PWRX ; + err =intel_pt_synth_event (session,"pwrx" , &attr, id); +if (err) +return err; + pt->pwrx_id = id; +intel_pt_set_event_name (evlist, id,"pwrx" ); + id +=1 ; + } + pt->synth_needs_swap = evsel->needs_swap;return 0 ;
@@ -2313,6 +2595,7 @@ int intel_pt_process_auxtrace_info(union perf_event *event,intel_pt_log ("TSC frequency %" PRIu64"\n" , tsc_freq);intel_pt_log ("Maximum non-turbo ratio %u\n" , pt->max_non_turbo_ratio); + pt->cbr2khz = tsc_freq / pt->max_non_turbo_ratio /1000 ; }if (pt->synth_opts.calls)
Adrian Hunter
reviewerPATCH v2 34/37 perf intel-pt: Add example script for power events and PTWRITE
In reply to Adrian HunterAdd script intel-pt-events.py that provides an example of how to unpack the raw data for power events and PTWRITE.
--- .../perf/scripts/python/bin/intel-pt-events-record | 13 +++ .../perf/scripts/python/bin/intel-pt-events-report | 3 + tools/perf/scripts/python/intel-pt-events.py | 128 +++++++++++++++++++++ 3 files changed, 144 insertions(+) create mode 100644 tools/perf/scripts/python/bin/intel-pt-events-record create mode 100644 tools/perf/scripts/python/bin/intel-pt-events-report create mode 100644 tools/perf/scripts/python/intel-pt-events.py
tools/perf/scripts/python/bin/intel-pt-events-record new file +13 -0
@@ -0,0 +1,13 @@ +#!/bin/bash + +# +# print Intel PT Power Events and PTWRITE. The intel_pt PMU event needs +# to be specified with appropriate config terms. +# +if ! echo "$@" | grep -q intel_pt ; then + echo "Options must include the Intel PT event e.g. -e intel_pt/pwr_evt,ptw/" + echo "and for power events it probably needs to be system wide i.e. -a option" + echo "For example: -a -e intel_pt/pwr_evt,branch=0/ sleep 1" + exit 1 +fi +perf record $@
tools/perf/scripts/python/bin/intel-pt-events-report new file +3 -0
@@ -0,0 +1,3 @@ +#!/bin/bash +# description: print Intel PT Power Events and PTWRITE +perf script $@ -s "$PERF_EXEC_PATH"/scripts/python/intel-pt-events.py
tools/perf/scripts/python/intel-pt-events.py new file +128 -0
128 lines not on this page · raw message
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Add example script for power events and PTWRITE
perf intel-pt: Add example script for power events and PTWRITE
Commit-ID: cc892720d85a31cc04f4c01c03d88a0eb3c437fa Gitweb: http://git.kernel.org/tip/cc892720d85a31cc04f4c01c03d88a0eb3c437fa Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:35 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 30 Jun 2017 11:50:53 -0300
perf intel-pt: Add example script for power events and PTWRITE
Add script intel-pt-events.py that provides an example of how to unpack the raw data for power events and PTWRITE.
--- .../perf/scripts/python/bin/intel-pt-events-record | 13 +++ .../perf/scripts/python/bin/intel-pt-events-report | 3 + tools/perf/scripts/python/intel-pt-events.py | 128 +++++++++++++++++++++ 3 files changed, 144 insertions(+)
tools/perf/scripts/python/bin/intel-pt-events-record new file +13 -0
@@ -0,0 +1,13 @@ +#!/bin/bash + +# +# print Intel PT Power Events and PTWRITE. The intel_pt PMU event needs +# to be specified with appropriate config terms. +# +if ! echo "$@" | grep -q intel_pt ; then + echo "Options must include the Intel PT event e.g. -e intel_pt/pwr_evt,ptw/" + echo "and for power events it probably needs to be system wide i.e. -a option" + echo "For example: -a -e intel_pt/pwr_evt,branch=0/ sleep 1" + exit 1 +fi +perf record $@
tools/perf/scripts/python/bin/intel-pt-events-report new file +3 -0
@@ -0,0 +1,3 @@ +#!/bin/bash +# description: print Intel PT Power Events and PTWRITE +perf script $@ -s "$PERF_EXEC_PATH"/scripts/python/intel-pt-events.py
tools/perf/scripts/python/intel-pt-events.py new file +128 -0
128 lines not on this page · raw message
Adrian Hunter
reviewerPATCH v2 35/37 perf intel-pt: Update documentation to include new ptwrite and power events
In reply to Adrian HunterUpdate documentation to include new ptwrite and power events.
--- tools/perf/Documentation/intel-pt.txt | 42 +++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-)
tools/perf/Documentation/intel-pt.txt +40 -2
@@ -108,6 +108,9 @@ approach is available to export the data to a postgresql database. Refer to script export-to-postgresql.py for more details, and to script call-graph-from-postgresql.py for an example of using the database. +There is also script intel-pt-events.py which provides an example of how to +unpack the raw data for power events and PTWRITE. + As mentioned above, it is easy to capture too much data. One way to limit the data captured is to use 'snapshot' mode which is explained further below. Refer to 'new snapshot option' and 'Intel PT modes of operation' further below.
@@ -710,13 +713,15 @@ Having no option is the same as which, in turn, is the same as - --itrace=ibxe + --itrace=ibxwpe The letters are: i synthesize "instructions" events b synthesize "branches" events x synthesize "transactions" events + w synthesize "ptwrite" events + p synthesize "power" events c synthesize branches events (calls only) r synthesize branches events (returns only) e synthesize tracing error events
@@ -735,7 +740,40 @@ and "r" can be combined to get calls and returns. 'flags' field can be used in perf script to determine whether the event is a tranasaction start, commit or abort. -Error events are new. They show where the decoder lost the trace. Error events +Note that "instructions", "branches" and "transactions" events depend on code +flow packets which can be disabled by using the config term "branch=0". Refer +to the config terms section above. + +"ptwrite" events record the payload of the ptwrite instruction and whether +"fup_on_ptw" was used. "ptwrite" events depend on PTWRITE packets which are +recorded only if the "ptw" config term was used. Refer to the config terms +section above. perf script "synth" field displays "ptwrite" information like +this: "ip: 0 payload: 0x123456789abcdef0" where "ip" is 1 if "fup_on_ptw" was +used. + +"Power" events correspond to power event packets and CBR (core-to-bus ratio) +packets. While CBR packets are always recorded when tracing is enabled, power +event packets are recorded only if the "pwr_evt" config term was used. Refer to +the config terms section above. The power events record information about +C-state changes, whereas CBR is indicative of CPU frequency. perf script +"event,synth" fields display information like this: + cbr: cbr: 22 freq: 2189 MHz (200%) + mwait: hints: 0x60 extensions: 0x1 + pwre: hw: 0 cstate: 2 sub-cstate: 0 + exstop: ip: 1 + pwrx: deepest cstate: 2 last cstate: 2 wake reason: 0x4 +Where: + "cbr" includes the frequency and the percentage of maximum non-turbo + "mwait" shows mwait hints and extensions + "pwre" shows C-state transitions (to a C-state deeper than C0) and + whether initiated by hardware + "exstop" indicates execution stopped and whether the IP was recorded + exactly, + "pwrx" indicates return to C0 +For more details refer to the Intel 64 and IA-32 Architectures Software +Developer Manuals. + +Error events show where the decoder lost the trace. Error events are quite important. Users must know if what they are seeing is a complete picture or not.
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Update documentation to include new ptwrite and power events
perf intel-pt: Update documentation to include new ptwrite and power events
Commit-ID: ead2bfdb85ab311bc3e1c2e55bff207aafaab096 Gitweb: http://git.kernel.org/tip/ead2bfdb85ab311bc3e1c2e55bff207aafaab096 Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:36 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 30 Jun 2017 11:50:54 -0300
perf intel-pt: Update documentation to include new ptwrite and power events
Update documentation to include new ptwrite and power events.
--- tools/perf/Documentation/intel-pt.txt | 42 +++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-)
tools/perf/Documentation/intel-pt.txt +40 -2
@@ -108,6 +108,9 @@ approach is available to export the data to a postgresql database. Refer to script export-to-postgresql.py for more details, and to script call-graph-from-postgresql.py for an example of using the database. +There is also script intel-pt-events.py which provides an example of how to +unpack the raw data for power events and PTWRITE. + As mentioned above, it is easy to capture too much data. One way to limit the data captured is to use 'snapshot' mode which is explained further below. Refer to 'new snapshot option' and 'Intel PT modes of operation' further below.
@@ -710,13 +713,15 @@ Having no option is the same as which, in turn, is the same as - --itrace=ibxe + --itrace=ibxwpe The letters are: i synthesize "instructions" events b synthesize "branches" events x synthesize "transactions" events + w synthesize "ptwrite" events + p synthesize "power" events c synthesize branches events (calls only) r synthesize branches events (returns only) e synthesize tracing error events
@@ -735,7 +740,40 @@ and "r" can be combined to get calls and returns. 'flags' field can be used in perf script to determine whether the event is a tranasaction start, commit or abort. -Error events are new. They show where the decoder lost the trace. Error events +Note that "instructions", "branches" and "transactions" events depend on code +flow packets which can be disabled by using the config term "branch=0". Refer +to the config terms section above. + +"ptwrite" events record the payload of the ptwrite instruction and whether +"fup_on_ptw" was used. "ptwrite" events depend on PTWRITE packets which are +recorded only if the "ptw" config term was used. Refer to the config terms +section above. perf script "synth" field displays "ptwrite" information like +this: "ip: 0 payload: 0x123456789abcdef0" where "ip" is 1 if "fup_on_ptw" was +used. + +"Power" events correspond to power event packets and CBR (core-to-bus ratio) +packets. While CBR packets are always recorded when tracing is enabled, power +event packets are recorded only if the "pwr_evt" config term was used. Refer to +the config terms section above. The power events record information about +C-state changes, whereas CBR is indicative of CPU frequency. perf script +"event,synth" fields display information like this: + cbr: cbr: 22 freq: 2189 MHz (200%) + mwait: hints: 0x60 extensions: 0x1 + pwre: hw: 0 cstate: 2 sub-cstate: 0 + exstop: ip: 1 + pwrx: deepest cstate: 2 last cstate: 2 wake reason: 0x4 +Where: + "cbr" includes the frequency and the percentage of maximum non-turbo + "mwait" shows mwait hints and extensions + "pwre" shows C-state transitions (to a C-state deeper than C0) and + whether initiated by hardware + "exstop" indicates execution stopped and whether the IP was recorded + exactly, + "pwrx" indicates return to C0 +For more details refer to the Intel 64 and IA-32 Architectures Software +Developer Manuals. + +Error events show where the decoder lost the trace. Error events are quite important. Users must know if what they are seeing is a complete picture or not.
Adrian Hunter
reviewerPATCH v2 36/37 perf intel-pt: Do not use TSC packets for calculating CPU cycles to TSC
In reply to Adrian HunterCBR (core-to-bus ratio) packets provide an indication of CPU frequency. A more accurate measure can be made by counting the cycles (given by CYC packets) in between other timing packets (either MTC or TSC). Using TSC packets has at least 2 issues: 1) timing might have stopped (e.g. mwait) or
2) TSC packets within PSB+ might slip past CYC packets. For now, simply do not use TSC packets for calculating CPU cycles to TSC. That leaves the case where 2 MTC packets are used, otherwise falling back to the CBR value.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +14 -0
@@ -711,6 +711,12 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info)break ;case INTEL_PT_TSC : +/* +* For now, do not support using TSC packets - refer +* intel_pt_calc_cyc_to_tsc(). +*/ +if (data->from_mtc) +return 1 ; timestamp = pkt_info->packet.payload | (data->timestamp & (0xffULL <<56 )); if (data->from_mtc && timestamp < data->timestamp &&
@@ -828,6 +834,14 @@ static void intel_pt_calc_cyc_to_tsc(struct intel_pt_decoder *decoder, .cbr_cyc_to_tsc = 0, }; +/* +* For now, do not support using TSC packets for at least the reasons: +* 1) timing might have stopped +* 2) TSC packets within PSB+ can slip against CYC packets +*/ +if (!from_mtc) +return ; +intel_pt_pkt_lookahead (decoder, intel_pt_calc_cyc_cb, &data); }
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf intel-pt: Do not use TSC packets for calculating CPU cycles to TSC
perf intel-pt: Do not use TSC packets for calculating CPU cycles to TSC
Commit-ID: 38b65b0891dc129dc0a5ce148a21c481e667b395 Gitweb: http://git.kernel.org/tip/38b65b0891dc129dc0a5ce148a21c481e667b395 Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:37 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 30 Jun 2017 11:50:55 -0300
perf intel-pt: Do not use TSC packets for calculating CPU cycles to TSC
CBR (core-to-bus ratio) packets provide an indication of CPU frequency. A more accurate measure can be made by counting the cycles (given by CYC packets) in between other timing packets (either MTC or TSC). Using TSC packets has at least 2 issues: 1) timing might have stopped (e.g. mwait) or
2) TSC packets within PSB+ might slip past CYC packets. For now, simply do not use TSC packets for calculating CPU cycles to TSC. That leaves the case where 2 MTC packets are used, otherwise falling back to the CBR value.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +14 -0
@@ -711,6 +711,12 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info)break ;case INTEL_PT_TSC : +/* +* For now, do not support using TSC packets - refer +* intel_pt_calc_cyc_to_tsc(). +*/ +if (data->from_mtc) +return 1 ; timestamp = pkt_info->packet.payload | (data->timestamp & (0xffULL <<56 )); if (data->from_mtc && timestamp < data->timestamp &&
@@ -828,6 +834,14 @@ static void intel_pt_calc_cyc_to_tsc(struct intel_pt_decoder *decoder, .cbr_cyc_to_tsc = 0, }; +/* +* For now, do not support using TSC packets for at least the reasons: +* 1) timing might have stopped +* 2) TSC packets within PSB+ can slip against CYC packets +*/ +if (!from_mtc) +return ; +intel_pt_pkt_lookahead (decoder, intel_pt_calc_cyc_cb, &data); }
Adrian Hunter
reviewerPATCH v2 37/37 perf auxtrace: Add CPU filter support
In reply to Adrian HunterDecoding auxtrace data can take a long time. To avoid decoding unnecessarily, filter auxtrace data that is collected per-cpu before it is decoded.
--- tools/perf/builtin-report.c | 1 + tools/perf/builtin-script.c | 1 + tools/perf/util/auxtrace.c | 10 ++++++++++ tools/perf/util/auxtrace.h | 2 ++ 4 files changed, 14 insertions(+)
tools/perf/builtin-report.c +1 -0
@@ -558,6 +558,7 @@ static int __cmd_report(struct report *rep)ui__error ("failed to set cpu bitmap\n" );return ret; } + session->itrace_synth_opts->cpu_bitmap = rep->cpu_bitmap; }if (rep->show_threads) {
tools/perf/builtin-script.c +1 -0
@@ -2874,6 +2874,7 @@ int cmd_script(int argc, const char **argv) err =perf_session__cpu_bitmap (session, cpu_list, cpu_bitmap);if (err <0 ) goto out_delete; + itrace_synth_opts.cpu_bitmap = cpu_bitmap; }if (!no_callchain)
tools/perf/util/auxtrace.c +10 -0
@@ -322,6 +322,13 @@ static int auxtrace_queues__add_event_buffer(struct auxtrace_queues *queues,return auxtrace_queues__add_buffer (queues, idx, buffer); } +static bool filter_cpu (struct perf_session *session,int cpu) +{ +unsigned long *cpu_bitmap = session->itrace_synth_opts->cpu_bitmap; + +return cpu_bitmap && cpu !=-1 && !test_bit (cpu, cpu_bitmap); +} + int auxtrace_queues__add_event(struct auxtrace_queues *queues, struct perf_session *session, union perf_event *event, off_t data_offset,
@@ -331,6 +338,9 @@ int auxtrace_queues__add_event(struct auxtrace_queues *queues,unsigned int idx;int err; +if (filter_cpu (session, event->auxtrace.cpu)) +return 0 ; + buffer =zalloc (sizeof (struct auxtrace_buffer ));if (!buffer)return -ENOMEM ;
tools/perf/util/auxtrace.h +2 -0
@@ -74,6 +74,7 @@ enum itrace_period_type {* @period: 'instructions' events period * @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 */ struct itrace_synth_opts {bool set;
@@ -96,6 +97,7 @@ struct itrace_synth_opts {unsigned long long period;enum itrace_period_type period_type;unsigned long initial_skip; +unsigned long *cpu_bitmap; };/**
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf auxtrace: Add CPU filter support
perf auxtrace: Add CPU filter support
Commit-ID: 644e0840ad4615e032d67adec6ee60f821b669fe Gitweb: http://git.kernel.org/tip/644e0840ad4615e032d67adec6ee60f821b669fe Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 26 May 2017 11:17:38 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 30 Jun 2017 11:50:55 -0300
perf auxtrace: Add CPU filter support
Decoding auxtrace data can take a long time. To avoid decoding unnecessarily, filter auxtrace data that is collected per-cpu before it is decoded.
--- tools/perf/builtin-report.c | 1 + tools/perf/builtin-script.c | 1 + tools/perf/util/auxtrace.c | 10 ++++++++++ tools/perf/util/auxtrace.h | 2 ++ 4 files changed, 14 insertions(+)
tools/perf/builtin-report.c +1 -0
@@ -557,6 +557,7 @@ static int __cmd_report(struct report *rep)ui__error ("failed to set cpu bitmap\n" );return ret; } + session->itrace_synth_opts->cpu_bitmap = rep->cpu_bitmap; }if (rep->show_threads) {
tools/perf/builtin-script.c +1 -0
@@ -2992,6 +2992,7 @@ int cmd_script(int argc, const char **argv) err =perf_session__cpu_bitmap (session, cpu_list, cpu_bitmap);if (err <0 ) goto out_delete; + itrace_synth_opts.cpu_bitmap = cpu_bitmap; }if (!no_callchain)
tools/perf/util/auxtrace.c +10 -0
@@ -322,6 +322,13 @@ static int auxtrace_queues__add_event_buffer(struct auxtrace_queues *queues,return auxtrace_queues__add_buffer (queues, idx, buffer); } +static bool filter_cpu (struct perf_session *session,int cpu) +{ +unsigned long *cpu_bitmap = session->itrace_synth_opts->cpu_bitmap; + +return cpu_bitmap && cpu !=-1 && !test_bit (cpu, cpu_bitmap); +} + int auxtrace_queues__add_event(struct auxtrace_queues *queues, struct perf_session *session, union perf_event *event, off_t data_offset,
@@ -331,6 +338,9 @@ int auxtrace_queues__add_event(struct auxtrace_queues *queues,unsigned int idx;int err; +if (filter_cpu (session, event->auxtrace.cpu)) +return 0 ; + buffer =zalloc (sizeof (struct auxtrace_buffer ));if (!buffer)return -ENOMEM ;
tools/perf/util/auxtrace.h +2 -0
@@ -74,6 +74,7 @@ enum itrace_period_type {* @period: 'instructions' events period * @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 */ struct itrace_synth_opts {bool set;
@@ -96,6 +97,7 @@ struct itrace_synth_opts {unsigned long long period;enum itrace_period_type period_type;unsigned long initial_skip; +unsigned long *cpu_bitmap; };/**
Adrian Hunter
reviewerQuoted 24 lines · Adrian Hunter
Hi
Here are some patches to support Intel PT Power events and PTWRITE. Power events report changes to C-state but I have also added support for the existing CBR (core-to-bus ratio) packet and included that when outputting power events. The PTWRITE packet is associated with the new ptwrite instruction, which is essentially just a way to stuff a 32 or 64 bit value into the PT trace. More details can be found in the patches that add documentation and in the Intel SDM.
As far as I know, there isn't any hardware released that supports the new packets, however the CBR packet is not new and will now be visible by default.
There are also some miscellaneous improvements to Intel PT.
There are 3 patches that introduce a new way to define synthesized events that carry arbitrary
raw_data. I sent an RFC about that earlier. The 3 patches are:
perf script: Add 'synth' event type for synthesized events perf script: Add 'synth' field for synthesized event payloads perf script: Add synthesized Intel PT power and ptwrite events
Quoted 4 lines
Changes in V2:
Reorder patches and add stable tags to fixes.
Apart from "perf script: Add 'synth' event type for synthesized events" patches still apply. Any comments?
Arnaldo Carvalho de Melo
maintainerEm Mon, Jun 12, 2017 at 04:04:44PM +0300, Adrian Hunter escreveu:
Quoted 25 lines · Adrian Hunter
Quoted 24 lines
Hi
Here are some patches to support Intel PT Power events and PTWRITE. Power events report changes to C-state but I have also added support for the existing CBR (core-to-bus ratio) packet and included that when outputting power events. The PTWRITE packet is associated with the new ptwrite instruction, which is essentially just a way to stuff a 32 or 64 bit value into the PT trace. More details can be found in the patches that add documentation and in the Intel SDM.
As far as I know, there isn't any hardware released that supports the new packets, however the CBR packet is not new and will now be visible by default.
There are also some miscellaneous improvements to Intel PT.
There are 3 patches that introduce a new way to define synthesized events that carry arbitrary
raw_data. I sent an RFC about that earlier. The 3 patches are:
perf script: Add 'synth' event type for synthesized events perf script: Add 'synth' field for synthesized event payloads perf script: Add synthesized Intel PT power and ptwrite events
Quoted 7 lines
Quoted 4 lines
Changes in V2:
Reorder patches and add stable tags to fixes.
Apart from "perf script: Add 'synth' event type for synthesized events" patches still apply. Any comments?
I'll look at it today,
- Arnaldo
Adrian Hunter
reviewerQuoted 28 lines · Arnaldo Carvalho de Melo
Em Mon, Jun 12, 2017 at 04:04:44PM +0300, Adrian Hunter escreveu:
Quoted 27 lines · Adrian Hunter
Quoted 26 lines
Hi
Here are some patches to support Intel PT Power events and PTWRITE. Power events report changes to C-state but I have also added support for the existing CBR (core-to-bus ratio) packet and included that when outputting power events. The PTWRITE packet is associated with the new ptwrite instruction, which is essentially just a way to stuff a 32 or 64 bit value into the PT trace. More details can be found in the patches that add documentation and in the Intel SDM.
As far as I know, there isn't any hardware released that supports the new packets, however the CBR packet is not new and will now be visible by default.
There are also some miscellaneous improvements to Intel PT.
There are 3 patches that introduce a new way to define synthesized events that carry arbitrary
raw_data. I sent an RFC about that earlier. The 3 patches are:
perf script: Add 'synth' event type for synthesized events perf script: Add 'synth' field for synthesized event payloads perf script: Add synthesized Intel PT power and ptwrite eventsChanges in V2:
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Reorder patches and add stable tags to fixes.
Apart from "perf script: Add 'synth' event type for synthesized events" patches still apply. Any comments?
I'll look at it today,
I have sent V3 of two patches that did not now apply cleanly.
Arnaldo Carvalho de Melo
maintainerEm Wed, Jun 21, 2017 at 01:20:52PM +0300, Adrian Hunter escreveu:
Quoted 32 lines · Arnaldo Carvalho de Melo
Quoted 31 lines
Em Mon, Jun 12, 2017 at 04:04:44PM +0300, Adrian Hunter escreveu:
Quoted 30 lines · Adrian Hunter
Quoted 28 lines
Hi
Here are some patches to support Intel PT Power events and PTWRITE. Power events report changes to C-state but I have also added support for the existing CBR (core-to-bus ratio) packet and included that when outputting power events. The PTWRITE packet is associated with the new ptwrite instruction, which is essentially just a way to stuff a 32 or 64 bit value into the PT trace. More details can be found in the patches that add documentation and in the Intel SDM.
As far as I know, there isn't any hardware released that supports the new packets, however the CBR packet is not new and will now be visible by default.
There are also some miscellaneous improvements to Intel PT.
There are 3 patches that introduce a new way to define synthesized events that carry arbitrary
raw_data. I sent an RFC about that earlier. The 3 patches are:
perf script: Add 'synth' event type for synthesized events perf script: Add 'synth' field for synthesized event payloads perf script: Add synthesized Intel PT power and ptwrite eventsChanges in V2:
Reorder patches and add stable tags to fixes.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Apart from "perf script: Add 'synth' event type for synthesized events" patches still apply. Any comments?
I'll look at it today,
I have sent V3 of two patches that did not now apply cleanly.
Thanks, I'm going thru that lot now, trying to understand the synth event types handling in perf script, the ones affected by these refreshed patches...
- Arnaldo
Arnaldo Carvalho de Melo
maintainerEm Mon, Jun 12, 2017 at 10:56:05AM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 28 lines
Em Mon, Jun 12, 2017 at 04:04:44PM +0300, Adrian Hunter escreveu:
Quoted 27 lines · Adrian Hunter
Quoted 26 lines
Hi
Here are some patches to support Intel PT Power events and PTWRITE. Power events report changes to C-state but I have also added support for the existing CBR (core-to-bus ratio) packet and included that when outputting power events. The PTWRITE packet is associated with the new ptwrite instruction, which is essentially just a way to stuff a 32 or 64 bit value into the PT trace. More details can be found in the patches that add documentation and in the Intel SDM.
As far as I know, there isn't any hardware released that supports the new packets, however the CBR packet is not new and will now be visible by default.
There are also some miscellaneous improvements to Intel PT.
There are 3 patches that introduce a new way to define synthesized events that carry arbitrary
raw_data. I sent an RFC about that earlier. The 3 patches are:
perf script: Add 'synth' event type for synthesized events perf script: Add 'synth' field for synthesized event payloads perf script: Add synthesized Intel PT power and ptwrite eventsChanges in V2:
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Reorder patches and add stable tags to fixes.
Apart from "perf script: Add 'synth' event type for synthesized events" patches still apply. Any comments?
I'll look at it today,
Applied, will do some testing on a Kaby Lake machine before pushing to Ingo, will leave in my tmp.perf/core branch before that.
- Arnaldo