Kernel: Add a name field to the Task structure
This commit is contained in:
parent
e7522c21ca
commit
ea8a42b8c0
@ -9,7 +9,7 @@ namespace Scheduler
|
||||
void yield();
|
||||
void exit(int status);
|
||||
void sleep(unsigned long ms);
|
||||
void add_kernel_task(void (*task)(void));
|
||||
void add_kernel_task(const char* taskname, void (*task)(void));
|
||||
|
||||
Task* create_user_task();
|
||||
|
||||
|
@ -63,4 +63,6 @@ struct Task
|
||||
void switch_to_address_space();
|
||||
|
||||
bool has_died();
|
||||
|
||||
char name[128];
|
||||
};
|
@ -23,6 +23,7 @@
|
||||
#include "memory/PMM.h"
|
||||
#include "memory/VMM.h"
|
||||
#include "misc/PCITypes.h"
|
||||
#include "misc/hang.h"
|
||||
#include "misc/reboot.h"
|
||||
#include "panic/Panic.h"
|
||||
#include "rand/Mersenne.h"
|
||||
@ -68,7 +69,13 @@ extern "C" void _start()
|
||||
|
||||
kinfoln("Prepared scheduler");
|
||||
|
||||
Scheduler::add_kernel_task([]() {
|
||||
#ifdef RUN_TEST_AS_INIT
|
||||
ASSERT(Scheduler::load_user_task(STRINGIZE_VALUE_OF(RUN_TEST_AS_INIT)) > 0);
|
||||
#else
|
||||
ASSERT(Scheduler::load_user_task("/bin/init") > 0);
|
||||
#endif
|
||||
|
||||
Scheduler::add_kernel_task("[moon-reaper]", []() {
|
||||
while (1)
|
||||
{
|
||||
sleep(400);
|
||||
@ -76,12 +83,6 @@ extern "C" void _start()
|
||||
}
|
||||
});
|
||||
|
||||
#ifdef RUN_TEST_AS_INIT
|
||||
ASSERT(Scheduler::load_user_task(STRINGIZE_VALUE_OF(RUN_TEST_AS_INIT)) > 0);
|
||||
#else
|
||||
ASSERT(Scheduler::load_user_task("/bin/init") > 0);
|
||||
#endif
|
||||
|
||||
kinfoln("Prepared scheduler tasks");
|
||||
|
||||
ASSERT(VFS::mkdir("/dev") == 0);
|
||||
@ -90,14 +91,10 @@ extern "C" void _start()
|
||||
Init::finish_kernel_boot();
|
||||
|
||||
PIC::remap();
|
||||
PIC::enable_master(0b11111100); // enable keyboard and PIT
|
||||
PIC::enable_master(0b11111100);
|
||||
PIC::enable_slave(0b11111111);
|
||||
|
||||
kinfoln("Interrupts enabled");
|
||||
Interrupts::enable();
|
||||
|
||||
PCI::scan([](PCI::Device& dev) {
|
||||
kinfoln("Found PCI device %x:%x, %s", dev.id().vendor, dev.id().device, pci_type_name(dev.type()));
|
||||
});
|
||||
|
||||
Scheduler::exit(0);
|
||||
while (1) halt();
|
||||
}
|
@ -44,6 +44,8 @@ void sys_fork(Context* context)
|
||||
child->regs.rax = 0;
|
||||
context->rax = child->id;
|
||||
|
||||
strlcpy(child->name, parent->name, sizeof(child->name));
|
||||
|
||||
child->state = child->Running;
|
||||
|
||||
kinfoln("fork(): forked parent %ld into child %ld", parent->id, child->id);
|
||||
@ -114,6 +116,8 @@ void sys_exec(Context* context, const char* pathname)
|
||||
ASSERT(image); // If check_elf_image succeeded, load_elf_from_vfs MUST succeed, unless something has gone terribly
|
||||
// wrong.
|
||||
|
||||
strlcpy(task->name, kpathname, sizeof(task->name));
|
||||
|
||||
Scheduler::reset_task(task, image);
|
||||
|
||||
task->restore_context(context);
|
||||
|
@ -66,22 +66,12 @@ void Scheduler::init()
|
||||
idle_task.user_task = false;
|
||||
idle_task.state = idle_task.Idle;
|
||||
|
||||
base_task = new Task;
|
||||
end_task = base_task;
|
||||
sched_current_task = base_task;
|
||||
sched_current_task->id = free_tid++;
|
||||
sched_current_task->task_time = 20; // gets 20 ms of cpu time before next switch
|
||||
sched_current_task->next_task = sched_current_task;
|
||||
sched_current_task->prev_task = sched_current_task;
|
||||
sched_current_task->state = sched_current_task->Running;
|
||||
sched_current_task->user_task = false;
|
||||
task_num++;
|
||||
// the other registers will be saved next task switch
|
||||
sched_current_task = &idle_task;
|
||||
|
||||
frequency = 1000 / PIT::frequency();
|
||||
}
|
||||
|
||||
void Scheduler::add_kernel_task(void (*task)(void))
|
||||
void Scheduler::add_kernel_task(const char* taskname, void (*task)(void))
|
||||
{
|
||||
Task* new_task = new Task;
|
||||
ASSERT(new_task);
|
||||
@ -98,11 +88,12 @@ void Scheduler::add_kernel_task(void (*task)(void))
|
||||
new_task->task_sleep = 0;
|
||||
new_task->task_time = 0;
|
||||
new_task->cpu_time = 0;
|
||||
strlcpy(new_task->name, taskname, sizeof(new_task->name));
|
||||
append_task(new_task);
|
||||
new_task->state = new_task->Running;
|
||||
task_num++;
|
||||
kinfoln("Adding kernel task: starts at %lx, tid %ld, stack at %lx, total tasks: %ld", new_task->regs.rip,
|
||||
new_task->id, new_task->regs.rsp, task_num);
|
||||
kinfoln("Adding kernel task: %s, starts at %lx, PID %ld, stack at %lx, total tasks: %ld", new_task->name,
|
||||
new_task->regs.rip, new_task->id, new_task->regs.rsp, task_num);
|
||||
}
|
||||
|
||||
Task* Scheduler::create_user_task()
|
||||
@ -170,11 +161,12 @@ long Scheduler::load_user_task(const char* filename)
|
||||
new_task->task_sleep = 0;
|
||||
new_task->task_time = 0;
|
||||
new_task->cpu_time = 0;
|
||||
strlcpy(new_task->name, filename, sizeof(new_task->name));
|
||||
append_task(new_task);
|
||||
new_task->state = new_task->Running;
|
||||
task_num++;
|
||||
kinfoln("Adding user task: loaded at %lx, tid %ld, stack at %lx, total tasks: %ld", new_task->regs.rip,
|
||||
new_task->id, new_task->regs.rsp, task_num);
|
||||
kinfoln("Adding user task: %s, loaded at %lx, PID %ld, stack at %lx, total tasks: %ld", new_task->name,
|
||||
new_task->regs.rip, new_task->id, new_task->regs.rsp, task_num);
|
||||
VMM::switch_back_to_kernel_address_space();
|
||||
Interrupts::pop();
|
||||
return (long)new_task->id;
|
||||
@ -193,8 +185,8 @@ void Scheduler::reset_task(Task* task, ELFImage* new_image)
|
||||
task->regs.rflags = (1 << 21) | (1 << 9); // enable interrupts
|
||||
task->task_sleep = 0;
|
||||
task->cpu_time = 0;
|
||||
kinfoln("Resetting task: loaded at %lx, tid %ld, stack at %lx, total tasks: %ld", task->regs.rip, task->id,
|
||||
task->regs.rsp, task_num);
|
||||
kinfoln("Resetting task: %s, loaded at %lx, PID %ld, stack at %lx, total tasks: %ld", task->name, task->regs.rip,
|
||||
task->id, task->regs.rsp, task_num);
|
||||
}
|
||||
|
||||
void Scheduler::reap_task(Task* task)
|
||||
@ -209,7 +201,8 @@ void Scheduler::reap_task(Task* task)
|
||||
VMM::apply_address_space();
|
||||
VMM::switch_to_user_address_space(exiting_task->address_space);
|
||||
}
|
||||
kinfoln("reaping task %ld, exited with code %ld", exiting_task->id, exiting_task->exit_status);
|
||||
kinfoln("reaping task %s, PID %ld, exited with code %ld", exiting_task->name, exiting_task->id,
|
||||
exiting_task->exit_status);
|
||||
if (exiting_task->allocated_stack && !exiting_task->is_user_task())
|
||||
MemoryManager::release_pages((void*)exiting_task->allocated_stack, TASK_PAGES_IN_STACK);
|
||||
if (exiting_task->image) // FIXME: Also free pages the task has mmap-ed but not munmap-ed.
|
||||
|
Loading…
Reference in New Issue
Block a user