coresight: Use per-sink trace ID maps for Perf sessions
Subsystems (5)
cover coresight: Use per-sink trace ID maps for Perf sessions
This will allow sessions with more than CORESIGHT_TRACE_IDS_MAX ETMs as long as there are fewer than that many ETMs connected to each sink.
Each sink owns its own trace ID map, and any Perf session connecting to that sink will allocate from it, even if the sink is currently in use by other users. This is similar to the existing behavior where the dynamic trace IDs are constant as long as there is any concurrent Perf session active. It's not completely optimal because slightly more IDs will be used than necessary, but the optimal solution involves tracking the PIDs of each session and allocating ID maps based on the session owner. This is difficult to do with the combination of per-thread and per-cpu modes and some scheduling issues. The complexity of this isn't likely to worth it because even with multiple users they'd just see a difference in the ordering of ID allocations rather than hitting any limits (unless the hardware does have too many ETMs connected to one sink).
Per-thread mode works but only until there are any overlapping IDs, at which point Perf will error out. Both per-thread mode and sysfs mode are left to future changes, but both can be added on top of this initial implementation and only sysfs mode requires further driver changes.
The HW_ID version field hasn't been bumped in order to not break Perf which already has an error condition for other values of that field. Instead a new minor version has been added which signifies that there are new fields but the old fields are backwards compatible.
James Clark (17):
perf cs-etm: Print error for new PERF_RECORD_AUX_OUTPUT_HW_ID versions perf auxtrace: Allow number of queues to be specified
perf: cs-etm: Create decoders after both AUX and HW_ID search passes
perf: cs-etm: Allocate queues for all CPUs
perf: cs-etm: Move traceid_list to each queue
perf: cs-etm: Create decoders based on the trace ID mappings
perf: cs-etm: Support version 0.1 of HW_ID packets
coresight: Remove unused stubs
coresight: Clarify comments around the PID of the sink owner
coresight: Move struct coresight_trace_id_map to common header
coresight: Expose map argument in trace ID API
coresight: Make CPU id map a property of a trace ID map
coresight: Pass trace ID map into source enable
coresight: Use per-sink trace ID maps for Perf sessions
coresight: Remove pending trace ID release mechanism
coresight: Re-emit trace IDs when the sink changes in per-thread mode
coresight: Emit HW_IDs for all ETMs that are using the sink
drivers/hwtracing/coresight/coresight-core.c | 10 + drivers/hwtracing/coresight/coresight-dummy.c | 3 +- .../hwtracing/coresight/coresight-etm-perf.c | 82 ++- .../hwtracing/coresight/coresight-etm-perf.h | 20 +- .../coresight/coresight-etm3x-core.c | 14 +- .../coresight/coresight-etm4x-core.c | 14 +- drivers/hwtracing/coresight/coresight-stm.c | 3 +- drivers/hwtracing/coresight/coresight-sysfs.c | 3 +- .../hwtracing/coresight/coresight-tmc-etr.c | 5 +- drivers/hwtracing/coresight/coresight-tmc.h | 5 +- drivers/hwtracing/coresight/coresight-tpdm.c | 3 +- .../hwtracing/coresight/coresight-trace-id.c | 107 +-- .../hwtracing/coresight/coresight-trace-id.h | 57 +- include/linux/coresight-pmu.h | 17 +- include/linux/coresight.h | 20 +- tools/include/linux/coresight-pmu.h | 17 +- tools/perf/util/auxtrace.c | 9 +- tools/perf/util/auxtrace.h | 1 + .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 28 +- tools/perf/util/cs-etm.c | 617 ++++++++++++------ tools/perf/util/cs-etm.h | 2 +- 21 files changed, 633 insertions(+), 404 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/17 perf cs-etm: Print error for new PERF_RECORD_AUX_OUTPUT_HW_ID versions
The likely fix for this is to update Perf so print a helpful message.
--- tools/perf/util/cs-etm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/cs-etm.c +4 -1
@@ -335,8 +335,11 @@ static int cs_etm__process_aux_output_hw_id(struct perf_session *session, trace_chan_id =FIELD_GET (CS_AUX_HW_ID_TRACE_ID_MASK , hw_id);/* check that we can handle this version */ -if (version >CS_AUX_HW_ID_CURR_VERSION ) +if (version >CS_AUX_HW_ID_CURR_VERSION ) { +pr_err ("CS ETM Trace: PERF_RECORD_AUX_OUTPUT_HW_ID version %d not supported. Please update Perf.\n" , + version);return -EINVAL ; + }/* get access to the etm metadata */ etm = container_of(session->auxtrace, struct cs_etm_auxtrace, auxtrace);
Signature · 1 line
2.34.1
PATCH 2/17 perf auxtrace: Allow number of queues to be specified
In reply to James ClarkCurrently it's only possible to initialize with the default number of queues and then use auxtrace_queues__add_event() to grow the array. But that's problematic if you don't have a real event to pass into that function yet.
The queues hold a void *priv member to store custom state, and for Coresight we want to create decoders upfront before receiving data, so add a new function that allows pre-allocating queues. One reason to do this is because we might need to store metadata (HW_ID events) that effects other queues, but never actually receive auxtrace data on that queue.
--- tools/perf/util/auxtrace.c | 9 +++++++-- tools/perf/util/auxtrace.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-)
tools/perf/util/auxtrace.c +7 -2
@@ -218,15 +218,20 @@ static struct auxtrace_queue *auxtrace_alloc_queue_array(unsigned int nr_queues)return queue_array; } -int auxtrace_queues__init (struct auxtrace_queues *queues) +int auxtrace_queues__init_nr (struct auxtrace_queues *queues,int nr_queues) { - queues->nr_queues =AUXTRACE_INIT_NR_QUEUES ; + queues->nr_queues = nr_queues; queues->queue_array =auxtrace_alloc_queue_array (queues->nr_queues);if (!queues->queue_array)return -ENOMEM ;return 0 ; } +int auxtrace_queues__init (struct auxtrace_queues *queues) +{ +return auxtrace_queues__init_nr (queues,AUXTRACE_INIT_NR_QUEUES ); +} +static int auxtrace_queues__grow (struct auxtrace_queues *queues,unsigned int new_nr_queues) {
tools/perf/util/auxtrace.h +1 -0
@@ -521,6 +521,7 @@ int auxtrace_mmap__read_snapshot(struct mmap *map, struct perf_tool *tool, process_auxtrace_t fn, size_t snapshot_size); +int auxtrace_queues__init_nr (struct auxtrace_queues *queues,int nr_queues);int auxtrace_queues__init (struct auxtrace_queues *queues); int auxtrace_queues__add_event(struct auxtrace_queues *queues, struct perf_session *session,
Signature · 1 line
2.34.1
PATCH 3/17 perf: cs-etm: Create decoders after both AUX and HW_ID search passes
In reply to James ClarkBoth of these passes gather information about how to create the decoders. AUX records determine formatted/unformatted, and the HW_IDs determine the traceID/metadata mappings. Therefore it makes sense to cache the information and wait until both passes are over until creating the decoders, rather than creating them at the first HW_ID found. This will allow a simplification of the creation process where cs_etm_queue->traceid_list will exclusively used to create the decoders, rather than the current two methods depending on whether the trace is formatted or not.
Previously the sample CPU from the AUX record was used to initialize the decoder CPU, but actually sample CPU == AUX queue index in per-CPU mode, so saving the sample CPU isn't required. Similarly formatted/unformatted was used upfront to create the decoders, but now it's cached until later.
--- tools/perf/util/cs-etm.c | 167 ++++++++++++++++++++++++--------------- 1 file changed, 102 insertions(+), 65 deletions(-)
tools/perf/util/cs-etm.c +102 -65
@@ -103,6 +103,7 @@ struct cs_etm_queue {struct auxtrace_buffer *buffer;unsigned int queue_nr;u8 pending_timestamp_chan_id; +bool formatted;u64 offset;const unsigned char *buf;size_t buf_len, buf_used;
@@ -738,8 +739,7 @@ static int cs_etm__init_trace_params(struct cs_etm_trace_params *t_params,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, -bool formatted) +enum cs_etm_decoder_operation mode) {int ret = -EINVAL ;
@@ -749,7 +749,7 @@ static int cs_etm__init_decoder_params(struct cs_etm_decoder_params *d_params, d_params->packet_printer = cs_etm__packet_dump; d_params->operation = mode; d_params->data = etmq; - d_params->formatted = formatted; + d_params->formatted = etmq->formatted; d_params->fsyncs = false; d_params->hsyncs = false; d_params->frame_aligned = true;
@@ -1041,81 +1041,34 @@ static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u8 trace_chan_id,return ret; } -static struct cs_etm_queue *cs_etm__alloc_queue (struct cs_etm_auxtrace *etm, -bool formatted,int sample_cpu) +static struct cs_etm_queue *cs_etm__alloc_queue (void ) { -struct cs_etm_decoder_params d_params; -struct cs_etm_trace_params *t_params =NULL ; -struct cs_etm_queue *etmq; -/* -* Each queue can only contain data from one CPU when unformatted, so only one decoder is -* needed. -*/ -int decoders = formatted ? etm->num_cpu :1 ; - - etmq =zalloc (sizeof (*etmq)); +struct cs_etm_queue *etmq =zalloc (sizeof (*etmq));if (!etmq)return NULL ; etmq->traceid_queues_list =intlist__new (NULL );if (!etmq->traceid_queues_list) - goto out_free; - -/* Use metadata to fill in trace parameters for trace decoder */ - t_params =zalloc (sizeof (*t_params) * decoders); +free (etmq); -if (!t_params) - goto out_free; - -if (cs_etm__init_trace_params (t_params, etm, formatted, sample_cpu, decoders)) - goto out_free; - -/* Set decoder parameters to decode trace packets */ -if (cs_etm__init_decoder_params (&d_params, etmq, - dump_trace ?CS_ETM_OPERATION_PRINT : -CS_ETM_OPERATION_DECODE , - formatted)) - goto out_free; - - etmq->decoder =cs_etm_decoder__new (decoders, &d_params, - t_params); - -if (!etmq->decoder) - goto out_free; - -/* -* Register a function to handle all memory accesses required by -* the trace decoder library. -*/ -if (cs_etm_decoder__add_mem_access_cb (etmq->decoder, -0x0L , ((u64) -1L ), - cs_etm__mem_access)) - goto out_free_decoder; - -zfree (&t_params);return etmq; - -out_free_decoder: -cs_etm_decoder__free (etmq->decoder); -out_free: -intlist__delete (etmq->traceid_queues_list); -free (etmq); - -return NULL ; }static int cs_etm__setup_queue (struct cs_etm_auxtrace *etm,struct auxtrace_queue *queue, -unsigned int queue_nr, -bool formatted, -int sample_cpu) +unsigned int queue_nr,bool formatted) {struct cs_etm_queue *etmq = queue->priv; +if (etmq && formatted != etmq->formatted) { +pr_err ("CS_ETM: mixed formatted and unformatted trace not supported\n" ); +return -EINVAL ; + } +if (list_empty (&queue->head) || etmq)return 0 ; - etmq =cs_etm__alloc_queue (etm, formatted, sample_cpu); + etmq =cs_etm__alloc_queue ();if (!etmq)return -ENOMEM ;
@@ -1123,7 +1076,9 @@ static int cs_etm__setup_queue(struct cs_etm_auxtrace *etm, queue->priv = etmq; etmq->etm = etm; etmq->queue_nr = queue_nr; + queue->cpu = queue_nr;/* Placeholder, may be reset to -1 in per-thread mode */ etmq->offset =0 ; + etmq->formatted = formatted;return 0 ; }
@@ -2843,7 +2798,7 @@ static int cs_etm__process_auxtrace_event(struct perf_session *session,* formatted in piped mode (true). */ err =cs_etm__setup_queue (etm, &etm->queues.queue_array[idx], - idx, true,-1 ); + idx, true);if (err)return err;
@@ -3048,8 +3003,8 @@ static int cs_etm__queue_aux_fragment(struct perf_session *session, off_t file_o idx = auxtrace_event->idx; formatted = !(aux_event->flags &PERF_AUX_FLAG_CORESIGHT_FORMAT_RAW ); -return cs_etm__setup_queue (etm, &etm->queues.queue_array[idx], - idx, formatted, sample->cpu); + +return cs_etm__setup_queue (etm, &etm->queues.queue_array[idx], idx, formatted); }/* Wasn't inside this buffer, but there were no parse errors. 1 == 'not found' */
@@ -3233,6 +3188,84 @@ static int cs_etm__clear_unused_trace_ids_metadata(int num_cpu, u64 **metadata)return 0 ; } +/* +* Use the data gathered by the peeks for HW_ID (trace ID mappings) and AUX +* (formatted or not) packets to create the decoders. +*/ +static int cs_etm__create_queue_decoders (struct cs_etm_queue *etmq) +{ +struct cs_etm_decoder_params d_params; + +/* +* Each queue can only contain data from one CPU when unformatted, so only one decoder is +* needed. +*/ +int decoders = etmq->formatted ? etmq->etm->num_cpu :1 ; + +/* Use metadata to fill in trace parameters for trace decoder */ +struct cs_etm_trace_params *t_params =zalloc (sizeof (*t_params) * decoders); + +if (!t_params) + goto out_free; + +if (cs_etm__init_trace_params (t_params, etmq->etm, etmq->formatted, + etmq->queue_nr, decoders)) + goto out_free; + +/* Set decoder parameters to decode trace packets */ +if (cs_etm__init_decoder_params (&d_params, etmq, + dump_trace ?CS_ETM_OPERATION_PRINT : +CS_ETM_OPERATION_DECODE )) + goto out_free; + + etmq->decoder =cs_etm_decoder__new (decoders, &d_params, + t_params); + +if (!etmq->decoder) + goto out_free; + +/* +* Register a function to handle all memory accesses required by +* the trace decoder library. +*/ +if (cs_etm_decoder__add_mem_access_cb (etmq->decoder, +0x0L , ((u64) -1L ), + cs_etm__mem_access)) + goto out_free_decoder; + +zfree (&t_params); +return 0 ; + +out_free_decoder: +cs_etm_decoder__free (etmq->decoder); +out_free: +zfree (&t_params); +return -EINVAL ; +} + +static int cs_etm__create_decoders (struct cs_etm_auxtrace *etm) +{ +struct auxtrace_queues *queues = &etm->queues; + +for (unsigned int i =0 ; i < queues->nr_queues; i++) { +bool empty =list_empty (&queues->queue_array[i].head); +struct cs_etm_queue *etmq = queues->queue_array[i].priv; +int ret; + +/* +* Don't create decoders for empty queues, mainly because +* etmq->formatted is unknown for empty queues. +*/ +if (empty) +continue ; + + ret =cs_etm__create_queue_decoders (etmq); +if (ret) +return ret; + } +return 0 ; +} +int cs_etm__process_auxtrace_info_full (union perf_event *event,struct perf_session *session) {
@@ -3396,6 +3429,10 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event,if (err) goto err_free_queues; + err =cs_etm__queue_aux_records (session); +if (err) + goto err_free_queues; +/* * Map Trace ID values to CPU metadata. *
@@ -3418,7 +3455,7 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event,* flags if present. */ -/* first scan for AUX_OUTPUT_HW_ID records to map trace ID values to CPU metadata */ +/* Scan for AUX_OUTPUT_HW_ID records to map trace ID values to CPU metadata */ aux_hw_id_found =0 ; err = perf_session__peek_events(session, session->header.data_offset, session->header.data_size,
@@ -3436,7 +3473,7 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event,if (err) goto err_free_queues; - err =cs_etm__queue_aux_records (session); + err =cs_etm__create_decoders (etm);if (err) goto err_free_queues;
Signature · 1 line
2.34.1
PATCH 4/17 perf: cs-etm: Allocate queues for all CPUs
In reply to James ClarkMake cs_etm__setup_queue() setup a queue even if it's empty, and pre-allocate queues based on the max CPU that was recorded. In per-CPU mode aux queues are indexed based on CPU ID even if all CPUs aren't recorded, sparse queue arrays aren't used.
This will allow HW_IDs to be saved even if no aux data was received in that queue without having to call cs_etm__setup_queue() from two different places.
--- tools/perf/util/cs-etm.c | 55 ++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 28 deletions(-)
tools/perf/util/cs-etm.c +27 -28
@@ -104,6 +104,7 @@ struct cs_etm_queue {unsigned int queue_nr;u8 pending_timestamp_chan_id;bool formatted; +bool formatted_set;u64 offset;const unsigned char *buf;size_t buf_len, buf_used;
@@ -1056,16 +1057,11 @@ static struct cs_etm_queue *cs_etm__alloc_queue(void)static int cs_etm__setup_queue (struct cs_etm_auxtrace *etm,struct auxtrace_queue *queue, -unsigned int queue_nr,bool formatted) +unsigned int queue_nr) {struct cs_etm_queue *etmq = queue->priv; -if (etmq && formatted != etmq->formatted) { -pr_err ("CS_ETM: mixed formatted and unformatted trace not supported\n" ); -return -EINVAL ; - } - -if (list_empty (&queue->head) || etmq) +if (etmq)return 0 ; etmq =cs_etm__alloc_queue ();
@@ -1078,7 +1074,6 @@ static int cs_etm__setup_queue(struct cs_etm_auxtrace *etm, etmq->queue_nr = queue_nr; queue->cpu = queue_nr;/* Placeholder, may be reset to -1 in per-thread mode */ etmq->offset =0 ; - etmq->formatted = formatted;return 0 ; }
@@ -2791,17 +2786,6 @@ static int cs_etm__process_auxtrace_event(struct perf_session *session,if (err)return err; -/* -* Knowing if the trace is formatted or not requires a lookup of -* the aux record so only works in non-piped mode where data is -* queued in cs_etm__queue_aux_records(). Always assume -* formatted in piped mode (true). -*/ - err =cs_etm__setup_queue (etm, &etm->queues.queue_array[idx], - idx, true); -if (err) -return err; -if (dump_trace)if (auxtrace_buffer__get_data (buffer, fd)) {cs_etm__dump_event (etm->queues.queue_array[idx].priv, buffer);
@@ -2918,7 +2902,6 @@ static int cs_etm__queue_aux_fragment(struct perf_session *session, off_t file_ostruct perf_record_auxtrace *auxtrace_event;union perf_event auxtrace_fragment;__u64 aux_offset, aux_size; -__u32 idx;bool formatted; struct cs_etm_auxtrace *etm = container_of(session->auxtrace,
@@ -2985,6 +2968,8 @@ static int cs_etm__queue_aux_fragment(struct perf_session *session, off_t file_oif (aux_offset >= auxtrace_event->offset && aux_offset + aux_size <= auxtrace_event->offset + auxtrace_event->size) { +struct cs_etm_queue *etmq = etm->queues.queue_array[auxtrace_event->idx].priv; +/* * If this AUX event was inside this buffer somewhere, create a new auxtrace event * based on the sizes of the aux event, and queue that fragment.
@@ -3001,10 +2986,14 @@ static int cs_etm__queue_aux_fragment(struct perf_session *session, off_t file_oif (err)return err; - idx = auxtrace_event->idx; formatted = !(aux_event->flags &PERF_AUX_FLAG_CORESIGHT_FORMAT_RAW ); - -return cs_etm__setup_queue (etm, &etm->queues.queue_array[idx], idx, formatted); +if (etmq->formatted_set && formatted != etmq->formatted) { +pr_err ("CS_ETM: mixed formatted and unformatted trace not supported\n" ); +return -EINVAL ; + } + etmq->formatted = formatted; + etmq->formatted_set = true; +return 0 ; }/* Wasn't inside this buffer, but there were no parse errors. 1 == 'not found' */
@@ -3256,6 +3245,7 @@ static int cs_etm__create_decoders(struct cs_etm_auxtrace *etm)* Don't create decoders for empty queues, mainly because * etmq->formatted is unknown for empty queues. */ +assert (empty == !etmq->formatted_set);if (empty)continue ;
@@ -3275,10 +3265,10 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event,int event_header_size =sizeof (struct perf_event_header );int total_size = auxtrace_info->header.size;int priv_size =0 ; -int num_cpu; +int num_cpu, max_cpu =0 ;int err =0 ;int aux_hw_id_found; -int i, j; +int i;u64 *ptr =NULL ;u64 **metadata =NULL ;
@@ -3309,7 +3299,7 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event,* required by the trace decoder to properly decode the trace due * to its highly compressed nature. */ -for (j =0 ; j < num_cpu; j++) { +for (int j =0 ; j < num_cpu; j++) {if (ptr[i] == __perf_cs_etmv3_magic) { metadata[j] = cs_etm__create_meta_blk(ptr, &i,
@@ -3333,6 +3323,9 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event, err = -ENOMEM ; goto err_free_metadata; } + +if ((int ) metadata[j][CS_ETM_CPU ] > max_cpu) + max_cpu = metadata[j][CS_ETM_CPU ]; }/*
@@ -3362,10 +3355,16 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event,*/ etm->pid_fmt =cs_etm__init_pid_fmt (metadata[0 ]); - err =auxtrace_queues__init (&etm->queues); + err =auxtrace_queues__init_nr (&etm->queues, max_cpu +1 );if (err) goto err_free_etm; +for (unsigned int j =0 ; j < etm->queues.nr_queues; ++j) { + err =cs_etm__setup_queue (etm, &etm->queues.queue_array[j], j); +if (err) + goto err_free_queues; + } +if (session->itrace_synth_opts->set) { etm->synth_opts = *session->itrace_synth_opts; }else {
@@ -3487,7 +3486,7 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event,zfree (&etm); err_free_metadata:/* No need to check @metadata[j], free(NULL) is supported */ -for (j =0 ; j < num_cpu; j++) +for (int j =0 ; j < num_cpu; j++)zfree (&metadata[j]);zfree (&metadata); err_free_traceid_list:
Signature · 1 line
2.34.1
PATCH 5/17 perf: cs-etm: Move traceid_list to each queue
In reply to James ClarkThe global list won't work for per-sink trace ID allocations, so put a list in each queue where the IDs will be unique to that queue.
To keep the same behavior as before, for version 0 of the HW_ID packets, copy all the HW_ID mappings into all queues.
This change doesn't effect the decoders, only trace ID lookups on the Perf side. The decoders are still created with global mappings which will be fixed in a later commit.
--- .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 28 +-- tools/perf/util/cs-etm.c | 195 ++++++++++-------- tools/perf/util/cs-etm.h | 2 +- 3 files changed, 126 insertions(+), 99 deletions(-)
tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +16 -12
@@ -388,7 +388,8 @@ cs_etm_decoder__reset_timestamp(struct cs_etm_packet_queue *packet_queue) }static ocsd_datapath_resp_t -cs_etm_decoder__buffer_packet (struct cs_etm_packet_queue *packet_queue, +cs_etm_decoder__buffer_packet (struct cs_etm_queue *etmq, +struct cs_etm_packet_queue *packet_queue,const u8 trace_chan_id,enum cs_etm_sample_type sample_type) {
@@ -398,7 +399,7 @@ cs_etm_decoder__buffer_packet(struct cs_etm_packet_queue *packet_queue,if (packet_queue->packet_count >=CS_ETM_PACKET_MAX_BUFFER -1 )return OCSD_RESP_FATAL_SYS_ERR ; -if (cs_etm__get_cpu (trace_chan_id, &cpu) <0 ) +if (cs_etm__get_cpu (etmq, trace_chan_id, &cpu) <0 )return OCSD_RESP_FATAL_SYS_ERR ; et = packet_queue->tail;
@@ -436,7 +437,7 @@ cs_etm_decoder__buffer_range(struct cs_etm_queue *etmq,int ret =0 ;struct cs_etm_packet *packet; - ret =cs_etm_decoder__buffer_packet (packet_queue, trace_chan_id, + ret =cs_etm_decoder__buffer_packet (etmq, packet_queue, trace_chan_id,CS_ETM_RANGE );if (ret !=OCSD_RESP_CONT && ret !=OCSD_RESP_WAIT )return ret;
@@ -496,7 +497,8 @@ cs_etm_decoder__buffer_range(struct cs_etm_queue *etmq, }static ocsd_datapath_resp_t -cs_etm_decoder__buffer_discontinuity (struct cs_etm_packet_queue *queue, +cs_etm_decoder__buffer_discontinuity (struct cs_etm_queue *etmq, +struct cs_etm_packet_queue *queue,const uint8_t trace_chan_id) {/*
@@ -504,18 +506,19 @@ cs_etm_decoder__buffer_discontinuity(struct cs_etm_packet_queue *queue,* reset time statistics. */ cs_etm_decoder__reset_timestamp (queue); -return cs_etm_decoder__buffer_packet (queue, trace_chan_id, +return cs_etm_decoder__buffer_packet (etmq, queue, trace_chan_id,CS_ETM_DISCONTINUITY ); }static ocsd_datapath_resp_t -cs_etm_decoder__buffer_exception (struct cs_etm_packet_queue *queue, +cs_etm_decoder__buffer_exception (struct cs_etm_queue *etmq, +struct cs_etm_packet_queue *queue,const ocsd_generic_trace_elem *elem,const uint8_t trace_chan_id) {int ret =0 ;struct cs_etm_packet *packet; - ret =cs_etm_decoder__buffer_packet (queue, trace_chan_id, + ret =cs_etm_decoder__buffer_packet (etmq, queue, trace_chan_id,CS_ETM_EXCEPTION );if (ret !=OCSD_RESP_CONT && ret !=OCSD_RESP_WAIT )return ret;
@@ -527,10 +530,11 @@ cs_etm_decoder__buffer_exception(struct cs_etm_packet_queue *queue, }static ocsd_datapath_resp_t -cs_etm_decoder__buffer_exception_ret (struct cs_etm_packet_queue *queue, +cs_etm_decoder__buffer_exception_ret (struct cs_etm_queue *etmq, +struct cs_etm_packet_queue *queue,const uint8_t trace_chan_id) { -return cs_etm_decoder__buffer_packet (queue, trace_chan_id, +return cs_etm_decoder__buffer_packet (etmq, queue, trace_chan_id,CS_ETM_EXCEPTION_RET ); }
@@ -599,7 +603,7 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer(case OCSD_GEN_TRC_ELEM_EO_TRACE :case OCSD_GEN_TRC_ELEM_NO_SYNC :case OCSD_GEN_TRC_ELEM_TRACE_ON : - resp =cs_etm_decoder__buffer_discontinuity (packet_queue, + resp =cs_etm_decoder__buffer_discontinuity (etmq, packet_queue, trace_chan_id);break ;case OCSD_GEN_TRC_ELEM_INSTR_RANGE :
@@ -607,11 +611,11 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( trace_chan_id);break ;case OCSD_GEN_TRC_ELEM_EXCEPTION : - resp =cs_etm_decoder__buffer_exception (packet_queue, elem, + resp =cs_etm_decoder__buffer_exception (etmq, packet_queue, elem, trace_chan_id);break ;case OCSD_GEN_TRC_ELEM_EXCEPTION_RET : - resp =cs_etm_decoder__buffer_exception_ret (packet_queue, + resp =cs_etm_decoder__buffer_exception_ret (etmq, packet_queue, trace_chan_id);break ;case OCSD_GEN_TRC_ELEM_TIMESTAMP :
tools/perf/util/cs-etm.c +109 -86
337 lines not on this page · raw message
tools/perf/util/cs-etm.h +1 -1
@@ -252,7 +252,7 @@ enum cs_etm_pid_fmt {#ifdef HAVE_CSTRACE_SUPPORT #include <opencsd/ocsd_if_types.h> -int cs_etm__get_cpu (u8 trace_chan_id,int *cpu); +int cs_etm__get_cpu (struct cs_etm_queue *etmq,u8 trace_chan_id,int *cpu);enum cs_etm_pid_fmt cs_etm__get_pid_fmt (struct cs_etm_queue *etmq);int cs_etm__etmq_set_tid_el (struct cs_etm_queue *etmq,pid_t tid,u8 trace_chan_id,ocsd_ex_level el);
Signature · 1 line
2.34.1
PATCH 6/17 perf: cs-etm: Create decoders based on the trace ID mappings
In reply to James ClarkNow that each queue has a unique set of trace ID mappings, use this list to create the decoders. This also works the same way for unformatted where a single dummy entry is added into the trace ID list.
Previously each queue would have a decoder created for each traced CPU on the system but this won't work anymore because CPUs can have overlapping trace IDs.
--- tools/perf/util/cs-etm.c | 143 +++++++++++++++++++++++---------------- 1 file changed, 85 insertions(+), 58 deletions(-)
tools/perf/util/cs-etm.c +85 -58
@@ -268,6 +268,10 @@ static int cs_etm__map_trace_id_v0(struct cs_etm_auxtrace *etm, u8 trace_chan_idint ret;struct cs_etm_queue *etmq = etm->queues.queue_array[i].priv; +/* Ignore HW_IDs on unformatted queues */ +if (etmq->formatted_set && !etmq->formatted) +continue ; + ret =cs_etm__insert_trace_id_node (etmq, trace_chan_id, cpu_metadata);if (ret)
@@ -673,80 +677,58 @@ static void cs_etm__packet_dump(const char *pkt_string) }static void cs_etm__set_trace_param_etmv3 (struct cs_etm_trace_params *t_params, -struct cs_etm_auxtrace *etm,int t_idx, -int m_idx,u32 etmidr) +u64 *metadata,u32 etmidr) { -u64 **metadata = etm->metadata; - - t_params[t_idx].protocol =cs_etm__get_v7_protocol_version (etmidr); - t_params[t_idx].etmv3.reg_ctrl = metadata[m_idx][CS_ETM_ETMCR ]; - t_params[t_idx].etmv3.reg_trc_id = metadata[m_idx][CS_ETM_ETMTRACEIDR ]; + t_params->protocol =cs_etm__get_v7_protocol_version (etmidr); + t_params->etmv3.reg_ctrl = metadata[CS_ETM_ETMCR ]; + t_params->etmv3.reg_trc_id = metadata[CS_ETM_ETMTRACEIDR ]; }static void cs_etm__set_trace_param_etmv4 (struct cs_etm_trace_params *t_params, -struct cs_etm_auxtrace *etm,int t_idx, -int m_idx) +u64 *metadata) { -u64 **metadata = etm->metadata; - - t_params[t_idx].protocol = CS_ETM_PROTO_ETMV4i; - t_params[t_idx].etmv4.reg_idr0 = metadata[m_idx][CS_ETMV4_TRCIDR0 ]; - t_params[t_idx].etmv4.reg_idr1 = metadata[m_idx][CS_ETMV4_TRCIDR1 ]; - t_params[t_idx].etmv4.reg_idr2 = metadata[m_idx][CS_ETMV4_TRCIDR2 ]; - t_params[t_idx].etmv4.reg_idr8 = metadata[m_idx][CS_ETMV4_TRCIDR8 ]; - t_params[t_idx].etmv4.reg_configr = metadata[m_idx][CS_ETMV4_TRCCONFIGR ]; - t_params[t_idx].etmv4.reg_traceidr = metadata[m_idx][CS_ETMV4_TRCTRACEIDR ]; + t_params->protocol = CS_ETM_PROTO_ETMV4i; + t_params->etmv4.reg_idr0 = metadata[CS_ETMV4_TRCIDR0 ]; + t_params->etmv4.reg_idr1 = metadata[CS_ETMV4_TRCIDR1 ]; + t_params->etmv4.reg_idr2 = metadata[CS_ETMV4_TRCIDR2 ]; + t_params->etmv4.reg_idr8 = metadata[CS_ETMV4_TRCIDR8 ]; + t_params->etmv4.reg_configr = metadata[CS_ETMV4_TRCCONFIGR ]; + t_params->etmv4.reg_traceidr = metadata[CS_ETMV4_TRCTRACEIDR ]; }static void cs_etm__set_trace_param_ete (struct cs_etm_trace_params *t_params, -struct cs_etm_auxtrace *etm,int t_idx, -int m_idx) +u64 *metadata) { -u64 **metadata = etm->metadata; - - t_params[t_idx].protocol =CS_ETM_PROTO_ETE ; - t_params[t_idx].ete.reg_idr0 = metadata[m_idx][CS_ETE_TRCIDR0 ]; - t_params[t_idx].ete.reg_idr1 = metadata[m_idx][CS_ETE_TRCIDR1 ]; - t_params[t_idx].ete.reg_idr2 = metadata[m_idx][CS_ETE_TRCIDR2 ]; - t_params[t_idx].ete.reg_idr8 = metadata[m_idx][CS_ETE_TRCIDR8 ]; - t_params[t_idx].ete.reg_configr = metadata[m_idx][CS_ETE_TRCCONFIGR ]; - t_params[t_idx].ete.reg_traceidr = metadata[m_idx][CS_ETE_TRCTRACEIDR ]; - t_params[t_idx].ete.reg_devarch = metadata[m_idx][CS_ETE_TRCDEVARCH ]; + t_params->protocol =CS_ETM_PROTO_ETE ; + t_params->ete.reg_idr0 = metadata[CS_ETE_TRCIDR0 ]; + t_params->ete.reg_idr1 = metadata[CS_ETE_TRCIDR1 ]; + t_params->ete.reg_idr2 = metadata[CS_ETE_TRCIDR2 ]; + t_params->ete.reg_idr8 = metadata[CS_ETE_TRCIDR8 ]; + t_params->ete.reg_configr = metadata[CS_ETE_TRCCONFIGR ]; + t_params->ete.reg_traceidr = metadata[CS_ETE_TRCTRACEIDR ]; + t_params->ete.reg_devarch = metadata[CS_ETE_TRCDEVARCH ]; }static int cs_etm__init_trace_params (struct cs_etm_trace_params *t_params, -struct cs_etm_auxtrace *etm, -bool formatted, -int sample_cpu, -int decoders) -{ -int t_idx, m_idx; -u32 etmidr; -u64 architecture; - -for (t_idx =0 ; t_idx < decoders; t_idx++) { -if (formatted) - m_idx = t_idx; -else { - m_idx =get_cpu_data_idx (etm, sample_cpu); -if (m_idx ==-1 ) { -pr_warning ("CS_ETM: unknown CPU, falling back to first metadata\n" ); - m_idx =0 ; - } - } +struct cs_etm_queue *etmq) +{ +struct int_node *inode; - architecture = etm->metadata[m_idx][CS_ETM_MAGIC ]; +intlist__for_each_entry (inode, etmq->traceid_list) { +u64 *metadata = inode->priv; +u64 architecture = metadata[CS_ETM_MAGIC ]; +u32 etmidr;switch (architecture) {case __perf_cs_etmv3_magic: - etmidr = etm->metadata[m_idx][CS_ETM_ETMIDR ]; -cs_etm__set_trace_param_etmv3 (t_params, etm, t_idx, m_idx, etmidr); + etmidr = metadata[CS_ETM_ETMIDR ]; +cs_etm__set_trace_param_etmv3 (t_params++, metadata, etmidr);break ;case __perf_cs_etmv4_magic: -cs_etm__set_trace_param_etmv4 (t_params, etm, t_idx, m_idx); +cs_etm__set_trace_param_etmv4 (t_params++, metadata);break ;case __perf_cs_ete_magic: -cs_etm__set_trace_param_ete (t_params, etm, t_idx, m_idx); +cs_etm__set_trace_param_ete (t_params++, metadata);break ;default :return -EINVAL ;
@@ -2918,6 +2900,42 @@ static u64 *cs_etm__create_meta_blk(u64 *buff_in, int *buff_in_offset,return metadata; } +/* +* traceid_list is used to create decoders and give them the trace ID +* mappings. In unformatted mode just insert one entry for the sample +* CPU so the decoder knows which settings to use. +*/ +static int cs_etm__map_trace_ids_unformatted (struct cs_etm_auxtrace *etm) +{ +for (unsigned int i =0 ; i < etm->queues.nr_queues; ++i) { +int ret; +struct cs_etm_queue *etmq; +u8 trace_chan_id; +u64 *cpu_data; + + etmq = etm->queues.queue_array[i].priv; +if (!etmq->formatted_set || etmq->formatted) +continue ; + +/* Giving it a real ID doesn't do much but can help with debugging */ + trace_chan_id =CORESIGHT_LEGACY_CPU_TRACE_ID (i); + cpu_data =get_cpu_data (etm, i); +if (cpu_data ==NULL ) { +pr_warning ("CS_ETM: unknown CPU, falling back to first metadata\n" ); + cpu_data = etm->metadata[0 ]; + } + + ret =cs_etm__insert_trace_id_node (etmq, trace_chan_id, cpu_data); +if (ret) +return ret; + + ret =cs_etm__metadata_set_trace_id (trace_chan_id, cpu_data); +if (ret) +return ret; + } +return 0 ; +} +/** * Puts a fragment of an auxtrace buffer into the auxtrace queues based * on the bounds of aux_event, if it matches with the buffer that's at
@@ -3220,21 +3238,26 @@ static int cs_etm__clear_unused_trace_ids_metadata(int num_cpu, u64 **metadata)static int cs_etm__create_queue_decoders (struct cs_etm_queue *etmq) {struct cs_etm_decoder_params d_params; +struct cs_etm_trace_params *t_params; +int decoders =intlist__nr_entries (etmq->traceid_list);/* * Each queue can only contain data from one CPU when unformatted, so only one decoder is * needed. */ -int decoders = etmq->formatted ? etmq->etm->num_cpu :1 ; +if (etmq->formatted_set && !etmq->formatted) +assert (decoders ==1 ); + +if (decoders ==0 ) +return 0 ;/* Use metadata to fill in trace parameters for trace decoder */ -struct cs_etm_trace_params *t_params =zalloc (sizeof (*t_params) * decoders); + t_params =zalloc (sizeof (*t_params) * decoders);if (!t_params) goto out_free; -if (cs_etm__init_trace_params (t_params, etmq->etm, etmq->formatted, - etmq->queue_nr, decoders)) +if (cs_etm__init_trace_params (t_params, etmq)) goto out_free;/* Set decoder parameters to decode trace packets */
@@ -3497,6 +3520,10 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event,if (err) goto err_free_queues; + err =cs_etm__map_trace_ids_unformatted (etm); +if (err) + goto err_free_queues; + err =cs_etm__create_decoders (etm);if (err) goto err_free_queues;
Signature · 1 line
2.34.1
PATCH 7/17 perf: cs-etm: Support version 0.1 of HW_ID packets
In reply to James Clarkv0.1 HW_ID packets have two new fields so that it's possible to describe mappings that may be for a different CPU, but are valid in that queue. Use the existing CPU field from the sample to decide which queue to write the new mapping into, but use both of the new fields to create the mapping.
When it becomes apparent that two queues share a sink by looking at which CPUs are writing into that sink, make both queues share the same traceid_list.
Also update the error message to show that overlapping IDs aren't an error in per-thread mode, just not supported. In the future we can use the CPU ID from the AUX record to place per-thread trace into the correct queue which will solve the problem.
--- tools/include/linux/coresight-pmu.h | 17 +++- tools/perf/util/cs-etm.c | 122 +++++++++++++++++++++++++--- 2 files changed, 125 insertions(+), 14 deletions(-)
tools/include/linux/coresight-pmu.h +13 -4
@@ -49,12 +49,21 @@* Interpretation of the PERF_RECORD_AUX_OUTPUT_HW_ID payload. * Used to associate a CPU with the CoreSight Trace ID. * [07:00] - Trace ID - uses 8 bits to make value easy to read in file. -* [59:08] - Unused (SBZ) -* [63:60] - Version +* [15:08] - V2 Trace ID - ID for the ETM/CPU referenced by V2 CPU +* [31:16] - V2 CPU ID - CPU that corresponds to the trace ID in V2 trace ID +* [55:32] - Unused (SBZ) +* [59:56] - Minor Version - previously existing fields are compatible with +* all minor versions. +* [63:60] - Major Version - previously existing fields mean different things +* in new major versions. */ #define CS_AUX_HW_ID_TRACE_ID_MASK GENMASK_ULL(7, 0) -#define CS_AUX_HW_ID_VERSION_MASK GENMASK_ULL(63, 60) +#define CS_AUX_HW_ID_V01_TRACE_ID_MASK GENMASK_ULL(15, 8) +#define CS_AUX_HW_ID_V01_CPU_MASK GENMASK_ULL(31, 16) +#define CS_AUX_HW_ID_MINOR_VERSION_MASK GENMASK_ULL(59, 56) +#define CS_AUX_HW_ID_MAJOR_VERSION_MASK GENMASK_ULL(63, 60) -#define CS_AUX_HW_ID_CURR_VERSION 0 +#define CS_AUX_HW_ID_MAJOR_VERSION 0 +#define CS_AUX_HW_ID_MINOR_VERSION 1#endif
tools/perf/util/cs-etm.c +112 -10
167 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 8/17 coresight: Remove unused stubs
In reply to James ClarkThis file is never included anywhere if CONFIG_CORESIGHT is not set so they are unused and aren't currently compile tested with any config so remove them.
--- .../hwtracing/coresight/coresight-etm-perf.h | 18 ------------------ 1 file changed, 18 deletions(-)
drivers/hwtracing/coresight/coresight-etm-perf.h +0 -18
@@ -62,7 +62,6 @@ struct etm_event_data {struct list_head *__percpu *path; }; -#if IS_ENABLED (CONFIG_CORESIGHT )int etm_perf_symlink (struct coresight_device *csdev,bool link);int etm_perf_add_symlink_sink (struct coresight_device *csdev);void etm_perf_del_symlink_sink (struct coresight_device *csdev);
@@ -77,23 +76,6 @@ static inline void *etm_perf_sink_config(struct perf_output_handle *handle)int etm_perf_add_symlink_cscfg (struct device *dev,struct cscfg_config_desc *config_desc);void etm_perf_del_symlink_cscfg (struct cscfg_config_desc *config_desc); -#else -static inline int etm_perf_symlink (struct coresight_device *csdev,bool link) -{return -EINVAL ; } -int etm_perf_add_symlink_sink (struct coresight_device *csdev) -{return -EINVAL ; } -void etm_perf_del_symlink_sink (struct coresight_device *csdev) {} -static inline void *etm_perf_sink_config (struct perf_output_handle *handle) -{ -return NULL ; -} -int etm_perf_add_symlink_cscfg (struct device *dev, -struct cscfg_config_desc *config_desc) -{return -EINVAL ; } -void etm_perf_del_symlink_cscfg (struct cscfg_config_desc *config_desc) {} - -#endif /* CONFIG_CORESIGHT */ -int __init etm_perf_init (void );void etm_perf_exit (void );
Signature · 1 line
2.34.1
PATCH 9/17 coresight: Clarify comments around the PID of the sink owner
In reply to James Clark"Process being monitored" and "pid of the process to monitor" imply that this would be the same PID if there were two sessions targeting the same process. But this is actually the PID of the process that did the Perf event open call, rather than the target of the session. So update the comments to make this clearer.
--- drivers/hwtracing/coresight/coresight-tmc-etr.c | 5 +++-- drivers/hwtracing/coresight/coresight-tmc.h | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/hwtracing/coresight/coresight-tmc-etr.c +3 -2
@@ -36,7 +36,8 @@ struct etr_buf_hw {* etr_perf_buffer - Perf buffer used for ETR * @drvdata - The ETR drvdaga this buffer has been allocated for. * @etr_buf - Actual buffer used by the ETR -* @pid - The PID this etr_perf_buffer belongs to. +* @pid - The PID of the session owner that etr_perf_buffer +* belongs to. * @snaphost - Perf session mode * @nr_pages - Number of pages in the ring buffer. * @pages - Array of Pages in the ring buffer.
@@ -1662,7 +1663,7 @@ static int tmc_enable_etr_sink_perf(struct coresight_device *csdev, void *data) goto unlock_out; } -/* Get a handle on the pid of the process to monitor */ +/* Get a handle on the pid of the session owner */ pid = etr_perf->pid;/* Do not proceed if this device is associated with another session */
drivers/hwtracing/coresight/coresight-tmc.h +3 -2
@@ -171,8 +171,9 @@ struct etr_buf {* @csdev: component vitals needed by the framework. * @miscdev: specifics to handle "/dev/xyz.tmc" entry. * @spinlock: only one at a time pls. -* @pid: Process ID of the process being monitored by the session -* that is using this component. +* @pid: Process ID of the process that owns the session that is using +* this component. For example this would be the pid of the Perf +* process. * @buf: Snapshot of the trace data for ETF/ETB. * @etr_buf: details of buffer used in TMC-ETR * @len: size of the available trace for ETF/ETB.
Signature · 1 line
2.34.1
PATCH 10/17 coresight: Move struct coresight_trace_id_map to common header
In reply to James ClarkThe trace ID maps will need to be created and stored by the core and Perf code so move the definition up to the common header.
--- .../hwtracing/coresight/coresight-trace-id.c | 1 + .../hwtracing/coresight/coresight-trace-id.h | 19 ------------------- include/linux/coresight.h | 18 ++++++++++++++++++ 3 files changed, 19 insertions(+), 19 deletions(-)
drivers/hwtracing/coresight/coresight-trace-id.c +1 -0
@@ -3,6 +3,7 @@* Copyright (c) 2022, Linaro Limited, All rights reserved. * Author: Mike Leach <[email protected]> */ +#include <linux/coresight.h> #include <linux/coresight-pmu.h> #include <linux/cpumask.h> #include <linux/kernel.h>
drivers/hwtracing/coresight/coresight-trace-id.h +0 -19
@@ -32,10 +32,6 @@#include <linux/bitops.h> #include <linux/types.h> - -/* architecturally we have 128 IDs some of which are reserved */ -#define CORESIGHT_TRACE_IDS_MAX 128 -/* ID 0 is reserved */ #define CORESIGHT_TRACE_ID_RES_0 0
@@ -46,21 +42,6 @@#define IS_VALID_CS_TRACE_ID (id) \ ((id > CORESIGHT_TRACE_ID_RES_0) && (id < CORESIGHT_TRACE_ID_RES_TOP)) -/** -* Trace ID map. -* -* @used_ids: Bitmap to register available (bit = 0) and in use (bit = 1) IDs. -* Initialised so that the reserved IDs are permanently marked as -* in use. -* @pend_rel_ids: CPU IDs that have been released by the trace source but not -* yet marked as available, to allow re-allocation to the same -* CPU during a perf session. -*/ -struct coresight_trace_id_map { - DECLARE_BITMAP(used_ids, CORESIGHT_TRACE_IDS_MAX); - DECLARE_BITMAP(pend_rel_ids, CORESIGHT_TRACE_IDS_MAX); -}; -/* Allocate and release IDs for a single default trace ID map */ /**
include/linux/coresight.h +18 -0
@@ -218,6 +218,24 @@ struct coresight_sysfs_link {const char *target_name; }; +/* architecturally we have 128 IDs some of which are reserved */ +#define CORESIGHT_TRACE_IDS_MAX 128 + +/** +* Trace ID map. +* +* @used_ids: Bitmap to register available (bit = 0) and in use (bit = 1) IDs. +* Initialised so that the reserved IDs are permanently marked as +* in use. +* @pend_rel_ids: CPU IDs that have been released by the trace source but not +* yet marked as available, to allow re-allocation to the same +* CPU during a perf session. +*/ +struct coresight_trace_id_map { + DECLARE_BITMAP(used_ids, CORESIGHT_TRACE_IDS_MAX); + DECLARE_BITMAP(pend_rel_ids, CORESIGHT_TRACE_IDS_MAX); +}; +/** * struct coresight_device - representation of a device as used by the framework * @pdata: Platform data with device connections associated to this device.
Signature · 1 line
2.34.1
PATCH 11/17 coresight: Expose map argument in trace ID API
In reply to James ClarkThe trace ID API is currently hard coded to always use the global map. The functions that take the map as an argument aren't currently public. Make them public so that Perf mode can pass in its own maps. At the moment all usages are still hard coded to use the global map, but now on the caller side.
System ID functions are unchanged because they will always use the default map.
--- .../hwtracing/coresight/coresight-etm-perf.c | 5 +++-- .../coresight/coresight-etm3x-core.c | 5 +++-- .../coresight/coresight-etm4x-core.c | 5 +++-- .../hwtracing/coresight/coresight-trace-id.c | 22 +++++++------------ .../hwtracing/coresight/coresight-trace-id.h | 9 +++++--- 5 files changed, 23 insertions(+), 23 deletions(-)
drivers/hwtracing/coresight/coresight-etm-perf.c +3 -2
@@ -232,7 +232,7 @@ static void free_event_data(struct work_struct *work)if (!(IS_ERR_OR_NULL (*ppath)))coresight_release_path (*ppath); *ppath =NULL ; -coresight_trace_id_put_cpu_id (cpu); +coresight_trace_id_put_cpu_id (cpu,coresight_trace_id_map_default ()); }/* mark perf event as done for trace id allocator */
@@ -401,7 +401,8 @@ static void *etm_setup_aux(struct perf_event *event, void **pages, }/* ensure we can allocate a trace ID for this CPU */ - trace_id =coresight_trace_id_get_cpu_id (cpu); + trace_id =coresight_trace_id_get_cpu_id (cpu, +coresight_trace_id_map_default ());if (!IS_VALID_CS_TRACE_ID (trace_id)) {cpumask_clear_cpu (cpu, mask);coresight_release_path (path);
drivers/hwtracing/coresight/coresight-etm3x-core.c +3 -2
@@ -465,7 +465,8 @@ int etm_read_alloc_trace_id(struct etm_drvdata *drvdata)* * trace id function has its own lock */ - trace_id =coresight_trace_id_get_cpu_id (drvdata->cpu); + trace_id =coresight_trace_id_get_cpu_id (drvdata->cpu, +coresight_trace_id_map_default ());if (IS_VALID_CS_TRACE_ID (trace_id)) drvdata->traceid = (u8 )trace_id;else
@@ -477,7 +478,7 @@ int etm_read_alloc_trace_id(struct etm_drvdata *drvdata)void etm_release_trace_id (struct etm_drvdata *drvdata) { -coresight_trace_id_put_cpu_id (drvdata->cpu); +coresight_trace_id_put_cpu_id (drvdata->cpu,coresight_trace_id_map_default ()); } static int etm_enable_perf(struct coresight_device *csdev,
drivers/hwtracing/coresight/coresight-etm4x-core.c +3 -2
@@ -241,7 +241,8 @@ int etm4_read_alloc_trace_id(struct etmv4_drvdata *drvdata)* or return the one currently allocated. * The trace id function has its own lock */ - trace_id =coresight_trace_id_get_cpu_id (drvdata->cpu); + trace_id =coresight_trace_id_get_cpu_id (drvdata->cpu, +coresight_trace_id_map_default ());if (IS_VALID_CS_TRACE_ID (trace_id)) drvdata->trcid = (u8 )trace_id;else
@@ -253,7 +254,7 @@ int etm4_read_alloc_trace_id(struct etmv4_drvdata *drvdata)void etm4_release_trace_id (struct etmv4_drvdata *drvdata) { -coresight_trace_id_put_cpu_id (drvdata->cpu); +coresight_trace_id_put_cpu_id (drvdata->cpu,coresight_trace_id_map_default ()); }struct etm4_enable_arg {
drivers/hwtracing/coresight/coresight-trace-id.c +8 -14
@@ -12,7 +12,7 @@#include "coresight-trace-id.h" -/* Default trace ID map. Used on systems that don't require per sink mappings */ +/* Default trace ID map. Used in sysfs mode and for system sources */ static struct coresight_trace_id_map id_map_default;/* maintain a record of the mapping of IDs and pending releases per cpu */
@@ -152,7 +152,7 @@ static void coresight_trace_id_release_all_pending(void)DUMP_ID_MAP (id_map); } -static int coresight_trace_id_map_get_cpu_id (int cpu,struct coresight_trace_id_map *id_map) +int coresight_trace_id_get_cpu_id (int cpu,struct coresight_trace_id_map *id_map) {unsigned long flags;int id;
@@ -195,8 +195,9 @@ static int coresight_trace_id_map_get_cpu_id(int cpu, struct coresight_trace_id_DUMP_ID_MAP (id_map);return id; } +EXPORT_SYMBOL_GPL (coresight_trace_id_get_cpu_id); -static void coresight_trace_id_map_put_cpu_id (int cpu,struct coresight_trace_id_map *id_map) +void coresight_trace_id_put_cpu_id (int cpu,struct coresight_trace_id_map *id_map) {unsigned long flags;int id;
@@ -222,6 +223,7 @@ static void coresight_trace_id_map_put_cpu_id(int cpu, struct coresight_trace_idDUMP_ID_CPU (cpu, id);DUMP_ID_MAP (id_map); } +EXPORT_SYMBOL_GPL (coresight_trace_id_put_cpu_id);static int coresight_trace_id_map_get_system_id (struct coresight_trace_id_map *id_map) {
@@ -250,19 +252,11 @@ static void coresight_trace_id_map_put_system_id(struct coresight_trace_id_map *DUMP_ID_MAP (id_map); } -/* API functions */ - -int coresight_trace_id_get_cpu_id (int cpu) -{ -return coresight_trace_id_map_get_cpu_id (cpu, &id_map_default); -} -EXPORT_SYMBOL_GPL (coresight_trace_id_get_cpu_id); - -void coresight_trace_id_put_cpu_id (int cpu) +struct coresight_trace_id_map *coresight_trace_id_map_default (void ) { -coresight_trace_id_map_put_cpu_id (cpu, &id_map_default); +return &id_map_default; } -EXPORT_SYMBOL_GPL (coresight_trace_id_put_cpu_id); +EXPORT_SYMBOL_GPL (coresight_trace_id_map_default);int coresight_trace_id_read_cpu_id (int cpu) {
drivers/hwtracing/coresight/coresight-trace-id.h +6 -3
@@ -42,7 +42,10 @@#define IS_VALID_CS_TRACE_ID (id) \ ((id > CORESIGHT_TRACE_ID_RES_0) && (id < CORESIGHT_TRACE_ID_RES_TOP)) -/* Allocate and release IDs for a single default trace ID map */ +/** +* Get the global map that's used by sysfs +*/ +struct coresight_trace_id_map *coresight_trace_id_map_default (void );/** * Read and optionally allocate a CoreSight trace ID and associate with a CPU.
@@ -57,7 +60,7 @@* * return: CoreSight trace ID or -EINVAL if allocation impossible. */ -int coresight_trace_id_get_cpu_id (int cpu); +int coresight_trace_id_get_cpu_id (int cpu,struct coresight_trace_id_map *id_map);/** * Release an allocated trace ID associated with the CPU.
@@ -70,7 +73,7 @@ int coresight_trace_id_get_cpu_id(int cpu);* * @cpu: The CPU index to release the associated trace ID. */ -void coresight_trace_id_put_cpu_id (int cpu); +void coresight_trace_id_put_cpu_id (int cpu,struct coresight_trace_id_map *id_map);/** * Read the current allocated CoreSight Trace ID value for the CPU.
Signature · 1 line
2.34.1
PATCH 11/17 coresight: Expose map arugment in trace ID API
In reply to James Clark...
System ID functions are unchanged because they will always use the default map.
--- .../hwtracing/coresight/coresight-etm-perf.c | 5 +++-- .../coresight/coresight-etm3x-core.c | 5 +++-- .../coresight/coresight-etm4x-core.c | 5 +++-- .../hwtracing/coresight/coresight-trace-id.c | 22 +++++++------------ .../hwtracing/coresight/coresight-trace-id.h | 9 +++++--- 5 files changed, 23 insertions(+), 23 deletions(-)
drivers/hwtracing/coresight/coresight-etm-perf.c +3 -2
@@ -232,7 +232,7 @@ static void free_event_data(struct work_struct *work)if (!(IS_ERR_OR_NULL (*ppath)))coresight_release_path (*ppath); *ppath =NULL ; -coresight_trace_id_put_cpu_id (cpu); +coresight_trace_id_put_cpu_id (cpu,coresight_trace_id_map_default ()); }/* mark perf event as done for trace id allocator */
@@ -401,7 +401,8 @@ static void *etm_setup_aux(struct perf_event *event, void **pages, }/* ensure we can allocate a trace ID for this CPU */ - trace_id =coresight_trace_id_get_cpu_id (cpu); + trace_id =coresight_trace_id_get_cpu_id (cpu, +coresight_trace_id_map_default ());if (!IS_VALID_CS_TRACE_ID (trace_id)) {cpumask_clear_cpu (cpu, mask);coresight_release_path (path);
drivers/hwtracing/coresight/coresight-etm3x-core.c +3 -2
@@ -465,7 +465,8 @@ int etm_read_alloc_trace_id(struct etm_drvdata *drvdata)* * trace id function has its own lock */ - trace_id =coresight_trace_id_get_cpu_id (drvdata->cpu); + trace_id =coresight_trace_id_get_cpu_id (drvdata->cpu, +coresight_trace_id_map_default ());if (IS_VALID_CS_TRACE_ID (trace_id)) drvdata->traceid = (u8 )trace_id;else
@@ -477,7 +478,7 @@ int etm_read_alloc_trace_id(struct etm_drvdata *drvdata)void etm_release_trace_id (struct etm_drvdata *drvdata) { -coresight_trace_id_put_cpu_id (drvdata->cpu); +coresight_trace_id_put_cpu_id (drvdata->cpu,coresight_trace_id_map_default ()); } static int etm_enable_perf(struct coresight_device *csdev,
drivers/hwtracing/coresight/coresight-etm4x-core.c +3 -2
@@ -241,7 +241,8 @@ int etm4_read_alloc_trace_id(struct etmv4_drvdata *drvdata)* or return the one currently allocated. * The trace id function has its own lock */ - trace_id =coresight_trace_id_get_cpu_id (drvdata->cpu); + trace_id =coresight_trace_id_get_cpu_id (drvdata->cpu, +coresight_trace_id_map_default ());if (IS_VALID_CS_TRACE_ID (trace_id)) drvdata->trcid = (u8 )trace_id;else
@@ -253,7 +254,7 @@ int etm4_read_alloc_trace_id(struct etmv4_drvdata *drvdata)void etm4_release_trace_id (struct etmv4_drvdata *drvdata) { -coresight_trace_id_put_cpu_id (drvdata->cpu); +coresight_trace_id_put_cpu_id (drvdata->cpu,coresight_trace_id_map_default ()); }struct etm4_enable_arg {
drivers/hwtracing/coresight/coresight-trace-id.c +8 -14
@@ -12,7 +12,7 @@#include "coresight-trace-id.h" -/* Default trace ID map. Used on systems that don't require per sink mappings */ +/* Default trace ID map. Used in sysfs mode and for system sources */ static struct coresight_trace_id_map id_map_default;/* maintain a record of the mapping of IDs and pending releases per cpu */
@@ -152,7 +152,7 @@ static void coresight_trace_id_release_all_pending(void)DUMP_ID_MAP (id_map); } -static int coresight_trace_id_map_get_cpu_id (int cpu,struct coresight_trace_id_map *id_map) +int coresight_trace_id_get_cpu_id (int cpu,struct coresight_trace_id_map *id_map) {unsigned long flags;int id;
@@ -195,8 +195,9 @@ static int coresight_trace_id_map_get_cpu_id(int cpu, struct coresight_trace_id_DUMP_ID_MAP (id_map);return id; } +EXPORT_SYMBOL_GPL (coresight_trace_id_get_cpu_id); -static void coresight_trace_id_map_put_cpu_id (int cpu,struct coresight_trace_id_map *id_map) +void coresight_trace_id_put_cpu_id (int cpu,struct coresight_trace_id_map *id_map) {unsigned long flags;int id;
@@ -222,6 +223,7 @@ static void coresight_trace_id_map_put_cpu_id(int cpu, struct coresight_trace_idDUMP_ID_CPU (cpu, id);DUMP_ID_MAP (id_map); } +EXPORT_SYMBOL_GPL (coresight_trace_id_put_cpu_id);static int coresight_trace_id_map_get_system_id (struct coresight_trace_id_map *id_map) {
@@ -250,19 +252,11 @@ static void coresight_trace_id_map_put_system_id(struct coresight_trace_id_map *DUMP_ID_MAP (id_map); } -/* API functions */ - -int coresight_trace_id_get_cpu_id (int cpu) -{ -return coresight_trace_id_map_get_cpu_id (cpu, &id_map_default); -} -EXPORT_SYMBOL_GPL (coresight_trace_id_get_cpu_id); - -void coresight_trace_id_put_cpu_id (int cpu) +struct coresight_trace_id_map *coresight_trace_id_map_default (void ) { -coresight_trace_id_map_put_cpu_id (cpu, &id_map_default); +return &id_map_default; } -EXPORT_SYMBOL_GPL (coresight_trace_id_put_cpu_id); +EXPORT_SYMBOL_GPL (coresight_trace_id_map_default);int coresight_trace_id_read_cpu_id (int cpu) {
drivers/hwtracing/coresight/coresight-trace-id.h +6 -3
@@ -42,7 +42,10 @@#define IS_VALID_CS_TRACE_ID (id) \ ((id > CORESIGHT_TRACE_ID_RES_0) && (id < CORESIGHT_TRACE_ID_RES_TOP)) -/* Allocate and release IDs for a single default trace ID map */ +/** +* Get the global map that's used by sysfs +*/ +struct coresight_trace_id_map *coresight_trace_id_map_default (void );/** * Read and optionally allocate a CoreSight trace ID and associate with a CPU.
@@ -57,7 +60,7 @@* * return: CoreSight trace ID or -EINVAL if allocation impossible. */ -int coresight_trace_id_get_cpu_id (int cpu); +int coresight_trace_id_get_cpu_id (int cpu,struct coresight_trace_id_map *id_map);/** * Release an allocated trace ID associated with the CPU.
@@ -70,7 +73,7 @@ int coresight_trace_id_get_cpu_id(int cpu);* * @cpu: The CPU index to release the associated trace ID. */ -void coresight_trace_id_put_cpu_id (int cpu); +void coresight_trace_id_put_cpu_id (int cpu,struct coresight_trace_id_map *id_map);/** * Read the current allocated CoreSight Trace ID value for the CPU.
Signature · 1 line
2.34.1
PATCH 12/17 coresight: Make CPU id map a property of a trace ID map
In reply to James ClarkThe global CPU ID mappings won't work for per-sink ID maps so move it to the ID map struct. coresight_trace_id_release_all_pending() is hard coded to operate on the default map, but once Perf sessions use their own maps the pending release mechanism will be deleted. So it doesn't need to be extended to accept a trace ID map argument at this point.
--- .../hwtracing/coresight/coresight-etm-perf.c | 3 +- .../coresight/coresight-etm3x-core.c | 3 +- .../coresight/coresight-etm4x-core.c | 3 +- .../hwtracing/coresight/coresight-trace-id.c | 28 ++++++++----------- .../hwtracing/coresight/coresight-trace-id.h | 2 +- include/linux/coresight.h | 1 + 6 files changed, 20 insertions(+), 20 deletions(-)
drivers/hwtracing/coresight/coresight-etm-perf.c +2 -1
@@ -508,7 +508,8 @@ static void etm_event_start(struct perf_event *event, int flags) hw_id =FIELD_PREP (CS_AUX_HW_ID_VERSION_MASK ,CS_AUX_HW_ID_CURR_VERSION ); hw_id |=FIELD_PREP (CS_AUX_HW_ID_TRACE_ID_MASK , -coresight_trace_id_read_cpu_id (cpu)); +coresight_trace_id_read_cpu_id (cpu, +coresight_trace_id_map_default ()));perf_report_aux_output_id (event, hw_id); }
drivers/hwtracing/coresight/coresight-etm3x-core.c +2 -1
@@ -501,7 +501,8 @@ static int etm_enable_perf(struct coresight_device *csdev,* with perf locks - we know the ID cannot change until perf shuts down * the session */ - trace_id =coresight_trace_id_read_cpu_id (drvdata->cpu); + trace_id =coresight_trace_id_read_cpu_id (drvdata->cpu, +coresight_trace_id_map_default ());if (!IS_VALID_CS_TRACE_ID (trace_id)) {dev_err (&drvdata->csdev->dev,"Failed to set trace ID for %s on CPU%d\n" ,dev_name (&drvdata->csdev->dev), drvdata->cpu);
drivers/hwtracing/coresight/coresight-etm4x-core.c +2 -1
@@ -776,7 +776,8 @@ static int etm4_enable_perf(struct coresight_device *csdev,* with perf locks - we know the ID cannot change until perf shuts down * the session */ - trace_id =coresight_trace_id_read_cpu_id (drvdata->cpu); + trace_id =coresight_trace_id_read_cpu_id (drvdata->cpu, +coresight_trace_id_map_default ());if (!IS_VALID_CS_TRACE_ID (trace_id)) {dev_err (&drvdata->csdev->dev,"Failed to set trace ID for %s on CPU%d\n" ,dev_name (&drvdata->csdev->dev), drvdata->cpu);
drivers/hwtracing/coresight/coresight-trace-id.c +12 -16
@@ -13,10 +13,12 @@#include "coresight-trace-id.h" /* Default trace ID map. Used in sysfs mode and for system sources */ -static struct coresight_trace_id_map id_map_default; +static DEFINE_PER_CPU(atomic_t, id_map_default_cpu_ids) = ATOMIC_INIT(0); +static struct coresight_trace_id_map id_map_default = { + .cpu_map = &id_map_default_cpu_ids +}; -/* maintain a record of the mapping of IDs and pending releases per cpu */ -static DEFINE_PER_CPU(atomic_t, cpu_id) = ATOMIC_INIT(0); +/* maintain a record of the pending releases per cpu */ static cpumask_t cpu_id_release_pending;/* perf session active counter */
@@ -46,12 +48,6 @@ static void coresight_trace_id_dump_table(struct coresight_trace_id_map *id_map,#define PERF_SESSION (n)#endif -/* unlocked read of current trace ID value for given CPU */ -static int _coresight_trace_id_read_cpu_id (int cpu) -{ -return atomic_read (&per_cpu (cpu_id, cpu)); -} -/* look for next available odd ID, return 0 if none found */ static int coresight_trace_id_find_odd_id (struct coresight_trace_id_map *id_map) {
@@ -145,7 +141,7 @@ static void coresight_trace_id_release_all_pending(void)clear_bit (bit, id_map->pend_rel_ids); }for_each_cpu (cpu, &cpu_id_release_pending) { -atomic_set (&per_cpu (cpu_id, cpu),0 ); +atomic_set (per_cpu_ptr (id_map_default.cpu_map, cpu),0 );cpumask_clear_cpu (cpu, &cpu_id_release_pending); }spin_unlock_irqrestore (&id_map_lock, flags);
@@ -160,7 +156,7 @@ int coresight_trace_id_get_cpu_id(int cpu, struct coresight_trace_id_map *id_mapspin_lock_irqsave (&id_map_lock, flags);/* check for existing allocation for this CPU */ - id =_coresight_trace_id_read_cpu_id (cpu); + id =coresight_trace_id_read_cpu_id (cpu, id_map);if (id) goto get_cpu_id_clr_pend;
@@ -181,7 +177,7 @@ int coresight_trace_id_get_cpu_id(int cpu, struct coresight_trace_id_map *id_map goto get_cpu_id_out_unlock;/* allocate the new id to the cpu */ -atomic_set (&per_cpu (cpu_id, cpu), id); +atomic_set (per_cpu_ptr (id_map->cpu_map, cpu), id); get_cpu_id_clr_pend:/* we are (re)using this ID - so ensure it is not marked for release */
@@ -203,7 +199,7 @@ void coresight_trace_id_put_cpu_id(int cpu, struct coresight_trace_id_map *id_maint id;/* check for existing allocation for this CPU */ - id =_coresight_trace_id_read_cpu_id (cpu); + id =coresight_trace_id_read_cpu_id (cpu, id_map);if (!id)return ;
@@ -216,7 +212,7 @@ void coresight_trace_id_put_cpu_id(int cpu, struct coresight_trace_id_map *id_ma }else {/* otherwise clear id */ coresight_trace_id_free (id, id_map); -atomic_set (&per_cpu (cpu_id, cpu),0 ); +atomic_set (per_cpu_ptr (id_map->cpu_map, cpu),0 ); }spin_unlock_irqrestore (&id_map_lock, flags);
@@ -258,9 +254,9 @@ struct coresight_trace_id_map *coresight_trace_id_map_default(void) }EXPORT_SYMBOL_GPL (coresight_trace_id_map_default); -int coresight_trace_id_read_cpu_id (int cpu) +int coresight_trace_id_read_cpu_id (int cpu,struct coresight_trace_id_map *id_map) { -return _coresight_trace_id_read_cpu_id (cpu); +return atomic_read (per_cpu_ptr (id_map->cpu_map, cpu)); }EXPORT_SYMBOL_GPL (coresight_trace_id_read_cpu_id);
drivers/hwtracing/coresight/coresight-trace-id.h +1 -1
@@ -93,7 +93,7 @@ void coresight_trace_id_put_cpu_id(int cpu, struct coresight_trace_id_map *id_ma* * return: current value, will be 0 if unallocated. */ -int coresight_trace_id_read_cpu_id (int cpu); +int coresight_trace_id_read_cpu_id (int cpu,struct coresight_trace_id_map *id_map);/** * Allocate a CoreSight trace ID for a system component.
include/linux/coresight.h +1 -0
@@ -234,6 +234,7 @@ struct coresight_sysfs_link {struct coresight_trace_id_map { DECLARE_BITMAP(used_ids, CORESIGHT_TRACE_IDS_MAX); DECLARE_BITMAP(pend_rel_ids, CORESIGHT_TRACE_IDS_MAX); +atomic_t __percpu *cpu_map; };/**
Signature · 1 line
2.34.1
PATCH 13/17 coresight: Pass trace ID map into source enable
In reply to James ClarkThis will allow Perf mode to pass in per-sink maps. System sources allocate IDs on probe so they don't use this and it's __maybe_unused.
Sysfs mode also has the global map hard coded in various places, so pass in NULL when enabling for sysfs. We could bubble the global map all the way down to where it's used, but it wouldn't have any functional difference, so it's probably not worth the code churn.
--- drivers/hwtracing/coresight/coresight-dummy.c | 3 ++- drivers/hwtracing/coresight/coresight-etm-perf.c | 3 ++- drivers/hwtracing/coresight/coresight-etm3x-core.c | 10 +++++----- drivers/hwtracing/coresight/coresight-etm4x-core.c | 10 +++++----- drivers/hwtracing/coresight/coresight-stm.c | 3 ++- drivers/hwtracing/coresight/coresight-sysfs.c | 3 ++- drivers/hwtracing/coresight/coresight-tpdm.c | 3 ++- include/linux/coresight.h | 2 +- 8 files changed, 21 insertions(+), 16 deletions(-)
drivers/hwtracing/coresight/coresight-dummy.c +2 -1
@@ -21,7 +21,8 @@ DEFINE_CORESIGHT_DEVLIST(source_devs, "dummy_source");DEFINE_CORESIGHT_DEVLIST (sink_devs,"dummy_sink" );static int dummy_source_enable (struct coresight_device *csdev, -struct perf_event *event,enum cs_mode mode) +struct perf_event *event,enum cs_mode mode, +__maybe_unused struct coresight_trace_id_map *id_map) {dev_dbg (csdev->dev.parent,"Dummy source enabled\n" );
drivers/hwtracing/coresight/coresight-etm-perf.c +2 -1
@@ -496,7 +496,8 @@ static void etm_event_start(struct perf_event *event, int flags) goto fail_end_stop;/* Finally enable the tracer */ -if (source_ops (csdev)->enable (csdev, event,CS_MODE_PERF )) +if (source_ops (csdev)->enable (csdev, event,CS_MODE_PERF , +coresight_trace_id_map_default ())) goto fail_disable_path;/*
drivers/hwtracing/coresight/coresight-etm3x-core.c +5 -5
@@ -482,7 +482,8 @@ void etm_release_trace_id(struct etm_drvdata *drvdata) }static int etm_enable_perf (struct coresight_device *csdev, -struct perf_event *event) +struct perf_event *event, +struct coresight_trace_id_map *id_map) {struct etm_drvdata *drvdata =dev_get_drvdata (csdev->dev.parent);int trace_id;
@@ -501,8 +502,7 @@ static int etm_enable_perf(struct coresight_device *csdev,* with perf locks - we know the ID cannot change until perf shuts down * the session */ - trace_id =coresight_trace_id_read_cpu_id (drvdata->cpu, -coresight_trace_id_map_default ()); + trace_id =coresight_trace_id_read_cpu_id (drvdata->cpu, id_map);if (!IS_VALID_CS_TRACE_ID (trace_id)) {dev_err (&drvdata->csdev->dev,"Failed to set trace ID for %s on CPU%d\n" ,dev_name (&drvdata->csdev->dev), drvdata->cpu);
@@ -555,7 +555,7 @@ static int etm_enable_sysfs(struct coresight_device *csdev) }static int etm_enable (struct coresight_device *csdev,struct perf_event *event, -enum cs_mode mode) +enum cs_mode mode,struct coresight_trace_id_map *id_map) {int ret;struct etm_drvdata *drvdata =dev_get_drvdata (csdev->dev.parent);
@@ -570,7 +570,7 @@ static int etm_enable(struct coresight_device *csdev, struct perf_event *event, ret =etm_enable_sysfs (csdev);break ;case CS_MODE_PERF : - ret =etm_enable_perf (csdev, event); + ret =etm_enable_perf (csdev, event, id_map);break ;default : ret = -EINVAL ;
drivers/hwtracing/coresight/coresight-etm4x-core.c +5 -5
@@ -753,7 +753,8 @@ static int etm4_parse_event_config(struct coresight_device *csdev, }static int etm4_enable_perf (struct coresight_device *csdev, -struct perf_event *event) +struct perf_event *event, +struct coresight_trace_id_map *id_map) {int ret =0 , trace_id;struct etmv4_drvdata *drvdata =dev_get_drvdata (csdev->dev.parent);
@@ -776,8 +777,7 @@ static int etm4_enable_perf(struct coresight_device *csdev,* with perf locks - we know the ID cannot change until perf shuts down * the session */ - trace_id =coresight_trace_id_read_cpu_id (drvdata->cpu, -coresight_trace_id_map_default ()); + trace_id =coresight_trace_id_read_cpu_id (drvdata->cpu, id_map);if (!IS_VALID_CS_TRACE_ID (trace_id)) {dev_err (&drvdata->csdev->dev,"Failed to set trace ID for %s on CPU%d\n" ,dev_name (&drvdata->csdev->dev), drvdata->cpu);
@@ -839,7 +839,7 @@ static int etm4_enable_sysfs(struct coresight_device *csdev) }static int etm4_enable (struct coresight_device *csdev,struct perf_event *event, -enum cs_mode mode) +enum cs_mode mode,struct coresight_trace_id_map *id_map) {int ret;
@@ -853,7 +853,7 @@ static int etm4_enable(struct coresight_device *csdev, struct perf_event *event, ret =etm4_enable_sysfs (csdev);break ;case CS_MODE_PERF : - ret =etm4_enable_perf (csdev, event); + ret =etm4_enable_perf (csdev, event, id_map);break ;default : ret = -EINVAL ;
drivers/hwtracing/coresight/coresight-stm.c +2 -1
@@ -194,7 +194,8 @@ static void stm_enable_hw(struct stm_drvdata *drvdata) }static int stm_enable (struct coresight_device *csdev,struct perf_event *event, -enum cs_mode mode) +enum cs_mode mode, +__maybe_unused struct coresight_trace_id_map *trace_id) {struct stm_drvdata *drvdata =dev_get_drvdata (csdev->dev.parent);
drivers/hwtracing/coresight/coresight-sysfs.c +2 -1
@@ -9,6 +9,7 @@#include <linux/kernel.h> #include "coresight-priv.h" +#include "coresight-trace-id.h" /* * Use IDR to map the hash of the source's device name
@@ -63,7 +64,7 @@ static int coresight_enable_source_sysfs(struct coresight_device *csdev,*/ lockdep_assert_held (&coresight_mutex);if (coresight_get_mode (csdev) !=CS_MODE_SYSFS ) { - ret =source_ops (csdev)->enable (csdev, data, mode); + ret =source_ops (csdev)->enable (csdev, data, mode,NULL );if (ret)return ret; }
drivers/hwtracing/coresight/coresight-tpdm.c +2 -1
@@ -439,7 +439,8 @@ static void __tpdm_enable(struct tpdm_drvdata *drvdata) }static int tpdm_enable (struct coresight_device *csdev,struct perf_event *event, -enum cs_mode mode) +enum cs_mode mode, +__maybe_unused struct coresight_trace_id_map *id_map) {struct tpdm_drvdata *drvdata =dev_get_drvdata (csdev->dev.parent);
include/linux/coresight.h +1 -1
@@ -384,7 +384,7 @@ struct coresight_ops_link {struct coresight_ops_source {int (*cpu_id)(struct coresight_device *csdev);int (*enable)(struct coresight_device *csdev,struct perf_event *event, -enum cs_mode mode); +enum cs_mode mode,struct coresight_trace_id_map *id_map);void (*disable)(struct coresight_device *csdev,struct perf_event *event); };
Signature · 1 line
2.34.1
PATCH 14/17 coresight: Use per-sink trace ID maps for Perf sessions
In reply to James ClarkThis will allow sessions with more than CORESIGHT_TRACE_IDS_MAX ETMs as long as there are fewer than that many ETMs connected to each sink.
Each sink owns its own trace ID map, and any Perf session connecting to that sink will allocate from it, even if the sink is currently in use by other users. This is similar to the existing behavior where the dynamic trace IDs are constant as long as there is any concurrent Perf session active. It's not completely optimal because slightly more IDs will be used than necessary, but the optimal solution involves tracking the PIDs of each session and allocating ID maps based on the session owner. This is difficult to do with the combination of per-thread and per-cpu modes and some scheduling issues. The complexity of this isn't likely to worth it because even with multiple users they'd just see a difference in the ordering of ID allocations rather than hitting any limits (unless the hardware does have too many ETMs connected to one sink).
--- drivers/hwtracing/coresight/coresight-core.c | 10 ++++++++++ drivers/hwtracing/coresight/coresight-etm-perf.c | 15 ++++++++------- include/linux/coresight.h | 1 + 3 files changed, 19 insertions(+), 7 deletions(-)
drivers/hwtracing/coresight/coresight-core.c +10 -0
@@ -902,6 +902,7 @@ static void coresight_device_release(struct device *dev)struct coresight_device *csdev =to_coresight_device (dev);fwnode_handle_put (csdev->dev.fwnode); +free_percpu (csdev->perf_id_map.cpu_map);kfree (csdev); }
@@ -1159,6 +1160,14 @@ struct coresight_device *coresight_register(struct coresight_desc *desc) csdev->dev.fwnode =fwnode_handle_get (dev_fwnode (desc->dev));dev_set_name (&csdev->dev,"%s" , desc->name); +if (csdev->type ==CORESIGHT_DEV_TYPE_SINK || + csdev->type ==CORESIGHT_DEV_TYPE_LINKSINK ) { + csdev->perf_id_map.cpu_map =alloc_percpu (atomic_t); +if (!csdev->perf_id_map.cpu_map) { + ret = -ENOMEM ; + goto err_out; + } + }/* * Make sure the device registration and the connection fixup * are synchronised, so that we don't see uninitialised devices
@@ -1216,6 +1225,7 @@ struct coresight_device *coresight_register(struct coresight_desc *desc) err_out:/* Cleanup the connection information */ coresight_release_platform_data (NULL , desc->dev, desc->pdata); +kfree (csdev);return ERR_PTR (ret); }EXPORT_SYMBOL_GPL (coresight_register);
drivers/hwtracing/coresight/coresight-etm-perf.c +8 -7
@@ -229,10 +229,13 @@ static void free_event_data(struct work_struct *work)struct list_head **ppath; ppath =etm_event_cpu_path_ptr (event_data, cpu); -if (!(IS_ERR_OR_NULL (*ppath))) +if (!(IS_ERR_OR_NULL (*ppath))) { +struct coresight_device *sink =coresight_get_sink (*ppath); + +coresight_trace_id_put_cpu_id (cpu, &sink->perf_id_map);coresight_release_path (*ppath); + } *ppath =NULL ; -coresight_trace_id_put_cpu_id (cpu,coresight_trace_id_map_default ()); }/* mark perf event as done for trace id allocator */
@@ -401,8 +404,7 @@ static void *etm_setup_aux(struct perf_event *event, void **pages, }/* ensure we can allocate a trace ID for this CPU */ - trace_id =coresight_trace_id_get_cpu_id (cpu, -coresight_trace_id_map_default ()); + trace_id =coresight_trace_id_get_cpu_id (cpu, &sink->perf_id_map);if (!IS_VALID_CS_TRACE_ID (trace_id)) {cpumask_clear_cpu (cpu, mask);coresight_release_path (path);
@@ -497,7 +499,7 @@ static void etm_event_start(struct perf_event *event, int flags)/* Finally enable the tracer */ if (source_ops (csdev)->enable (csdev, event,CS_MODE_PERF , -coresight_trace_id_map_default ())) + &sink->perf_id_map)) goto fail_disable_path;/*
@@ -509,8 +511,7 @@ static void etm_event_start(struct perf_event *event, int flags) hw_id =FIELD_PREP (CS_AUX_HW_ID_VERSION_MASK ,CS_AUX_HW_ID_CURR_VERSION ); hw_id |=FIELD_PREP (CS_AUX_HW_ID_TRACE_ID_MASK , -coresight_trace_id_read_cpu_id (cpu, -coresight_trace_id_map_default ())); +coresight_trace_id_read_cpu_id (cpu, &sink->perf_id_map));perf_report_aux_output_id (event, hw_id); }
include/linux/coresight.h +1 -0
@@ -290,6 +290,7 @@ struct coresight_device {bool sysfs_sink_activated;struct dev_ext_attribute *ea;struct coresight_device *def_sink; +struct coresight_trace_id_map perf_id_map;/* sysfs links between components */ int nr_links;bool has_conns_grp;
Signature · 1 line
2.34.1
PATCH 15/17 coresight: Remove pending trace ID release mechanism
In reply to James ClarkPending the release of IDs was a way of managing concurrent sysfs and Perf sessions in a single global ID map. Perf may have finished while sysfs hadn't, and Perf shouldn't release the IDs in use by sysfs and vice versa.
Now that Perf uses its own exclusive ID maps, pending release doesn't result in any different behavior than just releasing all IDs when the last Perf session finishes. As part of the per-sink trace ID change, we would have still had to make the pending mechanism work on a per-sink basis, due to the overlapping ID allocations, so instead of making that more complicated, just remove it.
--- .../hwtracing/coresight/coresight-etm-perf.c | 11 ++-- .../hwtracing/coresight/coresight-trace-id.c | 62 +++++-------------- .../hwtracing/coresight/coresight-trace-id.h | 31 +++++----- include/linux/coresight.h | 6 +- 4 files changed, 34 insertions(+), 76 deletions(-)
drivers/hwtracing/coresight/coresight-etm-perf.c +4 -7
@@ -232,15 +232,14 @@ static void free_event_data(struct work_struct *work)if (!(IS_ERR_OR_NULL (*ppath))) {struct coresight_device *sink =coresight_get_sink (*ppath); -coresight_trace_id_put_cpu_id (cpu, &sink->perf_id_map); +/* mark perf event as done for trace id allocator */ +coresight_trace_id_perf_stop (&sink->perf_id_map); +coresight_release_path (*ppath); } *ppath =NULL ; } -/* mark perf event as done for trace id allocator */ -coresight_trace_id_perf_stop (); -free_percpu (event_data->path);kfree (event_data); }
@@ -328,9 +327,6 @@ static void *etm_setup_aux(struct perf_event *event, void **pages, sink = user_sink =coresight_get_sink_by_id (id); } -/* tell the trace ID allocator that a perf event is starting up */ -coresight_trace_id_perf_start (); -/* check if user wants a coresight configuration selected */ cfg_hash = (u32)((event->attr.config2 &GENMASK_ULL (63 ,32 )) >>32 );if (cfg_hash) {
@@ -404,6 +400,7 @@ static void *etm_setup_aux(struct perf_event *event, void **pages, }/* ensure we can allocate a trace ID for this CPU */ +coresight_trace_id_perf_start (&sink->perf_id_map); trace_id =coresight_trace_id_get_cpu_id (cpu, &sink->perf_id_map);if (!IS_VALID_CS_TRACE_ID (trace_id)) {cpumask_clear_cpu (cpu, mask);
drivers/hwtracing/coresight/coresight-trace-id.c +14 -48
110 lines not on this page · raw message
drivers/hwtracing/coresight/coresight-trace-id.h +14 -17
@@ -17,9 +17,10 @@* released when done. * * In order to ensure that a consistent cpu / ID matching is maintained -* throughout a perf cs_etm event session - a session in progress flag will -* be maintained, and released IDs not cleared until the perf session is -* complete. This allows the same CPU to be re-allocated its prior ID. +* throughout a perf cs_etm event session - a session in progress flag will be +* maintained for each sink, and IDs are cleared when all the perf sessions +* complete. This allows the same CPU to be re-allocated its prior ID when +* events are scheduled in and out. * * * Trace ID maps will be created and initialised to prevent architecturally
@@ -65,11 +66,7 @@ int coresight_trace_id_get_cpu_id(int cpu, struct coresight_trace_id_map *id_map/** * Release an allocated trace ID associated with the CPU. * -* This will release the CoreSight trace ID associated with the CPU, -* unless a perf session is in operation. -* -* If a perf session is in operation then the ID will be marked as pending -* release. +* This will release the CoreSight trace ID associated with the CPU. * * @cpu: The CPU index to release the associated trace ID. */
@@ -120,21 +117,21 @@ void coresight_trace_id_put_system_id(int id);/** * Notify the Trace ID allocator that a perf session is starting. * -* Increase the perf session reference count - called by perf when setting up -* a trace event. +* Increase the perf session reference count - called by perf when setting up a +* trace event. * -* This reference count is used by the ID allocator to ensure that trace IDs -* associated with a CPU cannot change or be released during a perf session. +* Perf sessions never free trace IDs to ensure that the ID associated with a +* CPU cannot change during their and other's concurrent sessions. Instead, +* this refcount is used so that the last event to finish always frees all IDs. */ -void coresight_trace_id_perf_start (void ); +void coresight_trace_id_perf_start (struct coresight_trace_id_map *id_map);/** * Notify the ID allocator that a perf session is stopping. * -* Decrease the perf session reference count. -* if this causes the count to go to zero, then all Trace IDs marked as pending -* release, will be released. +* Decrease the perf session reference count. If this causes the count to go to +* zero, then all Trace IDs will be released. */ -void coresight_trace_id_perf_stop (void ); +void coresight_trace_id_perf_stop (struct coresight_trace_id_map *id_map);#endif /* _CORESIGHT_TRACE_ID_H */
include/linux/coresight.h +2 -4
@@ -227,14 +227,12 @@ struct coresight_sysfs_link {* @used_ids: Bitmap to register available (bit = 0) and in use (bit = 1) IDs. * Initialised so that the reserved IDs are permanently marked as * in use. -* @pend_rel_ids: CPU IDs that have been released by the trace source but not -* yet marked as available, to allow re-allocation to the same -* CPU during a perf session. +* @perf_cs_etm_session_active: Number of Perf sessions using this ID map. */ struct coresight_trace_id_map { DECLARE_BITMAP(used_ids, CORESIGHT_TRACE_IDS_MAX); - DECLARE_BITMAP(pend_rel_ids, CORESIGHT_TRACE_IDS_MAX);atomic_t __percpu *cpu_map; +atomic_t perf_cs_etm_session_active; };/**
Signature · 1 line
2.34.1
PATCH 16/17 coresight: Re-emit trace IDs when the sink changes in per-thread mode
In reply to James ClarkIn per-cpu mode there are multiple aux buffers and each one has a fixed sink, so the hw ID mappings which only need to be emitted once for each buffer, even with the new per-sink trace ID pools.
But in per-thread mode there is only a single buffer which can be written to from any sink with now potentially overlapping trace IDs, so hw ID mappings need to be re-emitted every time the sink changes.
This will require a change in Perf to track this so it knows which decode tree to use for each segment of the buffer. In theory it's also possible to look at the CPU ID on the AUX records, but this is more consistent with the existing system, and allows for correct decode using either mechanism.
--- drivers/hwtracing/coresight/coresight-etm-perf.c | 14 ++++++++++++++ drivers/hwtracing/coresight/coresight-etm-perf.h | 2 ++ 2 files changed, 16 insertions(+)
drivers/hwtracing/coresight/coresight-etm-perf.c +14 -0
@@ -499,6 +499,20 @@ static void etm_event_start(struct perf_event *event, int flags) &sink->perf_id_map)) goto fail_disable_path; +/* +* In per-cpu mode there are multiple aux buffers and each one has a +* fixed sink, so the hw ID mappings which only need to be emitted once +* for each buffer. +* +* But in per-thread mode there is only a single buffer which can be +* written to from any sink with potentially overlapping trace IDs, so +* hw ID mappings need to be re-emitted every time the sink changes. +*/ +if (event->cpu ==-1 && event_data->last_sink_hwid != sink) { +cpumask_clear (&event_data->aux_hwid_done); + event_data->last_sink_hwid = sink; + } +/* * output cpu / trace ID in perf record, once for the lifetime * of the event.
drivers/hwtracing/coresight/coresight-etm-perf.h +2 -0
@@ -52,6 +52,7 @@ struct etm_filters {* @snk_config: The sink configuration. * @cfg_hash: The hash id of any coresight config selected. * @path: An array of path, each slot for one CPU. +* @last_sink_hwid: Last sink that a hwid was emitted for. */ struct etm_event_data {struct work_struct work;
@@ -60,6 +61,7 @@ struct etm_event_data {void *snk_config;u32 cfg_hash;struct list_head *__percpu *path; +struct coresight_device *last_sink_hwid; };int etm_perf_symlink (struct coresight_device *csdev,bool link);
Signature · 1 line
2.34.1
PATCH 17/17 coresight: Emit HW_IDs for all ETMs that are using the sink
In reply to James ClarkFor Perf to be able to decode when per-sink trace IDs are used, emit all the mappings for each sink.
Perf currently errors out if it sees a newer packet version so instead of bumping it, add a new minor version field. This can be used to signify new versions that have backwards compatible fields. Considering this change is only for high core count machines, it doesn't make sense to make a breaking change for everyone.
--- .../hwtracing/coresight/coresight-etm-perf.c | 47 ++++++++++++++++--- include/linux/coresight-pmu.h | 17 +++++-- 2 files changed, 54 insertions(+), 10 deletions(-)
drivers/hwtracing/coresight/coresight-etm-perf.c +41 -6
@@ -444,6 +444,46 @@ static void *etm_setup_aux(struct perf_event *event, void **pages, goto out; } +static void etm_output_hw_ids (struct perf_event *event, +struct coresight_trace_id_map *id_map, +int this_events_cpu) +{ +int cpu; +u8 this_events_trace_id =coresight_trace_id_read_cpu_id (this_events_cpu, id_map); + +/* +* This isn't optimal because we likely only have a couple of IDs +* allocated per-sink, but we only currently track the used trace IDs as +* a bitmask, rather than the used CPUs in each ID map. It would also +* require some extra locking to iterate a used CPUs bitmask and then +* output the ID from a different structure. So at the moment just +* iterate all CPUs. +*/ +for_each_possible_cpu (cpu) { +u64 hw_id; +u8 trace_id =coresight_trace_id_read_cpu_id (cpu, id_map); + +if (!IS_VALID_CS_TRACE_ID (trace_id)) +continue ; + + hw_id =FIELD_PREP (CS_AUX_HW_ID_MAJOR_VERSION_MASK , +CS_AUX_HW_ID_MAJOR_VERSION ); + hw_id |=FIELD_PREP (CS_AUX_HW_ID_MINOR_VERSION_MASK , +CS_AUX_HW_ID_MINOR_VERSION ); + +/* Repeat sending the ID for this event so that it's backwards compatible */ + hw_id |=FIELD_PREP (CS_AUX_HW_ID_TRACE_ID_MASK , this_events_trace_id); + +/* +* Output the V0.1 HW_ID info that shows which other ID mappings +* are valid on this sink. +*/ + hw_id |=FIELD_PREP (CS_AUX_HW_ID_V01_CPU_MASK , cpu); + hw_id |=FIELD_PREP (CS_AUX_HW_ID_V01_TRACE_ID_MASK , trace_id); +perf_report_aux_output_id (event, hw_id); + } +} +static void etm_event_start (struct perf_event *event,int flags) {int cpu =smp_processor_id ();
@@ -452,7 +492,6 @@ static void etm_event_start(struct perf_event *event, int flags)struct perf_output_handle *handle = &ctxt->handle;struct coresight_device *sink, *csdev =per_cpu (csdev_src, cpu);struct list_head *path; -u64 hw_id;if (!csdev) goto fail;
@@ -519,11 +558,7 @@ static void etm_event_start(struct perf_event *event, int flags)*/ if (!cpumask_test_cpu (cpu, &event_data->aux_hwid_done)) {cpumask_set_cpu (cpu, &event_data->aux_hwid_done); - hw_id =FIELD_PREP (CS_AUX_HW_ID_VERSION_MASK , -CS_AUX_HW_ID_CURR_VERSION ); - hw_id |=FIELD_PREP (CS_AUX_HW_ID_TRACE_ID_MASK , -coresight_trace_id_read_cpu_id (cpu, &sink->perf_id_map)); -perf_report_aux_output_id (event, hw_id); +etm_output_hw_ids (event, &sink->perf_id_map, cpu); } out:
include/linux/coresight-pmu.h +13 -4
@@ -49,12 +49,21 @@* Interpretation of the PERF_RECORD_AUX_OUTPUT_HW_ID payload. * Used to associate a CPU with the CoreSight Trace ID. * [07:00] - Trace ID - uses 8 bits to make value easy to read in file. -* [59:08] - Unused (SBZ) -* [63:60] - Version +* [15:08] - V2 Trace ID - ID for the ETM/CPU referenced by V2 CPU +* [31:16] - V2 CPU ID - CPU that corresponds to the trace ID in V2 trace ID +* [55:32] - Unused (SBZ) +* [59:56] - Minor Version - previously existing fields are compatible with +* all minor versions. +* [63:60] - Major Version - previously existing fields mean different things +* in new major versions. */ #define CS_AUX_HW_ID_TRACE_ID_MASK GENMASK_ULL(7, 0) -#define CS_AUX_HW_ID_VERSION_MASK GENMASK_ULL(63, 60) +#define CS_AUX_HW_ID_V01_TRACE_ID_MASK GENMASK_ULL(15, 8) +#define CS_AUX_HW_ID_V01_CPU_MASK GENMASK_ULL(31, 16) +#define CS_AUX_HW_ID_MINOR_VERSION_MASK GENMASK_ULL(59, 56) +#define CS_AUX_HW_ID_MAJOR_VERSION_MASK GENMASK_ULL(63, 60) -#define CS_AUX_HW_ID_CURR_VERSION 0 +#define CS_AUX_HW_ID_MAJOR_VERSION 0 +#define CS_AUX_HW_ID_MINOR_VERSION 1#endif
Signature · 1 line
2.34.1
Re: [PATCH 11/17] coresight: Expose map arugment in trace ID API
In reply to James ClarkQuoted 6 lines · James Clark
...
System ID functions are unchanged because they will always use the default map.
Signed-off-by James Clark <[email protected]>
Ignore this patch, the other 11/17 is the correct one.
Re: [PATCH 02/17] perf auxtrace: Allow number of queues to be specified
In reply to James ClarkQuoted 5 lines · James Clark
Currently it's only possible to initialize with the default number of queues and then use
auxtrace_queues__add_event()to grow the array. But that's problematic if you don't have a real event to pass into that function yet.
Quoted 8 lines
The queues hold a void *priv member to store custom state, and for Coresight we want to create decoders upfront before receiving data, so add a new function that allows pre-allocating queues. One reason to do this is because we might need to store metadata (
HW_IDevents) that effects other queues, but never actually receive auxtrace data on that queue.Signed-off-by James Clark <[email protected]>
Quoted 44 lines
--- tools/perf/util/auxtrace.c | 9 +++++++-- tools/perf/util/auxtrace.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-)tools/perf/util/auxtrace.c +7
-2@@ -218,15 +218,20 @@ static struct auxtrace_queue *auxtrace_alloc_queue_array(unsigned int nr_queues)return queue_array; } -int auxtrace_queues__init (struct auxtrace_queues *queues) +int auxtrace_queues__init_nr (struct auxtrace_queues *queues,int nr_queues) { - queues->nr_queues =AUXTRACE_INIT_NR_QUEUES ; + queues->nr_queues = nr_queues; queues->queue_array =auxtrace_alloc_queue_array (queues->nr_queues);if (!queues->queue_array)return -ENOMEM ;return 0 ; } +int auxtrace_queues__init (struct auxtrace_queues *queues) +{ +return auxtrace_queues__init_nr (queues,AUXTRACE_INIT_NR_QUEUES ); +} +static int auxtrace_queues__grow (struct auxtrace_queues *queues,unsigned int new_nr_queues) {tools/perf/util/auxtrace.h +1
-0@@ -521,6 +521,7 @@ int auxtrace_mmap__read_snapshot(struct mmap *map, struct perf_tool *tool, process_auxtrace_t fn, size_t snapshot_size); +int auxtrace_queues__init_nr (struct auxtrace_queues *queues,int nr_queues);int auxtrace_queues__init (struct auxtrace_queues *queues); int auxtrace_queues__add_event(struct auxtrace_queues *queues, struct perf_session *session,
Re: [PATCH 11/17] coresight: Expose map argument in trace ID API
In reply to James ClarkHi James,
Quoted 130 lines · James Clark
The trace ID API is currently hard coded to always use the global map. The functions that take the map as an argument aren't currently public. Make them public so that Perf mode can pass in its own maps. At the moment all usages are still hard coded to use the global map, but now on the caller side.
System ID functions are unchanged because they will always use the default map.
Signed-off-by James Clark <[email protected]>--- .../hwtracing/coresight/coresight-etm-perf.c | 5 +++-- .../coresight/coresight-etm3x-core.c | 5 +++-- .../coresight/coresight-etm4x-core.c | 5 +++-- .../hwtracing/coresight/coresight-trace-id.c | 22 +++++++------------ .../hwtracing/coresight/coresight-trace-id.h | 9 +++++--- 5 files changed, 23 insertions(+), 23 deletions(-)drivers/hwtracing/coresight/coresight-etm-perf.c +3
-2@@ -232,7 +232,7 @@ static void free_event_data(struct work_struct *work)if (!(IS_ERR_OR_NULL (*ppath)))coresight_release_path (*ppath); *ppath =NULL ; -coresight_trace_id_put_cpu_id (cpu); +coresight_trace_id_put_cpu_id (cpu,coresight_trace_id_map_default ()); }/* mark perf event as done for trace id allocator */ @@ -401,7 +401,8 @@ static void *etm_setup_aux(struct perf_event *event, void **pages, }/* ensure we can allocate a trace ID for this CPU */ - trace_id =coresight_trace_id_get_cpu_id (cpu); + trace_id =coresight_trace_id_get_cpu_id (cpu, +coresight_trace_id_map_default ());if (!IS_VALID_CS_TRACE_ID (trace_id)) {cpumask_clear_cpu (cpu, mask);coresight_release_path (path);drivers/hwtracing/coresight/coresight-etm3x-core.c +3
-2@@ -465,7 +465,8 @@ int etm_read_alloc_trace_id(struct etm_drvdata *drvdata)* * trace id function has its own lock */ - trace_id =coresight_trace_id_get_cpu_id (drvdata->cpu); + trace_id =coresight_trace_id_get_cpu_id (drvdata->cpu, +coresight_trace_id_map_default ());if (IS_VALID_CS_TRACE_ID (trace_id)) drvdata->traceid = (u8 )trace_id;else @@ -477,7 +478,7 @@ int etm_read_alloc_trace_id(struct etm_drvdata *drvdata)void etm_release_trace_id (struct etm_drvdata *drvdata) { -coresight_trace_id_put_cpu_id (drvdata->cpu); +coresight_trace_id_put_cpu_id (drvdata->cpu,coresight_trace_id_map_default ()); } static int etm_enable_perf(struct coresight_device *csdev,drivers/hwtracing/coresight/coresight-etm4x-core.c +3
-2@@ -241,7 +241,8 @@ int etm4_read_alloc_trace_id(struct etmv4_drvdata *drvdata)* or return the one currently allocated. * The trace id function has its own lock */ - trace_id =coresight_trace_id_get_cpu_id (drvdata->cpu); + trace_id =coresight_trace_id_get_cpu_id (drvdata->cpu, +coresight_trace_id_map_default ());if (IS_VALID_CS_TRACE_ID (trace_id)) drvdata->trcid = (u8 )trace_id;else @@ -253,7 +254,7 @@ int etm4_read_alloc_trace_id(struct etmv4_drvdata *drvdata)void etm4_release_trace_id (struct etmv4_drvdata *drvdata) { -coresight_trace_id_put_cpu_id (drvdata->cpu); +coresight_trace_id_put_cpu_id (drvdata->cpu,coresight_trace_id_map_default ()); }struct etm4_enable_arg {drivers/hwtracing/coresight/coresight-trace-id.c +5
-3@@ -12,7 +12,7 @@#include "coresight-trace-id.h" -/* Default trace ID map. Used on systems that don't require per sink mappings */ +/* Default trace ID map. Used in sysfs mode and for system sources */ static struct coresight_trace_id_map id_map_default;/* maintain a record of the mapping of IDs and pending releases per cpu */ @@ -152,7 +152,7 @@ static void coresight_trace_id_release_all_pending(void)DUMP_ID_MAP (id_map); } -static int coresight_trace_id_map_get_cpu_id (int cpu,struct coresight_trace_id_map *id_map) +int coresight_trace_id_get_cpu_id (int cpu,struct coresight_trace_id_map *id_map) {unsigned long flags;int id;@@ -195,8 +195,9 @@ static int coresight_trace_id_map_get_cpu_id(int cpu, struct coresight_trace_id_DUMP_ID_MAP (id_map);return id; } +EXPORT_SYMBOL_GPL (coresight_trace_id_get_cpu_id); -static void coresight_trace_id_map_put_cpu_id (int cpu,struct coresight_trace_id_map *id_map) +void coresight_trace_id_put_cpu_id (int cpu,struct coresight_trace_id_map *id_map) {unsigned long flags;int id;@@ -222,6 +223,7 @@ static void coresight_trace_id_map_put_cpu_id(int cpu, struct coresight_trace_idDUMP_ID_CPU (cpu, id);DUMP_ID_MAP (id_map); } +EXPORT_SYMBOL_GPL (coresight_trace_id_put_cpu_id);static int coresight_trace_id_map_get_system_id (struct coresight_trace_id_map *id_map) {
drivers/hwtracing/coresight/coresight-trace-id.c static void coresight_trace_id_map_put_system_id(struct coresight_trace_id_map * · line 254
Quoted 5 lines
drivers/hwtracing/coresight/coresight-trace-id.c +0
-2@@ -250,19 +252,11 @@ static void coresight_trace_id_map_put_system_id(struct coresight_trace_id_map *DUMP_ID_MAP (id_map); } -/* API functions */ -
Rather than remove the existing default trace ID functions, simply add a few new ones...
e.g. given the existing...
void coresight_trace_id_put_cpu_id(int cpu)
{
coresight_trace_id_map_put_cpu_id(cpu, &id_map_default);
}EXPORT_SYMBOL_GPL(coresight_trace_id_put_cpu_id);
add:-
void coresight_trace_id_put_cpu_id_map(int cpu, struct coresight_trace_id_map *id_map)
{
coresight_trace_id_map_put_cpu_id(cpu, id_map);
}EXPORT_SYMBOL_GPL(coresight_trace_id_put_cpu_id_map);
This avoids a whole lot of churn in exposing the default map to external functions, putting it in there and then removing it later. When any location that was using coresight_trace_id_put_cpu_id() needs to supply its own map, change the function name at that point to coresight_trace_id_put_cpu_id_map()
Mike
Quoted 54 lines
drivers/hwtracing/coresight/coresight-trace-id.c +3
-9-int coresight_trace_id_get_cpu_id (int cpu) -{ -return coresight_trace_id_map_get_cpu_id (cpu, &id_map_default); -} -EXPORT_SYMBOL_GPL (coresight_trace_id_get_cpu_id); - -void coresight_trace_id_put_cpu_id (int cpu) +struct coresight_trace_id_map *coresight_trace_id_map_default (void ) { -coresight_trace_id_map_put_cpu_id (cpu, &id_map_default); +return &id_map_default; } -EXPORT_SYMBOL_GPL (coresight_trace_id_put_cpu_id); +EXPORT_SYMBOL_GPL (coresight_trace_id_map_default);int coresight_trace_id_read_cpu_id (int cpu) {drivers/hwtracing/coresight/coresight-trace-id.h +6
-4@@ -42,7 +42,10 @@#define IS_VALID_CS_TRACE_ID (id) \ ((id > CORESIGHT_TRACE_ID_RES_0) && (id < CORESIGHT_TRACE_ID_RES_TOP)) -/* Allocate and release IDs for a single default trace ID map */ +/** +* Get the global map that's used by sysfs +*/ +struct coresight_trace_id_map *coresight_trace_id_map_default (void );/** * Read and optionally allocate a CoreSight trace ID and associate with a CPU. @@ -57,7 +60,7 @@* * return: CoreSight trace ID or -EINVAL if allocation impossible. */ -int coresight_trace_id_get_cpu_id (int cpu); +int coresight_trace_id_get_cpu_id (int cpu,struct coresight_trace_id_map *id_map);/** * Release an allocated trace ID associated with the CPU. @@ -70,7 +73,7 @@ int coresight_trace_id_get_cpu_id(int cpu);* * @cpu: The CPU index to release the associated trace ID. */ -void coresight_trace_id_put_cpu_id (int cpu); +void coresight_trace_id_put_cpu_id (int cpu,struct coresight_trace_id_map *id_map);/** * Read the current allocated CoreSight Trace ID value for the CPU. -- 2.34.1
Signature · 3 lines
Mike Leach Principal Engineer, ARM Ltd. Manchester Design Centre. UK
Re: [PATCH 08/17] coresight: Remove unused stubs
In reply to James ClarkQuoted 47 lines · James Clark
This file is never included anywhere if
CONFIG_CORESIGHTis not set so they are unused and aren't currently compile tested with any config so remove them.Signed-off-by James Clark <[email protected]>--- .../hwtracing/coresight/coresight-etm-perf.h | 18 ------------------ 1 file changed, 18 deletions(-)drivers/hwtracing/coresight/coresight-etm-perf.h +0
-19@@ -62,7 +62,6 @@ struct etm_event_data {struct list_head *__percpu *path; }; -#if IS_ENABLED (CONFIG_CORESIGHT )int etm_perf_symlink (struct coresight_device *csdev,bool link);int etm_perf_add_symlink_sink (struct coresight_device *csdev);void etm_perf_del_symlink_sink (struct coresight_device *csdev);@@ -77,23 +76,6 @@ static inline void *etm_perf_sink_config(struct perf_output_handle *handle)int etm_perf_add_symlink_cscfg (struct device *dev,struct cscfg_config_desc *config_desc);void etm_perf_del_symlink_cscfg (struct cscfg_config_desc *config_desc); -#else -static inline int etm_perf_symlink (struct coresight_device *csdev,bool link) -{return -EINVAL ; } -int etm_perf_add_symlink_sink (struct coresight_device *csdev) -{return -EINVAL ; } -void etm_perf_del_symlink_sink (struct coresight_device *csdev) {} -static inline void *etm_perf_sink_config (struct perf_output_handle *handle) -{ -return NULL ; -} -int etm_perf_add_symlink_cscfg (struct device *dev, -struct cscfg_config_desc *config_desc) -{return -EINVAL ; } -void etm_perf_del_symlink_cscfg (struct cscfg_config_desc *config_desc) {} - -#endif /* CONFIG_CORESIGHT */ -int __init etm_perf_init (void );void etm_perf_exit (void ); --
Quoted 2 lines
2.34.1
Signature · 3 lines
Mike Leach Principal Engineer, ARM Ltd. Manchester Design Centre. UK
Re: [PATCH 09/17] coresight: Clarify comments around the PID of the sink owner
In reply to James ClarkQuoted 53 lines · James Clark
"Process being monitored" and "pid of the process to monitor" imply that this would be the same PID if there were two sessions targeting the same process. But this is actually the PID of the process that did the Perf event open call, rather than the target of the session. So update the comments to make this clearer.
Signed-off-by James Clark <[email protected]>--- drivers/hwtracing/coresight/coresight-tmc-etr.c | 5 +++-- drivers/hwtracing/coresight/coresight-tmc.h | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-)drivers/hwtracing/coresight/coresight-tmc-etr.c +3
-2@@ -36,7 +36,8 @@ struct etr_buf_hw {* etr_perf_buffer - Perf buffer used for ETR * @drvdata - The ETR drvdaga this buffer has been allocated for. * @etr_buf - Actual buffer used by the ETR -* @pid - The PID this etr_perf_buffer belongs to. +* @pid - The PID of the session owner that etr_perf_buffer +* belongs to. * @snaphost - Perf session mode * @nr_pages - Number of pages in the ring buffer. * @pages - Array of Pages in the ring buffer. @@ -1662,7 +1663,7 @@ static int tmc_enable_etr_sink_perf(struct coresight_device *csdev, void *data) goto unlock_out; } -/* Get a handle on the pid of the process to monitor */ +/* Get a handle on the pid of the session owner */ pid = etr_perf->pid;/* Do not proceed if this device is associated with another session */ drivers/hwtracing/coresight/coresight-tmc.h +3
-3@@ -171,8 +171,9 @@ struct etr_buf {* @csdev: component vitals needed by the framework. * @miscdev: specifics to handle "/dev/xyz.tmc" entry. * @spinlock: only one at a time pls. -* @pid: Process ID of the process being monitored by the session -* that is using this component. +* @pid: Process ID of the process that owns the session that is using +* this component. For example this would be the pid of the Perf +* process. * @buf: Snapshot of the trace data for ETF/ETB. * @etr_buf: details of buffer used in TMC-ETR * @len: size of the available trace for ETF/ETB. --
Quoted 2 lines
2.34.1
Signature · 3 lines
Mike Leach Principal Engineer, ARM Ltd. Manchester Design Centre. UK
Re: [PATCH 10/17] coresight: Move struct coresight_trace_id_map to common header
In reply to James ClarkQuoted 90 lines · James Clark
The trace ID maps will need to be created and stored by the core and Perf code so move the definition up to the common header.
Signed-off-by James Clark <[email protected]>--- .../hwtracing/coresight/coresight-trace-id.c | 1 + .../hwtracing/coresight/coresight-trace-id.h | 19 ------------------- include/linux/coresight.h | 18 ++++++++++++++++++ 3 files changed, 19 insertions(+), 19 deletions(-)drivers/hwtracing/coresight/coresight-trace-id.c +1
-0@@ -3,6 +3,7 @@* Copyright (c) 2022, Linaro Limited, All rights reserved. * Author: Mike Leach <[email protected]> */ +#include <linux/coresight.h> #include <linux/coresight-pmu.h> #include <linux/cpumask.h> #include <linux/kernel.h> drivers/hwtracing/coresight/coresight-trace-id.h +0
-19@@ -32,10 +32,6 @@#include <linux/bitops.h> #include <linux/types.h> - -/* architecturally we have 128 IDs some of which are reserved */ -#define CORESIGHT_TRACE_IDS_MAX 128 -/* ID 0 is reserved */ #define CORESIGHT_TRACE_ID_RES_0 0@@ -46,21 +42,6 @@#define IS_VALID_CS_TRACE_ID (id) \ ((id > CORESIGHT_TRACE_ID_RES_0) && (id < CORESIGHT_TRACE_ID_RES_TOP)) -/** -* Trace ID map. -* -* @used_ids: Bitmap to register available (bit = 0) and in use (bit = 1) IDs. -* Initialised so that the reserved IDs are permanently marked as -* in use. -* @pend_rel_ids: CPU IDs that have been released by the trace source but not -* yet marked as available, to allow re-allocation to the same -* CPU during a perf session. -*/ -struct coresight_trace_id_map { - DECLARE_BITMAP(used_ids, CORESIGHT_TRACE_IDS_MAX); - DECLARE_BITMAP(pend_rel_ids, CORESIGHT_TRACE_IDS_MAX); -}; -/* Allocate and release IDs for a single default trace ID map */ /** include/linux/coresight.h +18
-1@@ -218,6 +218,24 @@ struct coresight_sysfs_link {const char *target_name; }; +/* architecturally we have 128 IDs some of which are reserved */ +#define CORESIGHT_TRACE_IDS_MAX 128 + +/** +* Trace ID map. +* +* @used_ids: Bitmap to register available (bit = 0) and in use (bit = 1) IDs. +* Initialised so that the reserved IDs are permanently marked as +* in use. +* @pend_rel_ids: CPU IDs that have been released by the trace source but not +* yet marked as available, to allow re-allocation to the same +* CPU during a perf session. +*/ +struct coresight_trace_id_map { + DECLARE_BITMAP(used_ids, CORESIGHT_TRACE_IDS_MAX); + DECLARE_BITMAP(pend_rel_ids, CORESIGHT_TRACE_IDS_MAX); +}; +/** * struct coresight_device - representation of a device as used by the framework * @pdata: Platform data with device connections associated to this device. --
Quoted 2 lines
2.34.1
Signature · 3 lines
Mike Leach Principal Engineer, ARM Ltd. Manchester Design Centre. UK
Hi James
Quoted 113 lines · James Clark
This will allow sessions with more than
CORESIGHT_TRACE_IDS_MAXETMs as long as there are fewer than that many ETMs connected to each sink.Each sink owns its own trace ID map, and any Perf session connecting to that sink will allocate from it, even if the sink is currently in use by other users. This is similar to the existing behavior where the dynamic trace IDs are constant as long as there is any concurrent Perf session active. It's not completely optimal because slightly more IDs will be used than necessary, but the optimal solution involves tracking the PIDs of each session and allocating ID maps based on the session owner. This is difficult to do with the combination of per-thread and per-cpu modes and some scheduling issues. The complexity of this isn't likely to worth it because even with multiple users they'd just see a difference in the ordering of ID allocations rather than hitting any limits (unless the hardware does have too many ETMs connected to one sink).
Signed-off-by James Clark <[email protected]>--- drivers/hwtracing/coresight/coresight-core.c | 10 ++++++++++ drivers/hwtracing/coresight/coresight-etm-perf.c | 15 ++++++++------- include/linux/coresight.h | 1 + 3 files changed, 19 insertions(+), 7 deletions(-)drivers/hwtracing/coresight/coresight-core.c +10
-0@@ -902,6 +902,7 @@ static void coresight_device_release(struct device *dev)struct coresight_device *csdev =to_coresight_device (dev);fwnode_handle_put (csdev->dev.fwnode); +free_percpu (csdev->perf_id_map.cpu_map);kfree (csdev); }@@ -1159,6 +1160,14 @@ struct coresight_device *coresight_register(struct coresight_desc *desc) csdev->dev.fwnode =fwnode_handle_get (dev_fwnode (desc->dev));dev_set_name (&csdev->dev,"%s" , desc->name); +if (csdev->type ==CORESIGHT_DEV_TYPE_SINK || + csdev->type ==CORESIGHT_DEV_TYPE_LINKSINK ) { + csdev->perf_id_map.cpu_map =alloc_percpu (atomic_t); +if (!csdev->perf_id_map.cpu_map) { + ret = -ENOMEM ; + goto err_out; + } + }/* * Make sure the device registration and the connection fixup * are synchronised, so that we don't see uninitialised devices @@ -1216,6 +1225,7 @@ struct coresight_device *coresight_register(struct coresight_desc *desc) err_out:/* Cleanup the connection information */ coresight_release_platform_data (NULL , desc->dev, desc->pdata); +kfree (csdev);return ERR_PTR (ret); }EXPORT_SYMBOL_GPL (coresight_register);drivers/hwtracing/coresight/coresight-etm-perf.c +8
-7@@ -229,10 +229,13 @@ static void free_event_data(struct work_struct *work)struct list_head **ppath; ppath =etm_event_cpu_path_ptr (event_data, cpu); -if (!(IS_ERR_OR_NULL (*ppath))) +if (!(IS_ERR_OR_NULL (*ppath))) { +struct coresight_device *sink =coresight_get_sink (*ppath); + +coresight_trace_id_put_cpu_id (cpu, &sink->perf_id_map);coresight_release_path (*ppath); + } *ppath =NULL ; -coresight_trace_id_put_cpu_id (cpu,coresight_trace_id_map_default ()); }/* mark perf event as done for trace id allocator */ @@ -401,8 +404,7 @@ static void *etm_setup_aux(struct perf_event *event, void **pages, }/* ensure we can allocate a trace ID for this CPU */ - trace_id =coresight_trace_id_get_cpu_id (cpu, -coresight_trace_id_map_default ()); + trace_id =coresight_trace_id_get_cpu_id (cpu, &sink->perf_id_map);if (!IS_VALID_CS_TRACE_ID (trace_id)) {cpumask_clear_cpu (cpu, mask);coresight_release_path (path);@@ -497,7 +499,7 @@ static void etm_event_start(struct perf_event *event, int flags)/* Finally enable the tracer */ if (source_ops (csdev)->enable (csdev, event,CS_MODE_PERF , -coresight_trace_id_map_default ())) + &sink->perf_id_map)) goto fail_disable_path;/* @@ -509,8 +511,7 @@ static void etm_event_start(struct perf_event *event, int flags) hw_id =FIELD_PREP (CS_AUX_HW_ID_VERSION_MASK ,CS_AUX_HW_ID_CURR_VERSION ); hw_id |=FIELD_PREP (CS_AUX_HW_ID_TRACE_ID_MASK , -coresight_trace_id_read_cpu_id (cpu, -coresight_trace_id_map_default ())); +coresight_trace_id_read_cpu_id (cpu, &sink->perf_id_map));perf_report_aux_output_id (event, hw_id); }include/linux/coresight.h +0
-0
include/linux/coresight.h struct coresight_device { · line 293
Quoted 4 lines
include/linux/coresight.h +1
-0@@ -290,6 +290,7 @@ struct coresight_device {bool sysfs_sink_activated;struct dev_ext_attribute *ea;struct coresight_device *def_sink; +struct coresight_trace_id_map perf_id_map;
perhaps this should be sink_id_map? At some point sysfs may use is and naming is sink... is more consistent with other sink attributes in the structure.
Quoted 6 lines
include/linux/coresight.h +0
-1/* sysfs links between components */ int nr_links;bool has_conns_grp; --2.34.1
Mike
Signature · 3 lines
Mike Leach Principal Engineer, ARM Ltd. Manchester Design Centre. UK
Hi James
Quoted 22 lines · James Clark
This will allow sessions with more than
CORESIGHT_TRACE_IDS_MAXETMs as long as there are fewer than that many ETMs connected to each sink.Each sink owns its own trace ID map, and any Perf session connecting to that sink will allocate from it, even if the sink is currently in use by other users. This is similar to the existing behavior where the dynamic trace IDs are constant as long as there is any concurrent Perf session active. It's not completely optimal because slightly more IDs will be used than necessary, but the optimal solution involves tracking the PIDs of each session and allocating ID maps based on the session owner. This is difficult to do with the combination of per-thread and per-cpu modes and some scheduling issues. The complexity of this isn't likely to worth it because even with multiple users they'd just see a difference in the ordering of ID allocations rather than hitting any limits (unless the hardware does have too many ETMs connected to one sink).
Per-thread mode works but only until there are any overlapping IDs, at which point Perf will error out. Both per-thread mode and sysfs mode are left to future changes, but both can be added on top of this initial implementation and only sysfs mode requires further driver changes.
Quoted 5 lines
The
HW_IDversion field hasn't been bumped in order to not break Perf which already has an error condition for other values of that field. Instead a new minor version has been added which signifies that there are new fields but the old fields are backwards compatible.
Looking at this overall - would it not be better to introduce the concept of a "sink ID" to allow the detection of multiple sources into the single sink that is now done by emitting multiple AUX_HWID packets with the CPU+ID extra data?
This sink ID could be part of the sink csdev struct - or even the id_map struct - a simple count of sinks as the per sink maps are created would be sufficient. If this sink ID replaced the CPU+ID extra data in the HWID packets, then each packet could be emitted just once, and perf can then collate based on the sink id.
Moreover, once we are ready to address the per-thread issues - then the overlap would not matter. Generate OpenCSD decode trees per sink ID, add docoders to the tree per Trace ID. Thus if a buffer has data from sink 1 trace id 5, ans sink 2, trace ID 5, then pick the right decoder for the combo.
Finally in systems with ETE+TRBE were there is no use of trace IDs, a sink ID of 0x0 could potentially indicate that 1:1 relationship.
Regards
Mike
Quoted 46 lines
James Clark (17):
perf cs-etm: Print error for newPERF_RECORD_AUX_OUTPUT_HW_IDversions perf auxtrace: Allow number of queues to be specified
perf: cs-etm: Create decoders after both AUX andHW_IDsearch passes
perf: cs-etm: Allocate queues for all CPUs
perf: cs-etm: Movetraceid_listto each queue
perf: cs-etm: Create decoders based on the trace ID mappings
perf: cs-etm: Support version 0.1 ofHW_IDpackets
coresight: Remove unused stubs
coresight: Clarify comments around the PID of the sink owner
coresight: Move structcoresight_trace_id_mapto common header
coresight: Expose map argument in trace ID API
coresight: Make CPU id map a property of a trace ID map
coresight: Pass trace ID map into source enable
coresight: Use per-sink trace ID maps for Perf sessions
coresight: Remove pending trace ID release mechanism
coresight: Re-emit trace IDs when the sink changes in per-thread mode
coresight: EmitHW_IDsfor all ETMs that are using the sinkdrivers/hwtracing/coresight/coresight-core.c | 10 + drivers/hwtracing/coresight/coresight-dummy.c | 3 +- .../hwtracing/coresight/coresight-etm-perf.c | 82 ++- .../hwtracing/coresight/coresight-etm-perf.h | 20 +- .../coresight/coresight-etm3x-core.c | 14 +- .../coresight/coresight-etm4x-core.c | 14 +- drivers/hwtracing/coresight/coresight-stm.c | 3 +- drivers/hwtracing/coresight/coresight-sysfs.c | 3 +- .../hwtracing/coresight/coresight-tmc-etr.c | 5 +- drivers/hwtracing/coresight/coresight-tmc.h | 5 +- drivers/hwtracing/coresight/coresight-tpdm.c | 3 +- .../hwtracing/coresight/coresight-trace-id.c | 107 +-- .../hwtracing/coresight/coresight-trace-id.h | 57 +- include/linux/coresight-pmu.h | 17 +- include/linux/coresight.h | 20 +- tools/include/linux/coresight-pmu.h | 17 +- tools/perf/util/auxtrace.c | 9 +- tools/perf/util/auxtrace.h | 1 + .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 28 +- tools/perf/util/cs-etm.c | 617 ++++++++++++------ tools/perf/util/cs-etm.h | 2 +- 21 files changed, 633 insertions(+), 404 deletions(-)--
2.34.1
Signature · 3 lines
Mike Leach Principal Engineer, ARM Ltd. Manchester Design Centre. UK
Quoted 111 lines · Mike Leach
Hi James
Quoted 108 lines · James Clark
This will allow sessions with more than
CORESIGHT_TRACE_IDS_MAXETMs as long as there are fewer than that many ETMs connected to each sink.Each sink owns its own trace ID map, and any Perf session connecting to that sink will allocate from it, even if the sink is currently in use by other users. This is similar to the existing behavior where the dynamic trace IDs are constant as long as there is any concurrent Perf session active. It's not completely optimal because slightly more IDs will be used than necessary, but the optimal solution involves tracking the PIDs of each session and allocating ID maps based on the session owner. This is difficult to do with the combination of per-thread and per-cpu modes and some scheduling issues. The complexity of this isn't likely to worth it because even with multiple users they'd just see a difference in the ordering of ID allocations rather than hitting any limits (unless the hardware does have too many ETMs connected to one sink).
Signed-off-by James Clark <[email protected]>--- drivers/hwtracing/coresight/coresight-core.c | 10 ++++++++++ drivers/hwtracing/coresight/coresight-etm-perf.c | 15 ++++++++------- include/linux/coresight.h | 1 + 3 files changed, 19 insertions(+), 7 deletions(-)drivers/hwtracing/coresight/coresight-core.c +10
-0@@ -902,6 +902,7 @@ static void coresight_device_release(struct device *dev)struct coresight_device *csdev =to_coresight_device (dev);fwnode_handle_put (csdev->dev.fwnode); +free_percpu (csdev->perf_id_map.cpu_map);kfree (csdev); }@@ -1159,6 +1160,14 @@ struct coresight_device *coresight_register(struct coresight_desc *desc) csdev->dev.fwnode =fwnode_handle_get (dev_fwnode (desc->dev));dev_set_name (&csdev->dev,"%s" , desc->name); +if (csdev->type ==CORESIGHT_DEV_TYPE_SINK || + csdev->type ==CORESIGHT_DEV_TYPE_LINKSINK ) { + csdev->perf_id_map.cpu_map =alloc_percpu (atomic_t); +if (!csdev->perf_id_map.cpu_map) { + ret = -ENOMEM ; + goto err_out; + } + }/* * Make sure the device registration and the connection fixup * are synchronised, so that we don't see uninitialised devices @@ -1216,6 +1225,7 @@ struct coresight_device *coresight_register(struct coresight_desc *desc) err_out:/* Cleanup the connection information */ coresight_release_platform_data (NULL , desc->dev, desc->pdata); +kfree (csdev);return ERR_PTR (ret); }EXPORT_SYMBOL_GPL (coresight_register);drivers/hwtracing/coresight/coresight-etm-perf.c +8
-7@@ -229,10 +229,13 @@ static void free_event_data(struct work_struct *work)struct list_head **ppath; ppath =etm_event_cpu_path_ptr (event_data, cpu); -if (!(IS_ERR_OR_NULL (*ppath))) +if (!(IS_ERR_OR_NULL (*ppath))) { +struct coresight_device *sink =coresight_get_sink (*ppath); + +coresight_trace_id_put_cpu_id (cpu, &sink->perf_id_map);coresight_release_path (*ppath); + } *ppath =NULL ; -coresight_trace_id_put_cpu_id (cpu,coresight_trace_id_map_default ()); }/* mark perf event as done for trace id allocator */ @@ -401,8 +404,7 @@ static void *etm_setup_aux(struct perf_event *event, void **pages, }/* ensure we can allocate a trace ID for this CPU */ - trace_id =coresight_trace_id_get_cpu_id (cpu, -coresight_trace_id_map_default ()); + trace_id =coresight_trace_id_get_cpu_id (cpu, &sink->perf_id_map);if (!IS_VALID_CS_TRACE_ID (trace_id)) {cpumask_clear_cpu (cpu, mask);coresight_release_path (path);@@ -497,7 +499,7 @@ static void etm_event_start(struct perf_event *event, int flags)/* Finally enable the tracer */ if (source_ops (csdev)->enable (csdev, event,CS_MODE_PERF , -coresight_trace_id_map_default ())) + &sink->perf_id_map)) goto fail_disable_path;/* @@ -509,8 +511,7 @@ static void etm_event_start(struct perf_event *event, int flags) hw_id =FIELD_PREP (CS_AUX_HW_ID_VERSION_MASK ,CS_AUX_HW_ID_CURR_VERSION ); hw_id |=FIELD_PREP (CS_AUX_HW_ID_TRACE_ID_MASK , -coresight_trace_id_read_cpu_id (cpu, -coresight_trace_id_map_default ())); +coresight_trace_id_read_cpu_id (cpu, &sink->perf_id_map));perf_report_aux_output_id (event, hw_id); }
Quoted 14 lines
include/linux/coresight.h struct coresight_device { · line 293
Quoted 9 lines
include/linux/coresight.h +1
-0@@ -290,6 +290,7 @@ struct coresight_device {bool sysfs_sink_activated;struct dev_ext_attribute *ea;struct coresight_device *def_sink; +struct coresight_trace_id_map perf_id_map;perhaps this should be
sink_id_map? At some point sysfs may use is and naming is sink... is more consistent with other sink attributes in the structure.
When we implement this for sysfs I was thinking sysfs would use its own per-sink map. One reason is that the global map might be used if the sink is in use by a system source (which allocate their IDs on probe). Resulting in something like this:
struct coresight_trace_id_map perf_id_map; struct coresight_trace_id_map sysfs_id_map; struct coresight_trace_id_map *sysfs_id_map_in_use;
syfs_id_map_in_use could either be &sysfs_id_map or coresight_trace_id_map_default()
If sysfs did share the same map as Perf, the sink would have to have some kind of mechanism of saving and restoring the mappings depending on who was currently using the sink. At that point just storing two versions of the mappings is easier. I believe there are some scenarios for concurrent sysfs and Perf sessions that don't fail immediately, but that one will get -EBUSY when trying to use the sink, until the other session ends, at which point the other mappings need to be ready to use immediately.
Also sysfs might either use the per-sink map or the global map depending on the ordering of when the IDs were allocated or if a system source is used at the same time, which means sysfs needs to use a reference to a map.
We could also change system sources so that they only allocate IDs when the ID is read, rather than on probe. That might remove some of the above issues, but maybe not all of them because you can always read the ID before enabling the sink, at which point you have no choice but to use the global map.
Quoted 9 lines
Quoted 6 lines
include/linux/coresight.h +0
-1/* sysfs links between components */ int nr_links;bool has_conns_grp; --2.34.1
Mike
Arnaldo Carvalho de Melo
maintainerQuoted 21 lines · James Clark
This will allow sessions with more than
CORESIGHT_TRACE_IDS_MAXETMs as long as there are fewer than that many ETMs connected to each sink.Each sink owns its own trace ID map, and any Perf session connecting to that sink will allocate from it, even if the sink is currently in use by other users. This is similar to the existing behavior where the dynamic trace IDs are constant as long as there is any concurrent Perf session active. It's not completely optimal because slightly more IDs will be used than necessary, but the optimal solution involves tracking the PIDs of each session and allocating ID maps based on the session owner. This is difficult to do with the combination of per-thread and per-cpu modes and some scheduling issues. The complexity of this isn't likely to worth it because even with multiple users they'd just see a difference in the ordering of ID allocations rather than hitting any limits (unless the hardware does have too many ETMs connected to one sink).
Per-thread mode works but only until there are any overlapping IDs, at which point Perf will error out. Both per-thread mode and sysfs mode are left to future changes, but both can be added on top of this initial implementation and only sysfs mode requires further driver changes.
Quoted 4 lines
The
HW_IDversion field hasn't been bumped in order to not break Perf which already has an error condition for other values of that field. Instead a new minor version has been added which signifies that there are new fields but the old fields are backwards compatible.
I guess I can pick the tooling part now, right? Further reviewing would be nice tho.
- Arnaldo
Re: [PATCH 01/17] perf cs-etm: Print error for new PERF_RECORD_AUX_OUTPUT_HW_ID versions
In reply to James ClarkQuoted 12 lines · James Clark
The likely fix for this is to update Perf so print a helpful message.
Signed-off-by James Clark <[email protected]>--- tools/perf/util/cs-etm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)tools/perf/util/cs-etm.c +0
-0
tools/perf/util/cs-etm.c static int cs_etm__process_aux_output_hw_id(struct perf_session *session, · line 339
Quoted 6 lines
tools/perf/util/cs-etm.c +2
-1@@ -335,8 +335,11 @@ static int cs_etm__process_aux_output_hw_id(struct perf_session *session, trace_chan_id =FIELD_GET (CS_AUX_HW_ID_TRACE_ID_MASK , hw_id);/* check that we can handle this version */ -if (version >CS_AUX_HW_ID_CURR_VERSION ) +if (version >CS_AUX_HW_ID_CURR_VERSION ) { + pr_err("CS ETM Trace: PERF_RECORD_AUX_OUTPUT_HW_ID version %d not supported. Please update Perf.\n",
Is not this bit misleading ? PERF_RECORD_AUX_OUTPUT_HW_ID is just the perf record format identifier. The record version here, is derived from the platform specific hardware ID information embedded in this perf record.
Should not this be just s/PERF_RECORD_AUX_OUTPUT_HW_ID/hardware ID/ instead ?
Quoted 6 lines
tools/perf/util/cs-etm.c +2
-0+ version);return -EINVAL ; + }/* get access to the etm metadata */ etm = container_of(session->auxtrace, struct cs_etm_auxtrace, auxtrace);
Re: [PATCH 08/17] coresight: Remove unused stubs
In reply to James ClarkMinor nit: Should the subject line be "coresight: Remove unused etm perf stubs" ?
Quoted 3 lines · James Clark
This file is never included anywhere if
CONFIG_CORESIGHTis not set so they are unused and aren't currently compile tested with any config so remove them.
Searching for this header's inclusion throws up the following source files, all of which needs CONFIG_CORESIGHT to be enabled to be compiled.
git grep "coresight-etm-perf.h"
drivers/hwtracing/coresight/coresight-core.c:#include "coresight-etm-perf.h" drivers/hwtracing/coresight/coresight-etb10.c:#include "coresight-etm-perf.h" drivers/hwtracing/coresight/coresight-etm-perf.c:#include "coresight-etm-perf.h" drivers/hwtracing/coresight/coresight-etm3x-core.c:#include "coresight-etm-perf.h" drivers/hwtracing/coresight/coresight-etm4x-core.c:#include "coresight-etm-perf.h" drivers/hwtracing/coresight/coresight-syscfg.c:#include "coresight-etm-perf.h" drivers/hwtracing/coresight/coresight-tmc-etf.c:#include "coresight-etm-perf.h" drivers/hwtracing/coresight/coresight-tmc-etr.c:#include "coresight-etm-perf.h" drivers/hwtracing/coresight/coresight-trbe.h:#include "coresight-etm-perf.h" drivers/hwtracing/coresight/ultrasoc-smb.c:#include "coresight-etm-perf.h"
Quoted 2 lines
Signed-off-by James Clark <[email protected]>
LGTM, with or without the subject line change.
Quoted 40 lines
--- .../hwtracing/coresight/coresight-etm-perf.h | 18 ------------------ 1 file changed, 18 deletions(-)drivers/hwtracing/coresight/coresight-etm-perf.h +0
-18@@ -62,7 +62,6 @@ struct etm_event_data {struct list_head *__percpu *path; }; -#if IS_ENABLED (CONFIG_CORESIGHT )int etm_perf_symlink (struct coresight_device *csdev,bool link);int etm_perf_add_symlink_sink (struct coresight_device *csdev);void etm_perf_del_symlink_sink (struct coresight_device *csdev);@@ -77,23 +76,6 @@ static inline void *etm_perf_sink_config(struct perf_output_handle *handle)int etm_perf_add_symlink_cscfg (struct device *dev,struct cscfg_config_desc *config_desc);void etm_perf_del_symlink_cscfg (struct cscfg_config_desc *config_desc); -#else -static inline int etm_perf_symlink (struct coresight_device *csdev,bool link) -{return -EINVAL ; } -int etm_perf_add_symlink_sink (struct coresight_device *csdev) -{return -EINVAL ; } -void etm_perf_del_symlink_sink (struct coresight_device *csdev) {} -static inline void *etm_perf_sink_config (struct perf_output_handle *handle) -{ -return NULL ; -} -int etm_perf_add_symlink_cscfg (struct device *dev, -struct cscfg_config_desc *config_desc) -{return -EINVAL ; } -void etm_perf_del_symlink_cscfg (struct cscfg_config_desc *config_desc) {} - -#endif /* CONFIG_CORESIGHT */ -int __init etm_perf_init (void );void etm_perf_exit (void );
Re: [PATCH 09/17] coresight: Clarify comments around the PID of the sink owner
In reply to James ClarkQuoted 7 lines · James Clark
"Process being monitored" and "pid of the process to monitor" imply that this would be the same PID if there were two sessions targeting the same process. But this is actually the PID of the process that did the Perf event open call, rather than the target of the session. So update the comments to make this clearer.
Signed-off-by James Clark <[email protected]>
This indeed removes the ambiguity that the PID belongs to the perf session owner rather than the monitored or target process.
Quoted 44 lines
--- drivers/hwtracing/coresight/coresight-tmc-etr.c | 5 +++-- drivers/hwtracing/coresight/coresight-tmc.h | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-)drivers/hwtracing/coresight/coresight-tmc-etr.c +3
-2@@ -36,7 +36,8 @@ struct etr_buf_hw {* etr_perf_buffer - Perf buffer used for ETR * @drvdata - The ETR drvdaga this buffer has been allocated for. * @etr_buf - Actual buffer used by the ETR -* @pid - The PID this etr_perf_buffer belongs to. +* @pid - The PID of the session owner that etr_perf_buffer +* belongs to. * @snaphost - Perf session mode * @nr_pages - Number of pages in the ring buffer. * @pages - Array of Pages in the ring buffer. @@ -1662,7 +1663,7 @@ static int tmc_enable_etr_sink_perf(struct coresight_device *csdev, void *data) goto unlock_out; } -/* Get a handle on the pid of the process to monitor */ +/* Get a handle on the pid of the session owner */ pid = etr_perf->pid;/* Do not proceed if this device is associated with another session */ drivers/hwtracing/coresight/coresight-tmc.h +3
-2@@ -171,8 +171,9 @@ struct etr_buf {* @csdev: component vitals needed by the framework. * @miscdev: specifics to handle "/dev/xyz.tmc" entry. * @spinlock: only one at a time pls. -* @pid: Process ID of the process being monitored by the session -* that is using this component. +* @pid: Process ID of the process that owns the session that is using +* this component. For example this would be the pid of the Perf +* process. * @buf: Snapshot of the trace data for ETF/ETB. * @etr_buf: details of buffer used in TMC-ETR * @len: size of the available trace for ETF/ETB.
Re: [PATCH 02/17] perf auxtrace: Allow number of queues to be specified
In reply to James ClarkQuoted 5 lines · James Clark
Currently it's only possible to initialize with the default number of queues and then use
auxtrace_queues__add_event()to grow the array. But that's problematic if you don't have a real event to pass into that function yet.
Quoted 8 lines
The queues hold a void *priv member to store custom state, and for Coresight we want to create decoders upfront before receiving data, so add a new function that allows pre-allocating queues. One reason to do this is because we might need to store metadata (
HW_IDevents) that effects other queues, but never actually receive auxtrace data on that queue.Signed-off-by James Clark <[email protected]>
LGTM
Quoted 44 lines
--- tools/perf/util/auxtrace.c | 9 +++++++-- tools/perf/util/auxtrace.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-)tools/perf/util/auxtrace.c +7
-2@@ -218,15 +218,20 @@ static struct auxtrace_queue *auxtrace_alloc_queue_array(unsigned int nr_queues)return queue_array; } -int auxtrace_queues__init (struct auxtrace_queues *queues) +int auxtrace_queues__init_nr (struct auxtrace_queues *queues,int nr_queues) { - queues->nr_queues =AUXTRACE_INIT_NR_QUEUES ; + queues->nr_queues = nr_queues; queues->queue_array =auxtrace_alloc_queue_array (queues->nr_queues);if (!queues->queue_array)return -ENOMEM ;return 0 ; } +int auxtrace_queues__init (struct auxtrace_queues *queues) +{ +return auxtrace_queues__init_nr (queues,AUXTRACE_INIT_NR_QUEUES ); +} +static int auxtrace_queues__grow (struct auxtrace_queues *queues,unsigned int new_nr_queues) {tools/perf/util/auxtrace.h +1
-0@@ -521,6 +521,7 @@ int auxtrace_mmap__read_snapshot(struct mmap *map, struct perf_tool *tool, process_auxtrace_t fn, size_t snapshot_size); +int auxtrace_queues__init_nr (struct auxtrace_queues *queues,int nr_queues);int auxtrace_queues__init (struct auxtrace_queues *queues); int auxtrace_queues__add_event(struct auxtrace_queues *queues, struct perf_session *session,
Re: [PATCH 10/17] coresight: Move struct coresight_trace_id_map to common header
In reply to James ClarkQuoted 4 lines · James Clark
The trace ID maps will need to be created and stored by the core and Perf code so move the definition up to the common header.
Signed-off-by James Clark <[email protected]>
Quoted 84 lines
--- .../hwtracing/coresight/coresight-trace-id.c | 1 + .../hwtracing/coresight/coresight-trace-id.h | 19 ------------------- include/linux/coresight.h | 18 ++++++++++++++++++ 3 files changed, 19 insertions(+), 19 deletions(-)drivers/hwtracing/coresight/coresight-trace-id.c +1
-0@@ -3,6 +3,7 @@* Copyright (c) 2022, Linaro Limited, All rights reserved. * Author: Mike Leach <[email protected]> */ +#include <linux/coresight.h> #include <linux/coresight-pmu.h> #include <linux/cpumask.h> #include <linux/kernel.h> drivers/hwtracing/coresight/coresight-trace-id.h +0
-19@@ -32,10 +32,6 @@#include <linux/bitops.h> #include <linux/types.h> - -/* architecturally we have 128 IDs some of which are reserved */ -#define CORESIGHT_TRACE_IDS_MAX 128 -/* ID 0 is reserved */ #define CORESIGHT_TRACE_ID_RES_0 0@@ -46,21 +42,6 @@#define IS_VALID_CS_TRACE_ID (id) \ ((id > CORESIGHT_TRACE_ID_RES_0) && (id < CORESIGHT_TRACE_ID_RES_TOP)) -/** -* Trace ID map. -* -* @used_ids: Bitmap to register available (bit = 0) and in use (bit = 1) IDs. -* Initialised so that the reserved IDs are permanently marked as -* in use. -* @pend_rel_ids: CPU IDs that have been released by the trace source but not -* yet marked as available, to allow re-allocation to the same -* CPU during a perf session. -*/ -struct coresight_trace_id_map { - DECLARE_BITMAP(used_ids, CORESIGHT_TRACE_IDS_MAX); - DECLARE_BITMAP(pend_rel_ids, CORESIGHT_TRACE_IDS_MAX); -}; -/* Allocate and release IDs for a single default trace ID map */ /** include/linux/coresight.h +18
-0@@ -218,6 +218,24 @@ struct coresight_sysfs_link {const char *target_name; }; +/* architecturally we have 128 IDs some of which are reserved */ +#define CORESIGHT_TRACE_IDS_MAX 128 + +/** +* Trace ID map. +* +* @used_ids: Bitmap to register available (bit = 0) and in use (bit = 1) IDs. +* Initialised so that the reserved IDs are permanently marked as +* in use. +* @pend_rel_ids: CPU IDs that have been released by the trace source but not +* yet marked as available, to allow re-allocation to the same +* CPU during a perf session. +*/ +struct coresight_trace_id_map { + DECLARE_BITMAP(used_ids, CORESIGHT_TRACE_IDS_MAX); + DECLARE_BITMAP(pend_rel_ids, CORESIGHT_TRACE_IDS_MAX); +}; +/** * struct coresight_device - representation of a device as used by the framework * @pdata: Platform data with device connections associated to this device.
Re: [PATCH 11/17] coresight: Expose map argument in trace ID API
In reply to James ClarkQuoted 10 lines · James Clark
The trace ID API is currently hard coded to always use the global map. The functions that take the map as an argument aren't currently public. Make them public so that Perf mode can pass in its own maps. At the moment all usages are still hard coded to use the global map, but now on the caller side.
System ID functions are unchanged because they will always use the default map.
Signed-off-by James Clark <[email protected]>
Quoted 175 lines
--- .../hwtracing/coresight/coresight-etm-perf.c | 5 +++-- .../coresight/coresight-etm3x-core.c | 5 +++-- .../coresight/coresight-etm4x-core.c | 5 +++-- .../hwtracing/coresight/coresight-trace-id.c | 22 +++++++------------ .../hwtracing/coresight/coresight-trace-id.h | 9 +++++--- 5 files changed, 23 insertions(+), 23 deletions(-)drivers/hwtracing/coresight/coresight-etm-perf.c +3
-2@@ -232,7 +232,7 @@ static void free_event_data(struct work_struct *work)if (!(IS_ERR_OR_NULL (*ppath)))coresight_release_path (*ppath); *ppath =NULL ; -coresight_trace_id_put_cpu_id (cpu); +coresight_trace_id_put_cpu_id (cpu,coresight_trace_id_map_default ()); }/* mark perf event as done for trace id allocator */ @@ -401,7 +401,8 @@ static void *etm_setup_aux(struct perf_event *event, void **pages, }/* ensure we can allocate a trace ID for this CPU */ - trace_id =coresight_trace_id_get_cpu_id (cpu); + trace_id =coresight_trace_id_get_cpu_id (cpu, +coresight_trace_id_map_default ());if (!IS_VALID_CS_TRACE_ID (trace_id)) {cpumask_clear_cpu (cpu, mask);coresight_release_path (path);drivers/hwtracing/coresight/coresight-etm3x-core.c +3
-2@@ -465,7 +465,8 @@ int etm_read_alloc_trace_id(struct etm_drvdata *drvdata)* * trace id function has its own lock */ - trace_id =coresight_trace_id_get_cpu_id (drvdata->cpu); + trace_id =coresight_trace_id_get_cpu_id (drvdata->cpu, +coresight_trace_id_map_default ());if (IS_VALID_CS_TRACE_ID (trace_id)) drvdata->traceid = (u8 )trace_id;else @@ -477,7 +478,7 @@ int etm_read_alloc_trace_id(struct etm_drvdata *drvdata)void etm_release_trace_id (struct etm_drvdata *drvdata) { -coresight_trace_id_put_cpu_id (drvdata->cpu); +coresight_trace_id_put_cpu_id (drvdata->cpu,coresight_trace_id_map_default ()); } static int etm_enable_perf(struct coresight_device *csdev,drivers/hwtracing/coresight/coresight-etm4x-core.c +3
-2@@ -241,7 +241,8 @@ int etm4_read_alloc_trace_id(struct etmv4_drvdata *drvdata)* or return the one currently allocated. * The trace id function has its own lock */ - trace_id =coresight_trace_id_get_cpu_id (drvdata->cpu); + trace_id =coresight_trace_id_get_cpu_id (drvdata->cpu, +coresight_trace_id_map_default ());if (IS_VALID_CS_TRACE_ID (trace_id)) drvdata->trcid = (u8 )trace_id;else @@ -253,7 +254,7 @@ int etm4_read_alloc_trace_id(struct etmv4_drvdata *drvdata)void etm4_release_trace_id (struct etmv4_drvdata *drvdata) { -coresight_trace_id_put_cpu_id (drvdata->cpu); +coresight_trace_id_put_cpu_id (drvdata->cpu,coresight_trace_id_map_default ()); }struct etm4_enable_arg {drivers/hwtracing/coresight/coresight-trace-id.c +8
-14@@ -12,7 +12,7 @@#include "coresight-trace-id.h" -/* Default trace ID map. Used on systems that don't require per sink mappings */ +/* Default trace ID map. Used in sysfs mode and for system sources */ static struct coresight_trace_id_map id_map_default;/* maintain a record of the mapping of IDs and pending releases per cpu */ @@ -152,7 +152,7 @@ static void coresight_trace_id_release_all_pending(void)DUMP_ID_MAP (id_map); } -static int coresight_trace_id_map_get_cpu_id (int cpu,struct coresight_trace_id_map *id_map) +int coresight_trace_id_get_cpu_id (int cpu,struct coresight_trace_id_map *id_map) {unsigned long flags;int id;@@ -195,8 +195,9 @@ static int coresight_trace_id_map_get_cpu_id(int cpu, struct coresight_trace_id_DUMP_ID_MAP (id_map);return id; } +EXPORT_SYMBOL_GPL (coresight_trace_id_get_cpu_id); -static void coresight_trace_id_map_put_cpu_id (int cpu,struct coresight_trace_id_map *id_map) +void coresight_trace_id_put_cpu_id (int cpu,struct coresight_trace_id_map *id_map) {unsigned long flags;int id;@@ -222,6 +223,7 @@ static void coresight_trace_id_map_put_cpu_id(int cpu, struct coresight_trace_idDUMP_ID_CPU (cpu, id);DUMP_ID_MAP (id_map); } +EXPORT_SYMBOL_GPL (coresight_trace_id_put_cpu_id);static int coresight_trace_id_map_get_system_id (struct coresight_trace_id_map *id_map) {@@ -250,19 +252,11 @@ static void coresight_trace_id_map_put_system_id(struct coresight_trace_id_map *DUMP_ID_MAP (id_map); } -/* API functions */ - -int coresight_trace_id_get_cpu_id (int cpu) -{ -return coresight_trace_id_map_get_cpu_id (cpu, &id_map_default); -} -EXPORT_SYMBOL_GPL (coresight_trace_id_get_cpu_id); - -void coresight_trace_id_put_cpu_id (int cpu) +struct coresight_trace_id_map *coresight_trace_id_map_default (void ) { -coresight_trace_id_map_put_cpu_id (cpu, &id_map_default); +return &id_map_default; } -EXPORT_SYMBOL_GPL (coresight_trace_id_put_cpu_id); +EXPORT_SYMBOL_GPL (coresight_trace_id_map_default);int coresight_trace_id_read_cpu_id (int cpu) {drivers/hwtracing/coresight/coresight-trace-id.h +6
-3@@ -42,7 +42,10 @@#define IS_VALID_CS_TRACE_ID (id) \ ((id > CORESIGHT_TRACE_ID_RES_0) && (id < CORESIGHT_TRACE_ID_RES_TOP)) -/* Allocate and release IDs for a single default trace ID map */ +/** +* Get the global map that's used by sysfs +*/ +struct coresight_trace_id_map *coresight_trace_id_map_default (void );/** * Read and optionally allocate a CoreSight trace ID and associate with a CPU. @@ -57,7 +60,7 @@* * return: CoreSight trace ID or -EINVAL if allocation impossible. */ -int coresight_trace_id_get_cpu_id (int cpu); +int coresight_trace_id_get_cpu_id (int cpu,struct coresight_trace_id_map *id_map);/** * Release an allocated trace ID associated with the CPU. @@ -70,7 +73,7 @@ int coresight_trace_id_get_cpu_id(int cpu);* * @cpu: The CPU index to release the associated trace ID. */ -void coresight_trace_id_put_cpu_id (int cpu); +void coresight_trace_id_put_cpu_id (int cpu,struct coresight_trace_id_map *id_map);/** * Read the current allocated CoreSight Trace ID value for the CPU.
Re: [PATCH 12/17] coresight: Make CPU id map a property of a trace ID map
In reply to James ClarkQuoted 79 lines · James Clark
The global CPU ID mappings won't work for per-sink ID maps so move it to the ID map struct.
coresight_trace_id_release_all_pending()is hard coded to operate on the default map, but once Perf sessions use their own maps the pending release mechanism will be deleted. So it doesn't need to be extended to accept a trace ID map argument at this point.Signed-off-by James Clark <[email protected]>--- .../hwtracing/coresight/coresight-etm-perf.c | 3 +- .../coresight/coresight-etm3x-core.c | 3 +- .../coresight/coresight-etm4x-core.c | 3 +- .../hwtracing/coresight/coresight-trace-id.c | 28 ++++++++----------- .../hwtracing/coresight/coresight-trace-id.h | 2 +- include/linux/coresight.h | 1 + 6 files changed, 20 insertions(+), 20 deletions(-)drivers/hwtracing/coresight/coresight-etm-perf.c +2
-1@@ -508,7 +508,8 @@ static void etm_event_start(struct perf_event *event, int flags) hw_id =FIELD_PREP (CS_AUX_HW_ID_VERSION_MASK ,CS_AUX_HW_ID_CURR_VERSION ); hw_id |=FIELD_PREP (CS_AUX_HW_ID_TRACE_ID_MASK , -coresight_trace_id_read_cpu_id (cpu)); +coresight_trace_id_read_cpu_id (cpu, +coresight_trace_id_map_default ()));perf_report_aux_output_id (event, hw_id); }drivers/hwtracing/coresight/coresight-etm3x-core.c +2
-1@@ -501,7 +501,8 @@ static int etm_enable_perf(struct coresight_device *csdev,* with perf locks - we know the ID cannot change until perf shuts down * the session */ - trace_id =coresight_trace_id_read_cpu_id (drvdata->cpu); + trace_id =coresight_trace_id_read_cpu_id (drvdata->cpu, +coresight_trace_id_map_default ());if (!IS_VALID_CS_TRACE_ID (trace_id)) {dev_err (&drvdata->csdev->dev,"Failed to set trace ID for %s on CPU%d\n" ,dev_name (&drvdata->csdev->dev), drvdata->cpu);drivers/hwtracing/coresight/coresight-etm4x-core.c +2
-1@@ -776,7 +776,8 @@ static int etm4_enable_perf(struct coresight_device *csdev,* with perf locks - we know the ID cannot change until perf shuts down * the session */ - trace_id =coresight_trace_id_read_cpu_id (drvdata->cpu); + trace_id =coresight_trace_id_read_cpu_id (drvdata->cpu, +coresight_trace_id_map_default ());if (!IS_VALID_CS_TRACE_ID (trace_id)) {dev_err (&drvdata->csdev->dev,"Failed to set trace ID for %s on CPU%d\n" ,dev_name (&drvdata->csdev->dev), drvdata->cpu);drivers/hwtracing/coresight/coresight-trace-id.c +5
-3@@ -13,10 +13,12 @@#include "coresight-trace-id.h" /* Default trace ID map. Used in sysfs mode and for system sources */ -static struct coresight_trace_id_map id_map_default; +static DEFINE_PER_CPU(atomic_t, id_map_default_cpu_ids) = ATOMIC_INIT(0); +static struct coresight_trace_id_map id_map_default = { + .cpu_map = &id_map_default_cpu_ids +}; -/* maintain a record of the mapping of IDs and pending releases per cpu */ -static DEFINE_PER_CPU(atomic_t, cpu_id) = ATOMIC_INIT(0); +/* maintain a record of the pending releases per cpu */ static cpumask_t cpu_id_release_pending;/* perf session active counter */
drivers/hwtracing/coresight/coresight-trace-id.c static void coresight_trace_id_dump_table(struct coresight_trace_id_map *id_map, · line 53
Quoted 8 lines
drivers/hwtracing/coresight/coresight-trace-id.c +0
-5@@ -46,12 +48,6 @@ static void coresight_trace_id_dump_table(struct coresight_trace_id_map *id_map,#define PERF_SESSION (n)#endif -/* unlocked read of current trace ID value for given CPU */ -static int _coresight_trace_id_read_cpu_id (int cpu) -{ -return atomic_read (&per_cpu (cpu_id, cpu)); -}
Just wondering where this per cpu cpu_id ^^ is being dropped off as well OR is it still getting used ?
Quoted 86 lines
drivers/hwtracing/coresight/coresight-trace-id.c +7
-8-/* look for next available odd ID, return 0 if none found */ static int coresight_trace_id_find_odd_id (struct coresight_trace_id_map *id_map) {@@ -145,7 +141,7 @@ static void coresight_trace_id_release_all_pending(void)clear_bit (bit, id_map->pend_rel_ids); }for_each_cpu (cpu, &cpu_id_release_pending) { -atomic_set (&per_cpu (cpu_id, cpu),0 ); +atomic_set (per_cpu_ptr (id_map_default.cpu_map, cpu),0 );cpumask_clear_cpu (cpu, &cpu_id_release_pending); }spin_unlock_irqrestore (&id_map_lock, flags);@@ -160,7 +156,7 @@ int coresight_trace_id_get_cpu_id(int cpu, struct coresight_trace_id_map *id_mapspin_lock_irqsave (&id_map_lock, flags);/* check for existing allocation for this CPU */ - id =_coresight_trace_id_read_cpu_id (cpu); + id =coresight_trace_id_read_cpu_id (cpu, id_map);if (id) goto get_cpu_id_clr_pend;@@ -181,7 +177,7 @@ int coresight_trace_id_get_cpu_id(int cpu, struct coresight_trace_id_map *id_map goto get_cpu_id_out_unlock;/* allocate the new id to the cpu */ -atomic_set (&per_cpu (cpu_id, cpu), id); +atomic_set (per_cpu_ptr (id_map->cpu_map, cpu), id); get_cpu_id_clr_pend:/* we are (re)using this ID - so ensure it is not marked for release */ @@ -203,7 +199,7 @@ void coresight_trace_id_put_cpu_id(int cpu, struct coresight_trace_id_map *id_maint id;/* check for existing allocation for this CPU */ - id =_coresight_trace_id_read_cpu_id (cpu); + id =coresight_trace_id_read_cpu_id (cpu, id_map);if (!id)return ;@@ -216,7 +212,7 @@ void coresight_trace_id_put_cpu_id(int cpu, struct coresight_trace_id_map *id_ma }else {/* otherwise clear id */ coresight_trace_id_free (id, id_map); -atomic_set (&per_cpu (cpu_id, cpu),0 ); +atomic_set (per_cpu_ptr (id_map->cpu_map, cpu),0 ); }spin_unlock_irqrestore (&id_map_lock, flags);@@ -258,9 +254,9 @@ struct coresight_trace_id_map *coresight_trace_id_map_default(void) }EXPORT_SYMBOL_GPL (coresight_trace_id_map_default); -int coresight_trace_id_read_cpu_id (int cpu) +int coresight_trace_id_read_cpu_id (int cpu,struct coresight_trace_id_map *id_map) { -return _coresight_trace_id_read_cpu_id (cpu); +return atomic_read (per_cpu_ptr (id_map->cpu_map, cpu)); }EXPORT_SYMBOL_GPL (coresight_trace_id_read_cpu_id);drivers/hwtracing/coresight/coresight-trace-id.h +1
-1@@ -93,7 +93,7 @@ void coresight_trace_id_put_cpu_id(int cpu, struct coresight_trace_id_map *id_ma* * return: current value, will be 0 if unallocated. */ -int coresight_trace_id_read_cpu_id (int cpu); +int coresight_trace_id_read_cpu_id (int cpu,struct coresight_trace_id_map *id_map);/** * Allocate a CoreSight trace ID for a system component. include/linux/coresight.h +1
-0@@ -234,6 +234,7 @@ struct coresight_sysfs_link {struct coresight_trace_id_map { DECLARE_BITMAP(used_ids, CORESIGHT_TRACE_IDS_MAX); DECLARE_BITMAP(pend_rel_ids, CORESIGHT_TRACE_IDS_MAX); +atomic_t __percpu *cpu_map; };/**
Re: [PATCH 13/17] coresight: Pass trace ID map into source enable
In reply to James ClarkQuoted 2 lines · James Clark
This will allow Perf mode to pass in per-sink maps. System sources allocate IDs on probe so they don't use this and it's
__maybe_unused.
Right, makes sense.
Quoted 5 lines
Sysfs mode also has the global map hard coded in various places, so pass in NULL when enabling for sysfs. We could bubble the global map all the way down to where it's used, but it wouldn't have any functional difference, so it's probably not worth the code churn.
Agreed.
Quoted 179 lines
Signed-off-by James Clark <[email protected]>--- drivers/hwtracing/coresight/coresight-dummy.c | 3 ++- drivers/hwtracing/coresight/coresight-etm-perf.c | 3 ++- drivers/hwtracing/coresight/coresight-etm3x-core.c | 10 +++++----- drivers/hwtracing/coresight/coresight-etm4x-core.c | 10 +++++----- drivers/hwtracing/coresight/coresight-stm.c | 3 ++- drivers/hwtracing/coresight/coresight-sysfs.c | 3 ++- drivers/hwtracing/coresight/coresight-tpdm.c | 3 ++- include/linux/coresight.h | 2 +- 8 files changed, 21 insertions(+), 16 deletions(-)drivers/hwtracing/coresight/coresight-dummy.c +2
-1@@ -21,7 +21,8 @@ DEFINE_CORESIGHT_DEVLIST(source_devs, "dummy_source");DEFINE_CORESIGHT_DEVLIST (sink_devs,"dummy_sink" );static int dummy_source_enable (struct coresight_device *csdev, -struct perf_event *event,enum cs_mode mode) +struct perf_event *event,enum cs_mode mode, +__maybe_unused struct coresight_trace_id_map *id_map) {dev_dbg (csdev->dev.parent,"Dummy source enabled\n" );drivers/hwtracing/coresight/coresight-etm-perf.c +2
-1@@ -496,7 +496,8 @@ static void etm_event_start(struct perf_event *event, int flags) goto fail_end_stop;/* Finally enable the tracer */ -if (source_ops (csdev)->enable (csdev, event,CS_MODE_PERF )) +if (source_ops (csdev)->enable (csdev, event,CS_MODE_PERF , +coresight_trace_id_map_default ())) goto fail_disable_path;/* drivers/hwtracing/coresight/coresight-etm3x-core.c +5
-5@@ -482,7 +482,8 @@ void etm_release_trace_id(struct etm_drvdata *drvdata) }static int etm_enable_perf (struct coresight_device *csdev, -struct perf_event *event) +struct perf_event *event, +struct coresight_trace_id_map *id_map) {struct etm_drvdata *drvdata =dev_get_drvdata (csdev->dev.parent);int trace_id;@@ -501,8 +502,7 @@ static int etm_enable_perf(struct coresight_device *csdev,* with perf locks - we know the ID cannot change until perf shuts down * the session */ - trace_id =coresight_trace_id_read_cpu_id (drvdata->cpu, -coresight_trace_id_map_default ()); + trace_id =coresight_trace_id_read_cpu_id (drvdata->cpu, id_map);if (!IS_VALID_CS_TRACE_ID (trace_id)) {dev_err (&drvdata->csdev->dev,"Failed to set trace ID for %s on CPU%d\n" ,dev_name (&drvdata->csdev->dev), drvdata->cpu);@@ -555,7 +555,7 @@ static int etm_enable_sysfs(struct coresight_device *csdev) }static int etm_enable (struct coresight_device *csdev,struct perf_event *event, -enum cs_mode mode) +enum cs_mode mode,struct coresight_trace_id_map *id_map) {int ret;struct etm_drvdata *drvdata =dev_get_drvdata (csdev->dev.parent);@@ -570,7 +570,7 @@ static int etm_enable(struct coresight_device *csdev, struct perf_event *event, ret =etm_enable_sysfs (csdev);break ;case CS_MODE_PERF : - ret =etm_enable_perf (csdev, event); + ret =etm_enable_perf (csdev, event, id_map);break ;default : ret = -EINVAL ;drivers/hwtracing/coresight/coresight-etm4x-core.c +5
-5@@ -753,7 +753,8 @@ static int etm4_parse_event_config(struct coresight_device *csdev, }static int etm4_enable_perf (struct coresight_device *csdev, -struct perf_event *event) +struct perf_event *event, +struct coresight_trace_id_map *id_map) {int ret =0 , trace_id;struct etmv4_drvdata *drvdata =dev_get_drvdata (csdev->dev.parent);@@ -776,8 +777,7 @@ static int etm4_enable_perf(struct coresight_device *csdev,* with perf locks - we know the ID cannot change until perf shuts down * the session */ - trace_id =coresight_trace_id_read_cpu_id (drvdata->cpu, -coresight_trace_id_map_default ()); + trace_id =coresight_trace_id_read_cpu_id (drvdata->cpu, id_map);if (!IS_VALID_CS_TRACE_ID (trace_id)) {dev_err (&drvdata->csdev->dev,"Failed to set trace ID for %s on CPU%d\n" ,dev_name (&drvdata->csdev->dev), drvdata->cpu);@@ -839,7 +839,7 @@ static int etm4_enable_sysfs(struct coresight_device *csdev) }static int etm4_enable (struct coresight_device *csdev,struct perf_event *event, -enum cs_mode mode) +enum cs_mode mode,struct coresight_trace_id_map *id_map) {int ret;@@ -853,7 +853,7 @@ static int etm4_enable(struct coresight_device *csdev, struct perf_event *event, ret =etm4_enable_sysfs (csdev);break ;case CS_MODE_PERF : - ret =etm4_enable_perf (csdev, event); + ret =etm4_enable_perf (csdev, event, id_map);break ;default : ret = -EINVAL ;drivers/hwtracing/coresight/coresight-stm.c +2
-1@@ -194,7 +194,8 @@ static void stm_enable_hw(struct stm_drvdata *drvdata) }static int stm_enable (struct coresight_device *csdev,struct perf_event *event, -enum cs_mode mode) +enum cs_mode mode, +__maybe_unused struct coresight_trace_id_map *trace_id) {struct stm_drvdata *drvdata =dev_get_drvdata (csdev->dev.parent);drivers/hwtracing/coresight/coresight-sysfs.c +2
-1@@ -9,6 +9,7 @@#include <linux/kernel.h> #include "coresight-priv.h" +#include "coresight-trace-id.h" /* * Use IDR to map the hash of the source's device name @@ -63,7 +64,7 @@ static int coresight_enable_source_sysfs(struct coresight_device *csdev,*/ lockdep_assert_held (&coresight_mutex);if (coresight_get_mode (csdev) !=CS_MODE_SYSFS ) { - ret =source_ops (csdev)->enable (csdev, data, mode); + ret =source_ops (csdev)->enable (csdev, data, mode,NULL );if (ret)return ret; }drivers/hwtracing/coresight/coresight-tpdm.c +2
-1@@ -439,7 +439,8 @@ static void __tpdm_enable(struct tpdm_drvdata *drvdata) }static int tpdm_enable (struct coresight_device *csdev,struct perf_event *event, -enum cs_mode mode) +enum cs_mode mode, +__maybe_unused struct coresight_trace_id_map *id_map) {struct tpdm_drvdata *drvdata =dev_get_drvdata (csdev->dev.parent);include/linux/coresight.h +0
-0
include/linux/coresight.h struct coresight_ops_link { · line 390
Quoted 8 lines
include/linux/coresight.h +1
-1@@ -384,7 +384,7 @@ struct coresight_ops_link {struct coresight_ops_source {int (*cpu_id)(struct coresight_device *csdev);int (*enable)(struct coresight_device *csdev,struct perf_event *event, -enum cs_mode mode); +enum cs_mode mode,struct coresight_trace_id_map *id_map);void (*disable)(struct coresight_device *csdev,struct perf_event *event); };
LGTM
Re: [PATCH 12/17] coresight: Make CPU id map a property of a trace ID map
In reply to Anshuman KhandualQuoted 85 lines · Anshuman Khandual
Quoted 82 lines · James Clark
The global CPU ID mappings won't work for per-sink ID maps so move it to the ID map struct.
coresight_trace_id_release_all_pending()is hard coded to operate on the default map, but once Perf sessions use their own maps the pending release mechanism will be deleted. So it doesn't need to be extended to accept a trace ID map argument at this point.Signed-off-by James Clark <[email protected]>--- .../hwtracing/coresight/coresight-etm-perf.c | 3 +- .../coresight/coresight-etm3x-core.c | 3 +- .../coresight/coresight-etm4x-core.c | 3 +- .../hwtracing/coresight/coresight-trace-id.c | 28 ++++++++----------- .../hwtracing/coresight/coresight-trace-id.h | 2 +- include/linux/coresight.h | 1 + 6 files changed, 20 insertions(+), 20 deletions(-)drivers/hwtracing/coresight/coresight-etm-perf.c +2
-1@@ -508,7 +508,8 @@ static void etm_event_start(struct perf_event *event, int flags) hw_id =FIELD_PREP (CS_AUX_HW_ID_VERSION_MASK ,CS_AUX_HW_ID_CURR_VERSION ); hw_id |=FIELD_PREP (CS_AUX_HW_ID_TRACE_ID_MASK , -coresight_trace_id_read_cpu_id (cpu)); +coresight_trace_id_read_cpu_id (cpu, +coresight_trace_id_map_default ()));perf_report_aux_output_id (event, hw_id); }drivers/hwtracing/coresight/coresight-etm3x-core.c +2
-1@@ -501,7 +501,8 @@ static int etm_enable_perf(struct coresight_device *csdev,* with perf locks - we know the ID cannot change until perf shuts down * the session */ - trace_id =coresight_trace_id_read_cpu_id (drvdata->cpu); + trace_id =coresight_trace_id_read_cpu_id (drvdata->cpu, +coresight_trace_id_map_default ());if (!IS_VALID_CS_TRACE_ID (trace_id)) {dev_err (&drvdata->csdev->dev,"Failed to set trace ID for %s on CPU%d\n" ,dev_name (&drvdata->csdev->dev), drvdata->cpu);drivers/hwtracing/coresight/coresight-etm4x-core.c +2
-1@@ -776,7 +776,8 @@ static int etm4_enable_perf(struct coresight_device *csdev,* with perf locks - we know the ID cannot change until perf shuts down * the session */ - trace_id =coresight_trace_id_read_cpu_id (drvdata->cpu); + trace_id =coresight_trace_id_read_cpu_id (drvdata->cpu, +coresight_trace_id_map_default ());if (!IS_VALID_CS_TRACE_ID (trace_id)) {dev_err (&drvdata->csdev->dev,"Failed to set trace ID for %s on CPU%d\n" ,dev_name (&drvdata->csdev->dev), drvdata->cpu);drivers/hwtracing/coresight/coresight-trace-id.c +5
-3@@ -13,10 +13,12 @@#include "coresight-trace-id.h" /* Default trace ID map. Used in sysfs mode and for system sources */ -static struct coresight_trace_id_map id_map_default; +static DEFINE_PER_CPU(atomic_t, id_map_default_cpu_ids) = ATOMIC_INIT(0); +static struct coresight_trace_id_map id_map_default = { + .cpu_map = &id_map_default_cpu_ids +}; -/* maintain a record of the mapping of IDs and pending releases per cpu */ -static DEFINE_PER_CPU(atomic_t, cpu_id) = ATOMIC_INIT(0); +/* maintain a record of the pending releases per cpu */ static cpumask_t cpu_id_release_pending;/* perf session active counter */ @@ -46,12 +48,6 @@ static void coresight_trace_id_dump_table(struct coresight_trace_id_map *id_map,#define PERF_SESSION (n)#endif
Quoted 9 lines
drivers/hwtracing/coresight/coresight-trace-id.c static void coresight_trace_id_dump_table(struct coresight_trace_id_map *id_map, · line 53
Quoted 5 lines
drivers/hwtracing/coresight/coresight-trace-id.c +0
-5-/* unlocked read of current trace ID value for given CPU */ -static int _coresight_trace_id_read_cpu_id (int cpu) -{ -return atomic_read (&per_cpu (cpu_id, cpu)); -}Just wondering where this per cpu
cpu_id^^ is being dropped off as well OR is it still getting used ?
No it's still needed. It's not dropped in this set.
I just moved the implementation into coresight_trace_id_read_cpu_id() rather than add a new argument to _coresight_trace_id_read_cpu_id(). Although I might change that because of Mike's comment about keeping both the map and non map versions of the functions to reduce some of the churn changing the callers.
Quoted 27 lines · Arnaldo Carvalho de Melo
Quoted 21 lines · James Clark
This will allow sessions with more than
CORESIGHT_TRACE_IDS_MAXETMs as long as there are fewer than that many ETMs connected to each sink.Each sink owns its own trace ID map, and any Perf session connecting to that sink will allocate from it, even if the sink is currently in use by other users. This is similar to the existing behavior where the dynamic trace IDs are constant as long as there is any concurrent Perf session active. It's not completely optimal because slightly more IDs will be used than necessary, but the optimal solution involves tracking the PIDs of each session and allocating ID maps based on the session owner. This is difficult to do with the combination of per-thread and per-cpu modes and some scheduling issues. The complexity of this isn't likely to worth it because even with multiple users they'd just see a difference in the ordering of ID allocations rather than hitting any limits (unless the hardware does have too many ETMs connected to one sink).
Per-thread mode works but only until there are any overlapping IDs, at which point Perf will error out. Both per-thread mode and sysfs mode are left to future changes, but both can be added on top of this initial implementation and only sysfs mode requires further driver changes.
Quoted 4 lines
The
HW_IDversion field hasn't been bumped in order to not break Perf which already has an error condition for other values of that field. Instead a new minor version has been added which signifies that there are new fields but the old fields are backwards compatible.
Quoted 4 lines
I guess I can pick the tooling part now, right? Further reviewing would be nice tho.
- Arnaldo
Is it ok if we wait for the driver changes to be merged first? There might some review comments which need a format change to the packets and then a re-write of the tool changes.
You could take 1 and 2 though because they're unrelated.
Thanks
James
Re: [PATCH 01/17] perf cs-etm: Print error for new PERF_RECORD_AUX_OUTPUT_HW_ID versions
In reply to Anshuman KhandualQuoted 17 lines · Anshuman Khandual
Quoted 14 lines · James Clark
The likely fix for this is to update Perf so print a helpful message.
Signed-off-by James Clark <[email protected]>--- tools/perf/util/cs-etm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)tools/perf/util/cs-etm.c +0
-0@@ -335,8 +335,11 @@ static int cs_etm__process_aux_output_hw_id(struct perf_session *session, trace_chan_id =FIELD_GET (CS_AUX_HW_ID_TRACE_ID_MASK , hw_id);
Quoted 8 lines
tools/perf/util/cs-etm.c static int cs_etm__process_aux_output_hw_id(struct perf_session *session, · line 339
Quoted 4 lines
tools/perf/util/cs-etm.c +2
-1/* check that we can handle this version */ -if (version >CS_AUX_HW_ID_CURR_VERSION ) +if (version >CS_AUX_HW_ID_CURR_VERSION ) { + pr_err("CS ETM Trace: PERF_RECORD_AUX_OUTPUT_HW_ID version %d not supported. Please update Perf.\n",Is not this bit misleading ?
PERF_RECORD_AUX_OUTPUT_HW_IDis just the perf record format identifier. The record version here, is derived from the platform specific hardware ID information embedded in this perf record.
Not sure I follow what you mean here. 'version' is something that's output by the kernel. It's saved into a perf.data file, and if Perf can't handle version 2 for example, you need to update Perf.
Quoted 3 lines
Should not this be just s/PERF_RECORD_AUX_OUTPUT_HW_ID/hardware ID/ instead ?
It's just a way to go from the error message to the part of the code or docs that you need to look at. "hardware ID" wouldn't lead you anywhere so I don't think it would be useful.
Quoted 7 lines
Quoted 6 lines
tools/perf/util/cs-etm.c +2
-0+ version);return -EINVAL ; + }/* get access to the etm metadata */ etm = container_of(session->auxtrace, struct cs_etm_auxtrace, auxtrace);
Suzuki K Poulose
maintainerRe: [PATCH 13/17] coresight: Pass trace ID map into source enable
In reply to James ClarkHi James
Quoted 2 lines · James Clark
This will allow Perf mode to pass in per-sink maps. System sources allocate IDs on probe so they don't use this and it's
__maybe_unused.
I am wondering if we need this change ? We have event_data associated with each event and we allocate the traceid from the sink map at setup_aux. So, why not set the traceid or even link the id_map in the event_data ?
something like:
struct etm_event_data {
struct work_struct work;
cpumask_t mask;
cpumask_t aux_hwid_done;
void *snk_config;
u32 cfg_hash;
struct list_head * __percpu *path;+ u8 __percpu *traceid;
};
See my comment in the other patch.
Suzuki
Quoted 194 lines
Sysfs mode also has the global map hard coded in various places, so pass in NULL when enabling for sysfs. We could bubble the global map all the way down to where it's used, but it wouldn't have any functional difference, so it's probably not worth the code churn.
Signed-off-by James Clark <[email protected]>--- drivers/hwtracing/coresight/coresight-dummy.c | 3 ++- drivers/hwtracing/coresight/coresight-etm-perf.c | 3 ++- drivers/hwtracing/coresight/coresight-etm3x-core.c | 10 +++++----- drivers/hwtracing/coresight/coresight-etm4x-core.c | 10 +++++----- drivers/hwtracing/coresight/coresight-stm.c | 3 ++- drivers/hwtracing/coresight/coresight-sysfs.c | 3 ++- drivers/hwtracing/coresight/coresight-tpdm.c | 3 ++- include/linux/coresight.h | 2 +- 8 files changed, 21 insertions(+), 16 deletions(-)drivers/hwtracing/coresight/coresight-dummy.c +2
-1@@ -21,7 +21,8 @@ DEFINE_CORESIGHT_DEVLIST(source_devs, "dummy_source");DEFINE_CORESIGHT_DEVLIST (sink_devs,"dummy_sink" );static int dummy_source_enable (struct coresight_device *csdev, -struct perf_event *event,enum cs_mode mode) +struct perf_event *event,enum cs_mode mode, +__maybe_unused struct coresight_trace_id_map *id_map) {dev_dbg (csdev->dev.parent,"Dummy source enabled\n" );drivers/hwtracing/coresight/coresight-etm-perf.c +2
-1@@ -496,7 +496,8 @@ static void etm_event_start(struct perf_event *event, int flags) goto fail_end_stop;/* Finally enable the tracer */ -if (source_ops (csdev)->enable (csdev, event,CS_MODE_PERF )) +if (source_ops (csdev)->enable (csdev, event,CS_MODE_PERF , +coresight_trace_id_map_default ())) goto fail_disable_path;/* drivers/hwtracing/coresight/coresight-etm3x-core.c +5
-5@@ -482,7 +482,8 @@ void etm_release_trace_id(struct etm_drvdata *drvdata) }static int etm_enable_perf (struct coresight_device *csdev, -struct perf_event *event) +struct perf_event *event, +struct coresight_trace_id_map *id_map) {struct etm_drvdata *drvdata =dev_get_drvdata (csdev->dev.parent);int trace_id;@@ -501,8 +502,7 @@ static int etm_enable_perf(struct coresight_device *csdev,* with perf locks - we know the ID cannot change until perf shuts down * the session */ - trace_id =coresight_trace_id_read_cpu_id (drvdata->cpu, -coresight_trace_id_map_default ()); + trace_id =coresight_trace_id_read_cpu_id (drvdata->cpu, id_map);if (!IS_VALID_CS_TRACE_ID (trace_id)) {dev_err (&drvdata->csdev->dev,"Failed to set trace ID for %s on CPU%d\n" ,dev_name (&drvdata->csdev->dev), drvdata->cpu);@@ -555,7 +555,7 @@ static int etm_enable_sysfs(struct coresight_device *csdev) }static int etm_enable (struct coresight_device *csdev,struct perf_event *event, -enum cs_mode mode) +enum cs_mode mode,struct coresight_trace_id_map *id_map) {int ret;struct etm_drvdata *drvdata =dev_get_drvdata (csdev->dev.parent);@@ -570,7 +570,7 @@ static int etm_enable(struct coresight_device *csdev, struct perf_event *event, ret =etm_enable_sysfs (csdev);break ;case CS_MODE_PERF : - ret =etm_enable_perf (csdev, event); + ret =etm_enable_perf (csdev, event, id_map);break ;default : ret = -EINVAL ;drivers/hwtracing/coresight/coresight-etm4x-core.c +5
-5@@ -753,7 +753,8 @@ static int etm4_parse_event_config(struct coresight_device *csdev, }static int etm4_enable_perf (struct coresight_device *csdev, -struct perf_event *event) +struct perf_event *event, +struct coresight_trace_id_map *id_map) {int ret =0 , trace_id;struct etmv4_drvdata *drvdata =dev_get_drvdata (csdev->dev.parent);@@ -776,8 +777,7 @@ static int etm4_enable_perf(struct coresight_device *csdev,* with perf locks - we know the ID cannot change until perf shuts down * the session */ - trace_id =coresight_trace_id_read_cpu_id (drvdata->cpu, -coresight_trace_id_map_default ()); + trace_id =coresight_trace_id_read_cpu_id (drvdata->cpu, id_map);if (!IS_VALID_CS_TRACE_ID (trace_id)) {dev_err (&drvdata->csdev->dev,"Failed to set trace ID for %s on CPU%d\n" ,dev_name (&drvdata->csdev->dev), drvdata->cpu);@@ -839,7 +839,7 @@ static int etm4_enable_sysfs(struct coresight_device *csdev) }static int etm4_enable (struct coresight_device *csdev,struct perf_event *event, -enum cs_mode mode) +enum cs_mode mode,struct coresight_trace_id_map *id_map) {int ret;@@ -853,7 +853,7 @@ static int etm4_enable(struct coresight_device *csdev, struct perf_event *event, ret =etm4_enable_sysfs (csdev);break ;case CS_MODE_PERF : - ret =etm4_enable_perf (csdev, event); + ret =etm4_enable_perf (csdev, event, id_map);break ;default : ret = -EINVAL ;drivers/hwtracing/coresight/coresight-stm.c +2
-1@@ -194,7 +194,8 @@ static void stm_enable_hw(struct stm_drvdata *drvdata) }static int stm_enable (struct coresight_device *csdev,struct perf_event *event, -enum cs_mode mode) +enum cs_mode mode, +__maybe_unused struct coresight_trace_id_map *trace_id) {struct stm_drvdata *drvdata =dev_get_drvdata (csdev->dev.parent);drivers/hwtracing/coresight/coresight-sysfs.c +2
-1@@ -9,6 +9,7 @@#include <linux/kernel.h> #include "coresight-priv.h" +#include "coresight-trace-id.h" /* * Use IDR to map the hash of the source's device name @@ -63,7 +64,7 @@ static int coresight_enable_source_sysfs(struct coresight_device *csdev,*/ lockdep_assert_held (&coresight_mutex);if (coresight_get_mode (csdev) !=CS_MODE_SYSFS ) { - ret =source_ops (csdev)->enable (csdev, data, mode); + ret =source_ops (csdev)->enable (csdev, data, mode,NULL );if (ret)return ret; }drivers/hwtracing/coresight/coresight-tpdm.c +2
-1@@ -439,7 +439,8 @@ static void __tpdm_enable(struct tpdm_drvdata *drvdata) }static int tpdm_enable (struct coresight_device *csdev,struct perf_event *event, -enum cs_mode mode) +enum cs_mode mode, +__maybe_unused struct coresight_trace_id_map *id_map) {struct tpdm_drvdata *drvdata =dev_get_drvdata (csdev->dev.parent);include/linux/coresight.h +1
-1@@ -384,7 +384,7 @@ struct coresight_ops_link {struct coresight_ops_source {int (*cpu_id)(struct coresight_device *csdev);int (*enable)(struct coresight_device *csdev,struct perf_event *event, -enum cs_mode mode); +enum cs_mode mode,struct coresight_trace_id_map *id_map);void (*disable)(struct coresight_device *csdev,struct perf_event *event); };
Suzuki K Poulose
maintainerQuoted 79 lines · James Clark
This will allow sessions with more than
CORESIGHT_TRACE_IDS_MAXETMs as long as there are fewer than that many ETMs connected to each sink.Each sink owns its own trace ID map, and any Perf session connecting to that sink will allocate from it, even if the sink is currently in use by other users. This is similar to the existing behavior where the dynamic trace IDs are constant as long as there is any concurrent Perf session active. It's not completely optimal because slightly more IDs will be used than necessary, but the optimal solution involves tracking the PIDs of each session and allocating ID maps based on the session owner. This is difficult to do with the combination of per-thread and per-cpu modes and some scheduling issues. The complexity of this isn't likely to worth it because even with multiple users they'd just see a difference in the ordering of ID allocations rather than hitting any limits (unless the hardware does have too many ETMs connected to one sink).
Signed-off-by James Clark <[email protected]>--- drivers/hwtracing/coresight/coresight-core.c | 10 ++++++++++ drivers/hwtracing/coresight/coresight-etm-perf.c | 15 ++++++++------- include/linux/coresight.h | 1 + 3 files changed, 19 insertions(+), 7 deletions(-)drivers/hwtracing/coresight/coresight-core.c +10
-0@@ -902,6 +902,7 @@ static void coresight_device_release(struct device *dev)struct coresight_device *csdev =to_coresight_device (dev);fwnode_handle_put (csdev->dev.fwnode); +free_percpu (csdev->perf_id_map.cpu_map);kfree (csdev); }@@ -1159,6 +1160,14 @@ struct coresight_device *coresight_register(struct coresight_desc *desc) csdev->dev.fwnode =fwnode_handle_get (dev_fwnode (desc->dev));dev_set_name (&csdev->dev,"%s" , desc->name); +if (csdev->type ==CORESIGHT_DEV_TYPE_SINK || + csdev->type ==CORESIGHT_DEV_TYPE_LINKSINK ) { + csdev->perf_id_map.cpu_map =alloc_percpu (atomic_t); +if (!csdev->perf_id_map.cpu_map) { + ret = -ENOMEM ; + goto err_out; + } + }/* * Make sure the device registration and the connection fixup * are synchronised, so that we don't see uninitialised devices @@ -1216,6 +1225,7 @@ struct coresight_device *coresight_register(struct coresight_desc *desc) err_out:/* Cleanup the connection information */ coresight_release_platform_data (NULL , desc->dev, desc->pdata); +kfree (csdev);return ERR_PTR (ret); }EXPORT_SYMBOL_GPL (coresight_register);drivers/hwtracing/coresight/coresight-etm-perf.c +5
-2@@ -229,10 +229,13 @@ static void free_event_data(struct work_struct *work)struct list_head **ppath; ppath =etm_event_cpu_path_ptr (event_data, cpu); -if (!(IS_ERR_OR_NULL (*ppath))) +if (!(IS_ERR_OR_NULL (*ppath))) { +struct coresight_device *sink =coresight_get_sink (*ppath); + +coresight_trace_id_put_cpu_id (cpu, &sink->perf_id_map);coresight_release_path (*ppath); + } *ppath =NULL ; -coresight_trace_id_put_cpu_id (cpu,coresight_trace_id_map_default ()); }/* mark perf event as done for trace id allocator */
drivers/hwtracing/coresight/coresight-etm-perf.c static void *etm_setup_aux(struct perf_event *event, void **pages, · line 407
Quoted 6 lines
drivers/hwtracing/coresight/coresight-etm-perf.c +1
-2@@ -401,8 +404,7 @@ static void *etm_setup_aux(struct perf_event *event, void **pages, }/* ensure we can allocate a trace ID for this CPU */ - trace_id =coresight_trace_id_get_cpu_id (cpu, -coresight_trace_id_map_default ()); + trace_id =coresight_trace_id_get_cpu_id (cpu, &sink->perf_id_map);
We could either store the perf_id_map or the traceid itself in the event_data isn't it ? Rather than passing the idmap to enable_source ?
Suzuki
Re: [PATCH 01/17] perf cs-etm: Print error for new PERF_RECORD_AUX_OUTPUT_HW_ID versions
In reply to James ClarkQuoted 29 lines · James Clark
Quoted 17 lines · Anshuman Khandual
Quoted 14 lines · James Clark
The likely fix for this is to update Perf so print a helpful message.
Signed-off-by James Clark <[email protected]>--- tools/perf/util/cs-etm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)tools/perf/util/cs-etm.c +0
-0@@ -335,8 +335,11 @@ static int cs_etm__process_aux_output_hw_id(struct perf_session *session, trace_chan_id =FIELD_GET (CS_AUX_HW_ID_TRACE_ID_MASK , hw_id);Quoted 8 lines
tools/perf/util/cs-etm.c static int cs_etm__process_aux_output_hw_id(struct perf_session *session, · line 339
Quoted 4 lines
tools/perf/util/cs-etm.c +2
-1/* check that we can handle this version */ -if (version >CS_AUX_HW_ID_CURR_VERSION ) +if (version >CS_AUX_HW_ID_CURR_VERSION ) { + pr_err("CS ETM Trace: PERF_RECORD_AUX_OUTPUT_HW_ID version %d not supported. Please update Perf.\n",Is not this bit misleading ?
PERF_RECORD_AUX_OUTPUT_HW_IDis just the perf record format identifier. The record version here, is derived from the platform specific hardware ID information embedded in this perf record.
Quoted 3 lines
Not sure I follow what you mean here. 'version' is something that's output by the kernel. It's saved into a perf.data file, and if Perf can't handle version 2 for example, you need to update Perf.
Got it.
Quoted 8 lines
Quoted 4 lines
Should not this be just s/PERF_RECORD_AUX_OUTPUT_HW_ID/hardware ID/ instead ?
It's just a way to go from the error message to the part of the code or docs that you need to look at. "hardware ID" wouldn't lead you anywhere so I don't think it would be useful.
Sure, fair enough.
Quoted 11 lines
Quoted 8 lines
tools/perf/util/cs-etm.c static int cs_etm__process_aux_output_hw_id(struct perf_session *session, · line 345
Quoted 7 lines
tools/perf/util/cs-etm.c +2
-0+ version);return -EINVAL ; + }/* get access to the etm metadata */ etm = container_of(session->auxtrace, struct cs_etm_auxtrace, auxtrace);_______________________________________________
CoreSight mailing list -- [email protected] To unsubscribe send an email to [email protected]
Hi James,
Quoted 60 lines · James Clark
This will allow sessions with more than
CORESIGHT_TRACE_IDS_MAXETMs as long as there are fewer than that many ETMs connected to each sink.Each sink owns its own trace ID map, and any Perf session connecting to that sink will allocate from it, even if the sink is currently in use by other users. This is similar to the existing behavior where the dynamic trace IDs are constant as long as there is any concurrent Perf session active. It's not completely optimal because slightly more IDs will be used than necessary, but the optimal solution involves tracking the PIDs of each session and allocating ID maps based on the session owner. This is difficult to do with the combination of per-thread and per-cpu modes and some scheduling issues. The complexity of this isn't likely to worth it because even with multiple users they'd just see a difference in the ordering of ID allocations rather than hitting any limits (unless the hardware does have too many ETMs connected to one sink).
Per-thread mode works but only until there are any overlapping IDs, at which point Perf will error out. Both per-thread mode and sysfs mode are left to future changes, but both can be added on top of this initial implementation and only sysfs mode requires further driver changes.
The
HW_IDversion field hasn't been bumped in order to not break Perf which already has an error condition for other values of that field. Instead a new minor version has been added which signifies that there are new fields but the old fields are backwards compatible.James Clark (17):
perf cs-etm: Print error for newPERF_RECORD_AUX_OUTPUT_HW_IDversions perf auxtrace: Allow number of queues to be specified
perf: cs-etm: Create decoders after both AUX andHW_IDsearch passes
perf: cs-etm: Allocate queues for all CPUs
perf: cs-etm: Movetraceid_listto each queue
perf: cs-etm: Create decoders based on the trace ID mappings
perf: cs-etm: Support version 0.1 ofHW_IDpackets
coresight: Remove unused stubs
coresight: Clarify comments around the PID of the sink owner
coresight: Move structcoresight_trace_id_mapto common header
coresight: Expose map argument in trace ID API
coresight: Make CPU id map a property of a trace ID map
coresight: Pass trace ID map into source enable
coresight: Use per-sink trace ID maps for Perf sessions
coresight: Remove pending trace ID release mechanism
coresight: Re-emit trace IDs when the sink changes in per-thread mode
coresight: EmitHW_IDsfor all ETMs that are using the sinkdrivers/hwtracing/coresight/coresight-core.c | 10 + drivers/hwtracing/coresight/coresight-dummy.c | 3 +- .../hwtracing/coresight/coresight-etm-perf.c | 82 ++- .../hwtracing/coresight/coresight-etm-perf.h | 20 +- .../coresight/coresight-etm3x-core.c | 14 +- .../coresight/coresight-etm4x-core.c | 14 +- drivers/hwtracing/coresight/coresight-stm.c | 3 +- drivers/hwtracing/coresight/coresight-sysfs.c | 3 +- .../hwtracing/coresight/coresight-tmc-etr.c | 5 +- drivers/hwtracing/coresight/coresight-tmc.h | 5 +- drivers/hwtracing/coresight/coresight-tpdm.c | 3 +- .../hwtracing/coresight/coresight-trace-id.c | 107 +-- .../hwtracing/coresight/coresight-trace-id.h | 57 +- include/linux/coresight-pmu.h | 17 +-
Quoted 9 lines
include/linux/coresight.h | 20 +- tools/include/linux/coresight-pmu.h | 17 +- tools/perf/util/auxtrace.c | 9 +- tools/perf/util/auxtrace.h | 1 + .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 28 +- tools/perf/util/cs-etm.c | 617 ++++++++++++------ tools/perf/util/cs-etm.h | 2 +- 21 files changed, 633 insertions(+), 404 deletions(-)
Thanks for implementing trace-id mapping per sink, with that we could try perf (coresight tracing) for more than 100+ CPUs.
Please feel free to add,
Thanks,
Ganapat
Suzuki K Poulose
maintainerRe: [PATCH 16/17] coresight: Re-emit trace IDs when the sink changes in per-thread mode
In reply to James ClarkQuoted 32 lines · James Clark
In per-cpu mode there are multiple aux buffers and each one has a fixed sink, so the hw ID mappings which only need to be emitted once for each buffer, even with the new per-sink trace ID pools.
But in per-thread mode there is only a single buffer which can be written to from any sink with now potentially overlapping trace IDs, so hw ID mappings need to be re-emitted every time the sink changes.
This will require a change in Perf to track this so it knows which decode tree to use for each segment of the buffer. In theory it's also possible to look at the CPU ID on the AUX records, but this is more consistent with the existing system, and allows for correct decode using either mechanism.
Signed-off-by James Clark <[email protected]>--- drivers/hwtracing/coresight/coresight-etm-perf.c | 14 ++++++++++++++ drivers/hwtracing/coresight/coresight-etm-perf.h | 2 ++ 2 files changed, 16 insertions(+)drivers/hwtracing/coresight/coresight-etm-perf.c +4
-0@@ -499,6 +499,20 @@ static void etm_event_start(struct perf_event *event, int flags) &sink->perf_id_map)) goto fail_disable_path; +/* +* In per-cpu mode there are multiple aux buffers and each one has a +* fixed sink, so the hw ID mappings which only need to be emitted once +* for each buffer.
drivers/hwtracing/coresight/coresight-etm-perf.c static void etm_event_start(struct perf_event *event, int flags) · line 515
Quoted 10 lines
drivers/hwtracing/coresight/coresight-etm-perf.c +10
-0+* +* But in per-thread mode there is only a single buffer which can be +* written to from any sink with potentially overlapping trace IDs, so +* hw ID mappings need to be re-emitted every time the sink changes. +*/ +if (event->cpu ==-1 && event_data->last_sink_hwid != sink) { +cpumask_clear (&event_data->aux_hwid_done); + event_data->last_sink_hwid = sink; + } +
With the traceid caching in the event_data per-cpu , we could avoid this step ?
Suzuki
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 01/17] perf cs-etm: Print error for new PERF_RECORD_AUX_OUTPUT_HW_ID versions
In reply to Anshuman KhandualQuoted 32 lines · Anshuman Khandual
Quoted 25 lines · James Clark
Quoted 15 lines · Anshuman Khandual
Quoted 14 lines · James Clark
The likely fix for this is to update Perf so print a helpful message.
Signed-off-by James Clark <[email protected]>--- tools/perf/util/cs-etm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)tools/perf/util/cs-etm.c +0
-0@@ -335,8 +335,11 @@ static int cs_etm__process_aux_output_hw_id(struct perf_session *session, trace_chan_id =FIELD_GET (CS_AUX_HW_ID_TRACE_ID_MASK , hw_id);Quoted 8 lines
tools/perf/util/cs-etm.c static int cs_etm__process_aux_output_hw_id(struct perf_session *session, · line 339
Quoted 4 lines
tools/perf/util/cs-etm.c +2
-1/* check that we can handle this version */ -if (version >CS_AUX_HW_ID_CURR_VERSION ) +if (version >CS_AUX_HW_ID_CURR_VERSION ) { + pr_err("CS ETM Trace: PERF_RECORD_AUX_OUTPUT_HW_ID version %d not supported. Please update Perf.\n",Is not this bit misleading ?
PERF_RECORD_AUX_OUTPUT_HW_IDis just the perf record format identifier. The record version here, is derived from the platform specific hardware ID information embedded in this perf record.Quoted 3 lines
Not sure I follow what you mean here. 'version' is something that's output by the kernel. It's saved into a perf.data file, and if Perf can't handle version 2 for example, you need to update Perf.
Got it.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Should not this be just s/PERF_RECORD_AUX_OUTPUT_HW_ID/hardware ID/ instead ?
It's just a way to go from the error message to the part of the code or docs that you need to look at. "hardware ID" wouldn't lead you anywhere so I don't think it would be useful.
Sure, fair enough.
I'm taking this as an Acked-by, ok?
- Arnaldo
Arnaldo Carvalho de Melo
maintainerQuoted 7 lines · James Clark
Quoted 2 lines · Arnaldo Carvalho de Melo
I guess I can pick the tooling part now, right? Further reviewing would be nice tho.
Is it ok if we wait for the driver changes to be merged first? There might some review comments which need a format change to the packets and then a re-write of the tool changes.
Ok
Quoted 1 line
You could take 1 and 2 though because they're unrelated.
Done.
- Arnaldo
Re: [PATCH 16/17] coresight: Re-emit trace IDs when the sink changes in per-thread mode
In reply to Suzuki K PouloseQuoted 50 lines · Suzuki K Poulose
Quoted 37 lines · James Clark
In per-cpu mode there are multiple aux buffers and each one has a fixed sink, so the hw ID mappings which only need to be emitted once for each buffer, even with the new per-sink trace ID pools.
But in per-thread mode there is only a single buffer which can be written to from any sink with now potentially overlapping trace IDs, so hw ID mappings need to be re-emitted every time the sink changes.
This will require a change in Perf to track this so it knows which decode tree to use for each segment of the buffer. In theory it's also possible to look at the CPU ID on the AUX records, but this is more consistent with the existing system, and allows for correct decode using either mechanism.
Signed-off-by James Clark <[email protected]>---
drivers/hwtracing/coresight/coresight-etm-perf.c| 14 ++++++++++++++drivers/hwtracing/coresight/coresight-etm-perf.h| 2 ++2 files changed, 16 insertions(+)drivers/hwtracing/coresight/coresight-etm-perf.c +0
-0@@ -499,6 +499,20 @@ static void etm_event_start(struct perf_event *event, int flags) &sink->perf_id_map)) goto fail_disable_path;+ /*
+ * In per-cpu mode there are multiple aux buffers and each one has a + * fixed sink, so the hw ID mappings which only need to be emitted once
+ * for each buffer.
+ *
+ * But in per-thread mode there is only a single buffer which can be + * written to from any sink with potentially overlapping traceQuoted 8 lines
IDs, so
+ * hw ID mappings need to be re-emitted every time the sink changes. + */
+ if (event->cpu== -1 &&event_data->last_sink_hwid!= sink) { +cpumask_clear(&event_data->aux_hwid_done);
+event_data->last_sink_hwid= sink;
+ }
+With the traceid caching in the
event_dataper-cpu , we could avoid this step ?
Quoted 3 lines
Suzuki
I don't think so, this is to inform the tool that the mappings have changed if the tool doesn't want to follow switch events.
Unless I'm missing something, moving where the trace ids are stored doesn't mean that they will be re-sent when the mappings change?
Quoted 93 lines · Suzuki K Poulose
Quoted 81 lines · James Clark
This will allow sessions with more than
CORESIGHT_TRACE_IDS_MAXETMs as long as there are fewer than that many ETMs connected to each sink.Each sink owns its own trace ID map, and any Perf session connecting to that sink will allocate from it, even if the sink is currently in use by other users. This is similar to the existing behavior where the dynamic trace IDs are constant as long as there is any concurrent Perf session active. It's not completely optimal because slightly more IDs will be used than necessary, but the optimal solution involves tracking the PIDs of each session and allocating ID maps based on the session owner. This is difficult to do with the combination of per-thread and per-cpu modes and some scheduling issues. The complexity of this isn't likely to worth it because even with multiple users they'd just see a difference in the ordering of ID allocations rather than hitting any limits (unless the hardware does have too many ETMs connected to one sink).
Signed-off-by James Clark <[email protected]>---
drivers/hwtracing/coresight/coresight-core.c | 10 ++++++++++drivers/hwtracing/coresight/coresight-etm-perf.c| 15 ++++++++------- include/linux/coresight.h | 1 +3 files changed, 19 insertions(+), 7 deletions(-)drivers/hwtracing/coresight/coresight-core.c +1
-0@@ -902,6 +902,7 @@ static void coresight_device_release(struct device *dev) struct coresight_device *csdev = to_coresight_device(dev); fwnode_handle_put(csdev->dev.fwnode); + free_percpu(csdev->perf_id_map.cpu_map); kfree(csdev); }@@ -1159,6 +1160,14 @@ struct
coresight_device*coresight_register(structcoresight_desc*desc)csdev->dev.fwnode= fwnode_handle_get(dev_fwnode(desc->dev));dev_set_name(&csdev->dev, "%s", desc->name);
+ if (csdev->type==CORESIGHT_DEV_TYPE_SINK||
+csdev->type==CORESIGHT_DEV_TYPE_LINKSINK) {
+csdev->perf_id_map.cpu_map=alloc_percpu(atomic_t); + if (!csdev->perf_id_map.cpu_map) {
+ ret =-ENOMEM;
+ gotoerr_out;
+ }
+ }
/*
* Make sure the device registration and the connection fixup
* are synchronised, so that we don't see uninitialised devicesdrivers/hwtracing/coresight/coresight-core.c +0
-0@@ -1216,6 +1225,7 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
err_out:
/* Cleanup the connection information */coresight_release_platform_data(NULL, desc->dev, desc->pdata); + kfree(csdev);
returnERR_PTR(ret);
}
EXPORT_SYMBOL_GPL(coresight_register);drivers/hwtracing/coresight/coresight-etm-perf.c +5
-2@@ -229,10 +229,13 @@ static void free_event_data(struct work_struct *work) struct list_head **ppath; ppath = etm_event_cpu_path_ptr(event_data, cpu); - if (!(IS_ERR_OR_NULL(*ppath))) + if (!(IS_ERR_OR_NULL(*ppath))) { + struct coresight_device *sink = coresight_get_sink(*ppath); + + coresight_trace_id_put_cpu_id(cpu, &sink->perf_id_map); coresight_release_path(*ppath); + } *ppath = NULL; - coresight_trace_id_put_cpu_id(cpu, coresight_trace_id_map_default()); } /* mark perf event as done for trace id allocator */drivers/hwtracing/coresight/coresight-etm-perf.c static void *etm_setup_aux(struct perf_event · line 408
Quoted 7 lines
drivers/hwtracing/coresight/coresight-etm-perf.c +1
-2@@ -401,8 +404,7 @@ static void *etm_setup_aux(struct perf_event *event, void **pages, } /* ensure we can allocate a trace ID for this CPU */ - trace_id = coresight_trace_id_get_cpu_id(cpu, - coresight_trace_id_map_default()); + trace_id = coresight_trace_id_get_cpu_id(cpu, &sink->perf_id_map);We could either store the
perf_id_mapor the traceid itself in theevent_dataisn't it ? Rather than passing the idmap toenable_source?
Quoted 2 lines
Suzuki
Yes the end result would be the same. By doing it this way I was keeping in mind the potential change for sysfs mode in the future. This way there is common path between the two modes.
IMO an argument is easier to understand, rather than having to know where/how/at what point the ID is initialised before calling enable_source().
James
Re: [PATCH 11/17] coresight: Expose map argument in trace ID API
In reply to Mike LeachQuoted 159 lines · Mike Leach
Hi James,
Quoted 130 lines · James Clark
The trace ID API is currently hard coded to always use the global map. The functions that take the map as an argument aren't currently public. Make them public so that Perf mode can pass in its own maps. At the moment all usages are still hard coded to use the global map, but now on the caller side.
System ID functions are unchanged because they will always use the default map.
Signed-off-by James Clark <[email protected]>--- .../hwtracing/coresight/coresight-etm-perf.c | 5 +++-- .../coresight/coresight-etm3x-core.c | 5 +++-- .../coresight/coresight-etm4x-core.c | 5 +++-- .../hwtracing/coresight/coresight-trace-id.c | 22 +++++++------------ .../hwtracing/coresight/coresight-trace-id.h | 9 +++++--- 5 files changed, 23 insertions(+), 23 deletions(-)drivers/hwtracing/coresight/coresight-etm-perf.c +3
-2@@ -232,7 +232,7 @@ static void free_event_data(struct work_struct *work)if (!(IS_ERR_OR_NULL (*ppath)))coresight_release_path (*ppath); *ppath =NULL ; -coresight_trace_id_put_cpu_id (cpu); +coresight_trace_id_put_cpu_id (cpu,coresight_trace_id_map_default ()); }/* mark perf event as done for trace id allocator */ @@ -401,7 +401,8 @@ static void *etm_setup_aux(struct perf_event *event, void **pages, }/* ensure we can allocate a trace ID for this CPU */ - trace_id =coresight_trace_id_get_cpu_id (cpu); + trace_id =coresight_trace_id_get_cpu_id (cpu, +coresight_trace_id_map_default ());if (!IS_VALID_CS_TRACE_ID (trace_id)) {cpumask_clear_cpu (cpu, mask);coresight_release_path (path);drivers/hwtracing/coresight/coresight-etm3x-core.c +3
-2@@ -465,7 +465,8 @@ int etm_read_alloc_trace_id(struct etm_drvdata *drvdata)* * trace id function has its own lock */ - trace_id =coresight_trace_id_get_cpu_id (drvdata->cpu); + trace_id =coresight_trace_id_get_cpu_id (drvdata->cpu, +coresight_trace_id_map_default ());if (IS_VALID_CS_TRACE_ID (trace_id)) drvdata->traceid = (u8 )trace_id;else @@ -477,7 +478,7 @@ int etm_read_alloc_trace_id(struct etm_drvdata *drvdata)void etm_release_trace_id (struct etm_drvdata *drvdata) { -coresight_trace_id_put_cpu_id (drvdata->cpu); +coresight_trace_id_put_cpu_id (drvdata->cpu,coresight_trace_id_map_default ()); } static int etm_enable_perf(struct coresight_device *csdev,drivers/hwtracing/coresight/coresight-etm4x-core.c +3
-2@@ -241,7 +241,8 @@ int etm4_read_alloc_trace_id(struct etmv4_drvdata *drvdata)* or return the one currently allocated. * The trace id function has its own lock */ - trace_id =coresight_trace_id_get_cpu_id (drvdata->cpu); + trace_id =coresight_trace_id_get_cpu_id (drvdata->cpu, +coresight_trace_id_map_default ());if (IS_VALID_CS_TRACE_ID (trace_id)) drvdata->trcid = (u8 )trace_id;else @@ -253,7 +254,7 @@ int etm4_read_alloc_trace_id(struct etmv4_drvdata *drvdata)void etm4_release_trace_id (struct etmv4_drvdata *drvdata) { -coresight_trace_id_put_cpu_id (drvdata->cpu); +coresight_trace_id_put_cpu_id (drvdata->cpu,coresight_trace_id_map_default ()); }struct etm4_enable_arg {drivers/hwtracing/coresight/coresight-trace-id.c +5
-3@@ -12,7 +12,7 @@#include "coresight-trace-id.h" -/* Default trace ID map. Used on systems that don't require per sink mappings */ +/* Default trace ID map. Used in sysfs mode and for system sources */ static struct coresight_trace_id_map id_map_default;/* maintain a record of the mapping of IDs and pending releases per cpu */ @@ -152,7 +152,7 @@ static void coresight_trace_id_release_all_pending(void)DUMP_ID_MAP (id_map); } -static int coresight_trace_id_map_get_cpu_id (int cpu,struct coresight_trace_id_map *id_map) +int coresight_trace_id_get_cpu_id (int cpu,struct coresight_trace_id_map *id_map) {unsigned long flags;int id;@@ -195,8 +195,9 @@ static int coresight_trace_id_map_get_cpu_id(int cpu, struct coresight_trace_id_DUMP_ID_MAP (id_map);return id; } +EXPORT_SYMBOL_GPL (coresight_trace_id_get_cpu_id); -static void coresight_trace_id_map_put_cpu_id (int cpu,struct coresight_trace_id_map *id_map) +void coresight_trace_id_put_cpu_id (int cpu,struct coresight_trace_id_map *id_map) {unsigned long flags;int id;@@ -222,6 +223,7 @@ static void coresight_trace_id_map_put_cpu_id(int cpu, struct coresight_trace_idDUMP_ID_CPU (cpu, id);DUMP_ID_MAP (id_map); } +EXPORT_SYMBOL_GPL (coresight_trace_id_put_cpu_id);static int coresight_trace_id_map_get_system_id (struct coresight_trace_id_map *id_map) {drivers/hwtracing/coresight/coresight-trace-id.c static void coresight_trace_id_map_put_system_id(struct coresight_trace_id_map * · line 254
Quoted 5 lines
drivers/hwtracing/coresight/coresight-trace-id.c +0
-2@@ -250,19 +252,11 @@ static void coresight_trace_id_map_put_system_id(struct coresight_trace_id_map *DUMP_ID_MAP (id_map); } -/* API functions */ -Rather than remove the existing default trace ID functions, simply add a few new ones...
e.g. given the existing...
void
coresight_trace_id_put_cpu_id(int cpu){ coresight_trace_id_map_put_cpu_id(cpu, &id_map_default); }
EXPORT_SYMBOL_GPL(coresight_trace_id_put_cpu_id);add:-
void
coresight_trace_id_put_cpu_id_map(int cpu, struct coresight_trace_id_map *id_map){ coresight_trace_id_map_put_cpu_id(cpu, id_map); }
EXPORT_SYMBOL_GPL(coresight_trace_id_put_cpu_id_map);
Quoted 9 lines
This avoids a whole lot of churn in exposing the default map to external functions, putting it in there and then removing it later. When any location that was using
coresight_trace_id_put_cpu_id()needs to supply its own map, change the function name at that point tocoresight_trace_id_put_cpu_id_map()Mike
Yeah I was on the fence about this one when writing it, but I agree I can make this change.
James
Quoted 31 lines · Mike Leach
Hi James
Quoted 22 lines · James Clark
This will allow sessions with more than
CORESIGHT_TRACE_IDS_MAXETMs as long as there are fewer than that many ETMs connected to each sink.Each sink owns its own trace ID map, and any Perf session connecting to that sink will allocate from it, even if the sink is currently in use by other users. This is similar to the existing behavior where the dynamic trace IDs are constant as long as there is any concurrent Perf session active. It's not completely optimal because slightly more IDs will be used than necessary, but the optimal solution involves tracking the PIDs of each session and allocating ID maps based on the session owner. This is difficult to do with the combination of per-thread and per-cpu modes and some scheduling issues. The complexity of this isn't likely to worth it because even with multiple users they'd just see a difference in the ordering of ID allocations rather than hitting any limits (unless the hardware does have too many ETMs connected to one sink).
Per-thread mode works but only until there are any overlapping IDs, at which point Perf will error out. Both per-thread mode and sysfs mode are left to future changes, but both can be added on top of this initial implementation and only sysfs mode requires further driver changes.
Quoted 5 lines
The
HW_IDversion field hasn't been bumped in order to not break Perf which already has an error condition for other values of that field. Instead a new minor version has been added which signifies that there are new fields but the old fields are backwards compatible.
Quoted 4 lines
Looking at this overall - would it not be better to introduce the concept of a "sink ID" to allow the detection of multiple sources into the single sink that is now done by emitting multiple
AUX_HWIDpackets with the CPU+ID extra data?
I think it's worth trying so I'll give it a go and see if it ends up being cleaner. One of the reasons for emitting multiple packets was to tie events and sinks together that may not have been created when the first set of HW_IDs were output. It seems like static sink IDs could solve this with less repetition.
Quoted 3 lines
This sink ID could be part of the sink csdev struct - or even the
id_mapstruct - a simple count of sinks as the per sink maps are created would be sufficient. If this sink ID replaced the CPU+ID extra
We could also use the existing sink IDs that are used to select the sink on the perf commandline: coresight_get_sink_by_id().
Quoted 8 lines
data in the HWID packets, then each packet could be emitted just once, and perf can then collate based on the sink id.
Moreover, once we are ready to address the per-thread issues - then the overlap would not matter. Generate OpenCSD decode trees per sink ID, add docoders to the tree per Trace ID. Thus if a buffer has data from sink 1 trace id 5, ans sink 2, trace ID 5, then pick the right decoder for the combo.
The issue is more about trace in a single buffer with overlapping IDs. Whether we use a sink ID or the CPU+ID mappings, Perf still needs to know when to change the tree. In either case we'd have to re-emit the mappings to prompt the decoder change.
So yes with either solution there would be multiple decode trees, it's just knowing which fragments to send to which tree that's the issue.
Quoted 4 lines
Finally in systems with ETE+TRBE were there is no use of trace IDs, a sink ID of
0x0could potentially indicate that 1:1 relationship.
This is already indicated with the PERF_AUX_FLAG_CORESIGHT_FORMAT_RAW flag on the AUX record. But I suppose we could add sink ID 0x0 as well for consistency with the new HW_ID packets. For backwards compatibility it probably makes sense to continue using the AUX flag in Perf, but I'll see how it looks with the sink ID implementation.
James
Quoted 52 lines
Regards
Mike
Quoted 46 lines
James Clark (17):
perf cs-etm: Print error for newPERF_RECORD_AUX_OUTPUT_HW_IDversions perf auxtrace: Allow number of queues to be specified
perf: cs-etm: Create decoders after both AUX andHW_IDsearch passes
perf: cs-etm: Allocate queues for all CPUs
perf: cs-etm: Movetraceid_listto each queue
perf: cs-etm: Create decoders based on the trace ID mappings
perf: cs-etm: Support version 0.1 ofHW_IDpackets
coresight: Remove unused stubs
coresight: Clarify comments around the PID of the sink owner
coresight: Move structcoresight_trace_id_mapto common header
coresight: Expose map argument in trace ID API
coresight: Make CPU id map a property of a trace ID map
coresight: Pass trace ID map into source enable
coresight: Use per-sink trace ID maps for Perf sessions
coresight: Remove pending trace ID release mechanism
coresight: Re-emit trace IDs when the sink changes in per-thread mode
coresight: EmitHW_IDsfor all ETMs that are using the sinkdrivers/hwtracing/coresight/coresight-core.c | 10 + drivers/hwtracing/coresight/coresight-dummy.c | 3 +- .../hwtracing/coresight/coresight-etm-perf.c | 82 ++- .../hwtracing/coresight/coresight-etm-perf.h | 20 +- .../coresight/coresight-etm3x-core.c | 14 +- .../coresight/coresight-etm4x-core.c | 14 +- drivers/hwtracing/coresight/coresight-stm.c | 3 +- drivers/hwtracing/coresight/coresight-sysfs.c | 3 +- .../hwtracing/coresight/coresight-tmc-etr.c | 5 +- drivers/hwtracing/coresight/coresight-tmc.h | 5 +- drivers/hwtracing/coresight/coresight-tpdm.c | 3 +- .../hwtracing/coresight/coresight-trace-id.c | 107 +-- .../hwtracing/coresight/coresight-trace-id.h | 57 +- include/linux/coresight-pmu.h | 17 +- include/linux/coresight.h | 20 +- tools/include/linux/coresight-pmu.h | 17 +- tools/perf/util/auxtrace.c | 9 +- tools/perf/util/auxtrace.h | 1 + .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 28 +- tools/perf/util/cs-etm.c | 617 ++++++++++++------ tools/perf/util/cs-etm.h | 2 +- 21 files changed, 633 insertions(+), 404 deletions(-)--
2.34.1