arch/riscv/kernel/smp.c
Source file repositories/reference/linux-study-clean/arch/riscv/kernel/smp.c
File Facts
- System
- Linux kernel
- Corpus path
arch/riscv/kernel/smp.c- Extension
.c- Size
- 7883 bytes
- Lines
- 367
- Domain
- Architecture Layer
- Bucket
- arch/riscv
- Inferred role
- Architecture Layer: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/cpu.hlinux/clockchips.hlinux/interrupt.hlinux/module.hlinux/kexec.hlinux/kgdb.hlinux/percpu.hlinux/profile.hlinux/smp.hlinux/sched.hlinux/seq_file.hlinux/delay.hlinux/irq.hlinux/irq_work.hlinux/nmi.hasm/tlbflush.hasm/cacheflush.hasm/cpu_ops.h
Detected Declarations
enum ipi_message_typefunction smp_setup_processor_idfunction riscv_hartid_to_cpuidfunction ipi_stopfunction ipi_cpu_crash_stopfunction ipi_cpu_crash_stopfunction send_ipi_maskfunction send_ipi_singlefunction arch_irq_work_raisefunction handle_IPIfunction riscv_ipi_enablefunction riscv_ipi_disablefunction riscv_ipi_have_virq_rangefunction riscv_ipi_set_virq_rangefunction show_ipi_statsfunction arch_send_call_function_ipi_maskfunction arch_send_call_function_single_ipifunction tick_broadcastfunction smp_send_stopfunction num_online_cpusfunction crash_smp_send_stopfunction smp_crash_stop_failedfunction arch_smp_send_reschedulefunction riscv_backtrace_ipifunction arch_trigger_cpumask_backtracefunction kgdb_roundup_cpusfunction for_each_online_cpuexport __cpuid_to_hartid_mapexport arch_smp_send_reschedule
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* SMP initialisation and IPI support
* Based on arch/arm64/kernel/smp.c
*
* Copyright (C) 2012 ARM Ltd.
* Copyright (C) 2015 Regents of the University of California
* Copyright (C) 2017 SiFive
*/
#include <linux/cpu.h>
#include <linux/clockchips.h>
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/kexec.h>
#include <linux/kgdb.h>
#include <linux/percpu.h>
#include <linux/profile.h>
#include <linux/smp.h>
#include <linux/sched.h>
#include <linux/seq_file.h>
#include <linux/delay.h>
#include <linux/irq.h>
#include <linux/irq_work.h>
#include <linux/nmi.h>
#include <asm/tlbflush.h>
#include <asm/cacheflush.h>
#include <asm/cpu_ops.h>
enum ipi_message_type {
IPI_RESCHEDULE,
IPI_CALL_FUNC,
IPI_CPU_STOP,
IPI_CPU_CRASH_STOP,
IPI_IRQ_WORK,
IPI_TIMER,
IPI_CPU_BACKTRACE,
IPI_KGDB_ROUNDUP,
IPI_MAX
};
static const char * const ipi_names[] = {
[IPI_RESCHEDULE] = "Rescheduling interrupts",
[IPI_CALL_FUNC] = "Function call interrupts",
[IPI_CPU_STOP] = "CPU stop interrupts",
[IPI_CPU_CRASH_STOP] = "CPU stop (for crash dump) interrupts",
[IPI_IRQ_WORK] = "IRQ work interrupts",
[IPI_TIMER] = "Timer broadcast interrupts",
[IPI_CPU_BACKTRACE] = "CPU backtrace interrupts",
[IPI_KGDB_ROUNDUP] = "KGDB roundup interrupts",
};
unsigned long __cpuid_to_hartid_map[NR_CPUS] __ro_after_init = {
[0 ... NR_CPUS-1] = INVALID_HARTID
};
EXPORT_SYMBOL_GPL(__cpuid_to_hartid_map);
void __init smp_setup_processor_id(void)
{
cpuid_to_hartid_map(0) = boot_cpu_hartid;
pr_info("Booting Linux on hartid %lu\n", boot_cpu_hartid);
}
static DEFINE_PER_CPU_READ_MOSTLY(int, ipi_dummy_dev);
static int ipi_virq_base __ro_after_init;
static int nr_ipi __ro_after_init = IPI_MAX;
static struct irq_desc *ipi_desc[IPI_MAX] __read_mostly;
int riscv_hartid_to_cpuid(unsigned long hartid)
{
int i;
for (i = 0; i < NR_CPUS; i++)
if (cpuid_to_hartid_map(i) == hartid)
return i;
return -ENOENT;
}
static void ipi_stop(void)
{
set_cpu_online(smp_processor_id(), false);
while (1)
wait_for_interrupt();
}
#ifdef CONFIG_KEXEC_CORE
static atomic_t waiting_for_crash_ipi = ATOMIC_INIT(0);
Annotation
- Immediate include surface: `linux/cpu.h`, `linux/clockchips.h`, `linux/interrupt.h`, `linux/module.h`, `linux/kexec.h`, `linux/kgdb.h`, `linux/percpu.h`, `linux/profile.h`.
- Detected declarations: `enum ipi_message_type`, `function smp_setup_processor_id`, `function riscv_hartid_to_cpuid`, `function ipi_stop`, `function ipi_cpu_crash_stop`, `function ipi_cpu_crash_stop`, `function send_ipi_mask`, `function send_ipi_single`, `function arch_irq_work_raise`, `function handle_IPI`.
- Atlas domain: Architecture Layer / arch/riscv.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.