Skip to content

Commit c06c703

Browse files
Add ssqosid extension and csr yaml (#653)
This PR adds: - Extension YAML file for `Ssqosid` - CSR YAML file for `Ssqosid`: `srmcfg` Closes #567 --------- Signed-off-by: Syed Owais Ali Shah <113125582+syedowaisalishah@users.noreply.github.com>
1 parent 825cc5e commit c06c703

File tree

4 files changed

+209
-2
lines changed

4 files changed

+209
-2
lines changed

arch/csr/Ssqosid/srmcfg.yaml

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# yaml-language-server: $schema=../../../schemas/csr_schema.json
2+
$schema: csr_schema.json#
3+
kind: csr
4+
name: srmcfg
5+
long_name: Supervisor Resource Management Configuration
6+
address: 0x181
7+
priv_mode: S
8+
length: SXLEN
9+
definedBy: Ssqosid
10+
description:
11+
- id: csr-srmcfg-purpose
12+
normative: true
13+
text: |
14+
The `srmcfg` register is used to configure a Resource Control ID (`RCID`) and a Monitoring Counter ID (`MCID`).
15+
Both `RCID` and `MCID` are WARL fields.
16+
17+
- id: csr-`srmcfg`-field-usage
18+
normative: true
19+
text: |
20+
The `RCID` and `MCID` accompany each request made by the hart to shared resource controllers.
21+
The `RCID` is used to determine the resource allocations (e.g., cache occupancy limits, memory bandwidth limits, etc.) to enforce.
22+
The `MCID` is used to identify a counter to monitor resource usage.
23+
24+
- id: csr-srmcfg-default-scope
25+
normative: true
26+
text: |
27+
The `RCID` and `MCID` configured in the `srmcfg` CSR apply to all privilege modes of software execution on that hart by default,
28+
but this behavior may be overridden by future extensions.
29+
30+
- id: csr-srmcfg-smstateen-interaction
31+
normative: true
32+
text: |
33+
If extension `Smstateen` is implemented together with `Ssqosid`, then `Ssqosid` also requires the `SRMCFG` bit in `mstateen0` to be implemented.
34+
If `mstateen0.SRMCFG` is `0`, attempts to access `srmcfg` in privilege modes less privileged than M-mode raise an illegal-instruction exception.
35+
36+
- id: csr-srmcfg-vsmode-exception
37+
normative: true
38+
text: |
39+
If `mstateen0.SRMCFG` is `1` or if extension `Smstateen` is not implemented, attempts to access `srmcfg` when `V=1` raise a virtual-instruction exception.
40+
41+
- id: csr-srmcfg-rcid-reset
42+
normative: false
43+
text: |
44+
A reset value of `0` is suggested for the `RCID` field, matching resource controllers' default behavior of associating all capacity with `RCID=0`.
45+
46+
- id: csr-srmcfg-mcid-reset
47+
normative: false
48+
text: |
49+
The `MCID` reset value does not affect functionality and may be implementation-defined.
50+
51+
- id: csr-srmcfg-id-bit-allocation
52+
normative: false
53+
text: |
54+
Typically, fewer bits are allocated for `RCID` (e.g., to support tens of `RCID`s) than for `MCID` (e.g., to support hundreds of `MCID`s).
55+
56+
- id: csr-srmcfg-rcid-grouping
57+
normative: false
58+
text: |
59+
A common `RCID` is usually used to group apps or VMs, pooling resource allocations to meet collective SLAs.
60+
61+
- id: csr-srmcfg-mcid-granularity
62+
normative: false
63+
text: |
64+
If an SLA breach occurs, unique `MCID`s enable granular monitoring, aiding decisions on resource adjustment,
65+
associating a different `RCID` with a subset of members, or migrating members to other machines.
66+
The larger pool of `MCID`s speeds up this analysis.
67+
68+
- id: csr-srmcfg-privilege-behavior
69+
normative: false
70+
text: |
71+
The `RCID` and `MCID` in `srmcfg` apply across all privilege levels on the hart.
72+
Typically, higher-privilege modes don't modify `srmcfg`, as they often serve lower-privileged tasks.
73+
If differentiation is needed, higher privilege code can update `srmcfg` and restore it before returning to a lower privilege level.
74+
75+
- id: csr-srmcfg-vm-virtualization
76+
normative: false
77+
text: |
78+
In VM environments, hypervisors usually manage resource allocations, keeping the Guest OS out of QoS flows.
79+
If needed, the hypervisor can virtualize the `srmcfg` CSR for a VM using the virtual-instruction exceptions triggered upon Guest access.
80+
81+
- id: csr-srmcfg-vs-mode-future
82+
normative: false
83+
text: |
84+
If the direct selection of `RCID` and `MCID` by the VM becomes common and emulation overhead is an issue,
85+
future extensions may allow VS-mode to use a selector for a hypervisor-configured set of CSRs holding `RCID` and `MCID` values designated for that Guest OS use.
86+
87+
- id: csr-srmcfg-context-switch
88+
normative: false
89+
text: |
90+
During context switches, the supervisor may choose to execute with the `srmcfg` of the outgoing context to attribute the execution to it.
91+
Prior to restoring the new context, it switches to the new VM’s `srmcfg`.
92+
The supervisor can also use a separate configuration for execution not to be attributed to either context.
93+
fields:
94+
RCID:
95+
location: 11-0
96+
type: RW
97+
long_name: Resource Control ID
98+
description: |
99+
The `RCID` is used to determine the resource allocations (e.g., cache occupancy limits,
100+
memory bandwidth limits, etc.) to enforce.
101+
reset_value: UNDEFINED_LEGAL
102+
sw_write(csr_value): |
103+
if (implemented?(ExtensionName::Smstateen)) {
104+
if (mode() < PrivilegeMode::M && CSR[mstateen0].SRMCFG == 0) {
105+
raise(ExceptionCode::IllegalInstruction, mode(), $encoding);
106+
}
107+
if (virtual_mode?() && CSR[mstateen0].SRMCFG == 1) {
108+
raise(ExceptionCode::VirtualInstruction, mode(), $encoding);
109+
}
110+
} else {
111+
if (virtual_mode?()) {
112+
raise(ExceptionCode::VirtualInstruction, mode(), $encoding);
113+
}
114+
}
115+
return csr_value.RCID & ((1 `<< RCID_WIDTH) - 1);
116+
117+
MCID:
118+
location: 27-16
119+
type: RW
120+
long_name: Monitoring Counter ID
121+
description: |
122+
The `MCID` is used to identify a counter to monitor resource usage.
123+
reset_value: UNDEFINED_LEGAL
124+
sw_write(csr_value): |
125+
if (implemented?(ExtensionName::Smstateen)) {
126+
if (mode() < PrivilegeMode::M && CSR[mstateen0].SRMCFG == 0) {
127+
raise(ExceptionCode::IllegalInstruction, mode(), $encoding);
128+
}
129+
if (virtual_mode?() && CSR[mstateen0].SRMCFG == 1) {
130+
raise(ExceptionCode::VirtualInstruction, mode(), $encoding);
131+
}
132+
} else {
133+
if (virtual_mode?()) {
134+
raise(ExceptionCode::VirtualInstruction, mode(), $encoding);
135+
}
136+
}
137+
return csr_value.MCID & ((1 `<< MCID_WIDTH) - 1);
138+
139+
sw_read(): |
140+
if (implemented?(ExtensionName::Smstateen)) {
141+
if (mode() < PrivilegeMode::M && CSR[mstateen0].SRMCFG == 0) {
142+
raise(ExceptionCode::IllegalInstruction, mode(), $encoding);
143+
}
144+
if (virtual_mode?() && CSR[mstateen0].SRMCFG == 1) {
145+
raise(ExceptionCode::VirtualInstruction, mode(), $encoding);
146+
}
147+
} else {
148+
if (virtual_mode?()) {
149+
raise(ExceptionCode::VirtualInstruction, mode(), $encoding);
150+
}
151+
}
152+
return $bits(CSR[mstateen0]);

arch/csr/mstateen0.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ fields:
129129
SRMCFG:
130130
long_name: srmcfg access control
131131
location: 55
132-
#definedBy: Ssqosid
132+
definedBy: Ssqosid
133133
description: |
134134
The SRMCFG bit in `mstateen0` controls access to the `srmcfg`` CSR introduced by the Ssqosid Chapter 18
135135
extension.

arch/csr/mstateen0h.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fields:
111111
SRMCFG:
112112
long_name: srmcfg access control
113113
location: 23
114-
#definedBy: Ssqosid
114+
definedBy: Ssqosid
115115
alias: mstateen0.SRMCFG
116116
sw_write(csr_value): |
117117
CSR[mstateen0].SRMCFG = csr_value.SRMCFG;

arch/ext/Ssqosid.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# yaml-language-server: $schema=../../schemas/ext_schema.json
2+
3+
$schema: "ext_schema.json#"
4+
kind: extension
5+
name: Ssqosid
6+
type: privileged
7+
long_name: Quality-of-Service Identifiers
8+
description: |
9+
Quality of Service (QoS) is defined as the minimal end-to-end performance guaranteed in advance by a service level agreement (SLA) to a workload.
10+
Performance metrics might include measures such as instructions per cycle (IPC), latency of service, etc.
11+
12+
When multiple workloads execute concurrently on modern processors—equipped with large core counts, multiple cache hierarchies, and multiple memory
13+
controllers—the performance of any given workload becomes less deterministic, or even non-deterministic, due to shared resource contention.
14+
15+
To manage performance variability, system software needs resource allocation and monitoring capabilities.
16+
These capabilities allow for the reservation of resources like cache and bandwidth, thus meeting individual performance targets while minimizing interference.
17+
For resource management, hardware should provide monitoring features that allow system software to profile workload resource consumption and allocate resources accordingly.
18+
19+
To facilitate this, the QoS Identifiers extension (Ssqosid) introduces the srmcfg register,
20+
which configures a hart with two identifiers: a Resource Control ID (RCID) and a Monitoring Counter ID (MCID).
21+
These identifiers accompany each request issued by the hart to shared resource controllers.
22+
23+
Additional metadata, like the nature of the memory access and the ID of the originating supervisor domain,
24+
can accompany RCID and MCID. Resource controllers may use this metadata for differentiated service such as a different capacity allocation for code storage vs. data storage.
25+
Resource controllers can use this data for security policies such as not exposing statistics of one security domain to another.
26+
27+
These identifiers are crucial for the RISC-V Capacity and Bandwidth Controller QoS Register Interface (CBQRI) specification,
28+
which provides methods for setting resource usage limits and monitoring resource consumption.
29+
The RCID controls resource allocations, while the MCID is used for tracking resource usage.
30+
31+
params:
32+
RCID_WIDTH:
33+
description: |
34+
Number of bits used for the Resource Control ID field (RCID).
35+
Default is 12.
36+
schema:
37+
type: integer
38+
minimum: 1
39+
maximum: 12
40+
41+
MCID_WIDTH:
42+
description: |
43+
Number of bits used for the Monitoring Counter ID field (MCID).
44+
Default is 12.
45+
schema:
46+
type: integer
47+
minimum: 1
48+
maximum: 12
49+
50+
versions:
51+
- version: "1.0.0"
52+
state: ratified
53+
ratification_date: "2024-06"
54+
url: "https://github.com/riscv/riscv-isa-manual/releases/tag/riscv-isa-release-5308687-2025-04-22"
55+
requires: { name: S, version: ~> 1.13 }

0 commit comments

Comments
 (0)