The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
cpu.h File Reference

the data of each core (per-CPU data). More...

#include "arch/arch_cpu.h"
#include "common/stdint.h"

Go to the source code of this file.

Data Structures

struct  cpu_times_t
 the timer ticks of a core since boot, as the "cpu" lines of Linux's /proc/stat. More...
struct  cpu
 the data of one core More...

Macros

#define CPU_MAX   64
 the most cores that ginnOS uses
#define CPU_SELF   0
 the offsets that the assembly uses (asm64/syscall.asm); cpu.c checks them
#define CPU_KERNEL_SP   (1 * (int)sizeof(uintptr_t))
#define CPU_USER_SP   (2 * (int)sizeof(uintptr_t))

Typedefs

typedef struct cpu cpu_t
 the data of one core

Functions

void cpu_init_boot (void)
 set up the cpu_t of the boot core and point the per-CPU segment at it.
void smp_init (void)
 start the other cores that the ACPI MADT gives, one at a time.
void cpu_ap_main (cpu_t *cpu, bool has_timer) __attribute__((noreturn))
 the rest of the start of a core other than the boot core, after the arch code has set up its registers, tables and local APIC.

Variables

cpu_t cpus [CPU_MAX]
 the data of all cores; index 0 is the boot core
bool cpu_ready
 true once cpu_init_boot() has run, so cpu_current() is valid
uint32_t cpu_count
 the number of cores that run: cpus[0] to cpus[cpu_count - 1]

Detailed Description

the data of each core (per-CPU data).

each core has a cpu_t, and a segment base points at it (arch/arch_cpu.h), so cpu_current() is one load. the state that belongs to "the core that runs this code", not to a process, is here.

the boot core starts the other cores (smp.c). each core runs processes from its own run queue (scheduler.c).

Macro Definition Documentation

◆ CPU_MAX

#define CPU_MAX   64

the most cores that ginnOS uses

◆ CPU_SELF

#define CPU_SELF   0

the offsets that the assembly uses (asm64/syscall.asm); cpu.c checks them

◆ CPU_KERNEL_SP

#define CPU_KERNEL_SP   (1 * (int)sizeof(uintptr_t))

◆ CPU_USER_SP

#define CPU_USER_SP   (2 * (int)sizeof(uintptr_t))

Typedef Documentation

◆ cpu_t

typedef struct cpu cpu_t

the data of one core

Function Documentation

◆ cpu_init_boot()

void cpu_init_boot ( void )

set up the cpu_t of the boot core and point the per-CPU segment at it.

call it once, right after the GDT is loaded, before anything uses cpu_current().

◆ smp_init()

void smp_init ( void )

start the other cores that the ACPI MADT gives, one at a time.

the kernel command line can limit them: "nosmp" keeps only the boot core, "maxcpus=N" starts at most N cores, the boot core included. call it on the boot core with interrupts on, after apic_init.

◆ cpu_ap_main()

void cpu_ap_main ( cpu_t * cpu,
bool has_timer )

the rest of the start of a core other than the boot core, after the arch code has set up its registers, tables and local APIC.

it marks the core online and becomes the idle task of the core, which runs processes from the run queue of the core.

Parameters
cputhe cpu_t of the core that runs the call.
has_timertrue if the core has a timer. without one the scheduler cannot end a time slice on the core, so the core only halts and runs no processes.

Variable Documentation

◆ cpus

cpu_t cpus[CPU_MAX]
extern

the data of all cores; index 0 is the boot core

◆ cpu_ready

bool cpu_ready
extern

true once cpu_init_boot() has run, so cpu_current() is valid

◆ cpu_count

uint32_t cpu_count
extern

the number of cores that run: cpus[0] to cpus[cpu_count - 1]