1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Refactor scheduler API.

This commit is contained in:
Jonas 'Sortie' Termansen 2013-01-09 10:47:22 +01:00
parent 9ba7f26bf0
commit 193b76f8cb
17 changed files with 59 additions and 36 deletions

View file

@ -1,6 +1,6 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013.
This file is part of Sortix.
@ -17,17 +17,27 @@
You should have received a copy of the GNU General Public License along with
Sortix. If not, see <http://www.gnu.org/licenses/>.
scheduler.h
sortix/kernel/scheduler.h
Decides the order to execute threads in and switching between them.
*******************************************************************************/
#ifndef SORTIX_SCHEDULER_H
#define SORTIX_SCHEDULER_H
#ifndef INCLUDE_SORTIX_KERNEL_SCHEDULER_H
#define INCLUDE_SORTIX_KERNEL_SCHEDULER_H
#include "thread.h"
#include <sortix/kernel/decl.h>
namespace Sortix {
class Process;
class Thread;
namespace CPU {
struct InterruptRegisters;
} // namespace CPU
enum ThreadState { NONE, RUNNABLE, BLOCKING, DEAD };
namespace Scheduler {
void Init();
@ -39,14 +49,15 @@ inline static void ExitThread()
asm volatile ("int $132");
__builtin_unreachable();
}
void SetThreadState(Thread* thread, Thread::State state);
Thread::State GetThreadState(Thread* thread);
void SetThreadState(Thread* thread, ThreadState state);
ThreadState GetThreadState(Thread* thread);
void SetIdleThread(Thread* thread);
void SetDummyThreadOwner(Process* process);
void SetInitProcess(Process* init);
Process* GetInitProcess();
} // namespace Scheduler
} // namespace Sortix
#endif

View file

@ -25,13 +25,13 @@
#include <sortix/kernel/platform.h>
#include <sortix/kernel/syscall.h>
#include <sortix/kernel/interrupt.h>
#include <sortix/kernel/scheduler.h>
#include <assert.h>
#include <errno.h>
#include <string.h>
#include "x86-family/idt.h"
#include "scheduler.h"
#include "signal.h"
#include "process.h"

View file

@ -44,6 +44,7 @@
#include <sortix/kernel/syscall.h>
#include <sortix/kernel/interrupt.h>
#include <sortix/kernel/time.h>
#include <sortix/kernel/scheduler.h>
#include <sortix/fcntl.h>
#include <sortix/stat.h>
@ -60,7 +61,6 @@
#include "multiboot.h"
#include "thread.h"
#include "process.h"
#include "scheduler.h"
#include "signal.h"
#include "ata.h"
#include "com.h"

View file

