perf tools: Get rid of unused 'swapped' parameter from perf_event__synthesize_sample()
Adrian Hunter
reviewercover perf tools: Get rid of unused 'swapped' parameter from perf_event__synthesize_sample()
Hi
Here is a minor tidy-up for perf_event__synthesize_sample().
Adrian Hunter (3):
perf intel-pt/bts: Do not swap when synthesizing samples
perf tools: Ensure reserved member of PERF_SAMPLE_CPU is zero in perf_event__synthesize_sample() perf tools: Get rid of unused 'swapped' parameter from perf_event__synthesize_sample()
tools/perf/builtin-inject.c | 3 +-- tools/perf/tests/sample-parsing.c | 2 +- tools/perf/util/event.h | 3 +-- tools/perf/util/evsel.c | 29 ++--------------------------- tools/perf/util/intel-bts.c | 6 +----- tools/perf/util/intel-pt.c | 11 +++-------- 6 files changed, 9 insertions(+), 45 deletions(-)
Regards
Adrian
Adrian Hunter
reviewerPATCH 1/3 perf intel-pt/bts: Do not swap when synthesizing samples
Both 'perf inject' and internal tools consume cpu endian samples, so there is never a need to do any swapping when synthesizing samples.
--- tools/perf/util/intel-bts.c | 6 +----- tools/perf/util/intel-pt.c | 11 +++-------- 2 files changed, 4 insertions(+), 13 deletions(-)
tools/perf/util/intel-bts.c +1 -5
@@ -67,7 +67,6 @@ struct intel_bts {u64 branches_sample_type;u64 branches_id;size_t branches_event_size; -bool synth_needs_swap;unsigned long num_events; };
@@ -303,8 +302,7 @@ static int intel_bts_synth_branch_sample(struct intel_bts_queue *btsq, event.sample.header.size = bts->branches_event_size; ret =perf_event__synthesize_sample (&event, bts->branches_sample_type, -0 , &sample, - bts->synth_needs_swap); +0 , &sample, false);if (ret)return ret; }
@@ -841,8 +839,6 @@ static int intel_bts_synth_events(struct intel_bts *bts,__perf_evsel__sample_size (attr.sample_type); } - bts->synth_needs_swap = evsel->needs_swap; -return 0 ; }
tools/perf/util/intel-pt.c +3 -8
@@ -104,8 +104,6 @@ struct intel_pt {u64 pwrx_id;u64 cbr_id; -bool synth_needs_swap; -u64 tsc_bit;u64 mtc_bit;u64 mtc_freq_bits;
@@ -1101,11 +1099,10 @@ static void intel_pt_prep_b_sample(struct intel_pt *pt, }static int intel_pt_inject_event (union perf_event *event, -struct perf_sample *sample,u64 type, -bool swapped) +struct perf_sample *sample,u64 type) { event->header.size =perf_event__sample_event_size (sample, type,0 ); -return perf_event__synthesize_sample (event, type,0 , sample, swapped); +return perf_event__synthesize_sample (event, type,0 , sample, false); } static inline int intel_pt_opt_inject(struct intel_pt *pt,
@@ -1115,7 +1112,7 @@ static inline int intel_pt_opt_inject(struct intel_pt *pt,if (!pt->synth_opts.inject)return 0 ; -return intel_pt_inject_event (event, sample, type, pt->synth_needs_swap); +return intel_pt_inject_event (event, sample, type); } static int intel_pt_deliver_synth_b_event(struct intel_pt *pt,
@@ -2329,8 +2326,6 @@ static int intel_pt_synth_events(struct intel_pt *pt, id +=1 ; } - 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/bts: Do not swap when synthesizing samples
perf intel-pt/bts: Do not swap when synthesizing samples
Commit-ID: a10eb530ae497e2411525fc1f5ec73f39eb11c11 Gitweb: https://git.kernel.org/tip/a10eb530ae497e2411525fc1f5ec73f39eb11c11 Author: Adrian Hunter <[email protected]> AuthorDate: Tue, 16 Jan 2018 15:14:50 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 18 Jan 2018 09:00:16 -0300
perf intel-pt/bts: Do not swap when synthesizing samples
Both 'perf inject' and internal tools consume cpu endian samples, so there is never a need to do any swapping when synthesizing samples.
--- tools/perf/util/intel-bts.c | 6 +----- tools/perf/util/intel-pt.c | 11 +++-------- 2 files changed, 4 insertions(+), 13 deletions(-)
tools/perf/util/intel-bts.c +1 -5
@@ -67,7 +67,6 @@ struct intel_bts {u64 branches_sample_type;u64 branches_id;size_t branches_event_size; -bool synth_needs_swap;unsigned long num_events; };
@@ -303,8 +302,7 @@ static int intel_bts_synth_branch_sample(struct intel_bts_queue *btsq, event.sample.header.size = bts->branches_event_size; ret =perf_event__synthesize_sample (&event, bts->branches_sample_type, -0 , &sample, - bts->synth_needs_swap); +0 , &sample, false);if (ret)return ret; }
@@ -841,8 +839,6 @@ static int intel_bts_synth_events(struct intel_bts *bts,__perf_evsel__sample_size (attr.sample_type); } - bts->synth_needs_swap = evsel->needs_swap; -return 0 ; }
tools/perf/util/intel-pt.c +3 -8
@@ -104,8 +104,6 @@ struct intel_pt {u64 pwrx_id;u64 cbr_id; -bool synth_needs_swap; -u64 tsc_bit;u64 mtc_bit;u64 mtc_freq_bits;
@@ -1101,11 +1099,10 @@ static void intel_pt_prep_b_sample(struct intel_pt *pt, }static int intel_pt_inject_event (union perf_event *event, -struct perf_sample *sample,u64 type, -bool swapped) +struct perf_sample *sample,u64 type) { event->header.size =perf_event__sample_event_size (sample, type,0 ); -return perf_event__synthesize_sample (event, type,0 , sample, swapped); +return perf_event__synthesize_sample (event, type,0 , sample, false); } static inline int intel_pt_opt_inject(struct intel_pt *pt,
@@ -1115,7 +1112,7 @@ static inline int intel_pt_opt_inject(struct intel_pt *pt,if (!pt->synth_opts.inject)return 0 ; -return intel_pt_inject_event (event, sample, type, pt->synth_needs_swap); +return intel_pt_inject_event (event, sample, type); } static int intel_pt_deliver_synth_b_event(struct intel_pt *pt,
@@ -2329,8 +2326,6 @@ static int intel_pt_synth_events(struct intel_pt *pt, id +=1 ; } - pt->synth_needs_swap = evsel->needs_swap; -return 0 ; }
Adrian Hunter
reviewerPATCH 2/3 perf tools: Ensure reserved member of PERF_SAMPLE_CPU is zero in perf_event__synthesize_sample()
In reply to Adrian HunterPERF_SAMPLE_CPU contains the cpu number in the first 4 bytes and the second 4 bytes are reserved. Ensure the reserved bytes are zero in perf_event__synthesize_sample().
--- tools/perf/util/evsel.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/util/evsel.c +1 -0
@@ -2523,6 +2523,7 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type,if (type &PERF_SAMPLE_CPU ) { u.val32[0 ] = sample->cpu; + u.val32[1 ] =0 ;if (swapped) {/* * Inverse of what is done in perf_evsel__parse_sample
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf evsel: Ensure reserved member of PERF_SAMPLE_CPU is zero in perf_event__synthesize_sample()
perf evsel: Ensure reserved member of PERF_SAMPLE_CPU is zero in perf_event__synthesize_sample()
Commit-ID: 59a87fdad1467d228acc5cb1303b0b568a9e86a8 Gitweb: https://git.kernel.org/tip/59a87fdad1467d228acc5cb1303b0b568a9e86a8 Author: Adrian Hunter <[email protected]> AuthorDate: Tue, 16 Jan 2018 15:14:51 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 18 Jan 2018 09:00:45 -0300
perf evsel: Ensure reserved member of PERF_SAMPLE_CPU is zero in perf_event__synthesize_sample()
PERF_SAMPLE_CPU contains the cpu number in the first 4 bytes and the second 4 bytes are reserved. Ensure the reserved bytes are zero in perf_event__synthesize_sample().
--- tools/perf/util/evsel.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/util/evsel.c +1 -0
@@ -2533,6 +2533,7 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type,if (type &PERF_SAMPLE_CPU ) { u.val32[0 ] = sample->cpu; + u.val32[1 ] =0 ;if (swapped) {/* * Inverse of what is done in perf_evsel__parse_sample
Adrian Hunter
reviewerPATCH 3/3 perf tools: Get rid of unused 'swapped' parameter from perf_event__synthesize_sample()
In reply to Adrian HunterThere is never a need to synthesize a 'swapped' sample, so all callers to perf_event__synthesize_sample() pass 'false' as the value to 'swapped'. So get rid of the unused 'swapped' parameter.
--- tools/perf/builtin-inject.c | 3 +-- tools/perf/tests/sample-parsing.c | 2 +- tools/perf/util/event.h | 3 +-- tools/perf/util/evsel.c | 28 +--------------------------- tools/perf/util/intel-bts.c | 2 +- tools/perf/util/intel-pt.c | 2 +- 6 files changed, 6 insertions(+), 34 deletions(-)
tools/perf/builtin-inject.c +1 -2
@@ -536,8 +536,7 @@ static int perf_inject__sched_stat(struct perf_tool *tool, sample_sw.period = sample->period; sample_sw.time = sample->time;perf_event__synthesize_sample (event_sw, evsel->attr.sample_type, - evsel->attr.read_format, &sample_sw, - false); + evsel->attr.read_format, &sample_sw);build_id__mark_dso_hit (tool, event_sw, &sample_sw, evsel, machine);return perf_event__repipe (tool, event_sw, &sample_sw, machine); }
tools/perf/tests/sample-parsing.c +1 -1
@@ -248,7 +248,7 @@ static int do_test(u64 sample_type, u64 sample_regs, u64 read_format) event->header.size = sz; err =perf_event__synthesize_sample (event, sample_type, read_format, - &sample, false); + &sample);if (err) {pr_debug ("%s failed for sample_type %#" PRIx64", error %d\n" ,"perf_event__synthesize_sample" , sample_type, err);
tools/perf/util/event.h +1 -2
@@ -775,8 +775,7 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, u64 read_format);int perf_event__synthesize_sample (union perf_event *event,u64 type,u64 read_format, -const struct perf_sample *sample, -bool swapped); +const struct perf_sample *sample); pid_t perf_event__synthesize_comm(struct perf_tool *tool, union perf_event *event, pid_t pid,
tools/perf/util/evsel.c +1 -27
@@ -2462,8 +2462,7 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,int perf_event__synthesize_sample (union perf_event *event,u64 type,u64 read_format, -const struct perf_sample *sample, -bool swapped) +const struct perf_sample *sample) {u64 *array;size_t sz;
@@ -2488,15 +2487,6 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type,if (type &PERF_SAMPLE_TID ) { u.val32[0 ] = sample->pid; u.val32[1 ] = sample->tid; -if (swapped) { -/* -* Inverse of what is done in perf_evsel__parse_sample -*/ - u.val32[0 ] =bswap_32 (u.val32[0 ]); - u.val32[1 ] =bswap_32 (u.val32[1 ]); - u.val64 =bswap_64 (u.val64); - } - *array = u.val64; array++; }
@@ -2524,13 +2514,6 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type,if (type &PERF_SAMPLE_CPU ) { u.val32[0 ] = sample->cpu; u.val32[1 ] =0 ; -if (swapped) { -/* -* Inverse of what is done in perf_evsel__parse_sample -*/ - u.val32[0 ] =bswap_32 (u.val32[0 ]); - u.val64 =bswap_64 (u.val64); - } *array = u.val64; array++; }
@@ -2577,15 +2560,6 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type,if (type &PERF_SAMPLE_RAW ) { u.val32[0 ] = sample->raw_size; -if (WARN_ONCE (swapped, -"Endianness of raw data not corrected!\n" )) { -/* -* Inverse of what is done in perf_evsel__parse_sample -*/ - u.val32[0 ] =bswap_32 (u.val32[0 ]); - u.val32[1 ] =bswap_32 (u.val32[1 ]); - u.val64 =bswap_64 (u.val64); - } *array = u.val64; array = (void *)array +sizeof (u32);
tools/perf/util/intel-bts.c +1 -1
@@ -302,7 +302,7 @@ static int intel_bts_synth_branch_sample(struct intel_bts_queue *btsq, event.sample.header.size = bts->branches_event_size; ret =perf_event__synthesize_sample (&event, bts->branches_sample_type, -0 , &sample, false); +0 , &sample);if (ret)return ret; }
tools/perf/util/intel-pt.c +1 -1
@@ -1102,7 +1102,7 @@ static int intel_pt_inject_event(union perf_event *event, struct perf_sample *sample, u64 type) { event->header.size =perf_event__sample_event_size (sample, type,0 ); -return perf_event__synthesize_sample (event, type,0 , sample, false); +return perf_event__synthesize_sample (event, type,0 , sample); } static inline int intel_pt_opt_inject(struct intel_pt *pt,
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge botperf tools: Get rid of unused 'swapped' parameter from perf_event__synthesize_sample()
Commit-ID: 936f1f30bb7892f010670f1edebc419d47b139b1 Gitweb: https://git.kernel.org/tip/936f1f30bb7892f010670f1edebc419d47b139b1 Author: Adrian Hunter <[email protected]> AuthorDate: Tue, 16 Jan 2018 15:14:52 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 18 Jan 2018 09:01:23 -0300
perf tools: Get rid of unused 'swapped' parameter from perf_event__synthesize_sample()
There is never a need to synthesize a 'swapped' sample, so all callers to perf_event__synthesize_sample() pass 'false' as the value to 'swapped'. So get rid of the unused 'swapped' parameter.
--- tools/perf/builtin-inject.c | 3 +-- tools/perf/tests/sample-parsing.c | 2 +- tools/perf/util/event.h | 3 +-- tools/perf/util/evsel.c | 28 +--------------------------- tools/perf/util/intel-bts.c | 2 +- tools/perf/util/intel-pt.c | 2 +- 6 files changed, 6 insertions(+), 34 deletions(-)
tools/perf/builtin-inject.c +1 -2
@@ -536,8 +536,7 @@ found: sample_sw.period = sample->period; sample_sw.time = sample->time;perf_event__synthesize_sample (event_sw, evsel->attr.sample_type, - evsel->attr.read_format, &sample_sw, - false); + evsel->attr.read_format, &sample_sw);build_id__mark_dso_hit (tool, event_sw, &sample_sw, evsel, machine);return perf_event__repipe (tool, event_sw, &sample_sw, machine); }
tools/perf/tests/sample-parsing.c +1 -1
@@ -248,7 +248,7 @@ static int do_test(u64 sample_type, u64 sample_regs, u64 read_format) event->header.size = sz; err =perf_event__synthesize_sample (event, sample_type, read_format, - &sample, false); + &sample);if (err) {pr_debug ("%s failed for sample_type %#" PRIx64", error %d\n" ,"perf_event__synthesize_sample" , sample_type, err);
tools/perf/util/event.h +1 -2
@@ -775,8 +775,7 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, u64 read_format);int perf_event__synthesize_sample (union perf_event *event,u64 type,u64 read_format, -const struct perf_sample *sample, -bool swapped); +const struct perf_sample *sample); pid_t perf_event__synthesize_comm(struct perf_tool *tool, union perf_event *event, pid_t pid,
tools/perf/util/evsel.c +1 -27
@@ -2472,8 +2472,7 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,int perf_event__synthesize_sample (union perf_event *event,u64 type,u64 read_format, -const struct perf_sample *sample, -bool swapped) +const struct perf_sample *sample) {u64 *array;size_t sz;
@@ -2498,15 +2497,6 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type,if (type &PERF_SAMPLE_TID ) { u.val32[0 ] = sample->pid; u.val32[1 ] = sample->tid; -if (swapped) { -/* -* Inverse of what is done in perf_evsel__parse_sample -*/ - u.val32[0 ] =bswap_32 (u.val32[0 ]); - u.val32[1 ] =bswap_32 (u.val32[1 ]); - u.val64 =bswap_64 (u.val64); - } - *array = u.val64; array++; }
@@ -2534,13 +2524,6 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type,if (type &PERF_SAMPLE_CPU ) { u.val32[0 ] = sample->cpu; u.val32[1 ] =0 ; -if (swapped) { -/* -* Inverse of what is done in perf_evsel__parse_sample -*/ - u.val32[0 ] =bswap_32 (u.val32[0 ]); - u.val64 =bswap_64 (u.val64); - } *array = u.val64; array++; }
@@ -2587,15 +2570,6 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type,if (type &PERF_SAMPLE_RAW ) { u.val32[0 ] = sample->raw_size; -if (WARN_ONCE (swapped, -"Endianness of raw data not corrected!\n" )) { -/* -* Inverse of what is done in perf_evsel__parse_sample -*/ - u.val32[0 ] =bswap_32 (u.val32[0 ]); - u.val32[1 ] =bswap_32 (u.val32[1 ]); - u.val64 =bswap_64 (u.val64); - } *array = u.val64; array = (void *)array +sizeof (u32);
tools/perf/util/intel-bts.c +1 -1
@@ -302,7 +302,7 @@ static int intel_bts_synth_branch_sample(struct intel_bts_queue *btsq, event.sample.header.size = bts->branches_event_size; ret =perf_event__synthesize_sample (&event, bts->branches_sample_type, -0 , &sample, false); +0 , &sample);if (ret)return ret; }
tools/perf/util/intel-pt.c +1 -1
@@ -1102,7 +1102,7 @@ static int intel_pt_inject_event(union perf_event *event, struct perf_sample *sample, u64 type) { event->header.size =perf_event__sample_event_size (sample, type,0 ); -return perf_event__synthesize_sample (event, type,0 , sample, false); +return perf_event__synthesize_sample (event, type,0 , sample); } static inline int intel_pt_opt_inject(struct intel_pt *pt,
Quoted 9 lines · Adrian Hunter
Hi
Here is a minor tidy-up for
perf_event__synthesize_sample().Adrian Hunter (3):
perf intel-pt/bts: Do not swap when synthesizing samples
perf tools: Ensure reserved member ofPERF_SAMPLE_CPUis zero inperf_event__synthesize_sample()perf tools: Get rid of unused 'swapped' parameter fromperf_event__synthesize_sample()
thanks,
jirka