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

kernel: smp: Optimize delivery of IPIs #69770

Merged
merged 5 commits into from
Jun 5, 2024

Conversation

peter-mitsis
Copy link
Collaborator

This set of commits is a step towards optimising the delivery of inter-processor interrupts (IPIs). It does this by attempting to deliver IPIs only to relevant CPUs.

The bulk of these changes revolve around three ideas.

  1. The kernel's pending_ipi field has been tweaked from being a single flag that indicates IPIs are needed to a bitmap whose bits indicate the CPUs that need to receive an IPI.
  2. When a thread is made ready, only CPUs that are executing a lower priority thread get flagged as needing an IPI as they are the only ones that have a chance to schedule the newly readied thread.
  3. The arch_sched_ipi() API now accepts a parameter identifying which CPUs should receive an IPI. If the platform allows it, a targeted IPI is sent. If not, then the IPIs are still broadcast to all CPUs.

@zephyrbot zephyrbot added area: RISCV RISCV Architecture (32-bit & 64-bit) area: X86 x86 Architecture (32-bit) area: Kernel platform: ESP32 Espressif ESP32 area: ARM64 ARM (64-bit) Architecture area: ARM ARM (32-bit) Architecture area: ARC ARC Architecture area: Base OS Base OS Library (lib/os) platform: Intel ADSP Intel Audio platforms labels Mar 4, 2024
@zephyrbot
Copy link
Collaborator

zephyrbot commented Mar 4, 2024

The following west manifest projects have been modified in this Pull Request:

Name Old Revision New Revision Diff
sof zephyrproject-rtos/sof@a447588 zephyrproject-rtos/sof@3f1716b (zephyr_wip2,zephyr) zephyrproject-rtos/sof@a4475888..3f1716b0

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@zephyrbot zephyrbot added manifest manifest-sof DNM This PR should not be merged (Do Not Merge) labels Mar 4, 2024
@zephyrbot zephyrbot removed the DNM This PR should not be merged (Do Not Merge) label Jun 4, 2024
@peter-mitsis
Copy link
Collaborator Author

Rebased to resolve a merge conflict.

andyross
andyross previously approved these changes Jun 4, 2024
Copy link
Contributor

@andyross andyross left a comment

Choose a reason for hiding this comment

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

Refresh +1

npitre
npitre previously approved these changes Jun 4, 2024
@nashif
Copy link
Member

nashif commented Jun 4, 2024

@peter-mitsis there is a failure because of another change in the SOF tree, I am working on resolving this now, but the conflict here not sure what is it about.

@@ -34,7 +34,7 @@ manifest:
groups:
- optional
- name: sof
revision: c11a3185afbc8e1b2a79916de3dfefaf326d9ad1
revision: ac1b774abfe2e8a9f6547f5bc305e499c51f9671
Copy link
Member

@nashif nashif Jun 4, 2024

Choose a reason for hiding this comment

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

point to this 1e4702f3080c68e6046b7b16eb030a3eba0ce231 instead.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@nashif
Copy link
Member

nashif commented Jun 4, 2024

but the conflict here not sure what is it about.

ok, that was the esf change...

@peter-mitsis
Copy link
Collaborator Author

Updated submanifest as per @nashif's request -- nothing else changed.

nashif
nashif previously approved these changes Jun 4, 2024
evgeniy-paltsev
evgeniy-paltsev previously approved these changes Jun 4, 2024
npitre
npitre previously approved these changes Jun 5, 2024
1. The flagging of IPIs is moved out of k_thread_priority_set() into
z_thread_prio_set(). This allows for an IPI to be done for a thread
that had its priority bumped due to the handling of priority
inheritance from a mutex.

2. k_thread_priority_set()'s check for sched_locked only applies to
non-SMP builds that are using the old arch_swap() framework to switch
between threads.

Incidentally, nearly all calls to flag_ipi() are now performed with
sched_spinlock being locked. The only exception is in slice_timeout().

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
The CONFIG_IPI_OPTIMIZE configuration option allows for the flagging
and subsequent signaling of IPIs to be optimized.

It does this by making each bit in the kernel's pending_ipi field
a flag that indicates whether the corresponding CPU might need an IPI
to trigger the scheduling of a new thread on that CPU.

When a new thread is made ready, we compare that thread against each
of the threads currently executing on the other CPUs. If there is a
chance that that thread should preempt the thread on the other CPU
then we flag that an IPI is needed for that CPU. That is, a clear bit
indicates that the CPU absolutely will not need to reschedule, while a
set bit indicates that the target CPU must make that determination for
itself.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
Platforms that support IPIs allow them to be broadcast via the
new arch_sched_broadcast_ipi() routine (replacing arch_sched_ipi()).
Those that also allow IPIs to be directed to specific CPUs may
use arch_sched_directed_ipi() to do so.

As the kernel has the capability to track which CPUs may need an IPI
(see CONFIG_IPI_OPTIMIZE), this commit updates the signalling of
tracked IPIs to use the directed version if supported; otherwise
they continue to use the broadcast version.

Platforms that allow directed IPIs may see a significant reduction
in the number of IPI related ISRs when CONFIG_IPI_OPTIMIZE is
enabled and the number of CPUs increases.  These platforms can be
identified by the Kconfig option CONFIG_ARCH_HAS_DIRECTED_IPIS.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
Updates the sof revision. This is needed for it to pick up a
change to the arch_sched_ipi() which has been renamed to
arch_sched_broadcast_ipi().

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
Adds several tests to verify that IPIs can be appropriately
targeted to specific CPUs.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
@nashif nashif dismissed stale reviews from npitre, evgeniy-paltsev, and themself via 05c473a June 5, 2024 01:00
Copy link
Contributor

@andyross andyross left a comment

Choose a reason for hiding this comment

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

Again

@nashif nashif merged commit 48285cb into zephyrproject-rtos:main Jun 5, 2024
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ARC ARC Architecture area: Architectures area: ARM ARM (32-bit) Architecture area: ARM64 ARM (64-bit) Architecture area: Base OS Base OS Library (lib/os) area: Kernel area: RISCV RISCV Architecture (32-bit & 64-bit) area: X86 x86 Architecture (32-bit) manifest manifest-sof platform: ESP32 Espressif ESP32 platform: Intel ADSP Intel Audio platforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.