Course contentsShow
← Linux
Lesson 572 of 1,8195. Process Management and SignalingFree lesson

Tracing Signal Routing in SMP Systems

Visualize how signals navigate across different cores in symmetric multiprocessing environments.

In this lesson, you will learn how the Linux kernel coordinates the delivery of signals when a process is running on a different CPU core than the one triggering the signal.

The Challenge of SMP Signal Routing

In a Symmetric Multiprocessing (SMP) environment, a system call or an external event might occur on Core A, while the target process is actively executing on Core B. The kernel cannot simply "poke" the process memory directly; it must ensure thread safety and cache coherency. When you send a signal (e.g., via kill), the kernel must perform a cross-CPU handshake to ensure the process reacts correctly without corrupting its state.

The Delivery Path

When a signal is generated, the kernel performs the following steps:

  1. Task Identification: The kernel locates the task_struct of the target process, regardless of which core that process is currently scheduled on.
  2. Pending Bitmask Update: The kernel updates the signal->shared_pending or signal->pending bitmask within the process’s control block. This is a protected structure, often locked with spin_lock_irqsave.
  3. The Inter-Processor Interrupt (IPI): If the target process is currently running on another core, the kernel triggers an IPI. This is a hardware-level mechanism where one CPU core sends a signal to another core, forcing it to stop what it is doing and execute a specific kernel routine.
  4. Rescheduling/Wakeup: If the process was in a "sleeping" state, the kernel sends the IPI to force the target CPU to wake the task and move it to the TASK_RUNNING state.

Visualizing the Routing

You can imagine the signal path as a three-hop journey:

  • Hop 1: The source process calls sys_kill, hitting the local CPU kernel logic.
  • Hop 2: The kernel identifies the target and writes the signal bit into the process structure.
  • Hop 3: An IPI tells the target CPU: "Stop your current work, check your pending signal flags, and execute the signal handler."
// Simplified kernel logic for signal delivery
void signal_wake_up(struct task_struct *t, int resume) {
    // 1. Mark the signal as pending
    set_tsk_thread_flag(t, TIF_SIGPENDING);
    
    // 2. Trigger an IPI to the CPU where task 't' is running
    smp_send_reschedule(task_cpu(t));
}

This ensures that the target process sees the signal at the next convenient scheduling boundary or upon the next transition from kernel-to-user mode.

Key Takeaway: Signal routing in SMP systems relies on Inter-Processor Interrupts (IPIs) to force target cores to synchronize state and acknowledge pending signals, ensuring that process signals remain consistent across the entire multi-core architecture.