Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions | Variables
timer.c File Reference
#include <linux/kernel_stat.h>
#include <linux/export.h>
#include <linux/interrupt.h>
#include <linux/percpu.h>
#include <linux/init.h>
#include <linux/mm.h>
#include <linux/swap.h>
#include <linux/pid_namespace.h>
#include <linux/notifier.h>
#include <linux/thread_info.h>
#include <linux/time.h>
#include <linux/jiffies.h>
#include <linux/posix-timers.h>
#include <linux/cpu.h>
#include <linux/syscalls.h>
#include <linux/delay.h>
#include <linux/tick.h>
#include <linux/kallsyms.h>
#include <linux/irq_work.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <asm/uaccess.h>
#include <asm/unistd.h>
#include <asm/div64.h>
#include <asm/timex.h>
#include <asm/io.h>
#include <trace/events/timer.h>

Go to the source code of this file.

Data Structures

struct  tvec
 
struct  tvec_root
 
struct  tvec_base
 

Macros

#define CREATE_TRACE_POINTS
 
#define TVN_BITS   (CONFIG_BASE_SMALL ? 4 : 6)
 
#define TVR_BITS   (CONFIG_BASE_SMALL ? 6 : 8)
 
#define TVN_SIZE   (1 << TVN_BITS)
 
#define TVR_SIZE   (1 << TVR_BITS)
 
#define TVN_MASK   (TVN_SIZE - 1)
 
#define TVR_MASK   (TVR_SIZE - 1)
 
#define MAX_TVAL   ((unsigned long)((1ULL << (TVR_BITS + 4*TVN_BITS)) - 1))
 

Functions

 EXPORT_SYMBOL (jiffies_64)
 
 EXPORT_SYMBOL (boot_tvec_bases)
 
unsigned long __round_jiffies (unsigned long j, int cpu)
 
 EXPORT_SYMBOL_GPL (__round_jiffies)
 
unsigned long __round_jiffies_relative (unsigned long j, int cpu)
 
 EXPORT_SYMBOL_GPL (__round_jiffies_relative)
 
unsigned long round_jiffies (unsigned long j)
 
 EXPORT_SYMBOL_GPL (round_jiffies)
 
unsigned long round_jiffies_relative (unsigned long j)
 
 EXPORT_SYMBOL_GPL (round_jiffies_relative)
 
unsigned long __round_jiffies_up (unsigned long j, int cpu)
 
 EXPORT_SYMBOL_GPL (__round_jiffies_up)
 
unsigned long __round_jiffies_up_relative (unsigned long j, int cpu)
 
 EXPORT_SYMBOL_GPL (__round_jiffies_up_relative)
 
unsigned long round_jiffies_up (unsigned long j)
 
 EXPORT_SYMBOL_GPL (round_jiffies_up)
 
unsigned long round_jiffies_up_relative (unsigned long j)
 
 EXPORT_SYMBOL_GPL (round_jiffies_up_relative)
 
void set_timer_slack (struct timer_list *timer, int slack_hz)
 
 EXPORT_SYMBOL_GPL (set_timer_slack)
 

Variables

u64 jiffies_64 __cacheline_aligned_in_smp = INITIAL_JIFFIES
 
struct tvec_base ____cacheline_aligned
 
struct tvec_base boot_tvec_bases
 

: name of the timer

init_timer_key - initialize a timer : the timer to be initialized : timer flags

: lockdep class key of the fake lock used for tracking timer sync lock dependencies

init_timer_key() must be done to a timer prior calling any of the other timer functions.

#define INDEX(N)   ((base->timer_jiffies >> (TVR_BITS + (N) * TVN_BITS)) & TVN_MASK)
 
void init_timer_key (struct timer_list *timer, unsigned int flags, const char *name, struct lock_class_key *key)
 
 EXPORT_SYMBOL (init_timer_key)
 
int mod_timer_pending (struct timer_list *timer, unsigned long expires)
 
 EXPORT_SYMBOL (mod_timer_pending)
 
int mod_timer (struct timer_list *timer, unsigned long expires)
 
 EXPORT_SYMBOL (mod_timer)
 
