sched.c File Reference

Implementation of simple scheduler. More...

#include "sched.h"
#include "thread.h"
#include "sys.h"
#include "debug.h"
#include "timers.h"
#include "int.h"
#include "tqueue.h"
#include "io.h"

Defines

#define THR_QUANTUM_MULTIPLIER   1
#define THR_DEFAULT_QUANTUM   2026

Functions

void init_scheduler (thread_t t)
void context_switch (struct thread_struct *t)
void schedule (void)
 Scheduling function Function wake up runnable threads(by timer checking), remove from system zombies, that could be removed, choose next thread from the ready to run list and switch context to this thread. Note: In the system is still at least one runnable thread (system thread). Note: zombie can not be removed (freed()), when this schedule rutine is runninin its context.

Variables

thread_queue_t runnable_threads
thread_queue_t zombies_to_kill_threads
thread_queue_t valid_threads
thread_queue_t sleeping_threads


Detailed Description

Implementation of simple scheduler.

Scheduler is implemented as simple round robin (no priorities). Scheduler holds all the time two queues of threads. One for runnable threads (unsorted double-linked cyclic fifo) and one for to_remove_zombie threads (), that are finished, somebody join them or they were detached and can be removed from system. These zombie threads are removed from system in function schedule(). Sleeping threads dont need any special queue, all the thread has internal timer, and rutine called from this timer wake up thread to be set as runnable. Scheduler at first try to wake up sleeping threads (check timers,so move them in queue of ready to run threads), Than remove zombies, that could be removed (thread can not free memory of itself), and than switch context for the first ready to run thread. In system is all the time at least one runnable thread, system thread with ID == 0.

This file is based on Kalisto, Development Kernel copyrighted (c) to Distributed Systems Research Group MFF UK, Czech republic.


Define Documentation

#define THR_DEFAULT_QUANTUM   2026

Default amount of time for a thread.

#define THR_QUANTUM_MULTIPLIER   1

Defined for debugging, allows to simly change time quantum for threads and try behavior on different time slices to run.


Function Documentation

void context_switch ( struct thread_struct *  t  ) 

Switch procesor context from the current thread to context of thread t

Parameters:
t - thread to be switched context to

void init_scheduler ( thread_t  t  ) 

Init the scheduler structures (all the queues). Insert first thread into runnable, then set next timer interrupt to start scheduling.

Parameters:
t - first, system thread to be enqueud into runnable list structure.


Variable Documentation

thread_queue_t runnable_threads

A list of ready-to-run threads. This serves as a round-robin queue -- the thread at the head will be activated by a schedule() call. Struture is organized as fifo, uses pointers prev, next of thread_t structure. (cyclic fifo, uses prev next items of thread_t structure)

See also:
thread_t

thread_queue_t valid_threads

A list of all valid threads int the system thread are enqued to it by thread_create() and remoded by thread_remove() (cyclic fifo, uses vprev vnext items of thread_t structure)

See also:
thread_t

thread_create()

thread

thread_queue_t zombies_to_kill_threads

A list of zombies, that can be romoved from the system (were detached or joined by some ohter thread). thread are enqued to this thread in thread_kill() function and are removed in schedule() call. (cyclic fifo, uses prev next items of thread_t structure)

See also:
thread_t

thread_kill()

__thread_wrapper()


Generated on Wed Nov 15 17:25:44 2006 for Kalisto by  doxygen 1.4.7