Skip to content

Commit

Permalink
kernel: rename scheduler to sched
Browse files Browse the repository at this point in the history
  • Loading branch information
mosmeh committed Aug 31, 2024
1 parent deedf72 commit a353fe6
Show file tree
Hide file tree
Showing 20 changed files with 55 additions and 64 deletions.
2 changes: 1 addition & 1 deletion kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ OBJS := \
memory/vm.o \
random.o \
safe_string.o \
scheduler.o \
sched.o \
smp.o \
syscall/clock.o \
syscall/fs.o \
Expand Down
2 changes: 1 addition & 1 deletion kernel/drivers/ac97.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <kernel/memory/memory.h>
#include <kernel/panic.h>
#include <kernel/safe_string.h>
#include <kernel/scheduler.h>
#include <kernel/sched.h>
#include <kernel/system.h>

#define PCI_CLASS_MULTIMEDIA 4
Expand Down
1 change: 0 additions & 1 deletion kernel/drivers/hid/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <kernel/lock.h>
#include <kernel/memory/memory.h>
#include <kernel/panic.h>
#include <kernel/scheduler.h>

#define QUEUE_SIZE 128

Expand Down
1 change: 0 additions & 1 deletion kernel/drivers/hid/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <kernel/interrupts/interrupts.h>
#include <kernel/memory/memory.h>
#include <kernel/panic.h>
#include <kernel/scheduler.h>