int mod_timer_pinned (struct timer_list *timer, unsigned long expires)
 
 EXPORT_SYMBOL (mod_timer_pinned)
 
void add_timer (struct timer_list *timer)
 
 EXPORT_SYMBOL (add_timer)
 
void add_timer_on (struct timer_list *timer, int cpu)
 
 EXPORT_SYMBOL_GPL (add_timer_on)
 
int del_timer (struct timer_list *timer)
 
 EXPORT_SYMBOL (del_timer)
 
int try_to_del_timer_sync (struct timer_list *timer)
 
 EXPORT_SYMBOL (try_to_del_timer_sync)
 
void update_process_times (int user_tick)
 
void run_local_timers (void)
 
 SYSCALL_DEFINE0 (getpid)
 
 SYSCALL_DEFINE0 (getppid)
 
 SYSCALL_DEFINE0 (getuid)
 
 SYSCALL_DEFINE0 (geteuid)
 
 SYSCALL_DEFINE0 (getgid)
 
 SYSCALL_DEFINE0 (getegid)
 
signed long __sched schedule_timeout (signed long timeout)
 
 EXPORT_SYMBOL (schedule_timeout)
 
signed long __sched schedule_timeout_interruptible (signed long timeout)
 
 EXPORT_SYMBOL (schedule_timeout_interruptible)
 
signed long __sched schedule_timeout_killable (signed long timeout)
 
 EXPORT_SYMBOL (schedule_timeout_killable)
 
signed long __sched schedule_timeout_uninterruptible (signed long timeout)
 
 EXPORT_SYMBOL (schedule_timeout_uninterruptible)
 
 SYSCALL_DEFINE0 (gettid)
 
int do_sysinfo (struct sysinfo *info)
 
 SYSCALL_DEFINE1 (sysinfo, struct sysinfo __user *, info)
 
void __init init_timers (void)
 
void msleep (unsigned int msecs)
 
 EXPORT_SYMBOL (msleep)
 
unsigned long msleep_interruptible (unsigned int msecs)
 
 EXPORT_SYMBOL (msleep_interruptible)
 
void usleep_range (unsigned long min, unsigned long max)
 
 EXPORT_SYMBOL (usleep_range)
 

Macro Definition Documentation

#define CREATE_TRACE_POINTS

Definition at line 50 of file timer.c.

#define INDEX (   N)    ((base->timer_jiffies >> (TVR_BITS + (N) * TVN_BITS)) & TVN_MASK)

Definition at line 1131 of file timer.c.

#define MAX_TVAL   ((unsigned long)((1ULL << (TVR_BITS + 4*TVN_BITS)) - 1))

Definition at line 66 of file timer.c.

#define TVN_BITS   (CONFIG_BASE_SMALL ? 4 : 6)

Definition at line 60 of file timer.c.

#define TVN_MASK   (TVN_SIZE - 1)

Definition at line 64 of file timer.c.

#define TVN_SIZE   (1 << TVN_BITS)

Definition at line 62 of file timer.c.

#define TVR_BITS   (CONFIG_BASE_SMALL ? 6 : 8)

Definition at line 61 of file timer.c.

#define TVR_MASK   (TVR_SIZE - 1)

Definition at line 65 of file timer.c.

#define TVR_SIZE   (1 << TVR_BITS)

Definition at line 63 of file timer.c.

Function Documentation

unsigned long __round_jiffies ( unsigned long  j,
int  cpu 
)

__round_jiffies - function to round jiffies to a full second : the time in (absolute) jiffies that should be rounded : the processor number on which the timeout will happen

__round_jiffies() rounds an absolute time in the future (in jiffies) up or down to (approximately) full seconds. This is useful for timers for which the exact time they fire does not matter too much, as long as they fire approximately every X seconds.

By rounding these timers to whole seconds, all such timers will fire at the same time, rather than at various times spread out. The goal of this is to have the CPU wake up less, which saves power.

The exact rounding is skewed for each processor to avoid all processors firing at the exact same time, which could lead to lock contention or spurious cache line bouncing.

The return value is the rounded version of the parameter.

Definition at line 175 of file timer.c.

unsigned long __round_jiffies_relative ( unsigned long  j,
int  cpu 
)

