From 175794624a7316d9e8d4dae5d5880da1d290f641 Mon Sep 17 00:00:00 2001 From: Derek Hower Date: Fri, 7 Nov 2025 15:06:32 -0600 Subject: [PATCH 1/6] fix(data): make Smctr/Ssctr require S and Smcsrind/Sscsrind --- spec/std/isa/ext/Smctr.yaml | 58 +++++++++++++++++++++++++ spec/std/isa/ext/Ssctr.yaml | 22 ++++++++++ spec/std/isa/inst/Smdbltrp/sctrclr.yaml | 3 +- 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 spec/std/isa/ext/Smctr.yaml create mode 100644 spec/std/isa/ext/Ssctr.yaml diff --git a/spec/std/isa/ext/Smctr.yaml b/spec/std/isa/ext/Smctr.yaml new file mode 100644 index 0000000000..9f3aab49fd --- /dev/null +++ b/spec/std/isa/ext/Smctr.yaml @@ -0,0 +1,58 @@ +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +# SPDX-License-Identifier: BSD-3-Clause-Clear + +# yaml-language-server: $schema=../../schemas/ext_schema.json + +$schema: "ext_schema.json#" +kind: extension +name: Smctr +long_name: Control Transfer Records +description: | + A method for recording control flow transfer history is valuable not only for performance + profiling but also for debugging. + Control flow transfers refer to jump instructions (including function calls and returns), taken + branch instructions, traps, and trap returns. + Profiling tools, such as Linux perf, collect control transfer history when sampling software + execution, thereby enabling tools, like AutoFDO, to identify hot paths for optimization. + + Control flow trace capabilities offer very deep transfer history, but the volume of data produced + can result in significant performance overheads due to memory bandwidth consumption, buffer + management, and decoder overhead. + The Control Transfer Records (CTR) extension provides a method to record a limited history in + register-accessible internal chip storage, with the intent of dramatically reducing the + performance overhead and complexity of collecting transfer history. + + CTR defines a circular (FIFO) buffer. Each buffer entry holds a record for a single recorded + control flow transfer. + The number of records that can be held in the buffer depends upon both the implementation (the + maximum supported depth) and the CTR configuration (the software selected depth). + + Only qualified transfers are recorded. + Qualified transfers are those that meet the filtering criteria, which include the privilege mode + and the transfer type. + + Recorded transfers are inserted at the write pointer, which is then incremented, while older + recorded transfers may be overwritten once the buffer is full. + Or the user can enable RAS (Return Address Stack) emulation mode, where only function calls are + recorded, and function returns pop the last call record. + The source PC, target PC, and some optional metadata (transfer type, elapsed cycles) are stored + for each recorded transfer. + + The CTR buffer is accessible through an indirect CSR interface, such that software can specify + which logical entry in the buffer it wishes to read or write. + Logical entry 0 always corresponds to the youngest recorded transfer, followed by entry 1 as the + next youngest, and so on. +type: privileged +versions: + - version: "1.0.0" + state: ratified + ratification_date: 2024-11 + implies: + name: Ssctr + version: "1.0.0" + requires: + allOf: + - name: S + version: ~> 1.13 # The latest ratified version of S when Sscntr was ratified + - name: Smcsrind + version: ~> 1.0 diff --git a/spec/std/isa/ext/Ssctr.yaml b/spec/std/isa/ext/Ssctr.yaml new file mode 100644 index 0000000000..36a2e6d707 --- /dev/null +++ b/spec/std/isa/ext/Ssctr.yaml @@ -0,0 +1,22 @@ +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +# SPDX-License-Identifier: BSD-3-Clause-Clear + +# yaml-language-server: $schema=../../schemas/ext_schema.json + +$schema: "ext_schema.json#" +kind: extension +name: Ssctr +long_name: Control Transfer Records +description: | + The supervisor view of `Smctr`. +type: privileged +versions: + - version: "1.0.0" + state: ratified + ratification_date: 2024-11 + requires: + allOf: + - name: S + version: ~> 1.13 # The latest ratified version of S when Sscntr was ratified + - name: Sscsrind + version: ~> 1.0 diff --git a/spec/std/isa/inst/Smdbltrp/sctrclr.yaml b/spec/std/isa/inst/Smdbltrp/sctrclr.yaml index 8dd49d276e..40fd37474b 100644 --- a/spec/std/isa/inst/Smdbltrp/sctrclr.yaml +++ b/spec/std/isa/inst/Smdbltrp/sctrclr.yaml @@ -9,7 +9,8 @@ name: sctrclr long_name: No synopsis available description: | No description available. -definedBy: Smdbltrp +definedBy: + anyOf: [Smctr, Ssctr] assembly: "" encoding: match: "00010000010000000000000001110011" From 0391333cfca83798a617c2e1599c1fd7950a4df3 Mon Sep 17 00:00:00 2001 From: Derek Hower Date: Thu, 3 Apr 2025 05:39:32 -0700 Subject: [PATCH 2/6] data(inst): add long_name and description for sctclr Co-authored-by: David Brash --- spec/std/isa/inst/Smdbltrp/sctrclr.yaml | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/spec/std/isa/inst/Smdbltrp/sctrclr.yaml b/spec/std/isa/inst/Smdbltrp/sctrclr.yaml index 40fd37474b..cf6bee5072 100644 --- a/spec/std/isa/inst/Smdbltrp/sctrclr.yaml +++ b/spec/std/isa/inst/Smdbltrp/sctrclr.yaml @@ -6,9 +6,27 @@ $schema: inst_schema.json# kind: instruction name: sctrclr -long_name: No synopsis available +long_name: Supervisor Control Transfer Record (CTR) clear description: | - No description available. + When `mstateen0.CTR`=1, the SCTRCLR instruction performs the following operations: + + * Zeroes all CTR Entry Registers, for all DEPTH values + * Reset to Zero the optional CTR cycle counter where implemented + ** `ctrdata.CC` and `ctrdata.CC` bit fields. + + Any read of `ctrsource`, `ctrtarget`, or `ctrdata` that follows SCTRCLR, such that it precedes the next + qualified control transfer, will return the value 0. + Further, the first recorded transfer following SCTRCLR will have `ctrdata.CCV`=0. + + SCTRCLR execution causes an `IllegalInstruction` exception if: + + * `Smctr` is not implemented + * The instruction is executed in S/VS/VU-mode and `Ssctr` is not implemented, or `mstateen0.CTR`=0 + * The instruction is executed in U-mode + + SCTRCLR execution causes a `VirtualInstruciton` exception if `mstateen0.CTR`=1 and: + * The instruction is executed in VS-mode and `hstateen0.CTR`=0 + * The instruction is executed in VU-mode definedBy: anyOf: [Smctr, Ssctr] assembly: "" From d4c6432e1231ca24560737bd44b56475fb4fd7f3 Mon Sep 17 00:00:00 2001 From: Derek Hower <134728312+dhower-qc@users.noreply.github.com> Date: Thu, 17 Apr 2025 14:13:01 -0400 Subject: [PATCH 3/6] refactor(data): convert SCTRCLR description to array form Signed-off-by: Derek Hower <134728312+dhower-qc@users.noreply.github.com> --- spec/std/isa/inst/Smdbltrp/sctrclr.yaml | 49 ++++++++++++++++--------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/spec/std/isa/inst/Smdbltrp/sctrclr.yaml b/spec/std/isa/inst/Smdbltrp/sctrclr.yaml index cf6bee5072..e3f99ea3b0 100644 --- a/spec/std/isa/inst/Smdbltrp/sctrclr.yaml +++ b/spec/std/isa/inst/Smdbltrp/sctrclr.yaml @@ -7,26 +7,39 @@ $schema: inst_schema.json# kind: instruction name: sctrclr long_name: Supervisor Control Transfer Record (CTR) clear -description: | - When `mstateen0.CTR`=1, the SCTRCLR instruction performs the following operations: +description: + - id: inst-sctrclr-operation + normative: false + text: | + When `mstateen0.CTR`=1, the SCTRCLR instruction performs the following operations: - * Zeroes all CTR Entry Registers, for all DEPTH values - * Reset to Zero the optional CTR cycle counter where implemented - ** `ctrdata.CC` and `ctrdata.CC` bit fields. + * Zeroes all CTR Entry Registers, for all DEPTH values + * Reset to Zero the optional CTR cycle counter where implemented + ** `ctrdata.CC` and `ctrdata.CC` bit fields. + - id: inst-sctrclr-csr-effect + normative: true + text: | + Any read of `ctrsource`, `ctrtarget`, or `ctrdata` that follows SCTRCLR, such that it precedes the next + qualified control transfer, will return the value 0. + - id: inst-sctrclr-after + normative: true + text: | + Further, the first recorded transfer following SCTRCLR will have `ctrdata.CCV`=0. + - id: inst-sctrclr-illegal + normative: false + text: | + SCTRCLR execution causes an `IllegalInstruction` exception if: - Any read of `ctrsource`, `ctrtarget`, or `ctrdata` that follows SCTRCLR, such that it precedes the next - qualified control transfer, will return the value 0. - Further, the first recorded transfer following SCTRCLR will have `ctrdata.CCV`=0. - - SCTRCLR execution causes an `IllegalInstruction` exception if: - - * `Smctr` is not implemented - * The instruction is executed in S/VS/VU-mode and `Ssctr` is not implemented, or `mstateen0.CTR`=0 - * The instruction is executed in U-mode - - SCTRCLR execution causes a `VirtualInstruciton` exception if `mstateen0.CTR`=1 and: - * The instruction is executed in VS-mode and `hstateen0.CTR`=0 - * The instruction is executed in VU-mode + * `Smctr` is not implemented + * The instruction is executed in S/VS/VU-mode and `Ssctr` is not implemented, or `mstateen0.CTR`=0 + * The instruction is executed in U-mode + - id: inst-sctrclr-virtual + normative: false + text: | + SCTRCLR execution causes a `VirtualInstruciton` exception if `mstateen0.CTR`=1 and: + + * The instruction is executed in VS-mode and `hstateen0.CTR`=0 + * The instruction is executed in VU-mode definedBy: anyOf: [Smctr, Ssctr] assembly: "" From 0880285fdbafddbcb8f97868c3f2b1789510a9d6 Mon Sep 17 00:00:00 2001 From: Derek Hower <134728312+dhower-qc@users.noreply.github.com> Date: Tue, 29 Apr 2025 15:01:46 -0400 Subject: [PATCH 4/6] Update sctrclr.yaml Signed-off-by: Derek Hower <134728312+dhower-qc@users.noreply.github.com> --- spec/std/isa/inst/Smdbltrp/sctrclr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/std/isa/inst/Smdbltrp/sctrclr.yaml b/spec/std/isa/inst/Smdbltrp/sctrclr.yaml index e3f99ea3b0..664de44e44 100644 --- a/spec/std/isa/inst/Smdbltrp/sctrclr.yaml +++ b/spec/std/isa/inst/Smdbltrp/sctrclr.yaml @@ -15,7 +15,7 @@ description: * Zeroes all CTR Entry Registers, for all DEPTH values * Reset to Zero the optional CTR cycle counter where implemented - ** `ctrdata.CC` and `ctrdata.CC` bit fields. + ** `ctrdata.CC` and `ctrdata.CCV` bit fields. - id: inst-sctrclr-csr-effect normative: true text: | From 00e9fb8afc58a785a843e05720e1ad5b7b79e26b Mon Sep 17 00:00:00 2001 From: "Paul A. Clarke" Date: Fri, 7 Nov 2025 15:32:38 -0600 Subject: [PATCH 5/6] feat(data): un-array sctrclr description Signed-off-by: Paul A. Clarke --- spec/std/isa/inst/Smdbltrp/sctrclr.yaml | 55 ++++++++++--------------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/spec/std/isa/inst/Smdbltrp/sctrclr.yaml b/spec/std/isa/inst/Smdbltrp/sctrclr.yaml index 664de44e44..5224c70869 100644 --- a/spec/std/isa/inst/Smdbltrp/sctrclr.yaml +++ b/spec/std/isa/inst/Smdbltrp/sctrclr.yaml @@ -7,39 +7,28 @@ $schema: inst_schema.json# kind: instruction name: sctrclr long_name: Supervisor Control Transfer Record (CTR) clear -description: - - id: inst-sctrclr-operation - normative: false - text: | - When `mstateen0.CTR`=1, the SCTRCLR instruction performs the following operations: - - * Zeroes all CTR Entry Registers, for all DEPTH values - * Reset to Zero the optional CTR cycle counter where implemented - ** `ctrdata.CC` and `ctrdata.CCV` bit fields. - - id: inst-sctrclr-csr-effect - normative: true - text: | - Any read of `ctrsource`, `ctrtarget`, or `ctrdata` that follows SCTRCLR, such that it precedes the next - qualified control transfer, will return the value 0. - - id: inst-sctrclr-after - normative: true - text: | - Further, the first recorded transfer following SCTRCLR will have `ctrdata.CCV`=0. - - id: inst-sctrclr-illegal - normative: false - text: | - SCTRCLR execution causes an `IllegalInstruction` exception if: - - * `Smctr` is not implemented - * The instruction is executed in S/VS/VU-mode and `Ssctr` is not implemented, or `mstateen0.CTR`=0 - * The instruction is executed in U-mode - - id: inst-sctrclr-virtual - normative: false - text: | - SCTRCLR execution causes a `VirtualInstruciton` exception if `mstateen0.CTR`=1 and: - - * The instruction is executed in VS-mode and `hstateen0.CTR`=0 - * The instruction is executed in VU-mode +description: | + When `mstateen0.CTR`=1, the SCTRCLR instruction performs the following operations: + + * Zeroes all CTR Entry Registers, for all DEPTH values + * Reset to Zero the optional CTR cycle counter where implemented + ** `ctrdata.CC` and `ctrdata.CCV` bit fields. + + Any read of `ctrsource`, `ctrtarget`, or `ctrdata` that follows SCTRCLR, such that it precedes the next + qualified control transfer, will return the value 0. + + Further, the first recorded transfer following SCTRCLR will have `ctrdata.CCV`=0. + + SCTRCLR execution causes an `IllegalInstruction` exception if: + + * `Smctr` is not implemented + * The instruction is executed in S/VS/VU-mode and `Ssctr` is not implemented, or `mstateen0.CTR`=0 + * The instruction is executed in U-mode + + SCTRCLR execution causes a `VirtualInstruciton` exception if `mstateen0.CTR`=1 and: + + * The instruction is executed in VS-mode and `hstateen0.CTR`=0 + * The instruction is executed in VU-mode definedBy: anyOf: [Smctr, Ssctr] assembly: "" From ae6bb37422e07ffe1187346696a8b96bad71c43c Mon Sep 17 00:00:00 2001 From: "Paul A. Clarke" Date: Fri, 7 Nov 2025 16:02:04 -0600 Subject: [PATCH 6/6] fix: update golden instructions appendix --- .../all_instructions.golden.adoc | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/backends/instructions_appendix/all_instructions.golden.adoc b/backends/instructions_appendix/all_instructions.golden.adoc index 3477142770..531c0438fe 100644 --- a/backends/instructions_appendix/all_instructions.golden.adoc +++ b/backends/instructions_appendix/all_instructions.golden.adoc @@ -17765,7 +17765,7 @@ Included in:: == sctrclr Synopsis:: -No synopsis available +Supervisor Control Transfer Record (CTR) clear Encoding:: [wavedrom, ,svg,subs='attributes',width="100%"] @@ -17774,7 +17774,27 @@ Encoding:: .... Description:: -No description available. +When xref:csrs:mstateen0.adoc#udb:doc:csr_field:mstateen0:CTR[mstateen0.CTR]=1, the SCTRCLR instruction performs the following operations: + +* Zeroes all CTR Entry Registers, for all DEPTH values +* Reset to Zero the optional CTR cycle counter where implemented +** `ctrdata.CC` and `ctrdata.CCV` bit fields. + +Any read of `ctrsource`, `ctrtarget`, or `ctrdata` that follows SCTRCLR, such that it precedes the next +qualified control transfer, will return the value 0. + +Further, the first recorded transfer following SCTRCLR will have `ctrdata.CCV`=0. + +SCTRCLR execution causes an `IllegalInstruction` exception if: + +* xref:exts:Smctr.adoc#udb:doc:ext:Smctr[Smctr] is not implemented +* 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 +* The instruction is executed in U-mode + +SCTRCLR execution causes a `VirtualInstruciton` exception if xref:csrs:mstateen0.adoc#udb:doc:csr_field:mstateen0:CTR[mstateen0.CTR]=1 and: + +* The instruction is executed in VS-mode and xref:csrs:hstateen0.adoc#udb:doc:csr_field:hstateen0:CTR[hstateen0.CTR]=0 +* The instruction is executed in VU-mode Decode Variables:: @@ -17785,7 +17805,9 @@ Included in:: |=== | Extension | Version -| *Smdbltrp* | ~> 1.0.0 +| *Smctr* | ~> 1.0.0 + +| *Ssctr* | ~> 1.0.0 |===