libnexus-rv
trace-decoder.h
Go to the documentation of this file.
1 #ifndef LIBNEXUS_RV_TRACE_DECODER_H
2 #define LIBNEXUS_RV_TRACE_DECODER_H
3 
4 #include "msg-decoder.h"
5 #include "hist-array.h"
6 #include "return-stack.h"
7 
87 typedef struct nexusrv_trace_indirect {
88  uint64_t target;
89  uint64_t context;
91  struct {
92  uint8_t interrupt : 1;
93  uint8_t exception : 1;
94  uint8_t ownership : 1;
95  uint8_t ownership_fmt : 2;
96  uint8_t ownership_priv : 2;
97  uint8_t ownership_v : 1;
98  };
100 
103 typedef struct nexusrv_trace_sync {
104  uint64_t addr;
105  struct {
106  uint8_t sync : 4;
107  };
109 
112 typedef struct nexusrv_trace_error {
113  uint32_t ecode;
114  struct {
115  uint8_t etype : 4;
116  };
118 
121 typedef struct nexusrv_trace_stop {
122  uint8_t evcode : 4;
124 
128  NEXUSRV_Trace_Event_None,
129  NEXUSRV_Trace_Event_Direct,
130  NEXUSRV_Trace_Event_DirectSync,
131  NEXUSRV_Trace_Event_Trap,
132  NEXUSRV_Trace_Event_Indirect,
133  NEXUSRV_Trace_Event_IndirectSync,
134  NEXUSRV_Trace_Event_Sync,
135  NEXUSRV_Trace_Event_Stop,
136  NEXUSRV_Trace_Event_Error,
137 };
138 
139 static inline const char
140 *str_nexusrv_trace_event(unsigned event) {
141  switch (event) {
142  case NEXUSRV_Trace_Event_None:
143  return "none";
144  case NEXUSRV_Trace_Event_Direct:
145  return "direct";
146  case NEXUSRV_Trace_Event_DirectSync:
147  return "direct-sync";
148  case NEXUSRV_Trace_Event_Trap:
149  return "trap";
150  case NEXUSRV_Trace_Event_Indirect:
151  return "indirect";
152  case NEXUSRV_Trace_Event_IndirectSync:
153  return "indirect-sync";
154  case NEXUSRV_Trace_Event_Sync:
155  return "sync";
156  case NEXUSRV_Trace_Event_Stop:
157  return "stop";
158  case NEXUSRV_Trace_Event_Error:
159  return "error";
160  default:
161  return "unknown";
162  }
163 }
164 
165 
172 typedef struct nexusrv_trace_decoder {
175  struct nexusrv_hist_array* res_hists;
177  uint32_t res_icnt;
178  uint32_t res_tnts;
179  uint32_t consumed_icnt;
180  uint8_t consumed_tnts;
181  bool synced;
182  bool msg_present;
184  uint64_t full_addr;
185  uint64_t timestamp;
188 
202  nexusrv_msg_decoder *msg_decoder);
203 
211 
222 static inline uint64_t nexusrv_trace_time(nexusrv_trace_decoder* decoder) {
223  unsigned ts_bits = decoder->msg_decoder->hw_cfg->ts_bits;
224  if (ts_bits >= 64)
225  return decoder->timestamp;
226  return decoder->timestamp & (((uint64_t)1 << ts_bits) - 1);
227 }
228 
264  uint32_t icnt,
265  unsigned *event);
266 
283  nexusrv_trace_sync *sync);
284 
293 
294 void nexusrv_trace_push_call(nexusrv_trace_decoder* decoder,
295  uint64_t callsite);
296 
297 int nexusrv_trace_pop_ret(nexusrv_trace_decoder* decoder,
298  uint64_t *callsite);
299 
300 unsigned nexusrv_trace_callstack_used(nexusrv_trace_decoder* decoder);
301 
310  nexusrv_trace_indirect *indirect);
311 
320  nexusrv_trace_sync *sync);
321 
330  nexusrv_trace_error *error);
331 
340  nexusrv_trace_stop *stop);
341 
342 #endif
unsigned ts_bits
Definition: msg-decoder.h:25
NexusRV Message decoder context.
Definition: msg-decoder.h:38
const nexusrv_hw_cfg * hw_cfg
Definition: msg-decoder.h:39
Decoded NexusRV Message.
Definition: msg-types.h:92
Definition: return-stack.h:8
NexusRV Trace decoder context.
Definition: trace-decoder.h:172
uint64_t full_addr
Definition: trace-decoder.h:184
struct nexusrv_hist_array * res_hists
Definition: trace-decoder.h:175
nexusrv_msg msg
Definition: trace-decoder.h:183
uint32_t res_icnt
Definition: trace-decoder.h:177
uint8_t consumed_tnts
Definition: trace-decoder.h:180
nexusrv_return_stack return_stack
Definition: trace-decoder.h:186
uint32_t consumed_icnt
Definition: trace-decoder.h:179
bool msg_present
Definition: trace-decoder.h:182
uint64_t timestamp
Definition: trace-decoder.h:185
uint32_t res_tnts
Definition: trace-decoder.h:178
nexusrv_msg_decoder * msg_decoder
Definition: trace-decoder.h:173
bool synced
Definition: trace-decoder.h:181
NexusRV Trace Error Event.
Definition: trace-decoder.h:112
uint32_t ecode
Definition: trace-decoder.h:113
uint8_t etype
Definition: trace-decoder.h:115
NexusRV Trace Indirect Branch Event.
Definition: trace-decoder.h:87
uint8_t interrupt
Definition: trace-decoder.h:92
uint8_t ownership_priv
Definition: trace-decoder.h:96
uint8_t ownership_v
Definition: trace-decoder.h:97
uint8_t ownership
Definition: trace-decoder.h:93
uint64_t context
Definition: trace-decoder.h:89
uint8_t ownership_fmt
Definition: trace-decoder.h:95
uint64_t target
Definition: trace-decoder.h:88
NexusRV Stop Event.
Definition: trace-decoder.h:121
uint8_t evcode
Definition: trace-decoder.h:122
NexusRV Trace Sync Event.
Definition: trace-decoder.h:103
uint64_t addr
Definition: trace-decoder.h:104
uint8_t sync
Definition: trace-decoder.h:106
int nexusrv_trace_decoder_init(nexusrv_trace_decoder *decoder, nexusrv_msg_decoder *msg_decoder)
Initialize the trace decoder.
int32_t nexusrv_trace_try_retire(nexusrv_trace_decoder *decoder, uint32_t icnt, unsigned *event)
Try to retire icnt from trace.
int nexusrv_trace_next_tnt(nexusrv_trace_decoder *decoder)
Get the next taken-not-taken.
int nexusrv_trace_sync_reset(nexusrv_trace_decoder *decoder, nexusrv_trace_sync *sync)
Synchronize the trace decoder.
struct nexusrv_trace_sync nexusrv_trace_sync
NexusRV Trace Sync Event.
nexusrv_trace_events
NexusRV trace events.
Definition: trace-decoder.h:127
void nexusrv_trace_decoder_fini(nexusrv_trace_decoder *decoder)
Finialize the trace decoder.
struct nexusrv_trace_error nexusrv_trace_error
NexusRV Trace Error Event.
int nexusrv_trace_next_stop(nexusrv_trace_decoder *decoder, nexusrv_trace_stop *stop)
Get the next Stop event.
struct nexusrv_trace_decoder nexusrv_trace_decoder
NexusRV Trace decoder context.
int nexusrv_trace_next_error(nexusrv_trace_decoder *decoder, nexusrv_trace_error *error)
Get the next Error event.
struct nexusrv_trace_stop nexusrv_trace_stop
NexusRV Stop Event.
struct nexusrv_trace_indirect nexusrv_trace_indirect
NexusRV Trace Indirect Branch Event.
int nexusrv_trace_next_indirect(nexusrv_trace_decoder *decoder, nexusrv_trace_indirect *indirect)
Get the next indirect branch.
int nexusrv_trace_next_sync(nexusrv_trace_decoder *decoder, nexusrv_trace_sync *sync)
Get the next Sync event.