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

arch: riscv: smp: refactor IPI functions and guard with CONFIG_RISCV_SMP_IPI_CLINT #78493

Closed
wants to merge 1 commit into from

Conversation

ycsin
Copy link
Member

@ycsin ycsin commented Sep 16, 2024

Currently, the RISC-V SMP IPI implementation is CLINT-based. However, IPI in RISC-V is not necessarily always done through a CLINT, in SoC with PLIC connected to the MSIP (i.e. Andes AE350's PLIC_SW), IPI has to be routed through the PLIC.

This patch refactor the IPI delivery into functions and guard it with CONFIG_RISCV_SMP_IPI_CLINT, so that for SoC that do not have a sifive,clint0 device, and has a different IPI mechanism, they can implement their own z_riscv_ipi_send() & z_riscv_ipi_clear().

Note

This is an alternative for #65824

  • probably should add an entry to the release note

@ycsin ycsin requested review from cfriedt and luchnikov September 16, 2024 15:04
@ycsin ycsin marked this pull request as ready for review September 16, 2024 15:04
@zephyrbot zephyrbot added the area: RISCV RISCV Architecture (32-bit & 64-bit) label Sep 16, 2024
arch/riscv/core/smp.c Outdated Show resolved Hide resolved
@ycsin
Copy link
Member Author

ycsin commented Sep 16, 2024

cc @cwshu @kevinwang821020 @jimmyzhe

@ycsin ycsin added the platform: Andes Andestech Platform label Sep 16, 2024
Copy link
Collaborator

@npitre npitre left a comment

Choose a reason for hiding this comment

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

Rather than adding another abstraction layer, I'd suggest creating ipi_clint.c
and ipi_plic.c then implement arch_sched_directed_ipi() and friends for each
of them. The cpu_pending_ipi[] array exists only because there is no way to
distinguish different IPI causes using CLINT. It might be the case that the
PLIC version doesn't need it.

@ycsin ycsin removed the platform: Andes Andestech Platform label Sep 17, 2024
@ycsin ycsin requested a review from nashif September 17, 2024 05:54
@ycsin ycsin force-pushed the pr/riscv-msip-trigger branch from cd58558 to bfc7977 Compare September 17, 2024 05:59
@ycsin
Copy link
Member Author

ycsin commented Sep 17, 2024

The cpu_pending_ipi[] array exists only because there is no way to
distinguish different IPI causes using CLINT. It might be the case that the
PLIC version doesn't need it.

True, but I think it depends on the way the ipi_plic.c is implemented, unless we are using one interrupt line for each of the IPI type per CPU, we will need cpu_pending_ipi[] to multiplex the interrupt (it is also used in arch_spin_relax()).

In any case, there's quite a bit of work to be done before we can get to ipi_plic.c upstream:

  • PLIC interrupt affinity - irq: introduce new irq_set_affinity() API - alternate #77828
  • Implement irq_set_pending() in PLIC - should be pretty straightforward
  • Determine how are we going to allocate the PLIC IRQs for IPI, potentially with the option to switch between:
    • 1 interrupt per core (total num of irqs: 1 x NUM_CPUs) - this allows plic/clint implementation to share basically all the existing code, the only difference is the signalling 'middleware', which will be abstracted by the z_riscv_ipi_send & z_riscv_ipi_clear in this PR, or
    • 1 interrupt per IPI per core (total num of irqs: NUM_IPIs x NUM_CPUs) - this allows dedicated irq handler for each of the IPI without the need to multiplex the IRQ

As an alternative to #65824 (compile out the entirety of clint IPI code), this PR is more like an incremental step for us to implement the ipi_plic upstream in the future, and meanwhile allow SoC without CLINT to implement their own IPI code if they wish

@ycsin ycsin changed the title arch: riscv: smp: refactor IPI functions and guard with "sifive,clint0" arch: riscv: smp: refactor IPI functions and guard with CONFIG_RISCV_SMP_IPI_CLINT Sep 17, 2024
@ycsin ycsin marked this pull request as draft September 24, 2024 15:23
Currently, the RISC-V SMP IPI implementation is CLINT-based.
However, IPI in RISC-V is not necessarily always done through a
CLINT, in SoC with PLIC connected to the MSIP
(i.e. Andes AE350), IPI has to be routed through the PLIC.

This patch refactor the IPI delivery into functions and guard
it with `CONFIG_RISCV_SMP_IPI_CLINT`, so that
for SoC that do not have a clint device, and requires a
different IPI mechanism, they can implement their own
`z_riscv_ipi_send()` & `z_riscv_ipi_clear()`.

Signed-off-by: Yong Cong Sin <[email protected]>
Signed-off-by: Yong Cong Sin <[email protected]>
@ycsin ycsin force-pushed the pr/riscv-msip-trigger branch from bfc7977 to 374aac5 Compare September 27, 2024 07:48
Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Nov 27, 2024
@ycsin ycsin closed this Nov 27, 2024
@ycsin ycsin deleted the pr/riscv-msip-trigger branch November 27, 2024 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: RISCV RISCV Architecture (32-bit & 64-bit) Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants