kernel: implement cpu IDs and per-cpu variables

This commit is contained in:
2023-03-18 19:35:00 +00:00
parent 56bc47f570
commit 57eaf4e01c
14 changed files with 232 additions and 18 deletions

View File

@@ -1,13 +1,33 @@
#ifndef SOCKS_CPU_H_
#define SOCKS_CPU_H_
#include <socks/bitmap.h>
#include <socks/machine/cpu.h>
#include <socks/sched.h>
typedef enum cpu_flags {
CPU_ONLINE = 0x01u,
} cpu_flags_t;
typedef struct cpu_data {
cpu_flags_t c_flags;
unsigned int c_id;
task_t *c_current_task;
runqueue_t c_rq;
} cpu_data_t;
/* maximum number of processor cores that the kernel can support.
TODO move to build config option */
#define CPU_MAX 128
DECLARE_BITMAP(cpu_available, CPU_MAX);
DECLARE_BITMAP(cpu_online, CPU_MAX);
#define this_cpu() (ml_cpu_block_get_id(ml_this_cpu()))
extern cpu_data_t *get_this_cpu(void);
extern void put_cpu(cpu_data_t *cpu);
extern void cpu_set_available(unsigned int cpu_id);
extern void cpu_set_online(unsigned int cpu_id);
extern unsigned int cpu_get_highest_available(void);
#endif

View File

@@ -1,6 +1,7 @@
#ifndef SOCKS_PERCPU_H_
#define SOCKS_PERCPU_H_
#include <socks/status.h>
#include <socks/compiler.h>
#define DEFINE_PERCPU_VAR(type, name) \
@@ -10,6 +11,7 @@
#define percpu_put(var)
extern kern_status_t init_per_cpu_areas(void);
extern void *__percpu_get(void *var);
#endif

View File

@@ -47,7 +47,7 @@ typedef struct task {
typedef struct thread {
thread_state_t tr_state;
task_t *tr_parent;
unsigned int tr_id;
unsigned int tr_prio;
@@ -64,10 +64,13 @@ typedef struct runqueue {
extern kern_status_t sched_init(void);
extern void runqueue_init(runqueue_t *rq);
extern task_t *task_alloc(void);
static inline task_t *task_ref(task_t *task) { return object_data(object_ref(object_header(task))); }
static inline void task_deref(task_t *task) { object_deref(object_header(task)); }
extern task_t *task_from_pid(unsigned int pid);
extern task_t *kernel_task(void);
static inline void task_lock_irqsave(task_t *task, unsigned long *flags)
{