diff mbox series

coresight: perf: Output trace id only once

Message ID 20230120103434.864318-1-suzuki.poulose@arm.com (mailing list archive)
State New, archived
Headers show
Series coresight: perf: Output trace id only once | expand

Commit Message

Suzuki K Poulose Jan. 20, 2023, 10:34 a.m. UTC
With the dynamic traceid allocation scheme in, we output the
AUX_OUTPUT_HWID packet every time event->start() is called.
This could cause too many such records in the perf.data,
while only one per CPU throughout the life time of
the event is required. Make sure we only output it once.

Before this patch:
  $ perf report -D | grep OUTPUT_HW_ID
  ...
  AUX_OUTPUT_HW_ID events:         55  (18.3%)

After this patch:

 $ perf report -D | grep OUTPUT_HW_ID
 ...
 AUX_OUTPUT_HW_ID events:          5  ( 1.9%)

Cc: Mike Leach <mike.leach@linaro.org>
Cc: James Clark <james.clark@arm.com>
Cc: Leo Yan <leo.yan@linaro.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/hwtracing/coresight/coresight-etm-perf.c | 16 ++++++++++++----
 drivers/hwtracing/coresight/coresight-etm-perf.h |  2 ++
 2 files changed, 14 insertions(+), 4 deletions(-)

Comments

