Commit graph

30 commits

Author SHA1 Message Date
Kent McLeod
34725d060b arm: Add new APIs for generating SGIs
Allow SGIs to be generated from non-SMP kernels.

Signed-off-by: Kent McLeod <kent@kry10.com>
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2025-07-07 08:50:47 +10:00
Indan Zupancic
81679f2b95 SMP: Fix IPI Race
Use atomic operations to get and set the IPI pending flag to
ensure that if an IPI is observed, the IPI arguments are also
observed.

Using atomics makes this requirement explicit to the compiler.

Without this change there is a race between setting up an IPI
and another core checking for ipi == 1. This can happen before
IPI_MEM_BARRIER has been executed.

Found by Yanyan Shen.

Signed-off-by: Indan Zupancic <indan@nul.nu>
2025-02-27 09:29:48 +11:00
Indan Zupancic
1c154c85f5 SMP: Avoid undefined CAS delays in kernel lock
Align the kernel lock to the exclusive reservation granule size.
Without this nearby writes can delay atomic operations implemented
with looping exclusive load/store instructions for an undefined time.

Cleanup IPI code.

Signed-off-by: Indan Zupancic <Indan.Zupancic@mep-info.com>
2025-02-27 09:29:48 +11:00
Indan Zupancic
33726d45a0 SMP: Align lock data instead of explicit padding
Signed-off-by: Indan Zupancic <Indan.Zupancic@mep-info.com>
2025-02-27 09:29:48 +11:00
Indan Zupancic
4e74d029cc SMP: Cleanup kernel lock
Remove cpu argument from clh_lock_acquire/release, it is never
valid to call them with something else than getCurrentCPUIndex().

Use clh_is_self_in_queue() instead of poking into lock internals
in ipiStallCoreCallback().

Add some comments from the paper to make it easier to match the
implementation with the description in the paper it's based on.
Don't use confusingly different naming, but follow naming from
the paper: Rename 'node' to 'myreq' and 'next' to 'watch', etc.

Signed-off-by: Indan Zupancic <Indan.Zupancic@mep-info.com>
2025-02-27 09:29:48 +11:00
Axel Heider
18944f5072 smp: avoid redundancy
Signed-off-by: Axel Heider <axelheider@gmx.de>
2025-02-27 09:29:48 +11:00
Indan Zupancic
17e968ad02 Remove try_arch_atomic_exchange_rlx
This reverts commit 3d2ae69f9c:
"ARM/SMP: Re-implement atomic exchange taking sel4 IPI into account"

Also removed riscv's try_arch_atomic_exchange_rlx().

This was added because CAS can take very long to finish on ARM if
the exclusive reservation granule (ERG) is large for the platform,
as any writes on other cores within up to 2Kb could make the CAS
fail.

The correct fix is to add padding around the global lock equal to ERG
to make CAS fast, which would make the extra IPI check redundant.

Signed-off-by: Indan Zupancic <Indan.Zupancic@mep-info.com>
2025-02-27 09:29:48 +11:00
Axel Heider
e44ef0efd1 create helper function handle_SysDebugSendIPI()
Halt system if syscall in unsupported on the current architecture.

Signed-off-by: Axel Heider <axelheider@gmx.de>
2022-01-10 11:58:30 +11:00
Indan Zupancic
503a5358c7 Remove unused doReschedule()
Signed-off-by: Indan Zupancic <Indan.Zupancic@mep-info.com>
2021-12-02 15:42:13 +11:00
jonas
fe1278326f Repair barriers in clh_lock_acquire
Strengthen the clh_lock_acquire to use release on the atomic_exchange
that makes the node public. Otherwise (on ARM & RISCV), the store to
the node value which sets its state to CLHState_Pending can become
visible some time after the node is visible.
In that window of time, the next thread which attempts to acquire the
lock will still see the old state (CLHState_Granted) and enters the
critical section, leading to a mutual exclusion violation.

Signed-off-by: jonas <s9joober@gmail.com>
2020-06-22 11:53:08 +10:00
jonas
8ba22dcdc5 Repair barriers in sel4_atomic_exchange
The implementation of try_arch_atomic_exchange does not correctly pass
RELEASE memory ordering (or stronger) to the exchange operation.
To acknowledge this, try_arch_atomic_exchange is replaced by a relaxed
try_arch_atomic_exchange_rlx which does not apply any memory ordering.
Instead, the memory ordering is now added manually by
sel4_atomic_exchange. This provides better latency for interrupts as no
barriers are evoked inside the loop which performs the relaxed exchange
and checks for interrupts.
Furthermore, the new manual application of barriers ensures the memory
ordering passed to sel4_atomic_exchange.

