phunix/kernel/smp.h
Tomas Hruby 6aa26565e6 SMP - Big kernel lock (BKL)
- to isolate execution inside kernel we use a big kernel lock
  implemented as a spinlock

- the lock is acquired asap after entering kernel mode and released as
  late as possible. Only one CPU as a time can execute the core kernel
  code

- measurement son real hw show that the overhead of this lock is close
  to 0% of kernel time for the currnet system

- the overhead of this lock may be as high as 45% of kernel time in
  virtual machines depending on the ratio between physical CPUs
  available and emulated CPUs. The performance degradation is
  significant
2010-09-15 14:10:03 +00:00

59 lines
1.6 KiB
C

#ifndef __SMP_H__
#define __SMP_H__
#ifdef CONFIG_SMP
#ifndef __ASSEMBLY__
#include "kernel.h"
#include "arch_smp.h"
#include "spinlock.h"
/* number of CPUs (execution strands in the system */
EXTERN unsigned ncpus;
/* Number of virtual strands per physical core */
EXTERN unsigned ht_per_core;
/* which cpu is bootstraping */
EXTERN unsigned bsp_cpu_id;
#define cpu_is_bsp(cpu) (bsp_cpu_id == cpu)
/*
* SMP initialization is largely architecture dependent and each architecture
* must provide a method how to do it. If initiating SMP fails the function does
* not report it. However it must put the system in such a state that it falls
* back to a uniprocessor system. Although the uniprocessor configuration may be
* suboptimal, the system must be able to run on the bootstrap processor as if
* it was the only processor in the system
*/
_PROTOTYPE(void smp_init, (void));
_PROTOTYPE(void smp_ipi_err_int, (void));
_PROTOTYPE(void smp_ipi_spv_int, (void));
_PROTOTYPE(void smp_ipi_sched, (void));
_PROTOTYPE(void smp_ipi_dequeue, (void));
_PROTOTYPE(void smp_ipi_stop, (void));
_PROTOTYPE(void smp_ipi_reboot, (void));
#define CPU_IS_BSP 1
#define CPU_IS_READY 2
struct cpu {
u32_t flags;
};
EXTERN struct cpu cpus[CONFIG_MAX_CPUS];
#define cpu_set_flag(cpu, flag) do { cpus[cpu].flags |= (flag); } while(0)
#define cpu_clear_flag(cpu, flag) do { cpus[cpu].flags &= ~(flag); } while(0)
#define cpu_test_flag(cpu, flag) (cpus[cpu].flags & (flag))
#define cpu_is_ready(cpu) cpu_test_flag(cpu, CPU_IS_READY)
SPINLOCK_DECLARE(big_kernel_lock)
#endif /* __ASSEMBLY__ */
#endif /* CONFIG_SMP */
#endif /* __SMP_H__ */