perf tools: CoreSight code cleanup and refactoring
cover perf tools: CoreSight code cleanup and refactoring
Good day Arnaldo,
The only reason I'm sending this set so late in the cycle is that it does absolutely nothing other than cleaning up and refactoring code - not a single new feature is added here.
As such if my colleagues on CoreSight get to review it fast enough I leave it entirely to you to decide if you want to queue it for the 5.1 merge window. If that is not enough time then ignore the whole thing and I will resend when a new rc1 has been released.
Thank you for your time,
Mathieu
Mathieu Poirier (13):
perf tools: Remove unused structure field "state" perf tools: Remove unused structure field "time" and "timestamp" perf tools: Fix wrong return values in error path perf tools: Introducing function cs_etm_decoder__init_dparams() perf tools: Fix memory leak in error path
perf tools: Introducing function cs_etm__init_trace_params() perf tools: Fix erroneous comment
perf tools: Cleaning up function cs_etm__alloc_queue() perf tools: Rethink kernel address initialisation perf tools: Make cs_etm__run_decoder() queue independent perf tools: Modularize main decoder function
perf tools: Modularize main packet processing loop perf tools: Modularize auxtrace_buffer fetch function
.../perf/util/cs-etm-decoder/cs-etm-decoder.h | 10 +- tools/perf/util/cs-etm.c | 457 ++++++++++-------- tools/perf/util/cs-etm.h | 4 +- 3 files changed, 262 insertions(+), 209 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/13 perf tools: Remove unused structure field "state"
Field "state" in structure cs_etm_queue is no longer used and needs to be removed.
--- tools/perf/util/cs-etm.c | 1 - 1 file changed, 1 deletion(-)
tools/perf/util/cs-etm.c +0 -1
@@ -65,7 +65,6 @@ struct cs_etm_queue {struct thread *thread;struct cs_etm_decoder *decoder;struct auxtrace_buffer *buffer; -const struct cs_etm_state *state;union perf_event *event_buf;unsigned int queue_nr;pid_t pid, tid;
Signature · 7 lines
2.17.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
tip-bot for Mathieu Poirier
merge bot[tip:perf/core] perf cs-etm: Remove unused structure field "state"
perf cs-etm: Remove unused structure field "state"
Commit-ID: b611f63bb1b7ba20e87d9d0d7af88d247bcf98eb Gitweb: https://git.kernel.org/tip/b611f63bb1b7ba20e87d9d0d7af88d247bcf98eb Author: Mathieu Poirier <[email protected]> AuthorDate: Tue, 12 Feb 2019 10:16:06 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 14 Feb 2019 15:18:06 -0300
perf cs-etm: Remove unused structure field "state"
Field "state" in structure cs_etm_queue is no longer used and needs to be removed.
--- tools/perf/util/cs-etm.c | 1 - 1 file changed, 1 deletion(-)
tools/perf/util/cs-etm.c +0 -1
@@ -65,7 +65,6 @@ struct cs_etm_queue {struct thread *thread;struct cs_etm_decoder *decoder;struct auxtrace_buffer *buffer; -const struct cs_etm_state *state;union perf_event *event_buf;unsigned int queue_nr;pid_t pid, tid;
PATCH 2/13 perf tools: Remove unused structure field "time" and "timestamp"
In reply to Mathieu PoirierField "time" and "timestamp" in structure cs_etm_queue are no longer used and need to be removed.
--- tools/perf/util/cs-etm.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
tools/perf/util/cs-etm.c +4 -8
@@ -69,8 +69,6 @@ struct cs_etm_queue {unsigned int queue_nr;pid_t pid, tid;int cpu; -u64 time; -u64 timestamp;u64 offset;u64 period_instructions;struct branch_stack *last_branch;
@@ -82,7 +80,7 @@ struct cs_etm_queue {static int cs_etm__update_queues (struct cs_etm_auxtrace *etm);static int cs_etm__process_timeless_queues (struct cs_etm_auxtrace *etm, -pid_t tid,u64 time_); +pid_t tid);/* PTMs ETMIDR [11:8] set to b0011 */ #define ETMIDR_PTM_VERSION 0x00000300
@@ -234,7 +232,7 @@ static int cs_etm__flush_events(struct perf_session *session,if (ret <0 )return ret; -return cs_etm__process_timeless_queues (etm,-1 ,MAX_TIMESTAMP -1 ); +return cs_etm__process_timeless_queues (etm,-1 ); }static void cs_etm__free_queue (void *priv)
@@ -1583,7 +1581,7 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq) }static int cs_etm__process_timeless_queues (struct cs_etm_auxtrace *etm, -pid_t tid,u64 time_) +pid_t tid) {unsigned int i;struct auxtrace_queues *queues = &etm->queues;
@@ -1593,7 +1591,6 @@ static int cs_etm__process_timeless_queues(struct cs_etm_auxtrace *etm,struct cs_etm_queue *etmq = queue->priv;if (etmq && ((tid ==-1 ) || (etmq->tid == tid))) { - etmq->time = time_;cs_etm__set_pid_tid_cpu (etm, queue);cs_etm__run_decoder (etmq); }
@@ -1637,8 +1634,7 @@ static int cs_etm__process_event(struct perf_session *session,if (event->header.type ==PERF_RECORD_EXIT )return cs_etm__process_timeless_queues (etm, - event->fork.tid, - sample->time); + event->fork.tid);return 0 ; }
Signature · 1 line
2.17.1
tip-bot for Mathieu Poirier
merge bot[tip:perf/core] perf cs-etm: Remove unused structure field "time" and "timestamp"
perf cs-etm: Remove unused structure field "time" and "timestamp"
Commit-ID: fc7ac4138cf5ab76850bca2b9a8f43449c762a37 Gitweb: https://git.kernel.org/tip/fc7ac4138cf5ab76850bca2b9a8f43449c762a37 Author: Mathieu Poirier <[email protected]> AuthorDate: Tue, 12 Feb 2019 10:16:07 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 14 Feb 2019 15:18:06 -0300
perf cs-etm: Remove unused structure field "time" and "timestamp"
Field "time" and "timestamp" in structure cs_etm_queue are no longer used and need to be removed.
--- tools/perf/util/cs-etm.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
tools/perf/util/cs-etm.c +4 -8
@@ -69,8 +69,6 @@ struct cs_etm_queue {unsigned int queue_nr;pid_t pid, tid;int cpu; -u64 time; -u64 timestamp;u64 offset;u64 period_instructions;struct branch_stack *last_branch;
@@ -82,7 +80,7 @@ struct cs_etm_queue {static int cs_etm__update_queues (struct cs_etm_auxtrace *etm);static int cs_etm__process_timeless_queues (struct cs_etm_auxtrace *etm, -pid_t tid,u64 time_); +pid_t tid);/* PTMs ETMIDR [11:8] set to b0011 */ #define ETMIDR_PTM_VERSION 0x00000300
@@ -234,7 +232,7 @@ static int cs_etm__flush_events(struct perf_session *session,if (ret <0 )return ret; -return cs_etm__process_timeless_queues (etm,-1 ,MAX_TIMESTAMP -1 ); +return cs_etm__process_timeless_queues (etm,-1 ); }static void cs_etm__free_queue (void *priv)
@@ -1583,7 +1581,7 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq) }static int cs_etm__process_timeless_queues (struct cs_etm_auxtrace *etm, -pid_t tid,u64 time_) +pid_t tid) {unsigned int i;struct auxtrace_queues *queues = &etm->queues;
@@ -1593,7 +1591,6 @@ static int cs_etm__process_timeless_queues(struct cs_etm_auxtrace *etm,struct cs_etm_queue *etmq = queue->priv;if (etmq && ((tid ==-1 ) || (etmq->tid == tid))) { - etmq->time = time_;cs_etm__set_pid_tid_cpu (etm, queue);cs_etm__run_decoder (etmq); }
@@ -1637,8 +1634,7 @@ static int cs_etm__process_event(struct perf_session *session,if (event->header.type ==PERF_RECORD_EXIT )return cs_etm__process_timeless_queues (etm, - event->fork.tid, - sample->time); + event->fork.tid);return 0 ; }
PATCH 3/13 perf tools: Fix wrong return values in error path
In reply to Mathieu PoirierFunction cs_etm__mem_access() is supposed to return a u32 but the error path returns negative values at a couple of places, something that really throws off the clients using it. Fix the situation by return '0'.
--- tools/perf/util/cs-etm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/cs-etm.c +2 -2
@@ -324,7 +324,7 @@ static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u64 address,struct addr_location al;if (!etmq) -return -1 ; +return 0 ; machine = etmq->etm->machine; cpumode =cs_etm__cpu_mode (etmq, address);
@@ -332,7 +332,7 @@ static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u64 address, thread = etmq->thread;if (!thread) {if (cpumode !=PERF_RECORD_MISC_KERNEL ) -return -EINVAL ; +return 0 ; thread = etmq->etm->unknown_thread; }
Signature · 7 lines
2.17.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
tip-bot for Mathieu Poirier
merge bot[tip:perf/core] perf cs-etm: Fix wrong return values in error path
perf cs-etm: Fix wrong return values in error path
Commit-ID: d3267ad43dd8b3778f9b3deb9a3946c844bdc9dc Gitweb: https://git.kernel.org/tip/d3267ad43dd8b3778f9b3deb9a3946c844bdc9dc Author: Mathieu Poirier <[email protected]> AuthorDate: Tue, 12 Feb 2019 10:16:08 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 14 Feb 2019 15:18:06 -0300
perf cs-etm: Fix wrong return values in error path
Function cs_etm__mem_access() is supposed to return a u32 but the error path returns negative values at a couple of places, something that really throws off the clients using it. Fix the situation by return '0'.
--- tools/perf/util/cs-etm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/cs-etm.c +2 -2
@@ -324,7 +324,7 @@ static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u64 address,struct addr_location al;if (!etmq) -return -1 ; +return 0 ; machine = etmq->etm->machine; cpumode =cs_etm__cpu_mode (etmq, address);
@@ -332,7 +332,7 @@ static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u64 address, thread = etmq->thread;if (!thread) {if (cpumode !=PERF_RECORD_MISC_KERNEL ) -return -EINVAL ; +return 0 ; thread = etmq->etm->unknown_thread; }
PATCH 4/13 perf tools: Introducing function cs_etm_decoder__init_dparams()
In reply to Mathieu PoirierIntroducing function cs_etm_decoder__init_dparams() to avoid repeating code at two different places.
--- .../perf/util/cs-etm-decoder/cs-etm-decoder.h | 3 +- tools/perf/util/cs-etm.c | 41 +++++++++++++------ 2 files changed, 30 insertions(+), 14 deletions(-)
tools/perf/util/cs-etm-decoder/cs-etm-decoder.h +2 -1
@@ -105,9 +105,10 @@ enum { CS_ETM_PROTO_PTM, }; -enum { +enum cs_etm_decoder_operation {CS_ETM_OPERATION_PRINT =1 ,CS_ETM_OPERATION_DECODE , +CS_ETM_OPERATION_MAX , }; int cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder,
tools/perf/util/cs-etm.c +28 -13
59 lines not on this page · raw message
Signature · 1 line
2.17.1
tip-bot for Mathieu Poirier
merge bot[tip:perf/core] perf cs-etm: Introducing function cs_etm_decoder__init_dparams()
perf cs-etm: Introducing function cs_etm_decoder__init_dparams()
Commit-ID: 65963e5b4dfa9b9ba4bdf7ef8dc7d4424cfd2097 Gitweb: https://git.kernel.org/tip/65963e5b4dfa9b9ba4bdf7ef8dc7d4424cfd2097 Author: Mathieu Poirier <[email protected]> AuthorDate: Tue, 12 Feb 2019 10:16:09 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 14 Feb 2019 15:18:06 -0300
perf cs-etm: Introducing function cs_etm_decoder__init_dparams()
Introducing function cs_etm_decoder__init_dparams() to avoid repeating code at two different places.
--- tools/perf/util/cs-etm-decoder/cs-etm-decoder.h | 3 +- tools/perf/util/cs-etm.c | 41 +++++++++++++++++-------- 2 files changed, 30 insertions(+), 14 deletions(-)
tools/perf/util/cs-etm-decoder/cs-etm-decoder.h +2 -1
@@ -105,9 +105,10 @@ enum { CS_ETM_PROTO_PTM, }; -enum { +enum cs_etm_decoder_operation {CS_ETM_OPERATION_PRINT =1 ,CS_ETM_OPERATION_DECODE , +CS_ETM_OPERATION_MAX , }; int cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder,
tools/perf/util/cs-etm.c +28 -13
59 lines not on this page · raw message
PATCH 5/13 perf tools: Fix memory leak in error path
In reply to Mathieu PoirierMemory allocated for variable 't_params' isn't released properly in the error path of function cs_etm_queue *cs_etm__alloc_queue() and cs_etm__dump_event(), something this patch addresses.
--- tools/perf/util/cs-etm.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
tools/perf/util/cs-etm.c +13 -7
@@ -175,6 +175,10 @@ static void cs_etm__dump_event(struct cs_etm_auxtrace *etm,/* Use metadata to fill in trace parameters for trace decoder */ t_params =zalloc (sizeof (*t_params) * etm->num_cpu); + +if (!t_params) +return ; +for (i =0 ; i < etm->num_cpu; i++) {if (etm->metadata[i][CS_ETM_MAGIC ] == __perf_cs_etmv3_magic) {u32 etmidr = etm->metadata[i][CS_ETM_ETMIDR ];
@@ -206,14 +210,12 @@ static void cs_etm__dump_event(struct cs_etm_auxtrace *etm,/* Set decoder parameters to simply print the trace packets */ if (cs_etm__init_decoder_params (&d_params,NULL ,CS_ETM_OPERATION_PRINT )) -return ; + goto out_free; decoder =cs_etm_decoder__new (etm->num_cpu, &d_params, t_params); -zfree (&t_params); -if (!decoder) -return ; + goto out_free; do { size_t consumed;
@@ -228,6 +230,9 @@ static void cs_etm__dump_event(struct cs_etm_auxtrace *etm, }while (buffer_used < buffer->size);cs_etm_decoder__free (decoder); + +out_free: +zfree (&t_params); } static int cs_etm__flush_events(struct perf_session *session,
@@ -379,7 +384,7 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, {int i;struct cs_etm_decoder_params d_params; -struct cs_etm_trace_params *t_params; +struct cs_etm_trace_params *t_params =NULL ;struct cs_etm_queue *etmq;size_t szp =sizeof (struct cs_etm_packet );
@@ -461,8 +466,6 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, etmq->decoder =cs_etm_decoder__new (etm->num_cpu, &d_params, t_params); -zfree (&t_params); -if (!etmq->decoder) goto out_free;
@@ -475,6 +478,8 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, cs_etm__mem_access)) goto out_free_decoder; +zfree (&t_params); + etmq->offset =0 ; etmq->period_instructions =0 ;
@@ -483,6 +488,7 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, out_free_decoder:cs_etm_decoder__free (etmq->decoder); out_free: +zfree (&t_params);zfree (&etmq->event_buf);zfree (&etmq->last_branch);zfree (&etmq->last_branch_rb);
Signature · 1 line
2.17.1
tip-bot for Mathieu Poirier
merge bot[tip:perf/core] perf cs-etm: Fix memory leak in error path
perf cs-etm: Fix memory leak in error path
Commit-ID: ae4d9f5236439ef08f9963f39d5984959b1ae04d Gitweb: https://git.kernel.org/tip/ae4d9f5236439ef08f9963f39d5984959b1ae04d Author: Mathieu Poirier <[email protected]> AuthorDate: Tue, 12 Feb 2019 10:16:10 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 14 Feb 2019 15:18:06 -0300
perf cs-etm: Fix memory leak in error path
Memory allocated for variable 't_params' isn't released properly in the error path of function cs_etm_queue *cs_etm__alloc_queue() and cs_etm__dump_event(), something this patch addresses.
--- tools/perf/util/cs-etm.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
tools/perf/util/cs-etm.c +13 -7
@@ -175,6 +175,10 @@ static void cs_etm__dump_event(struct cs_etm_auxtrace *etm,/* Use metadata to fill in trace parameters for trace decoder */ t_params =zalloc (sizeof (*t_params) * etm->num_cpu); + +if (!t_params) +return ; +for (i =0 ; i < etm->num_cpu; i++) {if (etm->metadata[i][CS_ETM_MAGIC ] == __perf_cs_etmv3_magic) {u32 etmidr = etm->metadata[i][CS_ETM_ETMIDR ];
@@ -206,14 +210,12 @@ static void cs_etm__dump_event(struct cs_etm_auxtrace *etm,/* Set decoder parameters to simply print the trace packets */ if (cs_etm__init_decoder_params (&d_params,NULL ,CS_ETM_OPERATION_PRINT )) -return ; + goto out_free; decoder =cs_etm_decoder__new (etm->num_cpu, &d_params, t_params); -zfree (&t_params); -if (!decoder) -return ; + goto out_free; do { size_t consumed;
@@ -228,6 +230,9 @@ static void cs_etm__dump_event(struct cs_etm_auxtrace *etm, }while (buffer_used < buffer->size);cs_etm_decoder__free (decoder); + +out_free: +zfree (&t_params); } static int cs_etm__flush_events(struct perf_session *session,
@@ -379,7 +384,7 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, {int i;struct cs_etm_decoder_params d_params; -struct cs_etm_trace_params *t_params; +struct cs_etm_trace_params *t_params =NULL ;struct cs_etm_queue *etmq;size_t szp =sizeof (struct cs_etm_packet );
@@ -461,8 +466,6 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, etmq->decoder =cs_etm_decoder__new (etm->num_cpu, &d_params, t_params); -zfree (&t_params); -if (!etmq->decoder) goto out_free;
@@ -475,6 +478,8 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, cs_etm__mem_access)) goto out_free_decoder; +zfree (&t_params); + etmq->offset =0 ; etmq->period_instructions =0 ;
@@ -483,6 +488,7 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, out_free_decoder:cs_etm_decoder__free (etmq->decoder); out_free: +zfree (&t_params);zfree (&etmq->event_buf);zfree (&etmq->last_branch);zfree (&etmq->last_branch_rb);
PATCH 6/13 perf tools: Introducing function cs_etm__init_trace_params()
In reply to Mathieu PoirierThe trace parameter initialisation code is repeated in two different places, something that bloats the file and can lead to errors. This is fixed by introducing a helper function and calling the right protocol initialisation code when required.
--- tools/perf/util/cs-etm.c | 112 +++++++++++++++++++-------------------- tools/perf/util/cs-etm.h | 4 +- 2 files changed, 58 insertions(+), 58 deletions(-)
tools/perf/util/cs-etm.c +56 -56
@@ -136,6 +136,57 @@ static void cs_etm__packet_dump(const char *pkt_string)fflush (stdout); } +static void cs_etm__set_trace_param_etmv3 (struct cs_etm_trace_params *t_params, +struct cs_etm_auxtrace *etm,int idx, +u32 etmidr) +{ +u64 **metadata = etm->metadata; + + t_params[idx].protocol =cs_etm__get_v7_protocol_version (etmidr); + t_params[idx].etmv3.reg_ctrl = metadata[idx][CS_ETM_ETMCR ]; + t_params[idx].etmv3.reg_trc_id = metadata[idx][CS_ETM_ETMTRACEIDR ]; +} + +static void cs_etm__set_trace_param_etmv4 (struct cs_etm_trace_params *t_params, +struct cs_etm_auxtrace *etm,int idx) +{ +u64 **metadata = etm->metadata; + + t_params[idx].protocol = CS_ETM_PROTO_ETMV4i; + t_params[idx].etmv4.reg_idr0 = metadata[idx][CS_ETMV4_TRCIDR0 ]; + t_params[idx].etmv4.reg_idr1 = metadata[idx][CS_ETMV4_TRCIDR1 ]; + t_params[idx].etmv4.reg_idr2 = metadata[idx][CS_ETMV4_TRCIDR2 ]; + t_params[idx].etmv4.reg_idr8 = metadata[idx][CS_ETMV4_TRCIDR8 ]; + t_params[idx].etmv4.reg_configr = metadata[idx][CS_ETMV4_TRCCONFIGR ]; + t_params[idx].etmv4.reg_traceidr = metadata[idx][CS_ETMV4_TRCTRACEIDR ]; +} + +static int cs_etm__init_trace_params (struct cs_etm_trace_params *t_params, +struct cs_etm_auxtrace *etm) +{ +int i; +u32 etmidr; +u64 architecture; + +for (i =0 ; i < etm->num_cpu; i++) { + architecture = etm->metadata[i][CS_ETM_MAGIC ]; + +switch (architecture) { +case __perf_cs_etmv3_magic: + etmidr = etm->metadata[i][CS_ETM_ETMIDR ]; +cs_etm__set_trace_param_etmv3 (t_params, etm, i, etmidr); +break ; +case __perf_cs_etmv4_magic: +cs_etm__set_trace_param_etmv4 (t_params, etm, i); +break ; +default : +return -EINVAL ; + } + } + +return 0 ; +} +static int cs_etm__init_decoder_params (struct cs_etm_decoder_params *d_params,struct cs_etm_queue *etmq,enum cs_etm_decoder_operation mode)
@@ -161,7 +212,7 @@ static int cs_etm__init_decoder_params(struct cs_etm_decoder_params *d_params,static void cs_etm__dump_event (struct cs_etm_auxtrace *etm,struct auxtrace_buffer *buffer) { -int i, ret; +int ret;const char *color =PERF_COLOR_BLUE ;struct cs_etm_decoder_params d_params;struct cs_etm_trace_params *t_params;
@@ -179,33 +230,8 @@ static void cs_etm__dump_event(struct cs_etm_auxtrace *etm,if (!t_params)return ; -for (i =0 ; i < etm->num_cpu; i++) { -if (etm->metadata[i][CS_ETM_MAGIC ] == __perf_cs_etmv3_magic) { -u32 etmidr = etm->metadata[i][CS_ETM_ETMIDR ]; - - t_params[i].protocol = -cs_etm__get_v7_protocol_version (etmidr); - t_params[i].etmv3.reg_ctrl = - etm->metadata[i][CS_ETM_ETMCR ]; - t_params[i].etmv3.reg_trc_id = - etm->metadata[i][CS_ETM_ETMTRACEIDR ]; - }else if (etm->metadata[i][CS_ETM_MAGIC ] == - __perf_cs_etmv4_magic) { - t_params[i].protocol = CS_ETM_PROTO_ETMV4i; - t_params[i].etmv4.reg_idr0 = - etm->metadata[i][CS_ETMV4_TRCIDR0 ]; - t_params[i].etmv4.reg_idr1 = - etm->metadata[i][CS_ETMV4_TRCIDR1 ]; - t_params[i].etmv4.reg_idr2 = - etm->metadata[i][CS_ETMV4_TRCIDR2 ]; - t_params[i].etmv4.reg_idr8 = - etm->metadata[i][CS_ETMV4_TRCIDR8 ]; - t_params[i].etmv4.reg_configr = - etm->metadata[i][CS_ETMV4_TRCCONFIGR ]; - t_params[i].etmv4.reg_traceidr = - etm->metadata[i][CS_ETMV4_TRCTRACEIDR ]; - } - } +if (cs_etm__init_trace_params (t_params, etm)) + goto out_free;/* Set decoder parameters to simply print the trace packets */ if (cs_etm__init_decoder_params(&d_params, NULL,
@@ -382,7 +408,6 @@ static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u64 address,static struct cs_etm_queue *cs_etm__alloc_queue (struct cs_etm_auxtrace *etm,unsigned int queue_nr) { -int i;struct cs_etm_decoder_params d_params;struct cs_etm_trace_params *t_params =NULL ;struct cs_etm_queue *etmq;
@@ -431,33 +456,8 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm,if (!t_params) goto out_free; -for (i =0 ; i < etm->num_cpu; i++) { -if (etm->metadata[i][CS_ETM_MAGIC ] == __perf_cs_etmv3_magic) { -u32 etmidr = etm->metadata[i][CS_ETM_ETMIDR ]; - - t_params[i].protocol = -cs_etm__get_v7_protocol_version (etmidr); - t_params[i].etmv3.reg_ctrl = - etm->metadata[i][CS_ETM_ETMCR ]; - t_params[i].etmv3.reg_trc_id = - etm->metadata[i][CS_ETM_ETMTRACEIDR ]; - }else if (etm->metadata[i][CS_ETM_MAGIC ] == - __perf_cs_etmv4_magic) { - t_params[i].protocol = CS_ETM_PROTO_ETMV4i; - t_params[i].etmv4.reg_idr0 = - etm->metadata[i][CS_ETMV4_TRCIDR0 ]; - t_params[i].etmv4.reg_idr1 = - etm->metadata[i][CS_ETMV4_TRCIDR1 ]; - t_params[i].etmv4.reg_idr2 = - etm->metadata[i][CS_ETMV4_TRCIDR2 ]; - t_params[i].etmv4.reg_idr8 = - etm->metadata[i][CS_ETMV4_TRCIDR8 ]; - t_params[i].etmv4.reg_configr = - etm->metadata[i][CS_ETMV4_TRCCONFIGR ]; - t_params[i].etmv4.reg_traceidr = - etm->metadata[i][CS_ETMV4_TRCTRACEIDR ]; - } - } +if (cs_etm__init_trace_params (t_params, etm)) + goto out_free;/* Set decoder parameters to simply print the trace packets */ if (cs_etm__init_decoder_params(&d_params, etmq,
tools/perf/util/cs-etm.h +2 -2
@@ -105,8 +105,8 @@ struct intlist *traceid_list;#define CS_ETM_HEADER_SIZE (CS_HEADER_VERSION_0_MAX * sizeof(u64)) -static const u64 __perf_cs_etmv3_magic =0x3030303030303030ULL ; -static const u64 __perf_cs_etmv4_magic =0x4040404040404040ULL ; +#define __perf_cs_etmv3_magic 0x3030303030303030ULL +#define __perf_cs_etmv4_magic 0x4040404040404040ULL#define CS_ETMV3_PRIV_SIZE (CS_ETM_PRIV_MAX * sizeof(u64))#define CS_ETMV4_PRIV_SIZE (CS_ETMV4_PRIV_MAX * sizeof(u64))
Signature · 1 line
2.17.1
tip-bot for Mathieu Poirier
merge bot[tip:perf/core] perf cs-etm: Introducing function cs_etm__init_trace_params()
perf cs-etm: Introducing function cs_etm__init_trace_params()
Commit-ID: 2507a3d982f2968168b53f4d1e67774d68f79b0c Gitweb: https://git.kernel.org/tip/2507a3d982f2968168b53f4d1e67774d68f79b0c Author: Mathieu Poirier <[email protected]> AuthorDate: Tue, 12 Feb 2019 10:16:11 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 14 Feb 2019 15:18:06 -0300
perf cs-etm: Introducing function cs_etm__init_trace_params()
The trace parameter initialisation code is repeated in two different places, something that bloats the file and can lead to errors. This is fixed by introducing a helper function and calling the right protocol initialisation code when required.
--- tools/perf/util/cs-etm.c | 112 +++++++++++++++++++++++------------------------ tools/perf/util/cs-etm.h | 4 +- 2 files changed, 58 insertions(+), 58 deletions(-)
tools/perf/util/cs-etm.c +56 -56
@@ -136,6 +136,57 @@ static void cs_etm__packet_dump(const char *pkt_string)fflush (stdout); } +static void cs_etm__set_trace_param_etmv3 (struct cs_etm_trace_params *t_params, +struct cs_etm_auxtrace *etm,int idx, +u32 etmidr) +{ +u64 **metadata = etm->metadata; + + t_params[idx].protocol =cs_etm__get_v7_protocol_version (etmidr); + t_params[idx].etmv3.reg_ctrl = metadata[idx][CS_ETM_ETMCR ]; + t_params[idx].etmv3.reg_trc_id = metadata[idx][CS_ETM_ETMTRACEIDR ]; +} + +static void cs_etm__set_trace_param_etmv4 (struct cs_etm_trace_params *t_params, +struct cs_etm_auxtrace *etm,int idx) +{ +u64 **metadata = etm->metadata; + + t_params[idx].protocol = CS_ETM_PROTO_ETMV4i; + t_params[idx].etmv4.reg_idr0 = metadata[idx][CS_ETMV4_TRCIDR0 ]; + t_params[idx].etmv4.reg_idr1 = metadata[idx][CS_ETMV4_TRCIDR1 ]; + t_params[idx].etmv4.reg_idr2 = metadata[idx][CS_ETMV4_TRCIDR2 ]; + t_params[idx].etmv4.reg_idr8 = metadata[idx][CS_ETMV4_TRCIDR8 ]; + t_params[idx].etmv4.reg_configr = metadata[idx][CS_ETMV4_TRCCONFIGR ]; + t_params[idx].etmv4.reg_traceidr = metadata[idx][CS_ETMV4_TRCTRACEIDR ]; +} + +static int cs_etm__init_trace_params (struct cs_etm_trace_params *t_params, +struct cs_etm_auxtrace *etm) +{ +int i; +u32 etmidr; +u64 architecture; + +for (i =0 ; i < etm->num_cpu; i++) { + architecture = etm->metadata[i][CS_ETM_MAGIC ]; + +switch (architecture) { +case __perf_cs_etmv3_magic: + etmidr = etm->metadata[i][CS_ETM_ETMIDR ]; +cs_etm__set_trace_param_etmv3 (t_params, etm, i, etmidr); +break ; +case __perf_cs_etmv4_magic: +cs_etm__set_trace_param_etmv4 (t_params, etm, i); +break ; +default : +return -EINVAL ; + } + } + +return 0 ; +} +static int cs_etm__init_decoder_params (struct cs_etm_decoder_params *d_params,struct cs_etm_queue *etmq,enum cs_etm_decoder_operation mode)
@@ -161,7 +212,7 @@ out:static void cs_etm__dump_event (struct cs_etm_auxtrace *etm,struct auxtrace_buffer *buffer) { -int i, ret; +int ret;const char *color =PERF_COLOR_BLUE ;struct cs_etm_decoder_params d_params;struct cs_etm_trace_params *t_params;
@@ -179,33 +230,8 @@ static void cs_etm__dump_event(struct cs_etm_auxtrace *etm,if (!t_params)return ; -for (i =0 ; i < etm->num_cpu; i++) { -if (etm->metadata[i][CS_ETM_MAGIC ] == __perf_cs_etmv3_magic) { -u32 etmidr = etm->metadata[i][CS_ETM_ETMIDR ]; - - t_params[i].protocol = -cs_etm__get_v7_protocol_version (etmidr); - t_params[i].etmv3.reg_ctrl = - etm->metadata[i][CS_ETM_ETMCR ]; - t_params[i].etmv3.reg_trc_id = - etm->metadata[i][CS_ETM_ETMTRACEIDR ]; - }else if (etm->metadata[i][CS_ETM_MAGIC ] == - __perf_cs_etmv4_magic) { - t_params[i].protocol = CS_ETM_PROTO_ETMV4i; - t_params[i].etmv4.reg_idr0 = - etm->metadata[i][CS_ETMV4_TRCIDR0 ]; - t_params[i].etmv4.reg_idr1 = - etm->metadata[i][CS_ETMV4_TRCIDR1 ]; - t_params[i].etmv4.reg_idr2 = - etm->metadata[i][CS_ETMV4_TRCIDR2 ]; - t_params[i].etmv4.reg_idr8 = - etm->metadata[i][CS_ETMV4_TRCIDR8 ]; - t_params[i].etmv4.reg_configr = - etm->metadata[i][CS_ETMV4_TRCCONFIGR ]; - t_params[i].etmv4.reg_traceidr = - etm->metadata[i][CS_ETMV4_TRCTRACEIDR ]; - } - } +if (cs_etm__init_trace_params (t_params, etm)) + goto out_free;/* Set decoder parameters to simply print the trace packets */ if (cs_etm__init_decoder_params(&d_params, NULL,
@@ -382,7 +408,6 @@ static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u64 address,static struct cs_etm_queue *cs_etm__alloc_queue (struct cs_etm_auxtrace *etm,unsigned int queue_nr) { -int i;struct cs_etm_decoder_params d_params;struct cs_etm_trace_params *t_params =NULL ;struct cs_etm_queue *etmq;
@@ -431,33 +456,8 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm,if (!t_params) goto out_free; -for (i =0 ; i < etm->num_cpu; i++) { -if (etm->metadata[i][CS_ETM_MAGIC ] == __perf_cs_etmv3_magic) { -u32 etmidr = etm->metadata[i][CS_ETM_ETMIDR ]; - - t_params[i].protocol = -cs_etm__get_v7_protocol_version (etmidr); - t_params[i].etmv3.reg_ctrl = - etm->metadata[i][CS_ETM_ETMCR ]; - t_params[i].etmv3.reg_trc_id = - etm->metadata[i][CS_ETM_ETMTRACEIDR ]; - }else if (etm->metadata[i][CS_ETM_MAGIC ] == - __perf_cs_etmv4_magic) { - t_params[i].protocol = CS_ETM_PROTO_ETMV4i; - t_params[i].etmv4.reg_idr0 = - etm->metadata[i][CS_ETMV4_TRCIDR0 ]; - t_params[i].etmv4.reg_idr1 = - etm->metadata[i][CS_ETMV4_TRCIDR1 ]; - t_params[i].etmv4.reg_idr2 = - etm->metadata[i][CS_ETMV4_TRCIDR2 ]; - t_params[i].etmv4.reg_idr8 = - etm->metadata[i][CS_ETMV4_TRCIDR8 ]; - t_params[i].etmv4.reg_configr = - etm->metadata[i][CS_ETMV4_TRCCONFIGR ]; - t_params[i].etmv4.reg_traceidr = - etm->metadata[i][CS_ETMV4_TRCTRACEIDR ]; - } - } +if (cs_etm__init_trace_params (t_params, etm)) + goto out_free;/* Set decoder parameters to simply print the trace packets */ if (cs_etm__init_decoder_params(&d_params, etmq,
tools/perf/util/cs-etm.h +2 -2
@@ -105,8 +105,8 @@ struct intlist *traceid_list;#define CS_ETM_HEADER_SIZE (CS_HEADER_VERSION_0_MAX * sizeof(u64)) -static const u64 __perf_cs_etmv3_magic =0x3030303030303030ULL ; -static const u64 __perf_cs_etmv4_magic =0x4040404040404040ULL ; +#define __perf_cs_etmv3_magic 0x3030303030303030ULL +#define __perf_cs_etmv4_magic 0x4040404040404040ULL#define CS_ETMV3_PRIV_SIZE (CS_ETM_PRIV_MAX * sizeof(u64))#define CS_ETMV4_PRIV_SIZE (CS_ETMV4_PRIV_MAX * sizeof(u64))
PATCH 7/13 perf tools: Fix erroneous comment
In reply to Mathieu PoirierThe comment just before initialising the decoder is plane wrong since it is part of the decoding queue setup function and the operation code specifically mention that trace data is to be decoded rather than printed out.
This patch simply fix the comment to prevent people from getting really confused.
--- tools/perf/util/cs-etm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/cs-etm.c +1 -1
@@ -459,7 +459,7 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm,if (cs_etm__init_trace_params (t_params, etm)) goto out_free; -/* Set decoder parameters to simply print the trace packets */ +/* Set decoder parameters to decode trace packets */ if (cs_etm__init_decoder_params (&d_params, etmq,CS_ETM_OPERATION_DECODE )) goto out_free;
Signature · 1 line
2.17.1
tip-bot for Mathieu Poirier
merge bot[tip:perf/core] perf cs-etm: Fix erroneous comment
perf cs-etm: Fix erroneous comment
Commit-ID: e4aa592d183228e5fbd3b49a317248c2895d3819 Gitweb: https://git.kernel.org/tip/e4aa592d183228e5fbd3b49a317248c2895d3819 Author: Mathieu Poirier <[email protected]> AuthorDate: Tue, 12 Feb 2019 10:16:12 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 14 Feb 2019 15:18:07 -0300
perf cs-etm: Fix erroneous comment
The comment just before initialising the decoder is plane wrong since it is part of the decoding queue setup function and the operation code specifically mention that trace data is to be decoded rather than printed out.
This patch simply fix the comment to prevent people from getting really confused.
--- tools/perf/util/cs-etm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/cs-etm.c +1 -1
@@ -459,7 +459,7 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm,if (cs_etm__init_trace_params (t_params, etm)) goto out_free; -/* Set decoder parameters to simply print the trace packets */ +/* Set decoder parameters to decode trace packets */ if (cs_etm__init_decoder_params (&d_params, etmq,CS_ETM_OPERATION_DECODE )) goto out_free;
PATCH 8/13 perf tools: Cleaning up function cs_etm__alloc_queue()
In reply to Mathieu PoirierFunction cs_etm__alloc_queue() should only be concerned with the allocation of memory for the etmq and accompanying decoder. Everything else should be done in the calling function.
--- tools/perf/util/cs-etm.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-)
tools/perf/util/cs-etm.c +16 -21
@@ -405,8 +405,7 @@ static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u64 address,return len; } -static struct cs_etm_queue *cs_etm__alloc_queue (struct cs_etm_auxtrace *etm, -unsigned int queue_nr) +static struct cs_etm_queue *cs_etm__alloc_queue (struct cs_etm_auxtrace *etm) {struct cs_etm_decoder_params d_params;struct cs_etm_trace_params *t_params =NULL ;
@@ -444,12 +443,6 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm,if (!etmq->event_buf) goto out_free; - etmq->etm = etm; - etmq->queue_nr = queue_nr; - etmq->pid =-1 ; - etmq->tid =-1 ; - etmq->cpu =-1 ; -/* Use metadata to fill in trace parameters for trace decoder */ t_params =zalloc (sizeof (*t_params) * etm->num_cpu);
@@ -479,10 +472,6 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, goto out_free_decoder;zfree (&t_params); - - etmq->offset =0 ; - etmq->period_instructions =0 ; -return etmq; out_free_decoder:
@@ -503,24 +492,30 @@ static int cs_etm__setup_queue(struct cs_etm_auxtrace *etm,struct auxtrace_queue *queue, unsigned int queue_nr) { + int ret = 0;struct cs_etm_queue *etmq = queue->priv;if (list_empty (&queue->head) || etmq) -return 0 ; + goto out; - etmq =cs_etm__alloc_queue (etm, queue_nr); + etmq =cs_etm__alloc_queue (etm); -if (!etmq) -return -ENOMEM ; +if (!etmq) { + ret = -ENOMEM ; + goto out; + } queue->priv = etmq; - -if (queue->cpu !=-1 ) - etmq->cpu = queue->cpu; - + etmq->etm = etm; + etmq->queue_nr = queue_nr; + etmq->cpu = queue->cpu; etmq->tid = queue->tid; + etmq->pid =-1 ; + etmq->offset =0 ; + etmq->period_instructions =0 ; -return 0 ; +out: +return ret; }static int cs_etm__setup_queues (struct cs_etm_auxtrace *etm)
Signature · 1 line
2.17.1
tip-bot for Mathieu Poirier
merge bot[tip:perf/core] perf cs-etm: Cleaning up function cs_etm__alloc_queue()
perf cs-etm: Cleaning up function cs_etm__alloc_queue()
Commit-ID: 4f5b37139fb3178b3db4e876eec0f2e92c82ac45 Gitweb: https://git.kernel.org/tip/4f5b37139fb3178b3db4e876eec0f2e92c82ac45 Author: Mathieu Poirier <[email protected]> AuthorDate: Tue, 12 Feb 2019 10:16:13 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 14 Feb 2019 15:18:07 -0300
perf cs-etm: Cleaning up function cs_etm__alloc_queue()
Function cs_etm__alloc_queue() should only be concerned with the allocation of memory for the etmq and accompanying decoder. Everything else should be done in the calling function.
--- tools/perf/util/cs-etm.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-)
tools/perf/util/cs-etm.c +16 -21
@@ -405,8 +405,7 @@ static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u64 address,return len; } -static struct cs_etm_queue *cs_etm__alloc_queue (struct cs_etm_auxtrace *etm, -unsigned int queue_nr) +static struct cs_etm_queue *cs_etm__alloc_queue (struct cs_etm_auxtrace *etm) {struct cs_etm_decoder_params d_params;struct cs_etm_trace_params *t_params =NULL ;
@@ -444,12 +443,6 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm,if (!etmq->event_buf) goto out_free; - etmq->etm = etm; - etmq->queue_nr = queue_nr; - etmq->pid =-1 ; - etmq->tid =-1 ; - etmq->cpu =-1 ; -/* Use metadata to fill in trace parameters for trace decoder */ t_params =zalloc (sizeof (*t_params) * etm->num_cpu);
@@ -479,10 +472,6 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, goto out_free_decoder;zfree (&t_params); - - etmq->offset =0 ; - etmq->period_instructions =0 ; -return etmq; out_free_decoder:
@@ -503,24 +492,30 @@ static int cs_etm__setup_queue(struct cs_etm_auxtrace *etm,struct auxtrace_queue *queue, unsigned int queue_nr) { + int ret = 0;struct cs_etm_queue *etmq = queue->priv;if (list_empty (&queue->head) || etmq) -return 0 ; + goto out; - etmq =cs_etm__alloc_queue (etm, queue_nr); + etmq =cs_etm__alloc_queue (etm); -if (!etmq) -return -ENOMEM ; +if (!etmq) { + ret = -ENOMEM ; + goto out; + } queue->priv = etmq; - -if (queue->cpu !=-1 ) - etmq->cpu = queue->cpu; - + etmq->etm = etm; + etmq->queue_nr = queue_nr; + etmq->cpu = queue->cpu; etmq->tid = queue->tid; + etmq->pid =-1 ; + etmq->offset =0 ; + etmq->period_instructions =0 ; -return 0 ; +out: +return ret; }static int cs_etm__setup_queues (struct cs_etm_auxtrace *etm)
PATCH 9/13 perf tools: Rethink kernel address initialisation
In reply to Mathieu PoirierMoving initialisation of the kernel start address to function cs_etm__setup_queues(), considered to be the common denominator for queue initialisation. That way we don't have to repeat the same code at different places.
No change of functionatlity is introduced by this patch.
--- tools/perf/util/cs-etm.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
tools/perf/util/cs-etm.c +3 -4
@@ -523,6 +523,9 @@ static int cs_etm__setup_queues(struct cs_etm_auxtrace *etm)unsigned int i;int ret; +if (!etm->kernel_start) + etm->kernel_start =machine__kernel_start (etm->machine); +for (i =0 ; i < etm->queues.nr_queues; i++) { ret =cs_etm__setup_queue (etm, &etm->queues.queue_array[i], i);if (ret)
@@ -1490,14 +1493,10 @@ static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq)static int cs_etm__run_decoder (struct cs_etm_queue *etmq) { -struct cs_etm_auxtrace *etm = etmq->etm;struct cs_etm_buffer buffer;size_t buffer_used, processed;int err =0 ; -if (!etm->kernel_start) - etm->kernel_start =machine__kernel_start (etm->machine); -/* Go through each buffer in the queue and decode them one by one */ while (1 ) { buffer_used =0 ;
Signature · 1 line
2.17.1
tip-bot for Mathieu Poirier
merge bot[tip:perf/core] perf cs-etm: Rethink kernel address initialisation
perf cs-etm: Rethink kernel address initialisation
Commit-ID: 4b6df11ab6cf13c5babe9ed1a935cd99d50bf3fe Gitweb: https://git.kernel.org/tip/4b6df11ab6cf13c5babe9ed1a935cd99d50bf3fe Author: Mathieu Poirier <[email protected]> AuthorDate: Tue, 12 Feb 2019 10:16:14 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 14 Feb 2019 15:18:07 -0300
perf cs-etm: Rethink kernel address initialisation
Moving initialisation of the kernel start address to function cs_etm__setup_queues(), considered to be the common denominator for queue initialisation. That way we don't have to repeat the same code at different places.
No change of functionatlity is introduced by this patch.
--- tools/perf/util/cs-etm.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
tools/perf/util/cs-etm.c +3 -4
@@ -523,6 +523,9 @@ static int cs_etm__setup_queues(struct cs_etm_auxtrace *etm)unsigned int i;int ret; +if (!etm->kernel_start) + etm->kernel_start =machine__kernel_start (etm->machine); +for (i =0 ; i < etm->queues.nr_queues; i++) { ret =cs_etm__setup_queue (etm, &etm->queues.queue_array[i], i);if (ret)
@@ -1490,14 +1493,10 @@ static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq)static int cs_etm__run_decoder (struct cs_etm_queue *etmq) { -struct cs_etm_auxtrace *etm = etmq->etm;struct cs_etm_buffer buffer;size_t buffer_used, processed;int err =0 ; -if (!etm->kernel_start) - etm->kernel_start =machine__kernel_start (etm->machine); -/* Go through each buffer in the queue and decode them one by one */ while (1 ) { buffer_used =0 ;
PATCH 10/13 perf tools: Make cs_etm__run_decoder() queue independent
In reply to Mathieu PoirierThis patch makes decoding of auxtrace buffer centered around a struct cs_etm_queue. This eliminates surperflous variables and is a precursor for work that simplifies the main decoder loop.
--- .../perf/util/cs-etm-decoder/cs-etm-decoder.h | 7 --- tools/perf/util/cs-etm.c | 52 +++++++++---------- 2 files changed, 26 insertions(+), 33 deletions(-)
tools/perf/util/cs-etm-decoder/cs-etm-decoder.h +0 -7
@@ -15,13 +15,6 @@struct cs_etm_decoder ; -struct cs_etm_buffer { -const unsigned char *buf; -size_t len; -u64 offset; -u64 ref_timestamp; -}; -enum cs_etm_sample_type {CS_ETM_EMPTY ,CS_ETM_RANGE ,
tools/perf/util/cs-etm.c +26 -26
104 lines not on this page · raw message
Signature · 1 line
2.17.1
tip-bot for Mathieu Poirier
merge bot[tip:perf/core] perf cs-etm: Make cs_etm__run_decoder() queue independent
perf cs-etm: Make cs_etm__run_decoder() queue independent
Commit-ID: 23cfcd6d75cc0c1a7f95c44658dc91380fb40770 Gitweb: https://git.kernel.org/tip/23cfcd6d75cc0c1a7f95c44658dc91380fb40770 Author: Mathieu Poirier <[email protected]> AuthorDate: Tue, 12 Feb 2019 10:16:15 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 14 Feb 2019 15:18:07 -0300
perf cs-etm: Make cs_etm__run_decoder() queue independent
This patch makes decoding of auxtrace buffer centered around a struct cs_etm_queue. This eliminates surperflous variables and is a precursor for work that simplifies the main decoder loop.
--- tools/perf/util/cs-etm-decoder/cs-etm-decoder.h | 7 ---- tools/perf/util/cs-etm.c | 52 ++++++++++++------------- 2 files changed, 26 insertions(+), 33 deletions(-)
tools/perf/util/cs-etm-decoder/cs-etm-decoder.h +0 -7
@@ -15,13 +15,6 @@struct cs_etm_decoder ; -struct cs_etm_buffer { -const unsigned char *buf; -size_t len; -u64 offset; -u64 ref_timestamp; -}; -enum cs_etm_sample_type {CS_ETM_EMPTY ,CS_ETM_RANGE ,
tools/perf/util/cs-etm.c +26 -26
104 lines not on this page · raw message
PATCH 11/13 perf tools: Modularize main decoder function
In reply to Mathieu PoirierMaking the main decoder block modular so that it can be called from different decoding context (timeless vs. non-timeless), avoiding to repeat code.
No change in functionality is introduced by this patch.
--- tools/perf/util/cs-etm.c | 41 ++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-)
tools/perf/util/cs-etm.c +29 -12
@@ -1491,9 +1491,36 @@ static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq)return 0 ; } +static int cs_etm__decode_data_block (struct cs_etm_queue *etmq) +{ +int ret =0 ; +size_t processed =0 ; + +/* +* Packets are decoded and added to the decoder's packet queue +* until the decoder packet processing callback has requested that +* processing stops or there is nothing left in the buffer. Normal +* operations that stop processing are a timestamp packet or a full +* decoder buffer queue. +*/ + ret =cs_etm_decoder__process_data_block (etmq->decoder, + etmq->offset, + &etmq->buf[etmq->buf_used], + etmq->buf_len, + &processed); +if (ret) + goto out; + + etmq->offset += processed; + etmq->buf_used += processed; + etmq->buf_len -= processed; + +out: +return ret; +} +static int cs_etm__run_decoder (struct cs_etm_queue *etmq) { -size_t processed;int err =0 ;/* Go through each buffer in the queue and decode them one by one */
@@ -1513,20 +1540,10 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq)/* Run trace decoder until buffer consumed or end of trace */ do { - processed = 0; - err = cs_etm_decoder__process_data_block( - etmq->decoder, - etmq->offset, - &etmq->buf[etmq->buf_used], - etmq->buf_len, - &processed); + err = cs_etm__decode_data_block(etmq); if (err) return err; - etmq->offset += processed; - etmq->buf_used += processed; - etmq->buf_len -= processed; - /* Process each packet in this chunk */ while (1) { err = cs_etm_decoder__get_packet(etmq->decoder,
Signature · 1 line
2.17.1
tip-bot for Mathieu Poirier
merge bot[tip:perf/core] perf cs-etm: Modularize main decoder function
perf cs-etm: Modularize main decoder function
Commit-ID: f74f349c211e3e62bc7fe35a132918c7f2c0fafb Gitweb: https://git.kernel.org/tip/f74f349c211e3e62bc7fe35a132918c7f2c0fafb Author: Mathieu Poirier <[email protected]> AuthorDate: Tue, 12 Feb 2019 10:16:16 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 14 Feb 2019 15:18:07 -0300
perf cs-etm: Modularize main decoder function
Making the main decoder block modular so that it can be called from different decoding context (timeless vs. non-timeless), avoiding to repeat code.
No change in functionality is introduced by this patch.
--- tools/perf/util/cs-etm.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-)
tools/perf/util/cs-etm.c +29 -12
@@ -1491,9 +1491,36 @@ static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq)return 0 ; } +static int cs_etm__decode_data_block (struct cs_etm_queue *etmq) +{ +int ret =0 ; +size_t processed =0 ; + +/* +* Packets are decoded and added to the decoder's packet queue +* until the decoder packet processing callback has requested that +* processing stops or there is nothing left in the buffer. Normal +* operations that stop processing are a timestamp packet or a full +* decoder buffer queue. +*/ + ret =cs_etm_decoder__process_data_block (etmq->decoder, + etmq->offset, + &etmq->buf[etmq->buf_used], + etmq->buf_len, + &processed); +if (ret) + goto out; + + etmq->offset += processed; + etmq->buf_used += processed; + etmq->buf_len -= processed; + +out: +return ret; +} +static int cs_etm__run_decoder (struct cs_etm_queue *etmq) { -size_t processed;int err =0 ;/* Go through each buffer in the queue and decode them one by one */
@@ -1513,20 +1540,10 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq)/* Run trace decoder until buffer consumed or end of trace */ do { - processed = 0; - err = cs_etm_decoder__process_data_block( - etmq->decoder, - etmq->offset, - &etmq->buf[etmq->buf_used], - etmq->buf_len, - &processed); + err = cs_etm__decode_data_block(etmq); if (err) return err; - etmq->offset += processed; - etmq->buf_used += processed; - etmq->buf_len -= processed; - /* Process each packet in this chunk */ while (1) { err = cs_etm_decoder__get_packet(etmq->decoder,
PATCH 12/13 perf tools: Modularize main packet processing loop
In reply to Mathieu PoirierMaking the main packet processing loop modular so that it can be called from different decoding context (timeless vs. non-timless), avoiding to repeat code.
--- tools/perf/util/cs-etm.c | 129 ++++++++++++++++++++++----------------- 1 file changed, 72 insertions(+), 57 deletions(-)
tools/perf/util/cs-etm.c +72 -57
@@ -1519,6 +1519,72 @@ static int cs_etm__decode_data_block(struct cs_etm_queue *etmq)return ret; } +static int cs_etm__process_decoder_queue (struct cs_etm_queue *etmq) +{ +int ret; + +/* Process each packet in this chunk */ +while (1 ) { + ret =cs_etm_decoder__get_packet (etmq->decoder, + etmq->packet); +if (ret <=0 ) +/* +* Stop processing this chunk on +* end of data or error +*/ +break ; + +/* +* Since packet addresses are swapped in packet +* handling within below switch() statements, +* thus setting sample flags must be called +* prior to switch() statement to use address +* information before packets swapping. +*/ + ret =cs_etm__set_sample_flags (etmq); +if (ret <0 ) +break ; + +switch (etmq->packet->sample_type) { +case CS_ETM_RANGE : +/* +* If the packet contains an instruction +* range, generate instruction sequence +* events. +*/ +cs_etm__sample (etmq); +break ; +case CS_ETM_EXCEPTION : +case CS_ETM_EXCEPTION_RET : +/* +* If the exception packet is coming, +* make sure the previous instruction +* range packet to be handled properly. +*/ +cs_etm__exception (etmq); +break ; +case CS_ETM_DISCONTINUITY : +/* +* Discontinuity in trace, flush +* previous branch stack +*/ +cs_etm__flush (etmq); +break ; +case CS_ETM_EMPTY : +/* +* Should not receive empty packet, +* report error. +*/ +pr_err ("CS ETM Trace: empty packet\n" ); +return -EINVAL ; +default : +break ; + } + } + +return ret; +} +static int cs_etm__run_decoder (struct cs_etm_queue *etmq) {int err =0 ;
@@ -1544,64 +1610,13 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq)if (err)return err; -/* Process each packet in this chunk */ -while (1 ) { - err =cs_etm_decoder__get_packet (etmq->decoder, - etmq->packet); -if (err <=0 ) -/* -* Stop processing this chunk on -* end of data or error -*/ -break ; +/* +* Process each packet in this chunk, nothing to do if +* an error occurs other than hoping the next one will +* be better. +*/ + err =cs_etm__process_decoder_queue (etmq); -/* -* Since packet addresses are swapped in packet -* handling within below switch() statements, -* thus setting sample flags must be called -* prior to switch() statement to use address -* information before packets swapping. -*/ - err =cs_etm__set_sample_flags (etmq); -if (err <0 ) -break ; - -switch (etmq->packet->sample_type) { -case CS_ETM_RANGE : -/* -* If the packet contains an instruction -* range, generate instruction sequence -* events. -*/ -cs_etm__sample (etmq); -break ; -case CS_ETM_EXCEPTION : -case CS_ETM_EXCEPTION_RET : -/* -* If the exception packet is coming, -* make sure the previous instruction -* range packet to be handled properly. -*/ -cs_etm__exception (etmq); -break ; -case CS_ETM_DISCONTINUITY : -/* -* Discontinuity in trace, flush -* previous branch stack -*/ -cs_etm__flush (etmq); -break ; -case CS_ETM_EMPTY : -/* -* Should not receive empty packet, -* report error. -*/ -pr_err ("CS ETM Trace: empty packet\n" ); -return -EINVAL ; -default : -break ; - } - } }while (etmq->buf_len);if (err ==0 )
Signature · 1 line
2.17.1
tip-bot for Mathieu Poirier
merge bot[tip:perf/core] perf cs-etm: Modularize main packet processing loop
perf cs-etm: Modularize main packet processing loop
Commit-ID: 3fa0e83e29488547b39f321fd5a239f08f129c72 Gitweb: https://git.kernel.org/tip/3fa0e83e29488547b39f321fd5a239f08f129c72 Author: Mathieu Poirier <[email protected]> AuthorDate: Tue, 12 Feb 2019 10:16:17 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 14 Feb 2019 15:18:07 -0300
perf cs-etm: Modularize main packet processing loop
Making the main packet processing loop modular so that it can be called from different decoding context (timeless vs. non-timless), avoiding to repeat code.
--- tools/perf/util/cs-etm.c | 129 ++++++++++++++++++++++++++--------------------- 1 file changed, 72 insertions(+), 57 deletions(-)
tools/perf/util/cs-etm.c +72 -57
@@ -1519,6 +1519,72 @@ out:return ret; } +static int cs_etm__process_decoder_queue (struct cs_etm_queue *etmq) +{ +int ret; + +/* Process each packet in this chunk */ +while (1 ) { + ret =cs_etm_decoder__get_packet (etmq->decoder, + etmq->packet); +if (ret <=0 ) +/* +* Stop processing this chunk on +* end of data or error +*/ +break ; + +/* +* Since packet addresses are swapped in packet +* handling within below switch() statements, +* thus setting sample flags must be called +* prior to switch() statement to use address +* information before packets swapping. +*/ + ret =cs_etm__set_sample_flags (etmq); +if (ret <0 ) +break ; + +switch (etmq->packet->sample_type) { +case CS_ETM_RANGE : +/* +* If the packet contains an instruction +* range, generate instruction sequence +* events. +*/ +cs_etm__sample (etmq); +break ; +case CS_ETM_EXCEPTION : +case CS_ETM_EXCEPTION_RET : +/* +* If the exception packet is coming, +* make sure the previous instruction +* range packet to be handled properly. +*/ +cs_etm__exception (etmq); +break ; +case CS_ETM_DISCONTINUITY : +/* +* Discontinuity in trace, flush +* previous branch stack +*/ +cs_etm__flush (etmq); +break ; +case CS_ETM_EMPTY : +/* +* Should not receive empty packet, +* report error. +*/ +pr_err ("CS ETM Trace: empty packet\n" ); +return -EINVAL ; +default : +break ; + } + } + +return ret; +} +static int cs_etm__run_decoder (struct cs_etm_queue *etmq) {int err =0 ;
@@ -1544,64 +1610,13 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq)if (err)return err; -/* Process each packet in this chunk */ -while (1 ) { - err =cs_etm_decoder__get_packet (etmq->decoder, - etmq->packet); -if (err <=0 ) -/* -* Stop processing this chunk on -* end of data or error -*/ -break ; +/* +* Process each packet in this chunk, nothing to do if +* an error occurs other than hoping the next one will +* be better. +*/ + err =cs_etm__process_decoder_queue (etmq); -/* -* Since packet addresses are swapped in packet -* handling within below switch() statements, -* thus setting sample flags must be called -* prior to switch() statement to use address -* information before packets swapping. -*/ - err =cs_etm__set_sample_flags (etmq); -if (err <0 ) -break ; - -switch (etmq->packet->sample_type) { -case CS_ETM_RANGE : -/* -* If the packet contains an instruction -* range, generate instruction sequence -* events. -*/ -cs_etm__sample (etmq); -break ; -case CS_ETM_EXCEPTION : -case CS_ETM_EXCEPTION_RET : -/* -* If the exception packet is coming, -* make sure the previous instruction -* range packet to be handled properly. -*/ -cs_etm__exception (etmq); -break ; -case CS_ETM_DISCONTINUITY : -/* -* Discontinuity in trace, flush -* previous branch stack -*/ -cs_etm__flush (etmq); -break ; -case CS_ETM_EMPTY : -/* -* Should not receive empty packet, -* report error. -*/ -pr_err ("CS ETM Trace: empty packet\n" ); -return -EINVAL ; -default : -break ; - } - } }while (etmq->buf_len);if (err ==0 )
PATCH 13/13 perf tools: Modularize auxtrace_buffer fetch function
In reply to Mathieu PoirierMaking the auxtrace_buffer fetch function modular so that it can be called from different decoding context (timeless vs. non-timeless), avoiding to repeat code.
No change in functionality is introduced by this patch.
--- tools/perf/util/cs-etm.c | 41 ++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-)
tools/perf/util/cs-etm.c +29 -12
@@ -1152,6 +1152,32 @@ static int cs_etm__end_block(struct cs_etm_queue *etmq)return 0 ; } +/* +* cs_etm__get_data_block: Fetch a block from the auxtrace_buffer queue +* if need be. +* Returns: < 0 if error +* = 0 if no more auxtrace_buffer to read +* > 0 if the current buffer isn't empty yet +*/ +static int cs_etm__get_data_block (struct cs_etm_queue *etmq) +{ +int ret; + +if (!etmq->buf_len) { + ret =cs_etm__get_trace (etmq); +if (ret <=0 ) +return ret; +/* +* We cannot assume consecutive blocks in the data file +* are contiguous, reset the decoder to force re-sync. +*/ + ret =cs_etm_decoder__reset (etmq->decoder); +if (ret) +return ret; + } + +return etmq->buf_len; +} static bool cs_etm__is_svc_instr(struct cs_etm_queue *etmq, struct cs_etm_packet *packet,
@@ -1591,18 +1617,9 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq)/* Go through each buffer in the queue and decode them one by one */ while (1 ) { -if (!etmq->buf_len) { - err =cs_etm__get_trace (etmq); -if (err <=0 ) -return err; -/* -* We cannot assume consecutive blocks in the data file -* are contiguous, reset the decoder to force re-sync. -*/ - err =cs_etm_decoder__reset (etmq->decoder); -if (err !=0 ) -return err; - } + err =cs_etm__get_data_block (etmq); +if (err <=0 ) +return err;/* Run trace decoder until buffer consumed or end of trace */ do {
Signature · 1 line
2.17.1
tip-bot for Mathieu Poirier
merge bot[tip:perf/core] perf cs-etm: Modularize auxtrace_buffer fetch function
perf cs-etm: Modularize auxtrace_buffer fetch function
Commit-ID: 8224531cf5a1246bbe1d43c5db26e5348aeb77c5 Gitweb: https://git.kernel.org/tip/8224531cf5a1246bbe1d43c5db26e5348aeb77c5 Author: Mathieu Poirier <[email protected]> AuthorDate: Tue, 12 Feb 2019 10:16:18 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 14 Feb 2019 15:18:08 -0300
perf cs-etm: Modularize auxtrace_buffer fetch function
Making the auxtrace_buffer fetch function modular so that it can be called from different decoding context (timeless vs. non-timeless), avoiding to repeat code.
No change in functionality is introduced by this patch.
--- tools/perf/util/cs-etm.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-)
tools/perf/util/cs-etm.c +29 -12
@@ -1152,6 +1152,32 @@ static int cs_etm__end_block(struct cs_etm_queue *etmq)return 0 ; } +/* +* cs_etm__get_data_block: Fetch a block from the auxtrace_buffer queue +* if need be. +* Returns: < 0 if error +* = 0 if no more auxtrace_buffer to read +* > 0 if the current buffer isn't empty yet +*/ +static int cs_etm__get_data_block (struct cs_etm_queue *etmq) +{ +int ret; + +if (!etmq->buf_len) { + ret =cs_etm__get_trace (etmq); +if (ret <=0 ) +return ret; +/* +* We cannot assume consecutive blocks in the data file +* are contiguous, reset the decoder to force re-sync. +*/ + ret =cs_etm_decoder__reset (etmq->decoder); +if (ret) +return ret; + } + +return etmq->buf_len; +} static bool cs_etm__is_svc_instr(struct cs_etm_queue *etmq, struct cs_etm_packet *packet,
@@ -1591,18 +1617,9 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq)/* Go through each buffer in the queue and decode them one by one */ while (1 ) { -if (!etmq->buf_len) { - err =cs_etm__get_trace (etmq); -if (err <=0 ) -return err; -/* -* We cannot assume consecutive blocks in the data file -* are contiguous, reset the decoder to force re-sync. -*/ - err =cs_etm_decoder__reset (etmq->decoder); -if (err !=0 ) -return err; - } + err =cs_etm__get_data_block (etmq); +if (err <=0 ) +return err;/* Run trace decoder until buffer consumed or end of trace */ do {