26
26
27
27
#include <nuttx/config.h>
28
28
29
+ #include <execinfo.h>
29
30
#include <inttypes.h>
30
31
#include <stdio.h>
31
32
#include <stdbool.h>
56
57
* Private Types
57
58
****************************************************************************/
58
59
60
+ struct rptun_trace_s
61
+ {
62
+ FAR void * hdr ;
63
+ FAR void * backtrace [16 ];
64
+ };
65
+
59
66
struct rptun_priv_s
60
67
{
61
68
struct rpmsg_s rpmsg ;
@@ -64,6 +71,7 @@ struct rptun_priv_s
64
71
struct remoteproc rproc ;
65
72
struct rpmsg_virtio_shm_pool pool [2 ];
66
73
sem_t semtx ;
74
+ FAR struct rptun_trace_s * traces ;
67
75
sem_t semrx ;
68
76
pid_t tid ;
69
77
uint16_t headrx ;
@@ -128,6 +136,20 @@ static void rptun_panic(FAR struct rpmsg_s *rpmsg);
128
136
static void rptun_dump (FAR struct rpmsg_s * rpmsg );
129
137
static FAR const char * rptun_get_local_cpuname (FAR struct rpmsg_s * rpmsg );
130
138
static FAR const char * rptun_get_cpuname (FAR struct rpmsg_s * rpmsg );
139
+ #ifdef CONFIG_OPENAMP_RPMSG_TRACE
140
+ static void rptun_trace_init (FAR struct rptun_priv_s * priv );
141
+ static void rptun_trace_uninit (FAR struct rptun_priv_s * priv );
142
+ static void rptun_trace_get_tx_buffer (FAR struct rpmsg_device * rdev ,
143
+ FAR void * hdr );
144
+ static void rptun_trace_release_tx_buffer (FAR struct rpmsg_device * rdev ,
145
+ FAR void * hdr );
146
+ static void rptun_dump_trace (FAR struct rpmsg_virtio_device * rvdev );
147
+
148
+ #else
149
+ # define rptun_trace_init (priv )
150
+ # define rptun_trace_uninit (priv )
151
+ # define rptun_dump_trace (rvdev );
152
+ #endif
131
153
132
154
/****************************************************************************
133
155
* Private Data
@@ -722,6 +744,8 @@ static void rptun_dump(FAR struct rpmsg_s *rpmsg)
722
744
metal_mutex_acquire (& rdev -> lock );
723
745
}
724
746
747
+ rptun_dump_trace (rvdev );
748
+
725
749
metal_log (METAL_LOG_EMERGENCY ,
726
750
"Dump rpmsg info between cpu (master: %s)%s <==> %s:\n" ,
727
751
rpmsg_virtio_get_role (rvdev ) == RPMSG_HOST ? "yes" : "no" ,
@@ -918,6 +942,7 @@ static int rptun_dev_start(FAR struct remoteproc *rproc)
918
942
return ret ;
919
943
}
920
944
945
+ rptun_trace_init (priv );
921
946
priv -> rvdev .rdev .ns_unbind_cb = rpmsg_ns_unbind ;
922
947
priv -> rvdev .notify_wait_cb = rptun_notify_wait ;
923
948
@@ -981,6 +1006,7 @@ static int rptun_dev_stop(FAR struct remoteproc *rproc, bool stop_ns)
981
1006
/* Remote proc stop and shutdown */
982
1007
983
1008
remoteproc_shutdown (rproc );
1009
+ rptun_trace_uninit (priv );
984
1010
985
1011
return OK ;
986
1012
}
@@ -1113,6 +1139,130 @@ static metal_phys_addr_t rptun_da_to_pa(FAR struct rptun_dev_s *dev,
1113
1139
return da ;
1114
1140
}
1115
1141
1142
+ #ifdef CONFIG_OPENAMP_RPMSG_TRACE
1143
+ static void * rptun_get_priv_by_rdev (FAR struct rpmsg_device * rdev )
1144
+ {
1145
+ FAR struct rpmsg_virtio_device * rvdev ;
1146
+ FAR struct virtio_device * vdev ;
1147
+ FAR struct remoteproc_virtio * rpvdev ;
1148
+ FAR struct remoteproc * rproc ;
1149
+
1150
+ if (!rdev )
1151
+ {
1152
+ return NULL ;
1153
+ }
1154
+
1155
+ rvdev = metal_container_of (rdev , struct rpmsg_virtio_device , rdev );
1156
+ vdev = rvdev -> vdev ;
1157
+ if (!vdev )
1158
+ {
1159
+ return NULL ;
1160
+ }
1161
+
1162
+ rpvdev = metal_container_of (vdev , struct remoteproc_virtio , vdev );
1163
+ rproc = rpvdev -> priv ;
1164
+ if (!rproc )
1165
+ {
1166
+ return NULL ;
1167
+ }
1168
+
1169
+ return rproc -> priv ;
1170
+ }
1171
+
1172
+ static void rptun_trace_init (FAR struct rptun_priv_s * priv )
1173
+ {
1174
+ int txnum = priv -> rvdev .svq -> vq_nentries ;
1175
+
1176
+ priv -> traces = kmm_zalloc (sizeof (* priv -> traces ) * txnum );
1177
+ DEBUGASSERT (priv -> traces != NULL );
1178
+
1179
+ priv -> rvdev .rdev .trace .get_tx_buffer = rptun_trace_get_tx_buffer ;
1180
+ priv -> rvdev .rdev .trace .release_tx_buffer = rptun_trace_release_tx_buffer ;
1181
+ }
1182
+
1183
+ static void rptun_trace_uninit (FAR struct rptun_priv_s * priv )
1184
+ {
1185
+ priv -> rvdev .rdev .trace .get_tx_buffer = NULL ;
1186
+ priv -> rvdev .rdev .trace .release_tx_buffer = NULL ;
1187
+
1188
+ kmm_free (priv -> traces );
1189
+ }
1190
+
1191
+ static void rptun_trace_get_tx_buffer (FAR struct rpmsg_device * rdev ,
1192
+ FAR void * hdr )
1193
+ {
1194
+ FAR struct rptun_priv_s * priv = rptun_get_priv_by_rdev (rdev );
1195
+ int txnum = priv -> rvdev .svq -> vq_nentries ;
1196
+ int i ;
1197
+
1198
+ for (i = 0 ; i < txnum ; i ++ )
1199
+ {
1200
+ if (priv -> traces [i ].hdr == NULL )
1201
+ {
1202
+ break ;
1203
+ }
1204
+ }
1205
+
1206
+ if (i >= txnum )
1207
+ {
1208
+ metal_log (METAL_LOG_EMERGENCY , "Not find empty buffer i=%d num=%d\n" ,
1209
+ i , txnum );
1210
+ PANIC ();
1211
+ }
1212
+
1213
+ priv -> traces [i ].hdr = hdr ;
1214
+ backtrace (priv -> traces [i ].backtrace , 16 );
1215
+ }
1216
+
1217
+ static void rptun_trace_release_tx_buffer (FAR struct rpmsg_device * rdev ,
1218
+ FAR void * hdr )
1219
+ {
1220
+ FAR struct rptun_priv_s * priv = rptun_get_priv_by_rdev (rdev );
1221
+ int txnum = priv -> rvdev .svq -> vq_nentries ;
1222
+ int i ;
1223
+ int j ;
1224
+
1225
+ for (i = 0 ; i < txnum ; i ++ )
1226
+ {
1227
+ if (priv -> traces [i ].hdr == hdr )
1228
+ {
1229
+ break ;
1230
+ }
1231
+ }
1232
+
1233
+ if (i >= txnum )
1234
+ {
1235
+ metal_log (METAL_LOG_EMERGENCY , "Not find tx buffer i=%d num=%d\n" ,
1236
+ i , txnum );
1237
+ PANIC ();
1238
+ }
1239
+
1240
+ priv -> traces [i ].hdr = NULL ;
1241
+
1242
+ for (j = 0 ; j < 16 ; j ++ )
1243
+ {
1244
+ priv -> traces [i ].backtrace [j ] = NULL ;
1245
+ }
1246
+ }
1247
+
1248
+ static void rptun_dump_trace (FAR struct rpmsg_virtio_device * rvdev )
1249
+ {
1250
+ FAR struct rptun_priv_s * priv = rptun_get_priv_by_rdev (& rvdev -> rdev );
1251
+ char backtrace [256 ];
1252
+ int txnum = rvdev -> svq -> vq_nentries ;
1253
+ int i ;
1254
+
1255
+ metal_log (METAL_LOG_EMERGENCY , "Dump not released tx buffer:\n" );
1256
+ for (i = 0 ; i < txnum ; i ++ )
1257
+ {
1258
+ backtrace_format (backtrace , sizeof (backtrace ),
1259
+ priv -> traces [i ].backtrace , 16 );
1260
+ metal_log (METAL_LOG_EMERGENCY , "hdr: %p backtrace: %s\n" ,
1261
+ priv -> traces [i ].hdr , backtrace );
1262
+ }
1263
+ }
1264
+ #endif
1265
+
1116
1266
/****************************************************************************
1117
1267
* Public Functions
1118
1268
****************************************************************************/
0 commit comments