proc.h File Reference

BeRTOS Kernel core (Process scheduler). More...

#include "cfg/cfg_proc.h"
#include "cfg/cfg_monitor.h"
#include <cfg/compiler.h>
#include <cpu/types.h>
#include <cpu/frame.h>

Go to the source code of this file.


Defines

#define PROC_ATOMIC(CODE)
 Execute a block of CODE atomically with respect to task scheduling.
#define CONFIG_KERN_MINSTACKSIZE
 Default stack size for each thread, in bytes.

Functions

void proc_exit (void)
 Terminate the current process.
void proc_yield (void)
 Co-operative context switch.
void proc_rename (struct Process *proc, const char *name)
 Rename a process.
const char * proc_name (struct Process *proc)
 Return the name of the specified process.
const char * proc_currentName (void)
 Return the name of the currently running process.
iptr_t proc_currentUserData (void)
 Get the pointer to the user data of the current process.
struct Process * proc_current (void)
 Return the context structure of the currently running process.
void proc_setPri (struct Process *proc, int pri)
 Change the scheduling priority of a process.
void proc_forbid (void)
 Disable preemptive task switching.
void proc_permit (void)
 Re-enable preemptive task switching.
bool proc_allowed (void)

Detailed Description

BeRTOS Kernel core (Process scheduler).

Version:
Id
proc.h 2640 2009-04-22 16:59:51Z asterix
Author:
Bernie Innocenti <bernie@codewiz.org>

Definition in file proc.h.


Define Documentation

#define CONFIG_KERN_MINSTACKSIZE

Value:

(CPU_SAVED_REGS_CNT * 2 * sizeof(cpu_stack_t) \
            + 48 * sizeof(int))
Default stack size for each thread, in bytes.

The goal here is to allow a minimal task to save all of its registers twice, plus push a maximum of 32 variables on the stack.

The actual size computed by the default formula is: AVR: 102 i386: 156 ARM: 164 x86_64: 184

Note that on most 16bit architectures, interrupts will also run on the stack of the currently running process. Nested interrupts will greatly increases the amount of stack space required per process. Use irqmanager to minimize stack usage.

Definition at line 241 of file proc.h.


Function Documentation

bool proc_allowed ( void   )  [inline]

Returns:
true if preemptive task switching is allowed.
Note:
This accessor is needed because _preempt_forbid_cnt must be absoultely private.

Definition at line 196 of file proc.h.

struct Process* proc_current ( void   )  [read]

Return the context structure of the currently running process.

The details of the Process structure are private to the scheduler. The address returned by this function is an opaque pointer that can be passed as an argument to other process-related functions.

Definition at line 92 of file proc.h.

void proc_forbid ( void   )  [inline]

Disable preemptive task switching.

The scheduler maintains a global nesting counter. Task switching is effectively re-enabled only when the number of calls to proc_permit() matches the number of calls to proc_forbid().

Note:
Calling functions that could sleep while task switching is disabled is dangerous and unsupported.

calling proc_forbid() from within an interrupt is illegal and meaningless.

proc_permit() expands inline to 1-2 asm instructions, so it's a very efficient locking primitive in simple but performance-critical situations. In all other cases, semaphores offer a more flexible and fine-grained locking primitive.

See also:
proc_permit()

Definition at line 126 of file proc.h.

const char* proc_name ( struct Process *  proc  ) 

Return the name of the specified process.

NULL is a legal argument and will return the name "<NULL>".

Definition at line 265 of file proc.c.

void proc_permit ( void   )  [inline]

Re-enable preemptive task switching.

See also:
proc_forbid()

Definition at line 168 of file proc.h.

void proc_setPri ( struct Process *  proc,
int  pri 
)

Change the scheduling priority of a process.

Process piorities are signed ints, whereas a larger integer value means higher scheduling priority. The default priority for new processes is 0. The idle process runs with the lowest possible priority: INT_MIN.

A process with a higher priority always preempts lower priority processes. Processes of equal priority share the CPU time according to a simple round-robin policy.

As a general rule to maximize responsiveness, compute-bound processes should be assigned negative priorities and tight, interactive processes should be assigned positive priorities.

To avoid interfering with system background activities such as input processing, application processes should remain within the range -10 and +10.

Definition at line 312 of file proc.c.