MentOS
0.8.0
The Mentoring Operating System
|
Programmable Interval Timer (PIT) definitions. More...
Go to the source code of this file.
Classes | |
struct | tvec_base_s |
Contains all the timers of a single CPU. More... | |
struct | timer_list |
Represents the request to execute a function in the future, also known as timer. More... | |
Macros | |
#define | ENABLE_REAL_TIMER_SYSTEM |
#define | ITIMER_REAL 0 |
Counts down in real (i.e., wall clock) time. More... | |
#define | ITIMER_VIRTUAL 1 |
Counts down against the user-mode CPU time consumed by the process. | |
#define | ITIMER_PROF 2 |
#define | TICKS_PER_SECOND 1193 |
Number of ticks per seconds. | |
#define | TVN_COUNT 4 |
Number of normal timer vectors. | |
#define | TVN_BITS 6 |
Number of bits for the normal timer vector. | |
#define | TVR_BITS 8 |
Number of bits for the root timer vector. | |
#define | TVN_SIZE (1 << TVN_BITS) |
Number of headers in a normal timer vector. | |
#define | TVR_SIZE (1 << TVR_BITS) |
Number of headers in a root timer vector. | |
#define | TVN_MASK (TVN_SIZE - 1) |
A mask with all 1s for the normal timer vector (0b00111111) | |
#define | TVR_MASK (TVR_SIZE - 1) |
A mask with all 1s for the root timer vector (0b11111111) | |
#define | TIMER_TICKS_BITS(tv) (TVR_BITS + TVN_BITS * (tv)) |
A shift used to calculate a timer position inside the tvec_base structure. | |
#define | TIMER_TICKS(tv) (1 << TIMER_TICKS_BITS(tv)) |
Expiration ticks of timer based on position inside tvec_base structure. | |
Typedefs | |
typedef struct tvec_base_s | tvec_base_t |
Contains all the timers of a single CPU. | |
Functions | |
void | timer_handler (pt_regs *f) |
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... | |
void | timer_phase (const uint32_t hz) |
Allows to set the timer phase to the given frequency. More... | |
void | dynamic_timers_install (void) |
Initialize dynamic timer system. | |
void | init_timer (struct timer_list *timer) |
Initializes a new timer struct. More... | |
void | run_timer_softirq (void) |
Updates the timer data structures. | |
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... | |
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... | |
Programmable Interval Timer (PIT) definitions.
#define ENABLE_REAL_TIMER_SYSTEM |
This enables the dynamic timer system use an hierarchical timing wheel, an optimized data structure that allows O(1) insertion, O(1) deletion and ammortized O(1) tick update.
#define ITIMER_PROF 2 |
This timer counts down against the total (i.e., both user and system) CPU time consumed by the process.
#define ITIMER_REAL 0 |
Counts down in real (i.e., wall clock) time.
This enables the system dump tvec_base timer vectors content on the console.
void add_timer | ( | struct timer_list * | timer | ) |
Add a new timer to the current CPU.
timer | The timer to add. |
void init_timer | ( | struct timer_list * | timer | ) |
Initializes a new timer struct.
timer | The timer to initialize. |
void remove_timer | ( | struct timer_list * | timer | ) |
Removes a timer from the current CPU.
timer | The timer to remove. |
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. |