Skip to content

Add ssqosid extension and csr yaml #653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

syedowaisalishah
Copy link
Contributor

This PR adds:

  • Extension YAML file for Ssqosid
  • CSR YAML file for Ssqosid: srmcfg

Closes #567

normative: true
text: |
If extension Smstateen is implemented together with Ssqosid, then Ssqosid also requires the SRMCFG bit in mstateen0 to be implemented.
If mstateen0.SRMCFG is 0, attempts to access srmcfg in privilege modes less privileged than M-mode raise an illegal-instruction exception.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this means you need to implement sw_read() and sw_write() to validate this restriction.

- id: csr-srmcfg-vsmode-exception
normative: true
text: |
If mstateen0.SRMCFG is 1 or if extension Smstateen is not implemented, attempts to access srmcfg when V=1 raise a virtual-instruction exception.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also needs to be similarly validated.

Copy link
Contributor Author

@syedowaisalishah syedowaisalishah May 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ThinkOpenly , I've implemented both sw_read() and sw_write() to enforce access restrictions based on Smstateen and the SRMCFG bit in mstateen0, as specified in the normative text. Here's what the logic looks like:

sw_read(): |
  if (has_ext("Smstateen")) {
    if (mode() < PrivilegeMode::M && !CSR[mstateen0].SRMCFG) {
      raise(ExceptionCode::IllegalInstruction, mode(), $encoding);
    }
    if (virt() && CSR[mstateen0].SRMCFG) {
      raise(ExceptionCode::VirtualInstruction, mode(), $encoding);
    }
  } else {
    if (virt()) {
      raise(ExceptionCode::VirtualInstruction, mode(), $encoding);
    }
  }
  return self.value;

sw_write(csr_value): |
  if (has_ext("Smstateen")) {
    if (mode() < PrivilegeMode::M && !CSR[mstateen0].SRMCFG) {
      raise(ExceptionCode::IllegalInstruction, mode(), $encoding);
    }
    if (virt() && CSR[mstateen0].SRMCFG) {
      raise(ExceptionCode::VirtualInstruction, mode(), $encoding);
    }
  } else {
    if (virt()) {
      raise(ExceptionCode::VirtualInstruction, mode(), $encoding);
    }
  }
  self.value = value;

However, I'm currently getting the following IDL validation error:
CSR 'mstateen0' is not defined
This is expected since mstateen0.yaml is introduced in PR #592, which hasn't been merged yet.
Could you please advise me on what I should do?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think #592 is getting close. I don't have much experience with this, but you can apparently rebase your branch on top of the branch for #592 and pick up those changes for your testing. Once #592 gets merged, your branch will automatically get rebased to main, and will continue working.

Copy link
Contributor Author

@syedowaisalishah syedowaisalishah May 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ThinkOpenly.
I struggled a bit with rebasing onto the branch from PR #592, so for testing purposes, I manually copied over the mstateen* CSR definitions and the Smstateen extension from that PR. I also added srmcfg as a field in mstateen0 to resolve the validation error.
With those changes, I was able to work through and resolve all the issues I faced during IDL writing—except for one that I’m still stuck on. Specifically, I get the following error:
A type error occurred no symbol named 'value' on line 146
idl code:

Here’s the relevant snippet:
return value;
I’m not sure what I’m doing wrong here. Do you have any guidance on how to resolve this?

sw_read(): |
  if (implemented?(ExtensionName::Smstateen)) {
    if (mode() < PrivilegeMode::M && CSR[mstateen0].SRMCFG == 0) {
      raise(ExceptionCode::IllegalInstruction, mode(), $encoding);
    }
    if (virtual_mode?() && CSR[mstateen0].SRMCFG == 1) {
      raise(ExceptionCode::VirtualInstruction, mode(), $encoding);
    }
  } else {
    if (virtual_mode?()) {
      raise(ExceptionCode::VirtualInstruction, mode(), $encoding);
    }
  }
  return value;
  
  sw_write(csr_value): |
      if (implemented?(ExtensionName::Smstateen)) {
        if (mode() < PrivilegeMode::M && CSR[mstateen0].SRMCFG == 0) {
          raise(ExceptionCode::IllegalInstruction, mode(), $encoding);
        }
        if (virtual_mode?() && CSR[mstateen0].SRMCFG == 1) {
          raise(ExceptionCode::VirtualInstruction, mode(), $encoding);
        }
      } else {
        if (virtual_mode?()) {
          raise(ExceptionCode::VirtualInstruction, mode(), $encoding);
        }
      }
      value = csr_value;

      rcid_mask = 0xFFF
      mcid_mask = 0xFFF

      rcid = csr_value & rcid_mask
      mcid = (csr_value >> 16) & mcid_mask

      value = (mcid << 16) | rcid

normative: true
text: |
The srmcfg register is used to configure a Resource Control ID (RCID) and a Monitoring Counter ID (MCID).
Both RCID and MCID are WARL fields.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"WARL fields" means that, technically, an implementation can decide to accept any set of valid identifiers (including nothing) and reject the rest. We can't model that, so I suggest we don't try.

Practically, this usually means that an implementation is going to select some number of bits to implement (>= the size of the fields) for each. We can model that.

To reflect the number of implemented bits, we need a parameter in Ssqosid for each of RCID and MCID widths, and sw_write() functions to enforce it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@syedowaisalishah, have you had a chance to try this yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dhower-qc I haven’t had a chance to try this yet—I just finished the earlier part and will be starting on this next.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, thanks for the update

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dhower-qc, I’ve implemented the validation logic in the sw_write() function to enforce the WARL constraints for RCID and MCID. Since the YAML schema doesn't allow top-level parameters:, I hardcoded the masks directly in the IDL code like this:

value = csr_value;
rcid_mask = 0xFFF       # 12-bit RCID
mcid_mask = 0xFFF       # 12-bit MCID
rcid = csr_value & rcid_mask
mcid = (csr_value >> 16) & mcid_mask
value = (mcid << 16) | rcid

This effectively limits both fields to their respective implemented widths (12 bits here).
Is this the correct way to handle it, given the schema limitation?

@syedowaisalishah syedowaisalishah requested a review from dhower-qc May 9, 2025 21:07
description: |
The `RCID` is used to determine the resource allocations (e.g., cache occupancy limits,
memory bandwidth limits, etc.) to enforce.
reset_value: UNDEFINED_LEGAL
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this should be 0, given the text:

A reset value of 0 is suggested for the RCID field

But, given the "suggested" language, I'm not sure, or if that implies a configuration parameter is required? @dhower-qc

@syedowaisalishah
Copy link
Contributor Author

syedowaisalishah commented May 13, 2025

@ThinkOpenly , @dhower-qc
I’ve updated the idl code with all the requested changes, and the local smoke tests are passing.
However, the smoke test is currently failing on GitHub because it depends on the mstateen0.yaml CSR and the Smstateen extension, which are not yet included in this PR. These components are available under PR #592. Once #592 is merged, the smoke tests for this PR should pass as expected.

That said, I noticed that mstateen0.yaml in PR #592 is missing the definition for the SRMCFG field under fields. This field is necessary for proper validation checks in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Ssqosid CSR
3 participants