MentOS
0.8.0
The Mentoring Operating System
|
Timer implementation. More...
Classes | |
struct | sleep_data |
Contains the entry of a wait queue and timespec which keeps trakc of the remaining time. More... | |
Macros | |
#define | __DEBUG_HEADER__ "[TIMER ]" |
Change header. | |
#define | __DEBUG_LEVEL__ LOGLEVEL_NOTICE |
Set log level. | |
#define | PIT_DATAREG0 0x40u |
Channel 0 data port (read/write). | |
#define | PIT_DATAREG1 0x41u |
Channel 1 data port (read/write). | |
#define | PIT_DATAREG2 0x42u |
Channel 2 data port (read/write). | |
#define | PIT_COMREG 0x43u |
Mode/Command register (write only, a read is ignored). | |
#define | PIT_DIVISOR 1193182 |
Frequency divider value (1.193182 MHz). | |
#define | PIT_CONFIGURATION 0x34u |
Command used to configure the PIT. More... | |
#define | PIT_MASK 0xFFu |
Mask used to set the divisor. | |
Typedefs | |
typedef struct sleep_data | sleep_data_t |
Contains the entry of a wait queue and timespec which keeps trakc of the remaining time. | |
Functions | |
void | timer_phase (const uint32_t hz) |
Allows to set the timer phase to the given frequency. More... | |
void | timer_handler (pt_regs *reg) |
Handles the timer. More... | |
void | timer_install (void) |
Sets up the system clock by installing the timer handler into IRQ0. | |
uint64_t | timer_get_seconds (void) |
Returns the number of seconds since the system started its execution. More... | |
unsigned long | timer_get_ticks (void) |
Returns the number of ticks since the system started its execution. More... | |
static void | __print_vector (list_head *vector) |
Prints the addresses of all the timers inside a vector. More... | |
static void | __print_vector_base (tvec_base_t *base) |
Prints the addresses of all the timers inside a vector base. More... | |
static void | __tvec_base_init (tvec_base_t *base) |
Initializes the tvec_base. More... | |
static list_head * | __timer_get_target_vector (tvec_base_t *base, struct timer_list *timer) |
Select correct timer vector and position inside of it for the input timer index contains the position inside of the tv_index timer vector. More... | |
static void | __timer_cascate_vector (tvec_base_t *base, list_head *current_vector) |
Move all timers from tv up one level. More... | |
static void | __timer_cascate_base (tvec_base_t *base) |
Move all timers from tv up one level. More... | |
static struct timer_list * | __timer_list_alloc (void) |
Allocates the memory for timer. More... | |
static void | __timer_list_dealloc (struct timer_list *timer) |
Frees the memory of a timer. More... | |
void | init_timer (struct timer_list *timer) |
Initializes a new timer struct. More... | |
void | add_timer (struct timer_list *timer) |
Add a new timer to the current CPU. More... | |
void | remove_timer (struct timer_list *timer) |
Removes a timer from the current CPU. More... | |
static sleep_data_t * | __sleep_data_alloc (void) |
Allocates the memory for sleep_data. More... | |
static void | __sleep_data_dealloc (sleep_data_t *sleep_data) |
Frees the memory of a sleep_data. More... | |
static void | __values_to_itimerval (time_t interval, time_t value, struct itimerval *timer) |
Transforms interval and value to the timer. More... | |
static void | __itimerval_to_values (time_t *interval, time_t *value, const struct itimerval *timer) |
Transforms an interval timer to values. More... | |
static void | __update_task_itimerval (int which, const struct itimerval *timer) |
Updates the timer for the given task. More... | |
void | dynamic_timers_install (void) |
Initialize dynamic timer system. | |
void | run_timer_softirq (void) |
Updates the timer data structures. | |
static void | debug_timeout (unsigned long data) |
Standard debugging function callback. More... | |
static void | sleep_timeout (unsigned long data) |
Callback for when a sleep timer expires. More... | |
static void | alarm_timeout (unsigned long task_ptr) |
Function executed when the real_timer of a process expires, sends SIGALRM to process. More... | |
static void | real_timer_timeout (unsigned long task_ptr) |
Function executed when the real_timer of a process expires, sends SIGALRM to process. More... | |
int | sys_nanosleep (const struct timespec *req, struct timespec *rem) |
Suspends the execution of the calling thread. More... | |
unsigned | sys_alarm (int seconds) |
Send signal to calling thread after desired seconds. More... | |
int | sys_getitimer (int which, struct itimerval *curr_value) |
Fills the structure pointed to by curr_value with the current setting for the timer specified by which. More... | |
int | sys_setitimer (int which, const struct itimerval *new_value, struct itimerval *old_value) |
Arms or disarms the timer specified by which, by setting the timer to the value specified by new_value. More... | |
void | update_process_profiling_timer (task_struct *proc) |
Update the profiling timer and generate SIGPROF if it has expired. More... | |
Variables | |
static __volatile__ unsigned long | timer_ticks = 0 |
The number of ticks since the system started its execution. | |
static tvec_base_t | cpu_base = { 0 } |
Contains timer for each CPU (for now only one) | |
static wait_queue_head_t | sleep_queue |
Contains all process waiting for a sleep. | |
Timer implementation.
#define PIT_CONFIGURATION 0x34u |
Command used to configure the PIT.
Bits Usage 6 and 7 [Select channel] 0 0 = Channel 0 0 1 = Channel 1 1 0 = Channel 2 1 1 = Read-back command (8254 only) 4 and 5 [Access mode] 0 0 = Latch count value command 0 1 = Access mode: lobyte only 1 0 = Access mode: hibyte only 1 1 = Access mode: lobyte/hibyte 1 to 3 [Operating mode] 0 0 0 = Mode 0 (interrupt on terminal count) 0 0 1 = Mode 1 (hardware re-triggerable one-shot) 0 1 0 = Mode 2 (rate generator) 0 1 1 = Mode 3 (square wave generator) 1 0 0 = Mode 4 (software triggered strobe) 1 0 1 = Mode 5 (hardware triggered strobe) 1 1 0 = Mode 2 (rate generator, same as 010b) 1 1 1 = Mode 3 (square wave generator, same as 011b) 0 [BCD/Binary mode] 0 = 16-bit binary 1 = four-digit BCD
Examples: 0x36 = 00|11|011|0 0x34 = 00|11|010|0
|
inlinestatic |
Transforms an interval timer to values.
interval | the output variable where to store the interval for periodic timer. |
value | the output variable where to store the time until next expiration. |
timer | the timer used to initialize the values. |
|
inlinestatic |
Prints the addresses of all the timers inside a vector.
vector | the vector for which we print the details. |
|
inlinestatic |
Prints the addresses of all the timers inside a vector base.
base | the base for which we print the details. |
|
inlinestatic |
Allocates the memory for sleep_data.
|
inlinestatic |
Frees the memory of a sleep_data.
sleep_data | pointer to the sleep_data. |
|
inlinestatic |
Move all timers from tv up one level.
base | the base for which we move the timers. |
Cascading means moving all dynamic timers in the base->tvn list into the proper lists of base->tvr; then, it returns a positive value, unless all base->tvn lists are now empty. If so, cascade() is invoked once more to replenish base->tvn with the timers included in a list of base->tvn, and so on.
|
inlinestatic |
Move all timers from tv up one level.
base | the base that contains the vector we want to cascate. |
current_vector | the vector we want to cascate. |
|
inlinestatic |
Select correct timer vector and position inside of it for the input timer index contains the position inside of the tv_index timer vector.
base | the vector base we use to search the vector. |
timer | the timer we use to determine the target vector. |
|
inlinestatic |
Allocates the memory for timer.
|
inlinestatic |
Frees the memory of a timer.
timer | pointer to the timer. |
|
inlinestatic |
Initializes the tvec_base.
base | the base to initialize. |
|
static |
Updates the timer for the given task.
which | the type of operation to execute. |
timer | the timer to update. |
|
inlinestatic |
Transforms interval and value to the timer.
interval | the interval for periodic timer. |
value | the time until next expiration. |
timer | where the final values should be stored. |
void add_timer | ( | struct timer_list * | timer | ) |
Add a new timer to the current CPU.
timer | The timer to add. |
|
inlinestatic |
Function executed when the real_timer of a process expires, sends SIGALRM to process.
task_ptr | pointer to the process whos associated timer has expired. |
|
inlinestatic |
Standard debugging function callback.
data | The data. |
void init_timer | ( | struct timer_list * | timer | ) |
Initializes a new timer struct.
timer | The timer to initialize. |
|
inlinestatic |
Function executed when the real_timer of a process expires, sends SIGALRM to process.
task_ptr | pointer to the process whos associated timer has expired. |
void remove_timer | ( | struct timer_list * | timer | ) |
Removes a timer from the current CPU.
timer | The timer to remove. |
|
inlinestatic |
Callback for when a sleep timer expires.
data | Custom data stored in the timer. |
unsigned sys_alarm | ( | int | seconds | ) |
Send signal to calling thread after desired seconds.
seconds | The number of seconds in the interval |
int sys_getitimer | ( | int | which, |
struct itimerval * | curr_value | ||
) |
Fills the structure pointed to by curr_value with the current setting for the timer specified by which.
which | The time domain (i.e., ITIMER_REAL, ITIMER_VIRTUAL, ITIMER_PROF) |
curr_value | There the values must be stored. |
Suspends the execution of the calling thread.
req | The amount of time we want to sleep. |
rem | The remaining time we did not sleep. |
The execution is suspended until either at least the time specified in *req has elapsed, or the delivery of a signal that triggers the invocation of a handler in the calling thread or that terminates the process.
Arms or disarms the timer specified by which, by setting the timer to the value specified by new_value.
The system provides each process with three interval timers, each decrementing in a distinct time domain. When any timer expires, a signal is sent to the process, and the timer (potentially) restarts.
which | The time domain (i.e., ITIMER_REAL, ITIMER_VIRTUAL, ITIMER_PROF) |
new_value | The new value to set. |
old_value | Where the old value must be stored. |
uint64_t timer_get_seconds | ( | void | ) |
Returns the number of seconds since the system started its execution.
unsigned long timer_get_ticks | ( | void | ) |
Returns the number of ticks since the system started its execution.
void timer_handler | ( | pt_regs * | f | ) |
Handles the timer.
f | The interrupt stack frame. |
In this case, it's very simple: We increment the 'timer_ticks' variable every time the timer fires. By default, the timer fires 18.222 times per second. Why 18.222Hz? Some engineer at IBM must've been smoking something funky.
void timer_phase | ( | const uint32_t | hz | ) |
Allows to set the timer phase to the given frequency.
hz | The frequency to set. |
void update_process_profiling_timer | ( | task_struct * | proc | ) |
Update the profiling timer and generate SIGPROF if it has expired.
proc | The process for which we must update the profiling. |