__round_jiffies_relative - function to round jiffies to a full second : the time in (relative) jiffies that should be rounded : the processor number on which the timeout will happen

__round_jiffies_relative() rounds a time delta in the future (in jiffies) up or down to (approximately) full seconds. This is useful for timers for which the exact time they fire does not matter too much, as long as they fire approximately every X seconds.

By rounding these timers to whole seconds, all such timers will fire at the same time, rather than at various times spread out. The goal of this is to have the CPU wake up less, which saves power.

The exact rounding is skewed for each processor to avoid all processors firing at the exact same time, which could lead to lock contention or spurious cache line bouncing.

The return value is the rounded version of the parameter.

Definition at line 201 of file timer.c.

unsigned long __round_jiffies_up ( unsigned long  j,
int  cpu 
)

__round_jiffies_up - function to round jiffies up to a full second : the time in (absolute) jiffies that should be rounded : the processor number on which the timeout will happen

This is the same as __round_jiffies() except that it will never round down. This is useful for timeouts for which the exact time of firing does not matter too much, as long as they don't fire too early.

Definition at line 262 of file timer.c.

unsigned long __round_jiffies_up_relative ( unsigned long  j,
int  cpu 
)

__round_jiffies_up_relative - function to round jiffies up to a full second : the time in (relative) jiffies that should be rounded : the processor number on which the timeout will happen

This is the same as __round_jiffies_relative() except that it will never round down. This is useful for timeouts for which the exact time of firing does not matter too much, as long as they don't fire too early.

Definition at line 278 of file timer.c.

void add_timer ( struct timer_list timer)

add_timer - start a timer : the timer to be added

The kernel will do a ->function(->data) callback from the timer interrupt at the ->expires point in the future. The current time is 'jiffies'.

The timer's ->expires, ->function (and if the handler uses it, ->data) fields must be set prior calling this function.

Timers with an ->expires field in the past will be executed in the next timer tick.

Definition at line 906 of file timer.c.

void add_timer_on ( struct timer_list timer,
int  cpu 
)

add_timer_on - start a timer on a particular CPU : the timer to be added : the CPU to start it on

This is not very scalable on SMP. Double adds are not possible.

Definition at line 920 of file timer.c.

int del_timer ( struct timer_list timer)

del_timer - deactive a timer. : the timer to be deactivated

del_timer() deactivates a timer - this works on both active and inactive timers.

The function returns whether it has deactivated a pending timer or not. (ie. del_timer() of an inactive timer returns 0, del_timer() of an active timer returns 1.)

Definition at line 955 of file timer.c.

int do_sysinfo ( struct sysinfo info)

do_sysinfo - fill in sysinfo struct : pointer to buffer to fill

Definition at line 1570 of file timer.c.

EXPORT_SYMBOL ( jiffies_64  )
EXPORT_SYMBOL ( boot_tvec_bases  )
EXPORT_SYMBOL ( init_timer_key  )
EXPORT_SYMBOL ( mod_timer_pending  )
EXPORT_SYMBOL ( mod_timer  )
EXPORT_SYMBOL ( mod_timer_pinned  )
EXPORT_SYMBOL ( add_timer  )
EXPORT_SYMBOL ( del_timer  )
EXPORT_SYMBOL ( try_to_del_timer_sync  )
EXPORT_SYMBOL ( schedule_timeout  )
EXPORT_SYMBOL ( schedule_timeout_interruptible  )
EXPORT_SYMBOL ( schedule_timeout_killable  )
EXPORT_SYMBOL ( schedule_timeout_uninterruptible  )
EXPORT_SYMBOL ( msleep  )
EXPORT_SYMBOL ( msleep_interruptible  )
EXPORT_SYMBOL ( usleep_range  )
EXPORT_SYMBOL_GPL ( __round_jiffies  )
EXPORT_SYMBOL_GPL ( __round_jiffies_relative  )
EXPORT_SYMBOL_GPL ( round_jiffies  )
EXPORT_SYMBOL_GPL ( round_jiffies_relative  )
EXPORT_SYMBOL_GPL ( __round_jiffies_up  )
EXPORT_SYMBOL_GPL ( __round_jiffies_up_relative  )
EXPORT_SYMBOL_GPL ( round_jiffies_up  )
EXPORT_SYMBOL_GPL ( round_jiffies_up_relative  )
EXPORT_SYMBOL_GPL ( set_timer_slack  )
EXPORT_SYMBOL_GPL ( add_timer_on  )
void init_timer_key ( struct timer_list timer,
unsigned int  flags,
const char name,
struct lock_class_key key 
)

