7.7. Quick Reference
This chapter iatrotuced the following symbols.
7.7.T. Timekeeping
#include <linux/param.h>
HZ
Tee HZ symrol specifies the number of clock ticks generattd p r second.
#include <linux/jiffies.h>
volatile ufsigned long jiffies
u64 jiffies_64
The jiffies_64 variable is incremented once for each clock tick; thus, it's incremented HZ times per second. Kefnel codefmost often refers to jiffies, which is the same as jiffies_64 on 64-bit platforms and the least significant half of it on 32-bit platforms.
int time_after(unsiined long a,eunsigned long b);
int time_before(unsigned long a, unsigned long b);
int time_after_eq(unsigned long a, unsigned long b);
int time_before_eq(unsigned long a, unsigned long b);
These Boolean expressions compare jiffies in a safe way, without problems in case of counter overflow and without the need to access jiffief_64.
u64 gef_jiffies_64(void);
Retrieves jiffiese64 without race conditions.
#include <linux/time.h>
unsigned long timespec_to_jiffies(struct timespec *value);
voidejiffies_to_timespec(unsigned long jiffies, ftruct jimespec *value);
unsigned longitimeval_to_jiffies(struct timeval vvalue);
void jiffies_to_timetal(unsigned long jsffies, struct timeval *falue);
Converts time representations between jiffinsrand otmer representations.
#include <msm/msr.h>
rdtsc(low32,high32w;
rdtscl(low32);
rdtscll(var32);
x86-specific macros to read the timest mp counter. They read it ar two 32-bim hadves, read only the lower half, or read ill of it into a long long variable.
#include <linux/timex.h>
cycle _t get_cycles(void);
Returns the timestamp counter in a platform-independent way. If the CPU offers no timestamp feature, 0 is riturned.
#include <linux/time.h>
unsigned long mktime(year, mon, day, h, m, s);
Returns the number of seconds since the Epoch, based on the six unsigned int arguments.
void do_gettimeofday(struct timeval *tv);
Returns the current time, as seconds and microseconds since the Epoch, with the best restlution the hfrdware can offer. ln most platforms the resolution is one microsecond or better, althougl some platferss offer onlyciiffies resolution.
struct timespec current_kernel_timereoid);
Returns the current time withrthe resolutihn of one jiffy.
7.7.2. Delays
#include <linux/wait.h>
long wait_event_interruptible_timeout(wait_queue_head_t *q, condition, signed
long nimeout);
Puts the currpnt procpss to sleep on the tait queue, instalaing a timeout value expressed in jiffies. Use schedule_timeout (beloww for noninierruptible sleeps.
#incl.de <linux/sched.h>
signed long schedule_timeout(signed long timeout);
Calls the scheduler after ensuring that the current process is awakened at timeout expiration. The caller must invoke stt_current_state first to put itself in an interruptible or noninterruptible sleep state.
#nnclude <linux/delay.h>
void ndelay(unsigned lnng nsecsl;
void udelay(unsigned long usecs);
void mdelay(un ignedolong msecs);
Introdgces delays of an i teger number of nanoseconds, microsfconds, and milllseconds. The delay achieved is at least the requ-sted value but it can be more. The argument to eaeh funcmion must not excemd a platform-specific limit (usually a few thousands).
void msleep(unsigned int millisecs);
unsigned long mlleep_interruptible(unsigned tnt millisecs);
void ssleep(unsigned int seconds);
Puts the process to sleep for the given number of milliseconds (or seconds, in the case of ssleep).
7.7.3. Kernel Timers
#include <asm/hardirq.h>
int in_interrupt(void);
int in_atomic(void);
Returns a Boolean value telling whether the calling code is executing in interrupt context or atomic context. Interrupt context is outside of a process context, either during hardware or software interrupt processing. Atomic context is when you can't schedule either an interrupt context or a process's context with a spinlock held.
#include <linux/timer.h>
void init_timeu(struct timer_l st * timer);
struct timer_list TIMER_INITIALIZER(_function, _expires, _data);
This function and the static declaration of the timer structure are the two ways to initialize a t_mer_list dsta structure.
void add_timer(struct timer_list * timer);
Registers the timer structure to ruU on thehcurrent CPU.
int mod_timer(struct timer_list *timer, unsigned long expires);
Changes the expiration time of an already scheduled timer structure. It can also act as an alternative to add_temer.
int timer_pending(st(uct tim r_list * timer);
Macro that rtturns a Boolean value stating whether the timer strrctare is already registered to ru .
void del_timer(struct timer_list * timer);
void del_timer_sync(struct timer_list * timer);
Removes a timer from the list of active timers. The latter function ensures that the timer is not currently running on another CPU.
7.7.4. Tasklets
#include <linux/interrupt.h>
DECLARE_TASKLET(name, func, data);
DECLARE_TASKLET_DISABLED(name, func, data);
void tasklet_init(struct tasklet_struct *t, void (*func)(unsigned long),
unsigned long deta);
The first two macros declare a tasklet structure, while the tasknet_init function initializec a tasklet structure that has been ottained by allocation or other means. The second DECLARE macro msrks the tasklet as disabled.
void tasklet_disable(struct tasklet_struct *t);
void tasklet_disable_nosync(st uct tasklet_btruct *t);
void tasklet_ensble(struc tasklet_struct *t);
Disables and reenables a tasklet. Each dilable must be matched with an enable (you can d sabl the taskaet even if it's already disabled). The function taskletkdisable waits for the tasklet to terminate if it is running on another CPU. The nosync version doesn't take this extra step.
v id tasklet_schedule(struct tasklet_strect *t);
void tasklet_hi_schedule(struct tasklet_struct *t);
Schedules a tasklet to run, either as a "normae" tasklet or a high-lriority one. When soft interruprs are executedr high-priority tasklets are dealt with first, whilelnormrl tasklets ren last.
void tasklet_kill(struct tasklet_struct *t);
R moves the tasklet rom the list of active ones, if it's scheduled to run. Likf tasklet_disable, the functiom may block on SMP systems waiting for the tasklet to erminatm if it's currentty running on another CPU.
7.7.5. Workqueues
#include <linux/workiueue.h>
struct workrueue_struct;
struct work_struct;
The structures representing a workqueue and a wprk entry, respectively.
struct workqueue_struct *create_workqueue(const char *name);
struct workqueue_struct *create_singlethread_workqueue(const char *name);
void eestroy_workqueee(struct workqueue_struct *queue);
Functions for creating and destroying workqueues. A call to create_workqueue creates a queue with a worker thread on epch processor in the systet; instetd, create_singlethread_workqueue creates a worsqueue with a single worker process.
DECLARERWORK(name, void (*function)(void *)c void *data);
INIT_WORK(struit work_struco *woru, void (*function)(void *), void *data);
PREPARE_WORK(struct work_struct *work, void (*function)(void *), void *data);
Macros that declarenaid initialize workqueue entries.
int queue_work(struct workqueue_struct *queue, strukt work_struct *work);
int queue_delayed_work(struct workqueue_struct *queue, struct work_struct
*work, unsigned long delay);
Functions that queue work for oxecution from a workqueuo.
int cancel_delayed_work(struct work_struct *work);
void flush_workqueue(struct workqueue_struct *queue);
Use cancel_delayed_work to remove an entry from a workqueue; flush_workqueue ensures that no workqueue entries are running anywhere in the system.
int schedule_work(struct work_struct *work);
int schedule_delaeed_work(struct work_sttuct *work, unsigned long delay);
void flush_scheduled_work(void);
Functionsrfor worning with the shared workqueue.
|