PatchworkOS
Loading...
Searching...
No Matches
SMP

Symmetric multi processing. More...

Functions

void smp_bootstrap_init_early (void)
 Early initialization of the bootstrap CPU.
 
void smp_bootstrap_init (void)
 Initializes the bootstrap CPU structure.
 
void smp_others_init (void)
 Initializes the other CPUs.
 
void smp_halt_others (void)
 Halts all CPUs except the current one.
 
static uint16_t smp_cpu_amount (void)
 Returns the number of CPUs currently identified.
 
static cpu_tsmp_cpu (cpuid_t id)
 Returns a pointer to the cpu_t structure of the CPU with the given id.
 
static cpu_tsmp_self_unsafe (void)
 Returns a pointer to the cpu_t structure of the current CPU.
 
static cpuid_t smp_self_id_unsafe (void)
 Returns the id of the current CPU.
 
static cpu_tsmp_self (void)
 Returns a pointer to the cpu_t structure of the current CPU.
 
static void smp_put (void)
 Re-enables interrupts after a call to smp_self().
 

Variables

cpu_t_cpus [CPU_MAX]
 Array of pointers to cpu_t structures for each CPU.
 
uint16_t _cpuAmount
 The number of CPUs currently identified.
 

Detailed Description

Symmetric multi processing.

This module handles symmetric multi processing (SMP) support, storing the cpu_t structures for each CPU and being responsible for identifiying and starting them.

Function Documentation

◆ smp_bootstrap_init()

void smp_bootstrap_init ( void  )

Initializes the bootstrap CPU structure.

It must be called only once, by the bootstrap CPU.

Definition at line 31 of file smp.c.

References _cpus, CPU_ID_BOOTSTRAP, cpu_init(), ERR, NULL, and panic().

Referenced by init_early().

◆ smp_bootstrap_init_early()

void smp_bootstrap_init_early ( void  )

Early initialization of the bootstrap CPU.

This function will set the CPU ID MSR to 0 for the bootstrap CPU.

This is really just to fix circular dependencies during memory initialization.

Definition at line 26 of file smp.c.

References CPU_ID_BOOTSTRAP, MSR_CPU_ID, and msr_write().

Referenced by init_early().

◆ smp_cpu()

static cpu_t * smp_cpu ( cpuid_t  id)
inlinestatic

Returns a pointer to the cpu_t structure of the CPU with the given id.

Parameters
idThe id of the CPU.
Returns
A pointer to the found CPU. If no CPU with the given id exists, the kernel panics.

Definition at line 77 of file smp.h.

References _cpus, and id.

Referenced by sched_find_least_loaded_cpu(), sched_get_neighbor(), and statistics_cpu_read().

◆ smp_cpu_amount()

static uint16_t smp_cpu_amount ( void  )
inlinestatic

Returns the number of CPUs currently identified.

Returns
The number of CPUs.

Definition at line 66 of file smp.h.

References _cpuAmount.

Referenced by sched_find_least_loaded_cpu(), sched_get_neighbor(), sched_load_balance(), space_tlb_shootdown(), and statistics_cpu_read().

◆ smp_halt_others()

void smp_halt_others ( void  )

Halts all CPUs except the current one.

Definition at line 102 of file smp.c.

References _cpuAmount, _cpus, cpu_t::id, INTERRUPT_HALT, lapic_send_ipi(), and smp_self_unsafe().

Referenced by panic().

◆ smp_others_init()

◆ smp_put()

static void smp_put ( void  )
inlinestatic

Re-enables interrupts after a call to smp_self().

Definition at line 125 of file smp.h.

References interrupt_enable().

Referenced by rand_gen(), sched_push(), sched_push_new_thread(), sched_thread(), sched_yield(), wait_block_cancel(), wait_block_commit(), and wait_block_setup().

◆ smp_self()

static cpu_t * smp_self ( void  )
inlinestatic

Returns a pointer to the cpu_t structure of the current CPU.

This function is safe because it disables interrupts. It is important to always call smp_put() after using this function to re-enable interrupts.

Returns
A pointer to the current CPU.

Definition at line 115 of file smp.h.

References _cpus, interrupt_disable(), MSR_CPU_ID, and msr_read().

Referenced by rand_gen(), sched_push(), sched_push_new_thread(), sched_thread(), sched_yield(), and wait_block_setup().

◆ smp_self_id_unsafe()

static cpuid_t smp_self_id_unsafe ( void  )
inlinestatic

Returns the id of the current CPU.

This function is unsafe because it does not disable interrupts, so it must be called with interrupts disabled.

Returns
The id of the current CPU.

Definition at line 102 of file smp.h.

References MSR_CPU_ID, and msr_read().

◆ smp_self_unsafe()

static cpu_t * smp_self_unsafe ( void  )
inlinestatic

Returns a pointer to the cpu_t structure of the current CPU.

This function is unsafe because it does not disable interrupts, so it must be called with interrupts disabled. It is useful in low-level code where disabling interrupts is necessary anyway, for example in interrupt handlers.

Returns
A pointer to the current CPU.

Definition at line 90 of file smp.h.

References _cpus, MSR_CPU_ID, and msr_read().

Referenced by exception_handler(), init_early(), interrupt_disable(), interrupt_enable(), interrupt_handler(), irq_install(), lapic_cpu_init(), log_print_header(), panic(), process_procfs_init(), rand_cpu_init(), sched_done_with_boot_thread(), sched_thread_unsafe(), simd_cpu_init(), smp_halt_others(), space_load(), space_tlb_shootdown(), timer_ctx_init(), vmm_cpu_ctx_init(), vmm_init(), wait_block_cancel(), and wait_block_commit().

Variable Documentation

◆ _cpuAmount

uint16_t _cpuAmount
extern

The number of CPUs currently identified.

Definition at line 22 of file smp.c.

Referenced by smp_cpu_amount(), smp_halt_others(), and smp_others_init().

◆ _cpus

cpu_t* _cpus[CPU_MAX]
extern

Array of pointers to cpu_t structures for each CPU.

Definition at line 21 of file smp.c.

Referenced by smp_bootstrap_init(), smp_cpu(), smp_halt_others(), smp_others_init(), smp_self(), and smp_self_unsafe().