Standard Support Packet v1.0 extension to Efficient Trace for RISC-V v2.0
Standard Support Packet v1.0 extension to Efficient Trace for RISC-V v2.0
|
This chapter is in the Ratified state.
No changes are allowed. Any desired or needed changes can be the subject of a follow-on new extension. Ratified extensions are never revised. |
The Efficient Trace for RISC-V v2.0 specification defines a support packet (see Format 3 Subformat 3) and when it must be sent. The general requirements for the content of this packet are described, but the exact details of the payload is left to the implementor. The original thinking was that this left flexibility for different encoder implementations to provide support information best suited to their specific capabilities, as well as allowing implementation-specific customizations.
However, this flexibility presents difficulties for applications such as Self-hosted Trace, where the operating system and decoding software need a single, consistent, standardized format. Furthermore, correct trace decoding is dependent on several discoverable attributes of the trace encoder. But in a Self-hosted context, the decoder will not be aware of which physical encoder instance is producing the trace it is decoding, and so will be unable to discover these attributes. This issue can be addressed by including these attributes directly in the support packet.
Additionally, the fully orthogonal Implicit Return and Multi-Memory Access and Compare and Swap extensions introduce revised te_inst and te_data packet formats, but the monotonically increasing protocol version does not provide a mechansim to indicate independent presence or absence of these extentions (see trTeImpl.trTeProtocolMajor and trTeImpl.trTeProtocolMinor in RISC-V Trace Control Interface Specification). This can resolved by indicating the presence of thes extensions directly in the support packet.
If this extension is implemented, the protocol version must be 2.1 or higher; if the protocol version is 2.1 or higher, this extension must be implemented.
This extension is required by the following extensions:
-
Smstrce* and Ssstrce* (Self-Hosted Trace)
-
Implicit Return extension to Efficient Trace for RISC-V v2.0 (see Implicit Return v1.0 extension to Efficient Trace for RISC-V v2.0)
-
Data Trace of Multiple-Memory Access and Compare and Swap extension to Efficient Trace for RISC-V v2.0 (see Data Trace of Multiple-Memory Access and Compare and Swap v1.0 extension to Efficient Trace for RISC-V v2.0)
Standard Support Packet format
| Field name | Bits | Description |
|---|---|---|
format |
2 |
11 (sync): synchronisation |
subformat |
2 |
11 (support): Supporting information for the decoder |
ienable |
1 |
Indicates if the instruction trace encoder is enabled |
encoder_mode |
2 |
Identifies trace algorithm. Currently Branch trace is the only mode defined, indicated by the value 0. |
qual_status |
2 |
00 (no_change): No change to filter qualification |
sijump |
1 |
When 1, targets of sequentially inferrable jumps not reported (see Sequentially Inferrable Jumps). |
implicit_return |
1 |
When 1, implicit return mode enabled (see Implicit Return). |
branch_predictor |
1 |
When 1, branch predictor enabled (see Branch Prediction). |
jump_target_cache |
1 |
When 1, jump target cache enabled (see Jump Target Cache). |
implicit_except |
1 |
When 1, implicit exception mode enabled (see Implicit Exception). |
full_iaddress |
1 |
When 1, te_inst packets always contain full (i.e. non-differential) addresses (see Full Address). |
resync_disabled |
1 |
When 1 indicates that resynchronization is disabled (trTeControl.trTeInstSyncMode == 0). |
iret_ext |
1 |
When 1, Implicit Return extension to E-trace v2.0 implemented. [Add link when extensions merged] |
time_width |
3 |
The width of the time field in sync-start and sync-trap packets (time_width_p) is 16 * time_width bits. |
f0s_width |
2 |
The value of f0s_width_p |
return_stack_size |
3 |
The number of entries in the return address stack is 2return_stack_size (no stack if 0). |
call_counter_size |
4 |
The number of bits in the call counter is 2call_counter_size (no counter if 0). |
bpred_size |
3 |
The number of entries in the branch predictor is 2bpred_size (no predictor if 0). |
cache_size |
3 |
The number of entries in the jump target cache is 2cache_size (no cache if 0). |
denable |
1 |
Indicates if data trace is enabled (if supported). |
dloss |
1 |
One of more data trace packets lost (if supported). |
mmacas_ext |
1 |
When 1, Multi-Memory Access and Compare & Swap extension to E-trace v2.0 implemented. [Add link when extensions merged] |
noaddr |
1 |
When 1, te_data packets exclude addresses (just report data). |
nodata |
1 |
When 1, te_data packets exclude data (just report addresses). |
full_daddress |
1 |
When 1, addresses in te_data packets are always full (i.e non-differential). |
full_data |
1 |
When 1, data values in te_data packets are always full (i.e non-differential). |
other |
>=0 |
Any other implementation specific information |
Implicit Return v1.0 extension to Efficient Trace for RISC-V v2.0
|
This chapter is in the Ratified state.
No changes are allowed. Any desired or needed changes can be the subject of a follow-on new extension. Ratified extensions are never revised. |
The Implicit Return mode information in the format 0, 1 and 2 packets defined in the Efficient Trace for RISC-V 2.0 specification does not produce correct trace decoding in some cases. This extension corrects this by replacing the irdepth field with irets.
If this extension is implemented, the Standard Support Packet extention to Efficient Trace for RISC-V v2.0 (see Standard Support Packet v1.0 extension to Efficient Trace for RISC-V v2.0) must also be implemented.
Background
As described in Implicit Return, when Implict Return mode is enabled, the target address of function returns is not usually reported. When it is reported (for example because it’s the last instruction retired before a trap), there are some circumstances where the decoder cannot determine precisely which return target it is without some additional information from the encoder.
One such circumstance occurs when decoding recursive functions. Each recursively called function will have the same return target address, and including the depth of the return address stack allowed the decoder to determine which one has been reported. However, it is now known that providing the stack depth results in incorrect decoding in other cases unrelated to recursive functions. Consider the following illustration:
A function is executed, and returns normally to the predicted target, so nothing is reported. Execution continues without any branches or uninferrable calls/jumps to a second function which also contains no branches or uninferrable calls/jumps. The return address of this 2nd function is reported for some reason (e.g. it is followed by a trap). Note that the stack depth is the same after the 1st function returns and after the 2nd function returns. This means that when the decoder reconstructed the execution path based on irdepth, it encountered the 1st return and because the stack depth in the te_inst packet matched the current stack depth it stopped decoding at this point, rather than carrying on to the second return.
Had there been any branches between the two functions or inside the 2nd function, decoding would have continued until all branches were processed (the 1st return would have been correctly treated as inferred), and stopped at the right place: the return target of the 2nd function. Similarly if there were uninferrable calls/jumps.
So in summary, the decoder needs additional information to correctly determine which return target has been reported when there have been multiple returns without any branches or uninferrable calls/jumps between them. This is true for all cases, including recursive functions.
Revised packet formats
The following packet definitions replace those detailed in Packet Formats. All formats and fields are the same, except irdepth is replaced by irets throughout.
| Field name | Bits | Description |
|---|---|---|
format |
2 |
10 (addr-only): differential address and no branch information |
address |
iaddress_width_p - iaddress_lsb_p |
Differential instruction address. |
notify |
1 |
If the value of this bit is different from the MSB of address, it indicates that this packet is reporting an instruction that is not the target of an uninferable discontinuity because a notification was requested via trigger[2]. |
updiscon |
1 |
If the value of this bit is different from notify, it indicates that this packet is reporting the instruction following an uninferable discontinuity and is also the instruction before an exception, privilege change or resync (i.e. it will be followed immediately by a format 3 te_inst). |
irreport |
1 |
If the value of this bit is different from updiscon, it indicates that this packet is reporting an instruction that is either: following a return because its address differs from the predicted return address at the top of the implicit return address stack, or the last retired before an exception, interrupt, privilege change or resync because it is necessary to report the implicit return count. |
irets |
8 |
If the value of irreport is different from updiscon, this field indicates the number of implicit returns that have occurred since the last branch, or te_inst packet if there have been no branches since then. If irreport is the same value as updiscon, all bits in this field will also be the same value as updiscon. |
Format 2 irreport and irets
These bits are encoded so that most of the time they will take the same value as the updiscon field, and will therefore compress away, having no impact on the encoding efficiency. If Implicit Return mode is enabled, the encoder keeps track of function calls and returns, and does not generate te_inst packets for return target addresses that can be inferred by the decoder, as described in Implicit Return.
When reporting an address via te_inst when Implicit Return mode is enabled, the packet will include details of the number of implicit returns (i.e. return targets that have not been reported explicitly) since the last branch or te_inst packet under the following conditions:
-
If the reported address is the instruction following a return, and:
-
it is mispredicted, or;
-
there have been 255 unreported returns, or;
-
it is correctly predicted but is being reported for some other reason (e.g. it is the instruction before a trap, privilege change, resync or is the final qualified instruction), or;
-
the return stack is empty, but the number of implicit returns is non-zero.
-
-
If the address is not the instruction following an updiscon but is being reported for some other reason (as listed above), and the number of implicit returns is non-zero.
Under the above conditions, irreport is set to the oppositive value to updiscon.
| Field name | Bits | Description |
|---|---|---|
format |
2 |
01 (diff-delta): includes branch information and may include differential address |
branches |
5 |
Number of valid bits branch_map. The number of bits
of branch_map is determined as follows: |
branch_map |
Determined by branches field. |
An array of bits
indicating whether branches are taken or not. Bit 0 represents the
oldest branch instruction executed. For each bit: |
address |
iaddress_width_p - iaddress_lsb_p |
Differential instruction address. |
notify |
1 |
If the value of this bit is different from the MSB of address, it indicates that this packet is reporting an instruction that is not the target of an uninferable discontinuity because a notification was requested via trigger[2]. |
updiscon |
1 |
If the value of this bit is different from the MSB of notify, it indicates that this packet is reporting the instruction following an uninferable discontinuity and is also the instruction before an exception, privilege change or resync (i.e. it will be followed immediately by a format 3 te_inst). |
irreport |
1 |
If the value of this bit is different from updiscon, it indicates that this packet is reporting an instruction that is either: following a return because its address differs from the predicted return address at the top of the implicit_return return address stack, or the last retired before an exception, interrupt, privilege change or resync because it is necessary to report the implicit return count. |
irets |
8 |
If the value of irreport is different from updiscon, this field indicates the number of implicit returns that have occurred since the last branch, or te_inst packet if there have been no branches since then. If irreport is the same value as updiscon, all bits in this field will also be the same value as updiscon. |
| Field name | Bits | Description |
|---|---|---|
format |
2 |
01 (diff-delta): includes branch information and may include differential address |
branches |
5 |
Number of valid bits in branch_map. The length of
branch_map is determined as follows: |
branch_map |
31 |
An array of bits indicating whether branches are
taken or not. Bit 0 represents the oldest branch instruction executed.
For each bit: |
Format 1 irreport and irets fields
| Field name | Bits | Description |
|---|---|---|
format |
2 |
00 (opt-ext): formats for optional efficiency extensions |
subformat |
0 (correctly predicted branches) |
|
branch_count |
32 |
Count of the number of correctly predicted branches, minus 31. |
branch_fmt |
2 |
10 (addr): Packet contains an address. If this
points to a branch instruction, then the branch was predicted correctly. |
address |
iaddress_width_p - iaddress_lsb_p |
Differential instruction address. |
notify |
1 |
If the value of this bit is different from the MSB of address, it indicates that this packet is reporting an instruction that is not the target of an uninferable discontinuity because a notification was requested via trigger[2]. |
updiscon |
1 |
If the value of this bit is different from notify, it indicates that this packet is reporting the instruction following an uninferable discontinuity and is also the instruction before an exception, privilege change or resync (i.e. it will be followed immediately by a format 3 te_inst). |
irreport |
1 |
If the value of this bit is different from updiscon, it indicates that this packet is reporting an instruction that is either: following a return because its address differs from the predicted return address at the top of the implicit_return return address stack, or the last retired before an exception, interrupt, privilege change or resync because it is necessary to report the implicit return count. |
irets |
8 |
If the value of irreport is different from updiscon, this field indicates the number of implicit returns that have occurred since the last branch, or te_inst packet if there have been no branches since then. If irreport is the same value as updiscon, all bits in this field will also be the same value as updiscon. |
| Field name | Bits | Description |
|---|---|---|
format |
2 |
00 (opt-ext): formats for optional efficiency extensions |
subformat |
1 (jump target cache) |
|
index |
cache_size_p |
Jump target cache index of entry containing target address. |
branches |
5 |
Number of valid bits in branch_map. The length of
branch_map is determined as follows:+
0: (cannot occur for this format) |
branch_map |
Determined by branches field. |
An array of bits indicating whether branches are taken or not. Bit 0 represents the oldest branch instruction executed. For each bit: : branch taken : branch not taken |
irreport |
1 |
If the value of this bit is different from branch_map[MSB], it indicates that this packet is reporting an instruction that is either: following a return because its address differs from the predicted return address at the top of the implicit_return return address stack, or the last retired before an exception, interrupt, privilege change or resync because it is necessary to report the implicit return count. |
irets |
8 |
If the value of irreport is different from branch_map[MSB], this field indicates the number of implicit returns that have occurred since the last branch, or te_inst packet if there have been no branches since then. If irreport is the same value as branch_map[MSB], all bits in this field will also be the same value as branch_map[MSB]. |
| Field name | Bits | Description |
|---|---|---|
format |
2 |
00 (opt-ext): formats for optional efficiency extensions |
subformat |
1 (jump target cache) |
|
index |
cache_size_p |
Jump target cache index of entry containing target address. |
branches |
5 |
Number of valid bits in branch_map. The length of branch_map is determined as follows: : no branch_map in packet -31: (cannot occur for this format) |
irreport |
1 |
If the value of this bit is different from branches[MSB], it indicates that this packet is reporting an instruction that is either: following a return because its address differs from the predicted return address at the top of the implicit_return return address stack, or the last retired before an exception, interrupt, privilege change or resync because it is necessary to report the implicit return count. |
irets |
8 |
If the value of irreport is different from branches[MSB], this field indicates the number of implicit returns that have occurred since the last branch, or te_inst packet if there have been no branches since then. If irreport is the same value as branches[MSB], all bits in this field will also be the same value as branches[MSB]. |
Format 0 irreport and irets fields
These bits are encoded so that most of the time they will take the same value as the immediately preceding bit (updiscon, branch_map[MSB] or branches[MSB] depending on the specific packet format). Purpose and behavior is as described in Format 2 irreport and irets.
For the jump target cache (subformat 1), they are included to allow return addresses that fail the implicit return prediction but which reside in the jump target cache to be reported using this format. An implementation could omit these if all implicit return failures are reported using format 1.
Data Trace of Multiple-Memory Access and Compare and Swap v1.0 extension to Efficient Trace for RISC-V v2.0
|
This chapter is in the Ratified state.
No changes are allowed. Any desired or needed changes can be the subject of a follow-on new extension. Ratified extensions are never revised. |
The RISC-V Hart to Trace Interface (RHTI) Specification is based on chapter 4 of the Efficient Trace for RISC-V v2.0 specification. It adds dtype encodings to support data trace of multi-memory access instructions as defined by the Zcmp and Vector extensions, as well as Compare and Swap as defined by the Zacas extension. This information also needs to be included in te_data packets generated by the Trace Encoder, but there are no available unused encodings in the existing packets defined by the Efficient Trace for RISC-V v2.0 specification. This extension defines revised packet formats that address this.
If this extension is implemented, the Standard Support Packet extention to Efficient Trace for RISC-V v2.0 (see Standard Support Packet v1.0 extension to Efficient Trace for RISC-V v2.0) must also be implemented.
Revised packet formats
The following packet definitions replace those defined in Data Trace Packets. The format and subtype fields have been restructured but all other fields are the same.
format field
Data trace packets are classified by the format field. This field is a maximum of 2 bits wide, but may be omitted completely if only unified loads and stores are supported, or reduced to 1 bit if unified multi-memory access load and stores are also supported. 2 bits are only required when tracing of atomics or CSRs is required, or if loads are split.
| Field name | Bits | Description |
|---|---|---|
format |
clog2(dtype_width_p) |
Transaction class: |
subformat |
2 |
Transaction type: |
size |
max(1, clog2(clog2( data_width_p/8 + 1))) |
Transfer size is 2size bytes |
diff |
2 |
00: Full address and data (sync) |
data_len |
size |
Number of bytes of data is data_len + 1 |
data |
8 * (data_len + 1) |
Data |
address |
daddress_width_p |
Byte address if format is unaligned, otherwise shift left by size to recover byte address |
The following packet format is used when the encoder is configured to omit data values from data trace packets (trTeDataControl.trTeDataNoValue is 1).
| Field name | Bits | Description |
|---|---|---|
format |
clog2(dtype_width_p) |
Transaction class: |
subformat |
2 |
Transaction type: |
size |
max(1, clog2(clog2( data_width_p/8 + 1))) |
Transfer size is 2size bytes |
diff |
1 |
0: Full address (sync) |
address |
daddress_width_p |
Byte address if format is unaligned, otherwise shift left by size to recover byte address |
The following packet format is used when the encoder is configured to omit address values from data trace packets (trTeDataControl.trTeDataNoAddr is 1).
| Field name | Bits | Description |
|---|---|---|
format |
clog2(dtype_width_p) |
Transaction class: |
subformat |
2 |
Transaction type: |
size |
max(1, clog2(clog2( data_width_p/8 + 1))) |
Transfer size is 2size bytes |
diff |
1 or 2 |
00: Full data (sync) |
data |
data_width_p |
Data |
The following packet is used for the request phase of a split load.
| Field name | Bits | Description |
|---|---|---|
format |
2 |
Transaction class: |
subformat |
2 |
Transaction type: |
size |
max(1, clog2(clog2( data_width_p/8 + 1))) |
Transfer size is 2size bytes |
lrid |
lrid_width_p |
Load request ID |
diff |
1 |
0: Full address (sync) |
address |
daddress_width_p |
Byte address if format is unaligned, otherwise shift left by size to recover byte address |
The following packet is used for the data phase of a split load and split atomic.
| Field name | Bits | Description |
|---|---|---|
format |
2 |
Transaction type |
size |
max(1, clog2(clog2( data_width_p/8 + 1))) |
Transfer size is 2size bytes |
lrid |
lrid_width_p |
Load request ID |
resp |
2 |
00: Error (no data) |
data |
data_width_p |
Data |
| Field name | Bits | Description |
|---|---|---|
format |
2 |
Transaction class: |
subformat |
4 |
Atomic sub-type |
size |
max(1, clog2(clog2( data_width_p/8 + 1))) |
Transfer size is 2size bytes |
diff |
2 |
00: Full address and data (sync) |
op_len |
size |
Number of bytes of operand is op_len + 1 |
operand |
8 * (op_len + 1) |
Operand. Value from rs2 before operator applied |
data_len |
size |
Number of bytes of data is data_len + 1 |
data |
8 * (data_len + 1) |
Data |
address |
daddress_width_p |
Address, aligned and encoded as per size |
| Field name | Bits | Description |
|---|---|---|
format |
2 |
Transaction class: |
subformat |
4 |
Atomic sub-type |
size |
max(1, clog2(clog2( data_width_p/8 + 1))) |
Transfer size is 2size bytes |
diff |
2 |
00: Full address and data (sync) |
op_len |
size |
Number of bytes of operand is op_len + 1 |
operand |
8 * (op_len + 1) |
Operand. Value from rs2 before operator applied |
address |
daddress_width_p |
Address, aligned and encoded as per size |
The following packet format is used when the encoder is configured to omit data values from data trace packets (trTeDataControl.trTeDataNoValue is 1)
| Field name | Bits | Description |
|---|---|---|
format |
2 |
Transaction class: |
subformat |
4 |
Atomic sub-type |
size |
max(1, clog2(clog2( data_width_p/8 + 1))) |
Transfer size is 2size bytes |
diff |
1 |
0: Full address |
address |
daddress_width_p |
Address, aligned and encoded as per size |
The following packet format is used when the encoder is configured to omit address values from data trace packets (trTeDataControl.trTeDataNoAddr is 1).
| Field name | Bits | Description |
|---|---|---|
format |
2 |
Transaction class: |
subformat |
4 |
Atomic sub-type |
size |
max(1, clog2(clog2( data_width_p/8 + 1))) |
Transfer size is 2size bytes |
diff |
1 or 2 |
00: Full data (sync) |
op_len |
size |
Number of bytes of operand is op_len + 1 |
operand |
8 * (op_len + 1) |
Operand. Value from rs2 before operator applied |
data |
data_width_p |
Data |
The following packet is used for the request phase of a split atomic:
| Field name | Bits | Description |
|---|---|---|
format |
2 |
Transaction class: |
subformat |
4 |
Atomic sub-type |
size |
max(1, clog2(clog2( data_width_p/8 + 1))) |
Transfer size is 2size bytes |
lrid |
lrid_width_p |
Load request ID |
diff |
2 |
00: Full address and operand (sync) |
op_len |
size |
Number of bytes of operand is op_len + 1 |
operand |
8 * (op_len + 1) |
Operand. Value from rs2 before operator applied |
address |
daddress_width_p |
Address, aligned and encoded as per size |
The following packet format is used when the encoder is configured to omit address values from data trace packets (trTeDataControl.trTeDataNoAddr is 1).
| Field name | Bits | Description |
|---|---|---|
format |
2 |
Transaction class: |
subformat |
4 |
Atomic sub-type |
size |
max(1, clog2(clog2( data_width_p/8 + 1))) |
Transfer size is 2size bytes |
lrid |
lrid_width_p |
Load request ID |
diff |
2 |
00: Full operand (sync) |
operand |
data_width_p |
Operand. Value from rs2 before operator applied |
| Field name | Bits | Description |
|---|---|---|
format |
2 |
Transaction class: |
subformat |
4 |
CSR sub-type |
diff |
1 or 2 |
00: Full data/operand (sync) |
data_len |
2 or 3 |
Number of bytes of data is data_len + 1 |
data |
8 * (data_len 1) |
Data |
addr_msbs |
6 |
Address[11:6] |
op_len |
2 or 3 |
Number of bytes of operand is op_len + 1 |
operand |
8 * (op_len + 1) |
Operand. Value from rs1 before operator applied |
addr_lsbs |
6 |
Address[5:0] |
| Field name | Bits | Description |
|---|---|---|
format |
2 |
Transaction class: |
subformat |
4 |
CSR sub-type |
diff |
1 or 2 |
00: Full data (sync) |
data_len |
2 or 3 |
Number of bytes of data is data_len + 1 |
data |
8 * (data_len + 1) |
Data |
addr_msbs |
6 |
Address[11:6] |
addr_lsbs |
6 |
Address[5:0] |
| Field name | Bits | Description |
|---|---|---|
format |
2 |
Transaction class: |
subformat |
4 |
CSR sub-type |
diff |
1 |
0: Full address |
addr_msbs |
6 |
Address[11:6] |
addr_lsbs |
6 |
Address[5:0] |