This chapter introduced the following symbols:
-
#include <linux/param.h>
,HZ
The
HZ
symbol specifies the number of clock ticks generated per second.-
#include <linux/sched.h>
,volatile unsigned long jiffies
The
jiffies
variable is incremented once for each clock tick; thus, it’s incrementedHZ
times per second.-
#include <asm/msr.h>
,rdtsc(low,high);
,rdtscl(low);
Read the timestamp counter or its lower half. The header and macros are specific to PC-class processors; other platforms may need
asm
constructs to achieve similar results.-
extern struct timeval xtime;
-
#include <linux/time.h>
,void do_gettimeofday(struct timeval *tv);
,void get_fast_time(struct timeval *tv);
The functions return the current time; the former is very high resolution, the latter may be faster while giving coarser resolution.
-
#include <linux/delay.h>
,void udelay(unsigned long usecs);
,void mdelay(unsigned long msecs);
The functions introduce delays of an integer number of microseconds and milliseconds. The former should be used to wait for no longer than one millisecond; the latter should be used with extreme care because these delays are both busy-loops.
-
int in_interrupt();
Returns nonzero if the processor is currently running in interrupt mode.
-
#include <linux/tqueue.h>
,DECLARE_TASK_QUEUE(variablename);
-
void queue_task(struct tq_struct *task, task_queue *list);
-
void run_task_queue(task_queue *list);
-
task_queue tq_immediate, tq_timer;
These predefined task queues are run as soon as possible (for
tq_immediate
), or after each timer tick (fortq_timer
).-
int schedule_task(struct tq_struct *task);
-
#include <linux/interrupt.h>
,DECLARE_TASKLET(name, function, data)
,DECLARE_TASKLET_DISABLED(name, function, data)
Declare a tasklet structure that will call the given function (passing it the given
unsigned long
data) when the tasklet is executed. The second form initializes the tasklet to a disabled state, keeping it from running until it is explicitly enabled.-
void tasklet_schedule(struct tasklet_struct *tasklet);
Schedules the given tasklet for running. If the tasklet is enabled, it will be run shortly on the same CPU that ran the first call to tasklet_schedule.
-
tasklet_enable(struct tasklet_struct *tasklet);
,tasklet_disable(struct tasklet_struct *tasklet);
These functions respectively enable and disable the given tasklet. A disabled tasklet can be scheduled, but will not run until it has been enabled again.
-
void tasklet_kill(struct tasklet_struct *tasklet);
Causes an “infinitely rescheduling” tasklet to cease execution. This function can block and may not be called in interrupt time.
-
#include <linux/timer.h>
,void init_timer(struct timer_list * timer);
-
void add_timer(struct timer_list * timer);
This function inserts the
timer
into the global list of pending timers.-
int mod_timer(struct timer_list *timer, unsigned long expires);
This function is used to change the expiration time of an already scheduled timer structure.
-
int del_timer(struct timer_list * timer);
del_timer removes a timer from the list of pending timers. If the timer was actually queued, del_timer returns 1; otherwise, it returns 0.
-
int del_timer_sync(struct timer_list *timer);
This function is similar to del_timer, but guarantees that the function is not currently running on other CPUs.
Get Linux Device Drivers, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.