@ -25,10 +25,12 @@
#include <sortix/kernel/platform.h>
#include <sortix/kernel/kthread.h>
#include <sortix/kernel/worker.h>
#include <sortix/kernel/scheduler.h>
#include <sortix/signal.h>
#include "signal.h"
#include "thread.h"
#include "scheduler.h"
namespace Sortix {
@ -36,7 +38,7 @@ namespace Sortix {
static void kthread_do_kill_thread(void* user)
{
Thread* thread = (Thread*) user;
while ( thread->state != Thread::State::DEAD )
while ( thread->state != ThreadState::DEAD )
kthread_yield();
delete thread;
}

View file

@ -26,8 +26,13 @@
#include <sortix/kernel/kthread.h>
#include <sortix/kernel/refcount.h>
#include <sortix/kernel/textbuffer.h>
#include <sortix/kernel/scheduler.h>
#include <sortix/vga.h>
#include <string.h>
#include "../thread.h"
#include "vga.h"
#include "lfbtextbuffer.h"

View file

@ -30,6 +30,7 @@
#include <sortix/kernel/inode.h>
#include <sortix/kernel/keyboard.h>
#include <sortix/kernel/poll.h>
#include <sortix/kernel/scheduler.h>
#include <sortix/termmode.h>
#include <sortix/termios.h>
@ -40,9 +41,9 @@
#include <errno.h>
#include <string.h>
#include "utf8.h"
#include "process.h"
#include "scheduler.h"
#include "logterminal.h"
namespace Sortix {

View file

@ -35,6 +35,7 @@
#include <sortix/kernel/string.h>
#include <sortix/kernel/syscall.h>
#include <sortix/kernel/sortedlist.h>
#include <sortix/kernel/scheduler.h>
#include <sortix/signal.h>
#include <sortix/unistd.h>
@ -50,7 +51,6 @@
#include "thread.h"
#include "process.h"
#include "scheduler.h"
#include "initrd.h"
#include "elf.h"

View file

@ -37,13 +37,13 @@
#include <sortix/kernel/syscall.h>
#include <sortix/kernel/interrupt.h>
#include <sortix/kernel/time.h>
#include <sortix/kernel/scheduler.h>
#include "x86-family/gdt.h"
#include "x86-family/float.h"
#include "thread.h"
#include "process.h"
#include "signal.h"
#include "scheduler.h"
namespace Sortix {
namespace Scheduler {
@ -196,7 +196,7 @@ static void ThreadExitCPU(CPU::InterruptRegisters* regs, void* /*user*/)
{
// Can't use floating point instructions from now.
Float::NofityTaskExit(currentthread);
SetThreadState(currentthread, Thread::State::DEAD);
SetThreadState(currentthread, ThreadState::DEAD);
InterruptYieldCPU(regs, NULL);
}
@ -206,7 +206,7 @@ void SetIdleThread(Thread* thread)
{
assert(!idlethread);
idlethread = thread;
SetThreadState(thread, Thread::State::NONE);
SetThreadState(thread, ThreadState::NONE);
SetCurrentThread(thread);
}
@ -225,13 +225,13 @@ Process* GetInitProcess()
return initprocess;
}
void SetThreadState(Thread* thread, Thread::State state)
void SetThreadState(Thread* thread, ThreadState state)
{
bool wasenabled = Interrupt::SetEnabled(false);
// Remove the thread from the list of runnable threads.
if ( thread->state == Thread::State::RUNNABLE &&
state != Thread::State::RUNNABLE )
if ( thread->state == ThreadState::RUNNABLE &&
state != ThreadState::RUNNABLE )
{
if ( thread == firstrunnablethread ) { firstrunnablethread = thread->schedulerlistnext; }
if ( thread == firstrunnablethread ) { firstrunnablethread = NULL; }
@ -244,8 +244,8 @@ void SetThreadState(Thread* thread, Thread::State state)
}
// Insert the thread into the scheduler's carousel linked list.
if ( thread->state != Thread::State::RUNNABLE &&
state == Thread::State::RUNNABLE )
if ( thread->state != ThreadState::RUNNABLE &&
state == ThreadState::RUNNABLE )
{
if ( firstrunnablethread == NULL ) { firstrunnablethread = thread; }
thread->schedulerlistprev = firstrunnablethread->schedulerlistprev;
@ -256,13 +256,13 @@ void SetThreadState(Thread* thread, Thread::State state)
thread->state = state;
assert(thread->state != Thread::State::RUNNABLE || thread->schedulerlistprev);
assert(thread->state != Thread::State::RUNNABLE || thread->schedulerlistnext);
assert(thread->state != ThreadState::RUNNABLE || thread->schedulerlistprev);
assert(thread->state != ThreadState::RUNNABLE || thread->schedulerlistnext);
Interrupt::SetEnabled(wasenabled);
}
Thread::State GetThreadState(Thread* thread)
ThreadState GetThreadState(Thread* thread)
{
return thread->state;
}

View file

@ -24,11 +24,13 @@
#include <sortix/kernel/platform.h>
#include <sortix/kernel/keyboard.h>
#include <sortix/kernel/scheduler.h>
#include <string.h>
#include "vga.h"
#include "uart.h"
#include "serialterminal.h"
#include "scheduler.h"
namespace Sortix
{

View file

@ -25,6 +25,8 @@
#ifndef SORTIX_SIGNAL_H
#define SORTIX_SIGNAL_H
#include <sortix/signal.h>
#include "cpu.h"
namespace Sortix {

View file

@ -26,10 +26,10 @@
#include <sortix/kernel/platform.h>
#include <sortix/kernel/syscall.h>
#include <sortix/kernel/scheduler.h>
#include "process.h"
#include "thread.h"
#include "scheduler.h"
namespace Sortix {
namespace Syscall {

View file

@ -28,6 +28,7 @@
#include <sortix/kernel/syscall.h>
#include <sortix/kernel/interrupt.h>
#include <sortix/kernel/time.h>
#include <sortix/kernel/scheduler.h>
#include <sortix/mman.h>
#include <sortix/signal.h>
@ -38,7 +39,6 @@
#include "process.h"
#include "thread.h"
#include "scheduler.h"
namespace Sortix
{
@ -152,7 +152,7 @@ namespace Sortix
void StartKernelThread(Thread* thread)
{
Scheduler::SetThreadState(thread, Thread::State::RUNNABLE);
Scheduler::SetThreadState(thread, ThreadState::RUNNABLE);
}
Thread* RunKernelThread(Process* process, CPU::InterruptRegisters* regs)

View file

@ -26,6 +26,9 @@
#define SORTIX_THREAD_H
#include <sortix/signal.h>
#include <sortix/kernel/scheduler.h>
#include "signal.h"
typedef struct multiboot_info multiboot_info_t;
@ -75,9 +78,6 @@ namespace Sortix
friend void KernelInit(unsigned long magic, multiboot_info_t* bootinfo);
friend void Thread__OnSigKill(Thread* thread);
public:
enum State { NONE, RUNNABLE, BLOCKING, DEAD };
public:
static void Init();
@ -99,7 +99,7 @@ namespace Sortix
public:
Thread* schedulerlistprev;
Thread* schedulerlistnext;
volatile State state;
volatile ThreadState state;
uint8_t fpuenv[512UL + 16UL];
uint8_t* fpuenvaligned;
bool fpuinitialized;

View file

@ -37,9 +37,9 @@
#include <sortix/kernel/interrupt.h>
#include <sortix/kernel/syscall.h>
#include <sortix/kernel/time.h>
#include <sortix/kernel/scheduler.h>
#include "process.h"
#include "scheduler.h"
#include "sound.h"
#ifdef PLATFORM_SERIAL

View file

@ -30,13 +30,13 @@
#include <sortix/kernel/descriptor.h>
#include <sortix/kernel/interlock.h>
#include <sortix/kernel/syscall.h>
#include <sortix/kernel/scheduler.h>
#include <errno.h>
#include <string.h>
#include "fs/util.h"
#include "vga.h"
#include "scheduler.h"
#include "process.h"
#define TEST_VGAFONT 0

View file

@ -24,7 +24,7 @@
#include <sortix/kernel/platform.h>
#include <sortix/kernel/memorymanagement.h>
#include "scheduler.h"
#include <sortix/kernel/scheduler.h>
namespace Sortix
{

View file

@ -23,7 +23,7 @@
*******************************************************************************/
#include <sortix/kernel/platform.h>
#include "scheduler.h"
#include <sortix/kernel/scheduler.h>
#include <sortix/kernel/memorymanagement.h>
namespace Sortix