PKUOS - Pintos
Pintos source browser for PKU Operating System course
Macros | Functions
timer.h File Reference
#include <round.h>
#include <stdint.h>
Include dependency graph for timer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define TIMER_FREQ   100
 Number of timer interrupts per second. More...
 

Functions

void timer_init (void)
 Sets up the timer to interrupt TIMER_FREQ times per second, and registers the corresponding interrupt. More...
 
void timer_calibrate (void)
 Calibrates loops_per_tick, used to implement brief delays. More...
 
int64_t timer_ticks (void)
 Returns the number of timer ticks since the OS booted. More...
 
int64_t timer_elapsed (int64_t)
 Returns the number of timer ticks elapsed since THEN, which should be a value once returned by timer_ticks(). More...
 
void timer_sleep (int64_t ticks)
 Sleep and yield the CPU to other threads. More...
 
void timer_msleep (int64_t milliseconds)
 Sleeps for approximately MS milliseconds. More...
 
void timer_usleep (int64_t microseconds)
 Sleeps for approximately US microseconds. More...
 
void timer_nsleep (int64_t nanoseconds)
 Sleeps for approximately NS nanoseconds. More...
 
void timer_mdelay (int64_t milliseconds)
 Busy waits. More...
 
void timer_udelay (int64_t microseconds)
 Sleeps for approximately US microseconds. More...
 
void timer_ndelay (int64_t nanoseconds)
 Sleeps execution for approximately NS nanoseconds. More...
 
void timer_print_stats (void)
 devices/timer.h More...
 

Macro Definition Documentation

◆ TIMER_FREQ

#define TIMER_FREQ   100

Number of timer interrupts per second.

Definition at line 8 of file timer.h.

Function Documentation

◆ timer_calibrate()

void timer_calibrate ( void  )

Calibrates loops_per_tick, used to implement brief delays.

Definition at line 44 of file timer.c.

References ASSERT, intr_get_level(), INTR_ON, loops_per_tick, printf(), PRIu64, TIMER_FREQ, and too_many_loops().

Referenced by pintos_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_elapsed()

int64_t timer_elapsed ( int64_t  then)

Returns the number of timer ticks elapsed since THEN, which should be a value once returned by timer_ticks().

Definition at line 82 of file timer.c.

References timer_ticks().

Referenced by alarm_priority_thread(), block_thread(), load_thread(), test_mlfqs_fair(), and timer_sleep().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_init()

void timer_init ( void  )

Sets up the timer to interrupt TIMER_FREQ times per second, and registers the corresponding interrupt.

Definition at line 36 of file timer.c.

References intr_register_ext(), pit_configure_channel(), TIMER_FREQ, and timer_interrupt.

Referenced by pintos_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_mdelay()

void timer_mdelay ( int64_t  ms)

Busy waits.

Busy waits.

Interrupts need not be turned on.

Busy waiting wastes CPU cycles, and busy waiting with interrupts off for the interval between timer ticks or longer will cause timer ticks to be lost. Thus, use timer_msleep() instead if interrupts are enabled.

Definition at line 131 of file timer.c.

References real_time_delay().

Here is the call graph for this function:

◆ timer_msleep()

void timer_msleep ( int64_t  ms)

Sleeps for approximately MS milliseconds.

Interrupts must be turned on.

Definition at line 102 of file timer.c.

References real_time_sleep().

Referenced by reset_channel(), speaker_beep(), and wait_while_busy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_ndelay()

void timer_ndelay ( int64_t  ns)

Sleeps execution for approximately NS nanoseconds.

Interrupts need not be turned on.

Busy waiting wastes CPU cycles, and busy waiting with interrupts off for the interval between timer ticks or longer will cause timer ticks to be lost. Thus, use timer_nsleep() instead if interrupts are enabled.

Definition at line 157 of file timer.c.

References real_time_delay().

Here is the call graph for this function:

◆ timer_nsleep()

void timer_nsleep ( int64_t  ns)

Sleeps for approximately NS nanoseconds.

Interrupts must be turned on.

Definition at line 118 of file timer.c.

References real_time_sleep().

Referenced by select_device().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_print_stats()

void timer_print_stats ( void  )

devices/timer.h

devices/timer.h

Definition at line 164 of file timer.c.

References PRId64, printf(), and timer_ticks().

Referenced by print_stats().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_sleep()

void timer_sleep ( int64_t  ticks)

Sleep and yield the CPU to other threads.

Sleep and yield the CPU to other threads.

Interrupts must be turned on.

Definition at line 90 of file timer.c.

References ASSERT, intr_get_level(), INTR_ON, start, thread_yield(), ticks, timer_elapsed(), and timer_ticks().

Referenced by alarm_priority_thread(), load_thread(), real_time_sleep(), sleeper(), test_mlfqs_fair(), and test_sleep().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_ticks()

int64_t timer_ticks ( void  )

Returns the number of timer ticks since the OS booted.

Definition at line 71 of file timer.c.

References intr_disable(), intr_set_level(), and ticks.

Referenced by alarm_priority_thread(), block_thread(), load_thread(), sleeper(), test_mlfqs_fair(), test_sleep(), timer_elapsed(), timer_print_stats(), and timer_sleep().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_udelay()

void timer_udelay ( int64_t  us)

Sleeps for approximately US microseconds.

Interrupts need not be turned on.

Busy waiting wastes CPU cycles, and busy waiting with interrupts off for the interval between timer ticks or longer will cause timer ticks to be lost. Thus, use timer_usleep() instead if interrupts are enabled.

Definition at line 144 of file timer.c.

References real_time_delay().

Referenced by shutdown_reboot().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_usleep()

void timer_usleep ( int64_t  us)

Sleeps for approximately US microseconds.

Interrupts must be turned on.

Definition at line 110 of file timer.c.

References real_time_sleep().

Referenced by reset_channel(), and wait_until_idle().

Here is the call graph for this function:
Here is the caller graph for this function: