Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

Context Class Reference

An execution context. More...

#include <context.h>

Inheritance diagram for Context:

Receiver Thread Kernel_thread List of all members.

Public Types

enum  Sched_mode { Periodic = 0x1, Nonstrict = 0x2 }
 Definition of different scheduling modes. More...
enum  Helping_mode { Helping, Not_Helping, Ignore_Helping }
 Definition of different helping modes. More...

Public Member Functions

void init_switch_time ()
 Initialize cpu time of the idle thread.
Cpu_time consumed_time ()
 Return consumed CPU time.
Utcbutcb () const
 Get the kernel UTCB pointer.
 Context (Thread_lock *thread_lock, Space *space, unsigned short prio, unsigned short mcp, Unsigned64 quantum)
 Initialize a context.
virtual ~Context ()
 Destroy context.
Mword state () const
 State flags.
Mword exists () const
 Does the context exist? .
void state_add (Mword const bits)
 Atomically add bits to state flags.
void state_del (Mword const bits)
 Atomically delete bits from state flags.
Mword state_change_safely (Mword const mask, Mword const bits)
 Atomically delete and add bits in state flags, provided the following rules apply (otherwise state is not changed at all):
  • Bits that are to be set must be clear in state or clear in mask
  • Bits that are to be cleared must be set in state.

Mword state_change (Mword const mask, Mword const bits)
 Atomically delete and add bits in state flags.
void state_change_dirty (Mword const mask, Mword const bits)
 Delete and add bits in state flags.
Spacespace () const
 Return the space context.
Thread_lock *const thread_lock () const
 Thread lock.
unsigned short const mcp () const
Entry_frame *const regs () const
 Registers used when iret'ing to user mode.
void inc_lock_cnt ()
 Increment lock count.
void dec_lock_cnt ()
 Decrement lock count.
int const lock_cnt () const
 Lock count.
void switch_sched (Sched_context *const next)
 Switch active timeslice of this Context.
void schedule ()
 Select a different context for running and activate it.
Sched_contextsched_context (unsigned short const id=0)
 Return Context's Sched_context with id 'id'; return time slice 0 as default.
Sched_contextsched () const
 Return Context's currently active Sched_context.
Unsigned64 const period () const
 Return Context's real-time period length.
Context::Sched_mode const mode () const
 Return Context's scheduling mode.
void set_mode (Context::Sched_mode const mode)
 Set Context's scheduling mode.
Mword const in_ready_list () const
 Check if Context is in ready-list.
void ready_enqueue ()
 Enqueue context in ready-list.
void ready_dequeue ()
 Remove context from ready-list.
Context *const helper () const
 Helper.
void set_helper (enum Helping_mode const mode)
Context *const donatee () const
 Donatee.
void set_donatee (Context *const donatee)
Mword *const get_kernel_sp () const
void set_kernel_sp (Mword *const esp)
Fpu_statefpu_state ()
void consume_time (Cpu_time const quantum)
 Add to consumed CPU time.
void switch_to (Context *t)
 Switch to scheduling context and execution context while not running under CPU lock.
void switch_to_locked (Context *t)
 Switch scheduling context and execution context.
void switch_exec (Context *t, enum Helping_mode mode)
 Switch execution context while not running under CPU lock.
void switch_exec_locked (Context *t, enum Helping_mode mode)
 Switch to a specific different execution context.
GThread_num gthread_calculated ()
LThread_num lthread_calculated ()
LThread_num task_calculated ()
void update_kip_switch_time (Context *t)

Static Public Member Functions

static bool const schedule_in_progress ()
 Return if there is currently a schedule() in progress.
static bool const can_preempt_current (Sched_context const *const s)
 Return true if s can preempt the current scheduling context, false otherwise.
static Sched_context *const current_sched ()
 Return currently active global Sched_context.

Static Public Attributes

static const size_t size = Config::thread_block_size
 Size of a Context (TCB + kernel stack).

Protected Member Functions

void update_consumed_time ()
 Update consumed CPU time during each context switch and when reading out the current thread's consumed CPU time.
void send_activation (unsigned)
void set_sched (Sched_context *const sched)
 Set Context's currently active Sched_context.
void set_period (Unsigned64 const period)
 Set Context's real-time period length.
void switch_gdt_tls ()
void load_segments ()
void store_segments ()

Static Protected Member Functions

static void set_current_sched (Sched_context *const sched)
 Set currently active global Sched_context.
static void invalidate_sched ()
 Invalidate (expire) currently active global Sched_context.

Protected Attributes

Mword _state
Mword * _kernel_sp

Private Member Functions

void switchin_context () asm("switchin_context_label") FIASCO_FASTCALL
 low level page table switching stuff
void switch_fpu (Context *t)
 low level fpu switching stuff
void switch_cpu (Context *t)
 low level cpu switching stuff
void update_ready_list ()
 Enqueue current() if ready to fix up ready-list invariant.

Static Private Member Functions

static Sched_context *_current_sched asm ("CONTEXT_CURRENT_SCHED")
static Cpu_time _switch_time asm ("CONTEXT_SWITCH_TIME")
static unsigned _prio_highest asm ("CONTEXT_PRIO_HIGHEST")
static Context *_prio_next[256] asm ("CONTEXT_PRIO_NEXT")

Private Attributes

Space_space
Context_donatee
Context_helper
int _lock_cnt
Thread_lock *const _thread_lock
Sched_context _sched_context
Sched_context_sched
Unsigned64 _period
Sched_mode _mode
unsigned short _mcp
Fpu_state _fpu_state
Cpu_time _consumed_time
Context_ready_next
Context_ready_prev

Static Private Attributes

static bool _schedule_in_progress

Friends

class Jdb_thread_list
class Jdb
class Jdb_tcb

Related Functions

(Note that these are not member functions.)

void thread_handle_fputrap ()
 A C interface for Context::handle_fpu_trap, callable from assembly code.

Detailed Description

An execution context.

A context is a runnable, schedulable activity. It carries along some state used by other subsystems: A lock count, and stack-element forward/next pointers.


Member Enumeration Documentation

enum Context::Helping_mode
 

Definition of different helping modes.

Enumeration values:
Helping 
Not_Helping 
Ignore_Helping 

enum Context::Sched_mode
 

Definition of different scheduling modes.

Enumeration values:
Periodic  0 = Conventional, 1 = Periodic
Nonstrict  0 = Strictly Periodic, 1 = Non-strictly periodic


Constructor & Destructor Documentation

Context::Context Thread_lock thread_lock,
Space space,
unsigned short  prio,
unsigned short  mcp,
Unsigned64  quantum
[inline]
 

Initialize a context.

After setup, a switch_exec to this context results in a return to user code using the return registers at regs(). The return registers are not initialized however; neither is the space_context to be used in thread switching (use set_space_context() for that).

Precondition:
(_kernel_sp == 0) && (* (stack end) == 0)
Parameters:
thread_lock pointer to lock used to lock this context
space_context the space context

Context::~Context  )  [virtual]
 

Destroy context.


Member Function Documentation

static Context* _prio_next [256] Context::asm "CONTEXT_PRIO_NEXT"   )  [static, private]
 

static unsigned _prio_highest Context::asm "CONTEXT_PRIO_HIGHEST"   )  [static, private]
 

static Cpu_time _switch_time Context::asm "CONTEXT_SWITCH_TIME"   )  [static, private]
 

static Sched_context* _current_sched Context::asm "CONTEXT_CURRENT_SCHED"   )  [static, private]
 

bool const Context::can_preempt_current Sched_context const *const   s  )  [inline, static]
 

Return true if s can preempt the current scheduling context, false otherwise.

void Context::consume_time Cpu_time const   quantum  )  [inline]
 

Add to consumed CPU time.

Parameters:
quantum Implementation-specific time quantum (TSC ticks or usecs)

Cpu_time Context::consumed_time  )  [inline]
 

Return consumed CPU time.

Returns:
Consumed CPU time in usecs

Sched_context *const Context::current_sched  )  [inline, static]
 

Return currently active global Sched_context.

void Context::dec_lock_cnt  )  [inline]
 

Decrement lock count.

Precondition:
lock_cnt() > 0

Context *const Context::donatee  )  const [inline]
 

Donatee.

Context that receives our time slices, for example because it has locked us.

Returns:
context that should be activated instead of us when we're switch_exec()'ed.

Mword Context::exists  )  const [inline]
 

Does the context exist? .

Returns:
true if this context has been initialized.

Fpu_state * Context::fpu_state  )  [inline]
 

Mword *const Context::get_kernel_sp  )  const [inline]
 

GThread_num Context::gthread_calculated  ) 
 

Context *const Context::helper  )  const [inline]
 

Helper.

Context that helps us by donating its time to us. It is set by switch_exec() if the calling thread says so.

Returns:
context that helps us and should be activated after freeing a lock.

Mword const Context::in_ready_list  )  const [inline]
 

Check if Context is in ready-list.

Returns:
1 if thread is in ready-list, 0 otherwise

void Context::inc_lock_cnt  )  [inline]
 

Increment lock count.

Postcondition:
lock_cnt() > 0

void Context::init_switch_time  )  [inline]
 

Initialize cpu time of the idle thread.

void Context::invalidate_sched  )  [static, protected]
 

Invalidate (expire) currently active global Sched_context.

void Context::load_segments  )  [inline, protected]
 

int const Context::lock_cnt  )  const [inline]
 

Lock count.

Returns:
lock count

LThread_num Context::lthread_calculated  )  [inline]
 

unsigned short const Context::mcp  )  const [inline]
 

Context::Sched_mode const Context::mode  )  const [inline]
 

Return Context's scheduling mode.

Returns:
Scheduling mode

Unsigned64 const Context::period  )  const [inline]
 

Return Context's real-time period length.

Returns:
Period length in usecs

void Context::ready_dequeue  )  [inline]
 

Remove context from ready-list.

void Context::ready_enqueue  ) 
 

Enqueue context in ready-list.

Entry_frame *const Context::regs  )  const [inline]
 

Registers used when iret'ing to user mode.

Returns:
return registers

Sched_context * Context::sched  )  const [inline]
 

Return Context's currently active Sched_context.

Returns:
Active Sched_context

Sched_context * Context::sched_context unsigned short const   id = 0  )  [inline]
 

Return Context's Sched_context with id 'id'; return time slice 0 as default.

Returns:
Sched_context with id 'id' or 0

void Context::schedule  ) 
 

Select a different context for running and activate it.

bool const Context::schedule_in_progress  )  [inline, static]
 

Return if there is currently a schedule() in progress.

void Context::send_activation unsigned   )  [inline, protected]
 

void Context::set_current_sched Sched_context *const   sched  )  [static, protected]
 

Set currently active global Sched_context.

void Context::set_donatee Context *const   donatee  )  [inline]
 

void Context::set_helper enum Helping_mode const   mode  )  [inline]
 

void Context::set_kernel_sp Mword *const   esp  )  [inline]
 

void Context::set_mode Context::Sched_mode const   mode  )  [inline]
 

Set Context's scheduling mode.

Parameters:
mode New scheduling mode

void Context::set_period Unsigned64 const   period  )  [inline, protected]
 

Set Context's real-time period length.

Parameters:
period New period length in usecs

void Context::set_sched Sched_context *const   sched  )  [inline, protected]
 

Set Context's currently active Sched_context.

Parameters:
sched Sched_context to be activated

Space * Context::space  )  const [inline]
 

Return the space context.

Returns:
space context used for this execution context. Set with set_space_context().

Mword Context::state  )  const [inline]
 

State flags.

Returns:
context's state flags

void Context::state_add Mword const   bits  )  [inline]
 

Atomically add bits to state flags.

Parameters:
bits bits to be added to state flags
Returns:
1 if none of the bits that were added had been set before

Mword Context::state_change Mword const   mask,
Mword const   bits
[inline]
 

Atomically delete and add bits in state flags.

Parameters:
mask bits not set in mask shall be deleted from state flags
bits bits to be added to state flags

void Context::state_change_dirty Mword const   mask,
Mword const   bits
[inline]
 

Delete and add bits in state flags.

Unsafe (non-atomic) and fast version -- you must hold the kernel lock when you use it.

Precondition:
cpu_lock.test() == true
Parameters:
mask Bits not set in mask shall be deleted from state flags
bits Bits to be added to state flags

