Skip to content

Commit c735fa3

Browse files
ThinkOpenlydhower-qcdbrash
authored
fix(data): add Smctr/Ssctr and update sctrclr (#1238)
Signed-off-by: Derek Hower <[email protected]> Signed-off-by: Paul A. Clarke <[email protected]> Co-authored-by: Derek Hower <[email protected]> Co-authored-by: David Brash <[email protected]> Co-authored-by: Derek Hower <[email protected]>
1 parent baebeb8 commit c735fa3

File tree

4 files changed

+129
-6
lines changed

4 files changed

+129
-6
lines changed

backends/instructions_appendix/all_instructions.golden.adoc

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23073,7 +23073,7 @@ Included in::
2307323073
== sctrclr
2307423074

2307523075
Synopsis::
23076-
No synopsis available
23076+
Supervisor Control Transfer Record (CTR) clear
2307723077

2307823078
Assembly::
2307923079
sctrclr
@@ -23085,7 +23085,27 @@ Encoding::
2308523085
....
2308623086

2308723087
Description::
23088-
No description available.
23088+
When xref:csrs:mstateen0.adoc#udb:doc:csr_field:mstateen0:CTR[mstateen0.CTR]=1, the SCTRCLR instruction performs the following operations:
23089+
23090+
* Zeroes all CTR Entry Registers, for all DEPTH values
23091+
* Reset to Zero the optional CTR cycle counter where implemented
23092+
** `ctrdata.CC` and `ctrdata.CCV` bit fields.
23093+
23094+
Any read of `ctrsource`, `ctrtarget`, or `ctrdata` that follows SCTRCLR, such that it precedes the next
23095+
qualified control transfer, will return the value 0.
23096+
23097+
Further, the first recorded transfer following SCTRCLR will have `ctrdata.CCV`=0.
23098+
23099+
SCTRCLR execution causes an `IllegalInstruction` exception if:
23100+
23101+
* xref:exts:Smctr.adoc#udb:doc:ext:Smctr[Smctr] is not implemented
23102+
* The instruction is executed in S/VS/VU-mode and xref:exts:Ssctr.adoc#udb:doc:ext:Ssctr[Ssctr] is not implemented, or xref:csrs:mstateen0.adoc#udb:doc:csr_field:mstateen0:CTR[mstateen0.CTR]=0
23103+
* The instruction is executed in U-mode
23104+
23105+
SCTRCLR execution causes a `VirtualInstruciton` exception if xref:csrs:mstateen0.adoc#udb:doc:csr_field:mstateen0:CTR[mstateen0.CTR]=1 and:
23106+
23107+
* The instruction is executed in VS-mode and xref:csrs:hstateen0.adoc#udb:doc:csr_field:hstateen0:CTR[hstateen0.CTR]=0
23108+
* The instruction is executed in VU-mode
2308923109

2309023110

2309123111
Decode Variables::
@@ -23096,7 +23116,9 @@ Included in::
2309623116
|===
2309723117
| Extension | Version
2309823118

23099-
| *Smdbltrp* | ~> 1.0.0
23119+
| *Smctr* | ~> 1.0.0
23120+
23121+
| *Ssctr* | ~> 1.0.0
2310023122

2310123123
|===
2310223124

spec/std/isa/ext/Smctr.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
2+
# SPDX-License-Identifier: BSD-3-Clause-Clear
3+
4+
# yaml-language-server: $schema=../../schemas/ext_schema.json
5+
6+
$schema: "ext_schema.json#"
7+
kind: extension
8+
name: Smctr
9+
long_name: Control Transfer Records
10+
description: |
11+
A method for recording control flow transfer history is valuable not only for performance
12+
profiling but also for debugging.
13+
Control flow transfers refer to jump instructions (including function calls and returns), taken
14+
branch instructions, traps, and trap returns.
15+
Profiling tools, such as Linux perf, collect control transfer history when sampling software
16+
execution, thereby enabling tools, like AutoFDO, to identify hot paths for optimization.
17+
18+
Control flow trace capabilities offer very deep transfer history, but the volume of data produced
19+
can result in significant performance overheads due to memory bandwidth consumption, buffer
20+
management, and decoder overhead.
21+
The Control Transfer Records (CTR) extension provides a method to record a limited history in
22+
register-accessible internal chip storage, with the intent of dramatically reducing the
23+
performance overhead and complexity of collecting transfer history.
24+
25+
CTR defines a circular (FIFO) buffer. Each buffer entry holds a record for a single recorded
26+
control flow transfer.
27+
The number of records that can be held in the buffer depends upon both the implementation (the
28+
maximum supported depth) and the CTR configuration (the software selected depth).
29+
30+
Only qualified transfers are recorded.
31+
Qualified transfers are those that meet the filtering criteria, which include the privilege mode
32+
and the transfer type.
33+
34+
Recorded transfers are inserted at the write pointer, which is then incremented, while older
35+
recorded transfers may be overwritten once the buffer is full.
36+
Or the user can enable RAS (Return Address Stack) emulation mode, where only function calls are
37+
recorded, and function returns pop the last call record.
38+
The source PC, target PC, and some optional metadata (transfer type, elapsed cycles) are stored
39+
for each recorded transfer.
40+
41+
The CTR buffer is accessible through an indirect CSR interface, such that software can specify
42+
which logical entry in the buffer it wishes to read or write.
43+
Logical entry 0 always corresponds to the youngest recorded transfer, followed by entry 1 as the
44+
next youngest, and so on.
45+
type: privileged
46+
versions:
47+
- version: "1.0.0"
48+
state: ratified
49+
ratification_date: 2024-11
50+
implies:
51+
name: Ssctr
52+
version: "1.0.0"
53+
requires:
54+
allOf:
55+
- name: S
56+
version: ~> 1.13 # The latest ratified version of S when Sscntr was ratified
57+
- name: Smcsrind
58+
version: ~> 1.0

spec/std/isa/ext/Ssctr.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
2+
# SPDX-License-Identifier: BSD-3-Clause-Clear
3+
4+
# yaml-language-server: $schema=../../schemas/ext_schema.json
5+
6+
$schema: "ext_schema.json#"
7+
kind: extension
8+
name: Ssctr
9+
long_name: Control Transfer Records
10+
description: |
11+
The supervisor view of `Smctr`.
12+
type: privileged
13+
versions:
14+
- version: "1.0.0"
15+
state: ratified
16+
ratification_date: 2024-11
17+
requires:
18+
allOf:
19+
- name: S
20+
version: ~> 1.13 # The latest ratified version of S when Sscntr was ratified
21+
- name: Sscsrind
22+
version: ~> 1.0

spec/std/isa/inst/Smdbltrp/sctrclr.yaml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,31 @@
66
$schema: inst_schema.json#
77
kind: instruction
88
name: sctrclr
9-
long_name: No synopsis available
9+
long_name: Supervisor Control Transfer Record (CTR) clear
1010
description: |
11-
No description available.
12-
definedBy: Smdbltrp
11+
When `mstateen0.CTR`=1, the SCTRCLR instruction performs the following operations:
12+
13+
* Zeroes all CTR Entry Registers, for all DEPTH values
14+
* Reset to Zero the optional CTR cycle counter where implemented
15+
** `ctrdata.CC` and `ctrdata.CCV` bit fields.
16+
17+
Any read of `ctrsource`, `ctrtarget`, or `ctrdata` that follows SCTRCLR, such that it precedes the next
18+
qualified control transfer, will return the value 0.
19+
20+
Further, the first recorded transfer following SCTRCLR will have `ctrdata.CCV`=0.
21+
22+
SCTRCLR execution causes an `IllegalInstruction` exception if:
23+
24+
* `Smctr` is not implemented
25+
* The instruction is executed in S/VS/VU-mode and `Ssctr` is not implemented, or `mstateen0.CTR`=0
26+
* The instruction is executed in U-mode
27+
28+
SCTRCLR execution causes a `VirtualInstruciton` exception if `mstateen0.CTR`=1 and:
29+
30+
* The instruction is executed in VS-mode and `hstateen0.CTR`=0
31+
* The instruction is executed in VU-mode
32+
definedBy:
33+
anyOf: [Smctr, Ssctr]
1334
assembly: ""
1435
encoding:
1536
match: "00010000010000000000000001110011"

0 commit comments

Comments
 (0)