1 #ifndef __SMP_H__ 2 #define __SMP_H__ 3 4 #ifdef CONFIG_SMP 5 6 #ifndef __ASSEMBLY__ 7 8 #include "kernel/kernel.h" 9 #include "arch_smp.h" 10 #include "spinlock.h" 11 12 /* number of CPUs (execution strands in the system */ 13 EXTERN unsigned ncpus; 14 /* Number of virtual strands per physical core */ 15 EXTERN unsigned ht_per_core; 16 /* which cpu is bootstrapping */ 17 EXTERN unsigned bsp_cpu_id; 18 19 #define cpu_is_bsp(cpu) (bsp_cpu_id == cpu) 20 21 /* 22 * SMP initialization is largely architecture dependent and each architecture 23 * must provide a method how to do it. If initiating SMP fails the function does 24 * not report it. However it must put the system in such a state that it falls 25 * back to a uniprocessor system. Although the uniprocessor configuration may be 26 * suboptimal, the system must be able to run on the bootstrap processor as if 27 * it was the only processor in the system 28 */ 29 void smp_init(void); 30 31 #define CPU_IS_BSP 1 32 #define CPU_IS_READY 2 33 34 struct cpu { 35 u32_t flags; 36 }; 37 38 EXTERN struct cpu cpus[CONFIG_MAX_CPUS]; 39 40 #define cpu_set_flag(cpu, flag) do { cpus[cpu].flags |= (flag); } while(0) 41 #define cpu_clear_flag(cpu, flag) do { cpus[cpu].flags &= ~(flag); } while(0) 42 #define cpu_test_flag(cpu, flag) (cpus[cpu].flags & (flag)) 43 #define cpu_is_ready(cpu) cpu_test_flag(cpu, CPU_IS_READY) 44 45 /* 46 * Big Kernel Lock prevents more then one cpu executing the kernel code 47 */ 48 SPINLOCK_DECLARE(big_kernel_lock) 49 /* 50 * to sync the booting APs 51 */ 52 SPINLOCK_DECLARE(boot_lock) 53 54 void wait_for_APs_to_finish_booting(void); 55 void ap_boot_finished(unsigned cpu); 56 void smp_shutdown_aps(void ); 57 58 /* IPI handlers */ 59 void smp_ipi_halt_handler(void); 60 void smp_ipi_sched_handler(void); 61 62 void smp_schedule(unsigned cpu); 63 /* stop a processes on a different cpu */ 64 void smp_schedule_stop_proc(struct proc * p); 65 /* stop a process on a different cpu because its address space is being changed */ 66 void smp_schedule_vminhibit(struct proc * p); 67 /* stop the process and for saving its full context */ 68 void smp_schedule_stop_proc_save_ctx(struct proc * p); 69 /* migrate the full context of a process to the destination CPU */ 70 void smp_schedule_migrate_proc(struct proc * p, unsigned dest_cpu); 71 72 void arch_send_smp_schedule_ipi(unsigned cpu); 73 void arch_smp_halt_cpu(void); 74 75 /* deal with x-cpu scheduling event */ 76 void smp_sched_handler(void); 77 78 #endif /* __ASSEMBLY__ */ 79 80 #endif /* CONFIG_SMP */ 81 82 #endif /* __SMP_H__ */ 83