Signed-off-by: jonas <s9joober@gmail.com>
2020-06-22 11:49:22 +10:00
Qian Ge
512a0200de replacing all ifndef with pargma once
All the kernel header files now use pargma once rather than the ifndef,
as the pre-processed C files do not change while header files
are protected with pargma once. This will also solve any naming issues
caused by ifndef.
2020-03-23 11:04:46 +11:00
Gerwin Klein
79da079239 Convert license tags to SPDX identifiers
This commit also converts our own copyright headers to directly use
SPDX, but leaves all other copyright header intact, only adding the
SPDX ident. As far as possible this commit also merges multiple
Data61 copyright statements/headers into one for consistency.
2020-03-09 13:21:49 +08:00
Anna Lyons
c4fe536984 arm: remote IPI call support for VIRQS
Added support for injecting remote IPI calls towards given VCPU's
on SMP configured systems. This introudcing a new type of
IpiRemoteCall and handlers for updating the vgic state on
incoming/outgoing IPI's.

Co-authored-by: Yanyan Shen <yanyan.shen@data61.csiro.au>
2020-02-20 12:53:04 +11:00
Kent McLeod
2d362cb7c8 arm,SMP: Refactor irq_t structure for smp
Explicitly create a struct definition for irq_t on SMP Arm
configurations. This makes it a lot harder to mistakenly use the wrong
irq encoding when moving an irq between a cnode index and hardware irq
number / core. A couple areas where this was being handled incorrectly
was fixed as part of the refactor. When performing an ipi for masking
PPI interrupts, the idx encoding is used as it fits into a single word.
2020-02-05 13:56:48 +11:00
Anna Lyons
d0930f67de style: consistently attach return type
Add attach-return-type to astyle
2019-03-19 14:05:36 +11:00
Anna Lyons
761006e03b style: consistently align pointer with name
Run astyle with align-pointer=name
2019-03-19 14:04:54 +11:00
Hesham Almatary
3d2ae69f9c ARM/SMP: Re-implement atomic exchange taking sel4 IPI into account 2017-11-23 14:35:54 +11:00
Adrian Danis
4e121d0c48 smp: Use explicit fences instead of volatile
This provides a more robust and efficient implementation that only forces memory reloads
at explicit known points, instead of the over approximation of every time they are
accessed that is forced by volatile.
2017-11-03 11:39:32 +11:00
Hesham Almatary
ee28936d48 SMP: Introduce ENABLE_SMP_SUPPORT
- Make it more readable and less confusing compared to the 'CONFIG_MAX_NUM_NODES > 1' check
2017-06-29 16:23:39 +10:00
Hesham Almatary
40970c300e SMP: allow an architecture to provide its own optimised IPI send function 2017-06-23 10:36:36 +10:00
Hesham Almatary
8f713ab44f SELFOUR-747: SMP/x86: generalize arch-independent IPI code 2017-06-23 10:36:36 +10:00
Anna Lyons
40c61e5c18 Fix licenses (the rest) 2017-06-22 15:29:12 +10:00
amrzar
93cc22b289 smp: fix bugs when stalling remote core
- Restart TCB from inside the lock if it is waiting for anything other than IRQ
- Only replace the TCB with idle thread if it is in ThreadState_RunningVM state

Also, this makes the design generic to be shared with arm.
2017-03-30 09:46:43 +11:00
Adrian Danis
eccaae51dc s/D61/DATA61/ in license headers for consistency 2017-02-21 16:38:51 +11:00
Hesham Almatary
48d17e1f58 ARM/SMP: Prepare for ARM SMP adding stubs
Currently building ARM/SMP is broken. This commit:
1- Makes it possible to build ARM/SMP with stubs. Run-time SMP for ARM
DOES NOT WORK.
2- Can be a reference for future SMP targets to follow in order to
layout/add the minimal required files and functions needed to support SMP.
3- Builds for Sabre only. In order to support other platforms, ipi
interrupt ID should be defined in machine.h
2017-02-16 15:28:00 +11:00
Bamboo
5845659ea0 [STYLE_FIX] 2017-01-16 22:32:08 +00:00
Hesham Almatary
ffc18fe880 SMP: use C++11 __atomic builtins instead of legacy __sync buitins 2017-01-16 16:27:16 +11:00
Hesham Almatary
af02927b69 SMP: move lock.h to architecture-independent include/smp
s/__sync_lock_test_and_set/__atomic_exchange_n in lock.h
2017-01-16 15:21:50 +11:00
Hesham Almatary
53c6b52438 SMP: Abstract architecture/platform independent parts of smp.h and ipi.h
This commit is a re-arrangement of SMP directory structure to make it
easier for other architectures/platforms (in general) and ARM (in
particular) to add SMP support.

* new include/smp directory to act as a centralised container of
"shared" architecture-independent SMP headers.
This makes it clearer what's needed for other architecture/platform to
support SMP.
* Each platform can define its own unique ipi.[h|c] that make sense,
since ipi implementation is SoC/platform dependent.
2017-01-13 15:35:41 +11:00