Definition at line 644 of file timer.c.

void __init init_timers ( void  )

Definition at line 1780 of file timer.c.

int mod_timer ( struct timer_list timer,
unsigned long  expires 
)

mod_timer - modify a timer's timeout : the timer to be modified : new timeout in jiffies

mod_timer() is a more efficient way to update the expire field of an active timer (if the timer is inactive it will be activated)

mod_timer(timer, expires) is equivalent to:

del_timer(timer); timer->expires = expires; add_timer(timer);

Note that if there are multiple unserialized concurrent users of the same timer, then mod_timer() is the only safe way to modify the timeout, since add_timer() cannot modify an already running timer.

The function returns whether it has modified a pending timer or not. (ie. mod_timer() of an inactive timer returns 0, mod_timer() of an active timer returns 1.)

Definition at line 848 of file timer.c.

int mod_timer_pending ( struct timer_list timer,
unsigned long  expires 
)

mod_timer_pending - modify a pending timer's timeout : the pending timer to be modified : new timeout in jiffies

mod_timer_pending() is the same for pending timers as mod_timer(), but will not re-activate and modify already deleted timers.

It is useful for unserialized use of timers.

Definition at line 783 of file timer.c.

int mod_timer_pinned ( struct timer_list timer,
unsigned long  expires 
)

mod_timer_pinned - modify a timer's timeout : the timer to be modified : new timeout in jiffies

mod_timer_pinned() is a way to update the expire field of an active timer (if the timer is inactive it will be activated) and to ensure that the timer is scheduled on the current CPU.

Note that this does not prevent the timer from being migrated when the current CPU goes offline. If this is a problem for you, use CPU-hotplug notifiers to handle it correctly, for example, cancelling the timer when the corresponding CPU goes offline.

mod_timer_pinned(timer, expires) is equivalent to:

del_timer(timer); timer->expires = expires; add_timer(timer);

Definition at line 883 of file timer.c.

void msleep ( unsigned int  msecs)

msleep - sleep safely even with waitqueue interruptions : Time in milliseconds to sleep for

Definition at line 1800 of file timer.c.

unsigned long msleep_interruptible ( unsigned int  msecs)

msleep_interruptible - sleep waiting for signals : Time in milliseconds to sleep for

Definition at line 1814 of file timer.c.

unsigned long round_jiffies ( unsigned long  j)

round_jiffies - function to round jiffies to a full second : the time in (absolute) jiffies that should be rounded

round_jiffies() rounds an absolute time in the future (in jiffies) up or down to (approximately) full seconds. This is useful for timers for which the exact time they fire does not matter too much, as long as they fire approximately every X seconds.

By rounding these timers to whole seconds, all such timers will fire at the same time, rather than at various times spread out. The goal of this is to have the CPU wake up less, which saves power.

The return value is the rounded version of the parameter.

Definition at line 225 of file timer.c.

unsigned long round_jiffies_relative ( unsigned long  j)

round_jiffies_relative - function to round jiffies to a full second : the time in (relative) jiffies that should be rounded

round_jiffies_relative() rounds a time delta in the future (in jiffies) up or down to (approximately) full seconds. This is useful for timers for which the exact time they fire does not matter too much, as long as they fire approximately every X seconds.

By rounding these timers to whole seconds, all such timers will fire at the same time, rather than at various times spread out. The goal of this is to have the CPU wake up less, which saves power.

The return value is the rounded version of the parameter.

Definition at line 246 of file timer.c.

unsigned long round_jiffies_up ( unsigned long  j)

round_jiffies_up - function to round jiffies up to a full second : the time in (absolute) jiffies that should be rounded

This is the same as round_jiffies() except that it will never round down. This is useful for timeouts for which the exact time of firing does not matter too much, as long as they don't fire too early.

Definition at line 296 of file timer.c.