James Clark Jan. 20, 2023, 3:43 p.m. UTC | #1
On 20/01/2023 10:34, Suzuki K Poulose wrote:
> With the dynamic traceid allocation scheme in, we output the
> AUX_OUTPUT_HWID packet every time event->start() is called.
> This could cause too many such records in the perf.data,
> while only one per CPU throughout the life time of
> the event is required. Make sure we only output it once.
> 
> Before this patch:
>   $ perf report -D | grep OUTPUT_HW_ID
>   ...
>   AUX_OUTPUT_HW_ID events:         55  (18.3%)
> 
> After this patch:
> 
>  $ perf report -D | grep OUTPUT_HW_ID
>  ...
>  AUX_OUTPUT_HW_ID events:          5  ( 1.9%)
> 
> Cc: Mike Leach <mike.leach@linaro.org>
> Cc: James Clark <james.clark@arm.com>
> Cc: Leo Yan <leo.yan@linaro.org>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
>  drivers/hwtracing/coresight/coresight-etm-perf.c | 16 ++++++++++++----
>  drivers/hwtracing/coresight/coresight-etm-perf.h |  2 ++
>  2 files changed, 14 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c
> index 12fff661456e..a48c97da8165 100644
> --- a/drivers/hwtracing/coresight/coresight-etm-perf.c
> +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
> @@ -495,10 +495,18 @@ static void etm_event_start(struct perf_event *event, int flags)
>  	if (source_ops(csdev)->enable(csdev, event, CS_MODE_PERF))
>  		goto fail_disable_path;
>  
> -	/* output cpu / trace ID in perf record */
> -	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));
> -	perf_report_aux_output_id(event, hw_id);
> +	/*
> +	 * output cpu / trace ID in perf record, once for the lifetime
> +	 * of the event.
> +	 */
> +	if (!cpumask_test_cpu(cpu, &event_data->aux_hwid_done)) {
> +		cpumask_set_cpu(cpu, &event_data->aux_hwid_done);

I had a look for somewhere that's only called once after the aux buffer
is available to avoid the new tracking bit, but didn't find anywhere
obvious. We can always move it later anyway.

Reviewed-by: James Clark <james.clark@arm.com>

> +		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));
> +		perf_report_aux_output_id(event, hw_id);
> +	}
>  
>  out:
>  	/* Tell the perf core the event is alive */
> diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.h b/drivers/hwtracing/coresight/coresight-etm-perf.h
> index 468f7799ab4f..bebbadee2ceb 100644
> --- a/drivers/hwtracing/coresight/coresight-etm-perf.h
> +++ b/drivers/hwtracing/coresight/coresight-etm-perf.h
> @@ -48,6 +48,7 @@ struct etm_filters {
>   * struct etm_event_data - Coresight specifics associated to an event
>   * @work:		Handle to free allocated memory outside IRQ context.
>   * @mask:		Hold the CPU(s) this event was set for.
> + * @aux_hwid_done:	Whether a CPU has emitted the TraceID packet or not.
>   * @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.
> @@ -55,6 +56,7 @@ struct etm_filters {
>  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;
Suzuki K Poulose Jan. 24, 2023, 10:43 a.m. UTC | #2
On 20/01/2023 15:43, James Clark wrote:
> 
> 
> On 20/01/2023 10:34, Suzuki K Poulose wrote:
>> With the dynamic traceid allocation scheme in, we output the
>> AUX_OUTPUT_HWID packet every time event->start() is called.
>> This could cause too many such records in the perf.data,
>> while only one per CPU throughout the life time of
>> the event is required. Make sure we only output it once.
>>
>> Before this patch:
>>    $ perf report -D | grep OUTPUT_HW_ID
>>    ...
>>    AUX_OUTPUT_HW_ID events:         55  (18.3%)
>>
>> After this patch:
>>
>>   $ perf report -D | grep OUTPUT_HW_ID
>>   ...
>>   AUX_OUTPUT_HW_ID events:          5  ( 1.9%)
>>
>> Cc: Mike Leach <mike.leach@linaro.org>
>> Cc: James Clark <james.clark@arm.com>
>> Cc: Leo Yan <leo.yan@linaro.org>
>> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
>> ---
>>   drivers/hwtracing/coresight/coresight-etm-perf.c | 16 ++++++++++++----
>>   drivers/hwtracing/coresight/coresight-etm-perf.h |  2 ++
>>   2 files changed, 14 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c
>> index 12fff661456e..a48c97da8165 100644
>> --- a/drivers/hwtracing/coresight/coresight-etm-perf.c
>> +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
>> @@ -495,10 +495,18 @@ static void etm_event_start(struct perf_event *event, int flags)
>>   	if (source_ops(csdev)->enable(csdev, event, CS_MODE_PERF))
>>   		goto fail_disable_path;
>>   
>> -	/* output cpu / trace ID in perf record */
>> -	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));
>> -	perf_report_aux_output_id(event, hw_id);
>> +	/*
>> +	 * output cpu / trace ID in perf record, once for the lifetime
>> +	 * of the event.
>> +	 */
>> +	if (!cpumask_test_cpu(cpu, &event_data->aux_hwid_done)) {
>> +		cpumask_set_cpu(cpu, &event_data->aux_hwid_done);
> 
> I had a look for somewhere that's only called once after the aux buffer
> is available to avoid the new tracking bit, but didn't find anywhere
> obvious. We can always move it later anyway.
> 
> Reviewed-by: James Clark <james.clark@arm.com>
> 

Thanks, pushed to next

https://git.kernel.org/coresight/c/a646ca099b18

Suzuki
diff mbox series

Patch

diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c
index 12fff661456e..a48c97da8165 100644
--- a/drivers/hwtracing/coresight/coresight-etm-perf.c
+++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
@@ -495,10 +495,18 @@  static void etm_event_start(struct perf_event *event, int flags)
 	if (source_ops(csdev)->enable(csdev, event, CS_MODE_PERF))
 		goto fail_disable_path;
 
-	/* output cpu / trace ID in perf record */
-	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));
-	perf_report_aux_output_id(event, hw_id);
+	/*
+	 * output cpu / trace ID in perf record, once for the lifetime
+	 * of the event.
+	 */
+	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));
+		perf_report_aux_output_id(event, hw_id);
+	}
 
 out:
 	/* Tell the perf core the event is alive */
diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.h b/drivers/hwtracing/coresight/coresight-etm-perf.h
index 468f7799ab4f..bebbadee2ceb 100644
--- a/drivers/hwtracing/coresight/coresight-etm-perf.h
+++ b/drivers/hwtracing/coresight/coresight-etm-perf.h
@@ -48,6 +48,7 @@  struct etm_filters {
  * struct etm_event_data - Coresight specifics associated to an event
  * @work:		Handle to free allocated memory outside IRQ context.
  * @mask:		Hold the CPU(s) this event was set for.
+ * @aux_hwid_done:	Whether a CPU has emitted the TraceID packet or not.
  * @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.
@@ -55,6 +56,7 @@  struct etm_filters {
 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;