Linux Kernel Programming - Time,Delays,and Deferred Work
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Linux Kernel Programming - Time,Delays,and Deferred Work,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2462字,纯文字阅读大概需要4分钟。
内容图文
![Linux Kernel Programming - Time,Delays,and Deferred Work](/upload/InfoBanner/zyjiaocheng/980/b3f5009d1948412ca2218e88b60deccb.jpg)
Measuring Time Lapses
The counter and the utility functions to read it live in <linux/jiffies.h>.Needless to say both jiffies and jiffies_64 must be considered read-only.
Processor-Specific Registers
#include <asm/msr.h>
rdtsc(low32,high32);
rdtscl(low32);
rdtscll(var64);
As an example using only the low half of the register,the following lines measure the execution of the instruction itself:
unsigned long ini,end;
rdtscl(ini);rdtscl(end);
printk("time lapse:%li\n",end - ini);
architecture-independent function:
#nclude <linux/timex.h>
cycles_t get_cycles(void);
Delaying Execution
#include <linux/wait.h>
long wait_event_timeout(wait_queue_head_t q,condition,long timeout);
long wait_event_interruptible_timeout(wait_queue_head_t q,condition,long timeout);
wait_queue_head_t wait;
init_waitqueue_head(&wait);
wait_event_interruptible_timeout(wait,0,delay);
Timeout value(delay) represents the number of jiffies to wait
#include <linux/sched.h>
signed long schedule_timeout(signed long timeout);
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(delay);
Short Delays
#include <linux/delay.h>
void ndelay(unsigned long nsecs);
void udelay(unsigned long usecs);
void mdelay(unsgined long msecs);
Kernel Timer
A kernel timer is a data structure that instructs the kernel to execute a user-defined function with a user-defined argument at user-defined time.
Timer functions must be atomic
No access to user space is allowed
No sleeping or scheduling may be performed
It's also worth knowing that in an SMP system,the timer function is executed by the same CPU that registered it
The Timer API
#include <linux/time.h>
struct timer_list{
/*.................*/
unsigned long expires;
void (*function)(unsigned long );
unsigned long data;
};
void init_timer(struct timer_list* timer);
struct timer_list TIMER_INITIALIZER(_function,_expires,_data);
void add_timer(struct timer_list *timer);
int del_timer(struct timer_list *timer);
Tasklets
Unlike kernel timers,however,you can't ask to execute the function at a speciic time.
Actually,a tasklet ,just like a kernel timer,is executed in the context of a "soft interrupt",a kernel mechanism that executes asynchronous task with hardware interrupts enabled.
#include <linux/interrupt.h>
struct tasklet_struct{
/*...*/
void (*func)(unsigned long);
unsigned long data;
};
void tasklet_init(struct tasklet_struct *t,void (*func)(unsigned long),unsigned long data);
DECLARE_TASKLET(name,func,data);
DECLATE_TASKLET_DISABLE(name,func,data);
内容总结
以上是互联网集市为您收集整理的Linux Kernel Programming - Time,Delays,and Deferred Work全部内容,希望文章能够帮你解决Linux Kernel Programming - Time,Delays,and Deferred Work所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。