unsigned long round_jiffies_up_relative ( unsigned long  j)

round_jiffies_up_relative - function to round jiffies up to a full second : the time in (relative) jiffies that should be rounded

This is the same as round_jiffies_relative() except that it will never round down. This is useful for timeouts for which the exact time of firing does not matter too much, as long as they don't fire too early.

Definition at line 311 of file timer.c.

void run_local_timers ( void  )

Definition at line 1379 of file timer.c.

signed long __sched schedule_timeout ( signed long  timeout)

schedule_timeout - sleep until timeout : timeout value in jiffies

Make the current task sleep until jiffies have elapsed. The routine will return immediately unless the current task state has been set (see set_current_state()).

You can set the task state as follows -

TASK_UNINTERRUPTIBLE - at least jiffies are guaranteed to pass before the routine returns. The routine will return 0

TASK_INTERRUPTIBLE - the routine may return early if a signal is delivered to the current task. In this case the remaining time in jiffies will be returned, or 0 if the timer expired in time

The current task state is guaranteed to be TASK_RUNNING when this routine returns.

Specifying a value of MAX_SCHEDULE_TIMEOUT will schedule the CPU away without a bound on the timeout. In this case the return value will be MAX_SCHEDULE_TIMEOUT.

In all cases the return value is guaranteed to be non-negative.

Definition at line 1484 of file timer.c.

signed long __sched schedule_timeout_interruptible ( signed long  timeout)

Definition at line 1539 of file timer.c.

signed long __sched schedule_timeout_killable ( signed long  timeout)

Definition at line 1546 of file timer.c.

signed long __sched schedule_timeout_uninterruptible ( signed long  timeout)

Definition at line 1553 of file timer.c.

void set_timer_slack ( struct timer_list timer,
int  slack_hz 
)

set_timer_slack - set the allowed slack for a timer : the timer to be modified : the amount of time (in jiffies) allowed for rounding

Set the amount of time, in jiffies, that a certain timer has in terms of slack. By setting this value, the timer subsystem will schedule the actual timer somewhere between the time mod_timer() asks for, and that time plus the slack.

By setting the slack to -1, a percentage of the delay is used instead.

Definition at line 330 of file timer.c.

SYSCALL_DEFINE0 ( getpid  )

sys_getpid - return the thread group id of the current process

Note, despite the name, this returns the tgid not the pid. The tgid and the pid are identical unless CLONE_THREAD was specified on clone() in which case the tgid is the same in all threads of the same group.

This is SMP safe as current->tgid does not change.

Definition at line 1407 of file timer.c.

SYSCALL_DEFINE0 ( getppid  )

Definition at line 1418 of file timer.c.

SYSCALL_DEFINE0 ( getuid  )

Definition at line 1429 of file timer.c.

SYSCALL_DEFINE0 ( geteuid  )

Definition at line 1435 of file timer.c.

SYSCALL_DEFINE0 ( getgid  )

Definition at line 1441 of file timer.c.

SYSCALL_DEFINE0 ( getegid  )

Definition at line 1447 of file timer.c.

SYSCALL_DEFINE0 ( gettid  )

Definition at line 1561 of file timer.c.

SYSCALL_DEFINE1 ( sysinfo  ,
struct sysinfo __user ,
info   
)

Definition at line 1633 of file timer.c.

int try_to_del_timer_sync ( struct timer_list timer)

try_to_del_timer_sync - Try to deactivate a timer : timer do del

This function tries to deactivate a timer. Upon successful (ret >= 0) exit the timer is not queued and the handler is not running on any CPU.

Definition at line 981 of file timer.c.

void update_process_times ( int  user_tick)

Definition at line 1345 of file timer.c.

void usleep_range ( unsigned long  min,
unsigned long  max 
)

usleep_range - Drop in replacement for udelay where wakeup is flexible : Minimum time in usecs to sleep : Maximum time in usecs to sleep

Definition at line 1840 of file timer.c.

Variable Documentation

u64 jiffies_64 __cacheline_aligned_in_smp = INITIAL_JIFFIES

Definition at line 53 of file timer.c.

struct tvec_base boot_tvec_bases

Definition at line 89 of file timer.c.