Mword Context::state_change_safely Mword const   mask,
Mword const   bits
[inline]
 

Atomically delete and add bits in state flags, provided the following rules apply (otherwise state is not changed at all):

  • Bits that are to be set must be clear in state or clear in mask
  • Bits that are to be cleared must be set in state.

Parameters:
mask Bits not set in mask shall be deleted from state flags
bits Bits to be added to state flags
Returns:
1 if state was changed, 0 otherwise

void Context::state_del Mword const   bits  )  [inline]
 

Atomically delete bits from state flags.

Parameters:
bits bits to be removed from state flags
Returns:
1 if all of the bits that were removed had previously been set

void Context::store_segments  )  [inline, protected]
 

void Context::switch_cpu Context t  )  [inline, private]
 

low level cpu switching stuff

void Context::switch_exec Context t,
enum Helping_mode  mode
[inline]
 

Switch execution context while not running under CPU lock.

void Context::switch_exec_locked Context t,
enum Helping_mode  mode
 

Switch to a specific different execution context.

If that context is currently locked, switch to its locker instead (except if current() is the locker)

Precondition:
current() == this && current() != t
Parameters:
t thread that shall be activated.
mode helping mode; we either help, don't help or leave the helping state unchanged

void Context::switch_fpu Context t  )  [inline, private]
 

low level fpu switching stuff

When switching back to the FPU owner, enable the FPU so we don't get an FPU trap on FPU access.

void Context::switch_gdt_tls  )  [inline, protected]
 

void Context::switch_sched Sched_context *const   next  ) 
 

Switch active timeslice of this Context.

Parameters:
next Sched_context to switch to

void Context::switch_to Context t  )  [inline]
 

Switch to scheduling context and execution context while not running under CPU lock.

void Context::switch_to_locked Context t  )  [inline]
 

Switch scheduling context and execution context.

Parameters:
t Destination thread whose scheduling context and execution context should be activated.

void Context::switchin_context  )  [private]
 

low level page table switching stuff

Called on every re-activation of a thread (switch_exec()). This method is public only because it is called from from assembly code in switch_cpu().

LThread_num Context::task_calculated  )  [inline]
 

Thread_lock *const Context::thread_lock  )  const [inline]
 

Thread lock.

Returns:
the thread lock used to lock this context.

void Context::update_consumed_time  )  [inline, protected]
 

Update consumed CPU time during each context switch and when reading out the current thread's consumed CPU time.

void Context::update_kip_switch_time Context t  )  [inline]
 

void Context::update_ready_list  )  [inline, private]
 

Enqueue current() if ready to fix up ready-list invariant.

Utcb * Context::utcb  )  const [inline]
 

Get the kernel UTCB pointer.

Returns:
UTCB pointer, or 0 if there is no UTCB


Friends And Related Function Documentation

friend class Jdb [friend]
 

Reimplemented in Thread.

friend class Jdb_tcb [friend]
 

Reimplemented in Thread.

friend class Jdb_thread_list [friend]
 

Reimplemented in Thread.

void thread_handle_fputrap  )  [related]
 

A C interface for Context::handle_fpu_trap, callable from assembly code.


Member Data Documentation

Cpu_time Context::_consumed_time [private]
 

Context* Context::_donatee [private]
 

Fpu_state Context::_fpu_state [private]
 

Context* Context::_helper [private]
 

Mword* Context::_kernel_sp [protected]
 

int Context::_lock_cnt [private]
 

unsigned short Context::_mcp [private]
 

Sched_mode Context::_mode [private]
 

Unsigned64 Context::_period [private]
 

Context* Context::_ready_next [private]
 

Context* Context::_ready_prev [private]
 

Sched_context* Context::_sched [private]
 

Sched_context Context::_sched_context [private]
 

bool Context::_schedule_in_progress [static, private]
 

Space* Context::_space [private]
 

Mword Context::_state [protected]
 

Thread_lock* const Context::_thread_lock [private]
 

Reimplemented in Thread.

const size_t Context::size = Config::thread_block_size [static]
 

Size of a Context (TCB + kernel stack).


The documentation for this class was generated from the following files:
Generated on Mon Sep 26 14:20:14 2005 for Fiasco by  doxygen 1.4.2