@@ -283,22 +283,31 @@ static int cs_etm__metadata_set_trace_id(u8 trace_chan_id, u64 *cpu_metadata)
283
283
}
284
284
285
285
/*
286
- * Get a metadata for a specific cpu from an array.
286
+ * Get a metadata index for a specific cpu from an array.
287
287
*
288
288
*/
289
- static u64 * get_cpu_data (struct cs_etm_auxtrace * etm , int cpu )
289
+ static int get_cpu_data_idx (struct cs_etm_auxtrace * etm , int cpu )
290
290
{
291
291
int i ;
292
- u64 * metadata = NULL ;
293
292
294
293
for (i = 0 ; i < etm -> num_cpu ; i ++ ) {
295
294
if (etm -> metadata [i ][CS_ETM_CPU ] == (u64 )cpu ) {
296
- metadata = etm -> metadata [i ];
297
- break ;
295
+ return i ;
298
296
}
299
297
}
300
298
301
- return metadata ;
299
+ return -1 ;
300
+ }
301
+
302
+ /*
303
+ * Get a metadata for a specific cpu from an array.
304
+ *
305
+ */
306
+ static u64 * get_cpu_data (struct cs_etm_auxtrace * etm , int cpu )
307
+ {
308
+ int idx = get_cpu_data_idx (etm , cpu );
309
+
310
+ return (idx != -1 ) ? etm -> metadata [idx ] : NULL ;
302
311
}
303
312
304
313
/*
@@ -641,66 +650,80 @@ static void cs_etm__packet_dump(const char *pkt_string)
641
650
}
642
651
643
652
static void cs_etm__set_trace_param_etmv3 (struct cs_etm_trace_params * t_params ,
644
- struct cs_etm_auxtrace * etm , int idx ,
645
- u32 etmidr )
653
+ struct cs_etm_auxtrace * etm , int t_idx ,
654
+ int m_idx , u32 etmidr )
646
655
{
647
656
u64 * * metadata = etm -> metadata ;
648
657
649
- t_params [idx ].protocol = cs_etm__get_v7_protocol_version (etmidr );
650
- t_params [idx ].etmv3 .reg_ctrl = metadata [idx ][CS_ETM_ETMCR ];
651
- t_params [idx ].etmv3 .reg_trc_id = metadata [idx ][CS_ETM_ETMTRACEIDR ];
658
+ t_params [t_idx ].protocol = cs_etm__get_v7_protocol_version (etmidr );
659
+ t_params [t_idx ].etmv3 .reg_ctrl = metadata [m_idx ][CS_ETM_ETMCR ];
660
+ t_params [t_idx ].etmv3 .reg_trc_id = metadata [m_idx ][CS_ETM_ETMTRACEIDR ];
652
661
}
653
662
654
663
static void cs_etm__set_trace_param_etmv4 (struct cs_etm_trace_params * t_params ,
655
- struct cs_etm_auxtrace * etm , int idx )
664
+ struct cs_etm_auxtrace * etm , int t_idx ,
665
+ int m_idx )
656
666
{
657
667
u64 * * metadata = etm -> metadata ;
658
668
659
- t_params [idx ].protocol = CS_ETM_PROTO_ETMV4i ;
660
- t_params [idx ].etmv4 .reg_idr0 = metadata [idx ][CS_ETMV4_TRCIDR0 ];
661
- t_params [idx ].etmv4 .reg_idr1 = metadata [idx ][CS_ETMV4_TRCIDR1 ];
662
- t_params [idx ].etmv4 .reg_idr2 = metadata [idx ][CS_ETMV4_TRCIDR2 ];
663
- t_params [idx ].etmv4 .reg_idr8 = metadata [idx ][CS_ETMV4_TRCIDR8 ];
664
- t_params [idx ].etmv4 .reg_configr = metadata [idx ][CS_ETMV4_TRCCONFIGR ];
665
- t_params [idx ].etmv4 .reg_traceidr = metadata [idx ][CS_ETMV4_TRCTRACEIDR ];
669
+ t_params [t_idx ].protocol = CS_ETM_PROTO_ETMV4i ;
670
+ t_params [t_idx ].etmv4 .reg_idr0 = metadata [m_idx ][CS_ETMV4_TRCIDR0 ];
671
+ t_params [t_idx ].etmv4 .reg_idr1 = metadata [m_idx ][CS_ETMV4_TRCIDR1 ];
672
+ t_params [t_idx ].etmv4 .reg_idr2 = metadata [m_idx ][CS_ETMV4_TRCIDR2 ];
673
+ t_params [t_idx ].etmv4 .reg_idr8 = metadata [m_idx ][CS_ETMV4_TRCIDR8 ];
674
+ t_params [t_idx ].etmv4 .reg_configr = metadata [m_idx ][CS_ETMV4_TRCCONFIGR ];
675
+ t_params [t_idx ].etmv4 .reg_traceidr = metadata [m_idx ][CS_ETMV4_TRCTRACEIDR ];
666
676
}
667
677
668
678
static void cs_etm__set_trace_param_ete (struct cs_etm_trace_params * t_params ,
669
- struct cs_etm_auxtrace * etm , int idx )
679
+ struct cs_etm_auxtrace * etm , int t_idx ,
680
+ int m_idx )
670
681
{
671
682
u64 * * metadata = etm -> metadata ;
672
683
673
- t_params [idx ].protocol = CS_ETM_PROTO_ETE ;
674
- t_params [idx ].ete .reg_idr0 = metadata [idx ][CS_ETE_TRCIDR0 ];
675
- t_params [idx ].ete .reg_idr1 = metadata [idx ][CS_ETE_TRCIDR1 ];
676
- t_params [idx ].ete .reg_idr2 = metadata [idx ][CS_ETE_TRCIDR2 ];
677
- t_params [idx ].ete .reg_idr8 = metadata [idx ][CS_ETE_TRCIDR8 ];
678
- t_params [idx ].ete .reg_configr = metadata [idx ][CS_ETE_TRCCONFIGR ];
679
- t_params [idx ].ete .reg_traceidr = metadata [idx ][CS_ETE_TRCTRACEIDR ];
680
- t_params [idx ].ete .reg_devarch = metadata [idx ][CS_ETE_TRCDEVARCH ];
684
+ t_params [t_idx ].protocol = CS_ETM_PROTO_ETE ;
685
+ t_params [t_idx ].ete .reg_idr0 = metadata [m_idx ][CS_ETE_TRCIDR0 ];
686
+ t_params [t_idx ].ete .reg_idr1 = metadata [m_idx ][CS_ETE_TRCIDR1 ];
687
+ t_params [t_idx ].ete .reg_idr2 = metadata [m_idx ][CS_ETE_TRCIDR2 ];
688
+ t_params [t_idx ].ete .reg_idr8 = metadata [m_idx ][CS_ETE_TRCIDR8 ];
689
+ t_params [t_idx ].ete .reg_configr = metadata [m_idx ][CS_ETE_TRCCONFIGR ];
690
+ t_params [t_idx ].ete .reg_traceidr = metadata [m_idx ][CS_ETE_TRCTRACEIDR ];
691
+ t_params [t_idx ].ete .reg_devarch = metadata [m_idx ][CS_ETE_TRCDEVARCH ];
681
692
}
682
693
683
694
static int cs_etm__init_trace_params (struct cs_etm_trace_params * t_params ,
684
695
struct cs_etm_auxtrace * etm ,
696
+ bool formatted ,
697
+ int sample_cpu ,
685
698
int decoders )
686
699
{
687
- int i ;
700
+ int t_idx , m_idx ;
688
701
u32 etmidr ;
689
702
u64 architecture ;
690
703
691
- for (i = 0 ; i < decoders ; i ++ ) {
692
- architecture = etm -> metadata [i ][CS_ETM_MAGIC ];
704
+ for (t_idx = 0 ; t_idx < decoders ; t_idx ++ ) {
705
+ if (formatted )
706
+ m_idx = t_idx ;
707
+ else {
708
+ m_idx = get_cpu_data_idx (etm , sample_cpu );
709
+ if (m_idx == -1 ) {
710
+ pr_warning ("CS_ETM: unknown CPU, falling back to first metadata\n" );
711
+ m_idx = 0 ;
712
+ }
713
+ }
714
+
715
+ architecture = etm -> metadata [m_idx ][CS_ETM_MAGIC ];
693
716
694
717
switch (architecture ) {
695
718
case __perf_cs_etmv3_magic :
696
- etmidr = etm -> metadata [i ][CS_ETM_ETMIDR ];
697
- cs_etm__set_trace_param_etmv3 (t_params , etm , i , etmidr );
719
+ etmidr = etm -> metadata [m_idx ][CS_ETM_ETMIDR ];
720
+ cs_etm__set_trace_param_etmv3 (t_params , etm , t_idx , m_idx , etmidr );
698
721
break ;
699
722
case __perf_cs_etmv4_magic :
700
- cs_etm__set_trace_param_etmv4 (t_params , etm , i );
723
+ cs_etm__set_trace_param_etmv4 (t_params , etm , t_idx , m_idx );
701
724
break ;
702
725
case __perf_cs_ete_magic :
703
- cs_etm__set_trace_param_ete (t_params , etm , i );
726
+ cs_etm__set_trace_param_ete (t_params , etm , t_idx , m_idx );
704
727
break ;
705
728
default :
706
729
return - EINVAL ;
@@ -1016,7 +1039,7 @@ static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u8 trace_chan_id,
1016
1039
}
1017
1040
1018
1041
static struct cs_etm_queue * cs_etm__alloc_queue (struct cs_etm_auxtrace * etm ,
1019
- bool formatted )
1042
+ bool formatted , int sample_cpu )
1020
1043
{
1021
1044
struct cs_etm_decoder_params d_params ;
1022
1045
struct cs_etm_trace_params * t_params = NULL ;
@@ -1041,7 +1064,7 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm,
1041
1064
if (!t_params )
1042
1065
goto out_free ;
1043
1066
1044
- if (cs_etm__init_trace_params (t_params , etm , decoders ))
1067
+ if (cs_etm__init_trace_params (t_params , etm , formatted , sample_cpu , decoders ))
1045
1068
goto out_free ;
1046
1069
1047
1070
/* Set decoder parameters to decode trace packets */
@@ -1081,14 +1104,15 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm,
1081
1104
static int cs_etm__setup_queue (struct cs_etm_auxtrace * etm ,
1082
1105
struct auxtrace_queue * queue ,
1083
1106
unsigned int queue_nr ,
1084
- bool formatted )
1107
+ bool formatted ,
1108
+ int sample_cpu )
1085
1109
{
1086
1110
struct cs_etm_queue * etmq = queue -> priv ;
1087
1111
1088
1112
if (list_empty (& queue -> head ) || etmq )
1089
1113
return 0 ;
1090
1114
1091
- etmq = cs_etm__alloc_queue (etm , formatted );
1115
+ etmq = cs_etm__alloc_queue (etm , formatted , sample_cpu );
1092
1116
1093
1117
if (!etmq )
1094
1118
return - ENOMEM ;
@@ -2816,7 +2840,7 @@ static int cs_etm__process_auxtrace_event(struct perf_session *session,
2816
2840
* formatted in piped mode (true).
2817
2841
*/
2818
2842
err = cs_etm__setup_queue (etm , & etm -> queues .queue_array [idx ],
2819
- idx , true);
2843
+ idx , true, -1 );
2820
2844
if (err )
2821
2845
return err ;
2822
2846
@@ -3022,7 +3046,7 @@ static int cs_etm__queue_aux_fragment(struct perf_session *session, off_t file_o
3022
3046
idx = auxtrace_event -> idx ;
3023
3047
formatted = !(aux_event -> flags & PERF_AUX_FLAG_CORESIGHT_FORMAT_RAW );
3024
3048
return cs_etm__setup_queue (etm , & etm -> queues .queue_array [idx ],
3025
- idx , formatted );
3049
+ idx , formatted , sample -> cpu );
3026
3050
}
3027
3051
3028
3052
/* Wasn't inside this buffer, but there were no parse errors. 1 == 'not found' */
0 commit comments