static void write_mouse(uint8_t data) {
ps2_write(PS2_COMMAND, 0xd4);
Expand Down
6 changes: 3 additions & 3 deletions kernel/drivers/pit.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <kernel/interrupts/interrupts.h>
#include <kernel/scheduler.h>
#include <kernel/sched.h>
#include <kernel/system.h>
#include <kernel/time.h>

Expand All @@ -13,10 +13,10 @@
static void tick(struct registers* regs) {
time_tick();

// When SMP is active, the scheduler_tick is called from the per-CPU
// When SMP is active, the sched_tick is called from the per-CPU
// local APIC timer interrupt handler.
if (!smp_active)
scheduler_tick(regs);
sched_tick(regs);
}

void pit_init(void) {
Expand Down
6 changes: 3 additions & 3 deletions kernel/drivers/virtio/virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <kernel/kmsg.h>
#include <kernel/memory/memory.h>
#include <kernel/panic.h>
#include <kernel/scheduler.h>
#include <kernel/sched.h>
#include <kernel/system.h>

// virtio spec: https://docs.oasis-open.org/virtio/virtio/v1.3/virtio-v1.3.html
Expand Down Expand Up @@ -154,8 +154,8 @@ int virtq_desc_chain_submit(struct virtq_desc_chain* chain) {
if (!(virtq->used->flags & VIRTQ_USED_F_NO_NOTIFY))
*virtq->notify = virtq->index;

int rc = scheduler_block((unblock_fn)virtq_is_ready, virtq,
BLOCK_UNINTERRUPTIBLE);
int rc =
sched_block((unblock_fn)virtq_is_ready, virtq, BLOCK_UNINTERRUPTIBLE);
full_memory_barrier();

// Return the descriptors to the free list.
Expand Down
2 changes: 1 addition & 1 deletion kernel/drivers/virtio/virtio_blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <kernel/kmsg.h>
#include <kernel/memory/memory.h>
#include <kernel/panic.h>
#include <kernel/scheduler.h>
#include <kernel/sched.h>

#define SECTOR_SIZE 512

Expand Down
4 changes: 2 additions & 2 deletions kernel/fs/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <kernel/memory/memory.h>
#include <kernel/panic.h>
#include <kernel/safe_string.h>
#include <kernel/scheduler.h>
#include <kernel/sched.h>

void inode_ref(struct inode* inode) {
ASSERT(inode);
Expand Down Expand Up @@ -286,5 +286,5 @@ short file_poll(struct file* file, short events) {
int file_block(struct file* file, bool (*unblock)(struct file*), int flags) {
if ((file->flags & O_NONBLOCK) && !unblock(file))
return -EAGAIN;
return scheduler_block((unblock_fn)unblock, file, flags);
return sched_block((unblock_fn)unblock, file, flags);
}
1 change: 0 additions & 1 deletion kernel/fs/proc/root.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <kernel/cpu.h>
#include <kernel/fs/dentry.h>
#include <kernel/panic.h>
#include <kernel/scheduler.h>
#include <kernel/system.h>
#include <kernel/task.h>
#include <kernel/time.h>
Expand Down
4 changes: 2 additions & 2 deletions kernel/interrupts/apic.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <kernel/cpu.h>
#include <kernel/kmsg.h>
#include <kernel/memory/memory.h>
#include <kernel/scheduler.h>
#include <kernel/sched.h>
#include <kernel/time.h>

#define LAPIC_ID 0x0020 // ID
Expand Down Expand Up @@ -43,7 +43,7 @@ void lapic_init(void) {
lapic = vm_phys_map(acpi->lapic_addr, PAGE_SIZE, VM_READ | VM_WRITE);
ASSERT(lapic);

idt_set_interrupt_handler(LAPIC_TIMER_VECTOR, scheduler_tick);
idt_set_interrupt_handler(LAPIC_TIMER_VECTOR, sched_tick);
}

static uint32_t lapic_read(uint32_t reg) {
Expand Down
6 changes: 3 additions & 3 deletions kernel/lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "cpu.h"
#include "interrupts/interrupts.h"
#include "panic.h"
#include "scheduler.h"
#include "sched.h"
#include "task.h"

void mutex_lock(struct mutex* m) {
Expand All @@ -21,7 +21,7 @@ void mutex_lock(struct mutex* m) {
}
atomic_store_explicit(&m->lock, false, memory_order_release);
}
scheduler_yield(true);
sched_yield(true);
}
}

Expand All @@ -40,7 +40,7 @@ void mutex_unlock(struct mutex* m) {
atomic_store_explicit(&m->lock, false, memory_order_release);
return;
}
scheduler_yield(true);
sched_yield(true);
}
}

Expand Down
6 changes: 3 additions & 3 deletions kernel/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "memory/memory.h"
#include "multiboot.h"
#include "panic.h"
#include "scheduler.h"
#include "sched.h"
#include "task.h"
#include "time.h"

Expand Down Expand Up @@ -83,11 +83,11 @@ noreturn void start(uint32_t mb_magic, uintptr_t mb_info_phys_addr) {
random_init();
console_init();
syscall_init();
scheduler_init();
sched_init();
smp_start();
kprint("\x1b[32mkernel initialization done\x1b[m\n");

ASSERT_OK(task_spawn("userland_init", userland_init));

scheduler_start();
sched_start();
}
29 changes: 17 additions & 12 deletions kernel/scheduler.c → kernel/sched.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "scheduler.h"
#include "sched.h"
#include "cpu.h"
#include "interrupts/interrupts.h"
#include "memory/memory.h"
Expand All @@ -17,7 +17,7 @@ static noreturn void do_idle(void) {
}
}

void scheduler_init(void) {
void sched_init(void) {
for (size_t i = 0; i < num_cpus; ++i) {
struct cpu* cpu = cpus[i];
char comm[SIZEOF_FIELD(struct task, comm)];
Expand Down Expand Up @@ -64,7 +64,7 @@ static struct task* dequeue_ready(void) {
return task;
}

void scheduler_register(struct task* task) {
void sched_register(struct task* task) {
ASSERT(task);
ASSERT(task->state == TASK_RUNNING);
task_ref(task);
Expand Down Expand Up @@ -162,9 +162,9 @@ noreturn void switch_context(void) {
UNREACHABLE();
}

void scheduler_start(void) { switch_context(); }
void sched_start(void) { switch_context(); }

void scheduler_yield(bool requeue_current) {
void sched_yield(bool requeue_current) {
bool int_flag = push_cli();
struct cpu* cpu = cpu_get_current();
struct task* task = cpu->current_task;
Expand Down Expand Up @@ -195,15 +195,20 @@ void scheduler_yield(bool requeue_current) {
pop_cli(int_flag);
}

void scheduler_tick(struct registers* regs) {
void sched_tick(struct registers* regs) {
ASSERT(!interrupts_enabled());
if (!current)
return;

bool in_kernel = (regs->cs & 3) == 0;
task_tick(in_kernel);
scheduler_yield(true);
if (in_kernel)
bool preempted_in_kernel = (regs->cs & 3) == 0;
if (preempted_in_kernel)
++current->kernel_ticks;
else
++current->user_ticks;

sched_yield(true);

if (preempted_in_kernel)
return;

struct sigaction act;
Expand All @@ -213,7 +218,7 @@ void scheduler_tick(struct registers* regs) {
task_handle_signal(regs, signum, &act);
}

int scheduler_block(unblock_fn unblock, void* data, int flags) {
int sched_block(unblock_fn unblock, void* data, int flags) {
ASSERT(!current->unblock);
ASSERT(!current->block_data);
current->interrupted = false;
Expand All @@ -228,7 +233,7 @@ int scheduler_block(unblock_fn unblock, void* data, int flags) {
current->state = (flags & BLOCK_UNINTERRUPTIBLE) ? TASK_UNINTERRUPTIBLE
: TASK_INTERRUPTIBLE;

scheduler_yield(false);
sched_yield(false);

pop_cli(int_flag);

Expand Down
12 changes: 6 additions & 6 deletions kernel/scheduler.h → kernel/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ struct cpu;
struct task;
struct registers;

void scheduler_init(void);
void sched_init(void);

// Registers a task to be scheduled.
void scheduler_register(struct task*);
void sched_register(struct task*);

// Starts the scheduler on the current CPU.
noreturn void scheduler_start(void);
noreturn void sched_start(void);

// Yields the current CPU to other tasks.
void scheduler_yield(bool requeue_current);
void sched_yield(bool requeue_current);

// Should be called on every timer tick.
void scheduler_tick(struct registers*);
void sched_tick(struct registers*);

#define BLOCK_UNINTERRUPTIBLE 1

Expand All @@ -30,4 +30,4 @@ typedef bool (*unblock_fn)(void*);

// Blocks the current task until the unblock function returns true.
// Returns -EINTR if the task was interrupted.
NODISCARD int scheduler_block(unblock_fn, void* data, int flags);
NODISCARD int sched_block(unblock_fn, void* data, int flags);
4 changes: 2 additions & 2 deletions kernel/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "kmsg.h"
#include "memory/memory.h"
#include "panic.h"
#include "scheduler.h"
#include "sched.h"
#include "system.h"
#include <common/string.h>

Expand Down Expand Up @@ -132,5 +132,5 @@ noreturn void ap_start(void) {
pause();
flush_tlb();

scheduler_start();
sched_start();
}
4 changes: 2 additions & 2 deletions kernel/syscall/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <kernel/api/time.h>
#include <kernel/panic.h>
#include <kernel/safe_string.h>
#include <kernel/scheduler.h>
#include <kernel/sched.h>
#include <kernel/time.h>

int sys_clock_gettime(clockid_t clk_id, struct timespec* user_tp) {
Expand Down Expand Up @@ -53,7 +53,7 @@ int sys_clock_nanosleep(clockid_t clockid, int flags,
}

struct sleep_blocker blocker = {.clock_id = clockid, .deadline = deadline};
rc = scheduler_block((unblock_fn)unblock_sleep, &blocker, 0);
rc = sched_block((unblock_fn)unblock_sleep, &blocker, 0);
if (IS_ERR(rc))
return rc;
if (user_remain && flags != TIMER_ABSTIME) {
Expand Down
3 changes: 1 addition & 2 deletions kernel/syscall/poll.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "syscall.h"
#include <kernel/panic.h>
#include <kernel/safe_string.h>
#include <kernel/scheduler.h>
#include <kernel/task.h>
#include <kernel/time.h>

Expand Down Expand Up @@ -87,7 +86,7 @@ int sys_poll(struct pollfd* user_fds, nfds_t nfds, int timeout) {
blocker.deadline = deadline;
}

ret = scheduler_block((unblock_fn)unblock_poll, &blocker, 0);
ret = sched_block((unblock_fn)unblock_poll, &blocker, 0);
if (IS_ERR(ret))
goto exit;

Expand Down
10 changes: 5 additions & 5 deletions kernel/syscall/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <kernel/lock.h>
#include <kernel/panic.h>
#include <kernel/safe_string.h>
#include <kernel/scheduler.h>
#include <kernel/sched.h>
#include <kernel/task.h>
#include <kernel/time.h>

Expand Down Expand Up @@ -49,7 +49,7 @@ pid_t sys_getpgid(pid_t pid) {
}

int sys_sched_yield(void) {
scheduler_yield(true);
sched_yield(true);
return 0;
}

Expand Down Expand Up @@ -194,7 +194,7 @@ int sys_clone(struct registers* regs, unsigned long flags, void* user_stack) {
}
++task->thread_group->num_running;

scheduler_register(task);
sched_register(task);
return tid;

fail:
Expand Down Expand Up @@ -292,7 +292,7 @@ int sys_sigsuspend(const sigset_t* user_mask) {
return -EFAULT;
sigset_t old_mask = current->blocked_signals;
current->blocked_signals = mask;
int rc = scheduler_block(unblock_suspend, NULL, 0);
int rc = sched_block(unblock_suspend, NULL, 0);
current->blocked_signals = old_mask;
return rc;
}
Expand Down Expand Up @@ -384,7 +384,7 @@ pid_t sys_waitpid(pid_t pid, int* user_wstatus, int options) {
return -ECHILD;
}
} else {
int rc = scheduler_block((unblock_fn)unblock_waitpid, &blocker, 0);
int rc = sched_block((unblock_fn)unblock_waitpid, &blocker, 0);
if (rc == -EINTR)
return -ERESTARTSYS;
if (IS_ERR(rc))
Expand Down
Loading

0 comments on commit a353fe6

Please sign in to comment.