Skip to content
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

Migrate to ACLINT #66

Merged
merged 2 commits into from
Dec 16, 2024
Merged

Migrate to ACLINT #66

merged 2 commits into from
Dec 16, 2024

Conversation

Mes0903
Copy link
Collaborator

@Mes0903 Mes0903 commented Dec 12, 2024

In this commit, based on the implementation of CLINT, an preliminary ACLINT is implemented, including the basic logic for operating mtimer, mswi, and sswi. And this commit replaced CLINT with ACLINT, the old CLINT implementation was removed.

Currently, due to the lack of implementation, the introduced ACLINT uses only supervisor-level IPI. Therefore, although the logic for mswi is implemented, it is not being used at the moment.

It can be tested by make check SMP=n, where n is the number of harts you want to simulate.

@jserv jserv requested review from chiangkd and ranvd December 12, 2024 14:46
feature.h Outdated Show resolved Hide resolved
reg = <0x4300000 0x10000>;
sswi0: sswi@4500000 {{
#interrupt-cells = <0>;
interrupt-controller;
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can add address-cells = <0> to suppress "Missing #address-cells" warning provided by DTC v1.6.1

Reference: #37


mswi0: mswi@4400000 {{
#interrupt-cells = <0>;
interrupt-controller;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto.

aclint.c Outdated Show resolved Hide resolved
@@ -53,7 +53,7 @@ OBJS := \
plic.o \
uart.o \
main.o \
clint.o \
aclint.o \
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm uncertain if the CLINT-related implementation will still exist once ACLINT is fully implemented. If it does, add an option here to use CLINT when ACLINT is unavailable.

@Mes0903
Copy link
Collaborator Author

Mes0903 commented Dec 13, 2024

In the latest commit, ENABLE_ACLINT was added to the Makefile. This flag determines whether to use CLINT or ACLINT, with CLINT being the default. The ACLINT can be tested by make check SMP=n ENABLE_ACLINT=1 now.

@jserv
Copy link
Collaborator

jserv commented Dec 14, 2024

In the latest commit, ENABLE_ACLINT was added to the Makefile. This flag determines whether to use CLINT or ACLINT, with CLINT being the default. The ACLINT can be tested by make check SMP=n ENABLE_ACLINT=1 now.

I don't think we should maintain both CLINT and ACLINT implementation. The RISC-V Advanced Core Local Interruptor (ACLINT) enhances the existing SiFive CLINT design through several key improvements:

  • Modular Architecture: ACLINT adopts a modular approach by separating timer and inter-processor interrupt (IPI) functionalities into distinct devices. This design enables RISC-V platforms to selectively implement only the necessary components, providing greater flexibility in system design.
  • Dedicated S-Level IPI Device: The specification introduces a dedicated memory-mapped I/O (MMIO) device specifically for supervisor-level IPIs. This innovation eliminates the need to use Supervisor Binary Interface (SBI) calls for interrupt communication in Linux RISC-V systems, streamlining interrupt handling.
  • Multi-Instance Support: ACLINT supports multiple timer and IPI device instances, a critical feature for multi-socket or multi-die Non-Uniform Memory Access (NUMA) system architectures. This capability allows for more complex and scalable system designs.
  • Backward Compatibility: The specification maintains full compatibility with the original SiFive CLINT, ensuring that existing RISC-V platforms can seamlessly conform to the new ACLINT specification without requiring extensive redesigns or hardware modifications.

The recent Linux kernel now provides support for ACLINT, and QEMU has also integrated this feature, allowing users to enable it through the -machine virt,aclint=on option. Given these developments, it is an opportune time to transition to the ACLINT architecture.

@Mes0903
Copy link
Collaborator Author

Mes0903 commented Dec 14, 2024

The latest commit removed all implementations of CLINT, including the previously introduced ENABLE_ACLINT and OBJS_IR_CTRL. Currently, the project only contains the implementation of ACLINT.

@Mes0903
Copy link
Collaborator Author

Mes0903 commented Dec 14, 2024

Due to two minor issues in the first commit of this PR—specifically, the absence of #address-cells = <0> causing DTC warnings, and the lack of a newline at the end of aclint.c—two additional small commits were added, making the commit history cluttered, also the commit message didn't follow the rule listed in https://cbea.ms/git-commit/.

To address this, the first commit message has been rewritten in accordance with the commit message rules, and the two minor issues have also been fixed in the process.

Copy link
Collaborator

@jserv jserv left a comment

Choose a reason for hiding this comment

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

Don't use backticks for the sake of terminal compatibility. Use single quotation marks instead.

@jserv jserv requested a review from chiangkd December 14, 2024 14:44
Copy link
Collaborator

@jserv jserv left a comment

Choose a reason for hiding this comment

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

Improve git commit messages by:

  1. Clearly articulating the rationale behind transitioning from CLINT to ACLINT, highlighting the motivations and potential benefits of this migration.
  2. Detailing the methodological approach for verifying and validating the functionalities of the proposed ACLINT support, including specific testing strategies or validation criteria.
  3. Summarize the Linux kernel support on ACLINT along with git revisions.
  4. Outlining potential future development paths to enhance and complete the SMP support, identifying specific areas for improvement or expansion.

By the way, it is not necessary to mention "preliminary" if the proposed change covers the functionalities of CLINT. Instead, the major consideration is to migrate.

aclint.c Outdated Show resolved Hide resolved
aclint.c Outdated Show resolved Hide resolved
device.h Outdated Show resolved Hide resolved
device.h Outdated Show resolved Hide resolved
@jserv jserv changed the title Preliminary ACLINT implementation Migrate to ACLINT Dec 14, 2024
@Mes0903
Copy link
Collaborator Author

Mes0903 commented Dec 15, 2024

The latest commit includes the following updates:

  • Unified the use of C-style comments throughout the code.
  • Removed the @brief notation, replacing it with plain and informative sentences.
  • Replaced backticks with single quotation marks for consistency.
  • Elaborated on the fundamental principles behind the transition from CLINT to ACLINT, emphasizing the motivations and benefits of this migration.
  • Summarized Linux kernel support for ACLINT along with relevant git revisions.
  • Provided detailed instructions on how to validate ACLINT functionalities, including specific testing strategies and validation methods.
  • Outlined potential future development paths to enhance and complete SMP support, specifying areas for improvement or expansion.

@jserv
Copy link
Collaborator

jserv commented Dec 15, 2024

The latest commit includes the following updates:

Don't attempt to summarize your changes. Instead, we always care about the changesets. Let's consolidate each git commit without unnecessary report.

aclint.c Outdated Show resolved Hide resolved
aclint.c Outdated Show resolved Hide resolved
device.h Outdated
*
* For more details, please refer to the register map at:
* https://github.com/riscv/riscv-aclint/blob/main/riscv-aclint.adoc#21-register-map
*/
uint64_t mtimecmp[4095];
Copy link
Collaborator

Choose a reason for hiding this comment

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

The pre-allocated mtimecmp causes unexpected memory waste since we don't really need all of its members. Consider allocating it on-demand.

device.h Outdated Show resolved Hide resolved
jserv

This comment was marked as resolved.

Makefile Outdated Show resolved Hide resolved
device.h Outdated
Comment on lines 177 to 179
#ifndef NUM_HARTS
#define NUM_HARTS 1
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto. Remove the uncertain code.

device.h Outdated
@@ -190,7 +196,7 @@ typedef struct {
* For more details, please refer to the register map at:
* https://github.com/riscv/riscv-aclint/blob/main/riscv-aclint.adoc#21-register-map
*/
uint64_t mtimecmp[4095];
uint64_t mtimecmp[NUM_HARTS];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Allocate via runtime instead of build-time.

main.c Outdated Show resolved Hide resolved
main.c Outdated Show resolved Hide resolved
To implement timer interrupts and inter-processor interrupts (IPIs) on
RISC-V, ACLINT and CLINT are the commonly used hardware components. The
key difference between ACLINT and CLINT lies in ACLINT’s ability to
support both Supervisor software interrupts (SSWI) and Machine software
interrupts (MSWI).

Additionally, ACLINT modularizes its hardware functionalities, such as
timers and IPI controllers, making the design and implementation more
flexible than CLINT.

According to the Linux kernel documentation:
https://www.kernel.org/doc/html/next/riscv/boot.html#kernel-entry,
there are two methods for entering the Linux kernel on SMP systems:
- RISCV_BOOT_SPINWAIT: Boots all harts simultaneously, mainly used
  for older firmwares without SBI HSM extension and M-mode RISC-V
  kernels.
- Ordered booting: Utilizes the SBI HSM extension to boot only one
  hart during the initial boot phase.

The Linux kernel introduced ordered booting (commit 'cfafe26') to
simplify multi-stage SMP boot management. The commit explains that the
previous method complicated the multi-stage boot process, requiring
management of all harts at each stage. The SBI HSM extension simplifies
this by booting only one hart initially, which can then bring up the
remaining harts sequentially.

To fully support the HSM extension, ACLINT is necessary. particularly
for supervisor-level interrupt management.

This commit transitions from CLINT to ACLINT, aligning with modern
RISC-V specifications and providing support for 'mtimer', 'mswi', and
'sswi'. The existing CLINT implementation has been removed entirely as
ACLINT covers its functionalities.

Testing instructions:
- Run the following command to test the implementation:
  'make check SMP=n', where 'n' is the number of harts to simulate.
- After booting the emulator:
  - Verify multi-core operation and HSM implementation with
    '/proc/cpuinfo'.
  - Check timer interrupts via '/proc/interrupts'.
  - Confirm ACLINT is correctly recognized using '/proc/device-tree'.

Future work:
Currently, due to the lack of implementation, the introduced ACLINT uses
only supervisor-level IPI. Therefore, although the logic for mswi is
implemented, it is not being used at the moment.

Also, SMP support remains incomplete. For example, the current semu
implementation sequentially simulates multi-core execution, causing a
slowdown as the number of cores increases. This leads to a time
desynchronization issue across cores.

To achieve multi-threaded system emulation, RFENCE extension
implementation is required. However, it is currently incomplete. After
completing ACLINT, the next step is to implement the RFENCE extension to
fully support multi-threaded system emulation.
@Mes0903
Copy link
Collaborator Author

Mes0903 commented Dec 15, 2024

Refine the wording in both comments and the previous git commit message. And use calloc to allocate the registers in ACLINT at runtime.

@jserv jserv merged commit d9cd460 into sysprog21:master Dec 16, 2024
3 checks passed
@jserv
Copy link
Collaborator

jserv commented Dec 16, 2024

Thank @Mes0903 for contributing!

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.

3 participants