From 427f2c60da0beb8b68e85bbcf2cbbfd59ad469f8 Mon Sep 17 00:00:00 2001 From: Peter Mitsis Date: Mon, 13 Jan 2025 10:04:24 -0800 Subject: [PATCH] kernel: arch: add directed IPIs to x86/intel64 Adds support for directed IPIs to x86/intel64. Use of direct IPIs can further reduce the number of schedule IPIs sent and processed in a system. Fewer IPI related ISRs mean that ... 1. Application code is interrupted less frequently 2. Lower likelihood of scheduler spinlock contention Signed-off-by: Peter Mitsis --- arch/x86/Kconfig | 1 + arch/x86/core/intel64/smp.c | 13 +++++++++++++ .../zephyr/drivers/interrupt_controller/loapic.h | 1 + 3 files changed, 15 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index c947c0afc1b..9a3412ba042 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -83,6 +83,7 @@ config X86_64 select X86_MMX select X86_SSE select X86_SSE2 + select ARCH_HAS_DIRECTED_IPIS menu "x86 Features" diff --git a/arch/x86/core/intel64/smp.c b/arch/x86/core/intel64/smp.c index 1e0aeb3e443..90bd9724667 100644 --- a/arch/x86/core/intel64/smp.c +++ b/arch/x86/core/intel64/smp.c @@ -38,3 +38,16 @@ void arch_sched_broadcast_ipi(void) { z_loapic_ipi(0, LOAPIC_ICR_IPI_OTHERS, CONFIG_SCHED_IPI_VECTOR); } + +void arch_sched_directed_ipi(uint32_t cpu_bitmap) +{ + unsigned int num_cpus = arch_num_cpus(); + + for (unsigned int i = 0; i < num_cpus; i++) { + if ((cpu_bitmap & BIT(i)) == 0) { + continue; + } + + z_loapic_ipi(i, LOAPIC_ICR_IPI_SPECIFIC, CONFIG_SCHED_IPI_VECTOR); + } +} diff --git a/include/zephyr/drivers/interrupt_controller/loapic.h b/include/zephyr/drivers/interrupt_controller/loapic.h index 75a47955bc6..f0e58ff95e0 100644 --- a/include/zephyr/drivers/interrupt_controller/loapic.h +++ b/include/zephyr/drivers/interrupt_controller/loapic.h @@ -43,6 +43,7 @@ #define LOAPIC_ICR_BUSY 0x00001000 /* delivery status: 1 = busy */ +#define LOAPIC_ICR_IPI_SPECIFIC 0x00004000U /* target IPI to specific CPU */ #define LOAPIC_ICR_IPI_OTHERS 0x000C4000U /* normal IPI to other CPUs */ #define LOAPIC_ICR_IPI_INIT 0x00004500U #define LOAPIC_ICR_IPI_STARTUP 0x00004600U