diff mbox series

[v3,4/5] perf cs-etm: Optimize copying last branches

Message ID 20200203015203.27882-5-leo.yan@linaro.org (mailing list archive)
State New, archived
Headers show
Series perf cs-etm: Fix synthesizing instruction samples | expand

Commit Message

Leo Yan Feb. 3, 2020, 1:52 a.m. UTC
If an instruction range packet can generate multiple instruction
samples, these samples share the same last branches; it's not necessary
to copy the same last branches repeatedly for these samples within the
same packet.

This patch moves out the last branches copying from function
cs_etm__synth_instruction_sample(), and execute it prior to generating
instruction samples.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 tools/perf/util/cs-etm.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

Comments

Mike Leach Feb. 6, 2020, 11:47 a.m. UTC | #1
Reviewed by: Mike Leach <mike.leach@linaro.org>

On Mon, 3 Feb 2020 at 01:53, Leo Yan <leo.yan@linaro.org> wrote:
>
> If an instruction range packet can generate multiple instruction
> samples, these samples share the same last branches; it's not necessary
> to copy the same last branches repeatedly for these samples within the
> same packet.
>
> This patch moves out the last branches copying from function
> cs_etm__synth_instruction_sample(), and execute it prior to generating
> instruction samples.
>
> Signed-off-by: Leo Yan <leo.yan@linaro.org>
> ---
>  tools/perf/util/cs-etm.c | 22 +++++++++++++++++-----
>  1 file changed, 17 insertions(+), 5 deletions(-)
>
> diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
> index c5a05f728eac..dbddf1eec2be 100644
> --- a/tools/perf/util/cs-etm.c
> +++ b/tools/perf/util/cs-etm.c
> @@ -1134,10 +1134,8 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq,
>
>         cs_etm__copy_insn(etmq, tidq->trace_chan_id, tidq->packet, &sample);
>
> -       if (etm->synth_opts.last_branch) {
> -               cs_etm__copy_last_branch_rb(etmq, tidq);
> +       if (etm->synth_opts.last_branch)
>                 sample.branch_stack = tidq->last_branch;
> -       }
>
>         if (etm->synth_opts.inject) {
>                 ret = cs_etm__inject_event(event, &sample,
> @@ -1407,6 +1405,10 @@ static int cs_etm__sample(struct cs_etm_queue *etmq,
>                  */
>                 u64 instrs_over = instrs_executed;
>
> +               /* Prepare last branches for instruction sample */
> +               if (etm->synth_opts.last_branch)
> +                       cs_etm__copy_last_branch_rb(etmq, tidq);
> +
>                 /*
>                  * 'head' is the instructions number of the head in the new
>                  * packet, it combines with the tail of previous packet to
> @@ -1526,6 +1528,11 @@ static int cs_etm__flush(struct cs_etm_queue *etmq,
>
>         if (etmq->etm->synth_opts.last_branch &&
>             tidq->prev_packet->sample_type == CS_ETM_RANGE) {
> +               u64 addr;
> +
> +               /* Prepare last branches for instruction sample */
> +               cs_etm__copy_last_branch_rb(etmq, tidq);
> +
>                 /*
>                  * Generate a last branch event for the branches left in the
>                  * circular buffer at the end of the trace.
> @@ -1533,7 +1540,7 @@ static int cs_etm__flush(struct cs_etm_queue *etmq,
>                  * Use the address of the end of the last reported execution
>                  * range
>                  */
> -               u64 addr = cs_etm__last_executed_instr(tidq->prev_packet);
> +               addr = cs_etm__last_executed_instr(tidq->prev_packet);
>
>                 err = cs_etm__synth_instruction_sample(
>                         etmq, tidq, addr,
> @@ -1587,11 +1594,16 @@ static int cs_etm__end_block(struct cs_etm_queue *etmq,
>          */
>         if (etmq->etm->synth_opts.last_branch &&
>             tidq->prev_packet->sample_type == CS_ETM_RANGE) {
> +               u64 addr;
> +
> +               /* Prepare last branches for instruction sample */
> +               cs_etm__copy_last_branch_rb(etmq, tidq);
> +
>                 /*
>                  * Use the address of the end of the last reported execution
>                  * range.
>                  */
> -               u64 addr = cs_etm__last_executed_instr(tidq->prev_packet);
> +               addr = cs_etm__last_executed_instr(tidq->prev_packet);
>
>                 err = cs_etm__synth_instruction_sample(
>                         etmq, tidq, addr,
> --
> 2.17.1
>
diff mbox series

Patch

diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index c5a05f728eac..dbddf1eec2be 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -1134,10 +1134,8 @@  static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq,
 
 	cs_etm__copy_insn(etmq, tidq->trace_chan_id, tidq->packet, &sample);
 
-	if (etm->synth_opts.last_branch) {
-		cs_etm__copy_last_branch_rb(etmq, tidq);
+	if (etm->synth_opts.last_branch)
 		sample.branch_stack = tidq->last_branch;
-	}
 
 	if (etm->synth_opts.inject) {
 		ret = cs_etm__inject_event(event, &sample,
@@ -1407,6 +1405,10 @@  static int cs_etm__sample(struct cs_etm_queue *etmq,
 		 */
 		u64 instrs_over = instrs_executed;
 
+		/* Prepare last branches for instruction sample */
+		if (etm->synth_opts.last_branch)
+			cs_etm__copy_last_branch_rb(etmq, tidq);
+
 		/*
 		 * 'head' is the instructions number of the head in the new
 		 * packet, it combines with the tail of previous packet to
@@ -1526,6 +1528,11 @@  static int cs_etm__flush(struct cs_etm_queue *etmq,
 
 	if (etmq->etm->synth_opts.last_branch &&
 	    tidq->prev_packet->sample_type == CS_ETM_RANGE) {
+		u64 addr;
+
+		/* Prepare last branches for instruction sample */
+		cs_etm__copy_last_branch_rb(etmq, tidq);
+
 		/*
 		 * Generate a last branch event for the branches left in the
 		 * circular buffer at the end of the trace.
@@ -1533,7 +1540,7 @@  static int cs_etm__flush(struct cs_etm_queue *etmq,
 		 * Use the address of the end of the last reported execution
 		 * range
 		 */
-		u64 addr = cs_etm__last_executed_instr(tidq->prev_packet);
+		addr = cs_etm__last_executed_instr(tidq->prev_packet);
 
 		err = cs_etm__synth_instruction_sample(
 			etmq, tidq, addr,
@@ -1587,11 +1594,16 @@  static int cs_etm__end_block(struct cs_etm_queue *etmq,
 	 */
 	if (etmq->etm->synth_opts.last_branch &&
 	    tidq->prev_packet->sample_type == CS_ETM_RANGE) {
+		u64 addr;
+
+		/* Prepare last branches for instruction sample */
+		cs_etm__copy_last_branch_rb(etmq, tidq);
+
 		/*
 		 * Use the address of the end of the last reported execution
 		 * range.
 		 */
-		u64 addr = cs_etm__last_executed_instr(tidq->prev_packet);
+		addr = cs_etm__last_executed_instr(tidq->prev_packet);
 
 		err = cs_etm__synth_instruction_sample(
 			etmq, tidq, addr,