Linux Kernel Programming - Time,Delays,and Deferred Work
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 - Allocating Memory
kmalloc #include <linux/slab.h> void *kmalloc(size_t size,int flags); void kfree(void *addr); ...
- Linux kernel Programming - Advanced Char Driver Operations
ioctl //user space int ioctl(int fd,unsigned long cmd,...); //kernel space int (*ioctl)(struct inode ...
- Linux kernel Programming - Concurrency and Race Conditions
Concurrency and Its Management Race condition can often lead to system crashes, memory leak,corrupte ...
- linux kernel RCU 以及读写锁
信号量有一个很明显的缺点,没有区分临界区的读写属性,读写锁允许多个线程进程并发的访问临界区,但是写访问只限于一个线程,在多处理器系统中允许多个读者访问共享资源,但是写者有排他性,读写锁的特性如下:允许 ...
- Linux Kernel中断子系统来龙去脉浅析【转】
转自:http://blog.csdn.net/u011461299/article/details/9772215 版权声明:本文为博主原创文章,未经博主允许不得转载. 一般来说,在一个device ...
- Linux Kernel C语言编程范式
介绍 不同的编程语言具有不同的抽象原语(如下),有的原语抽象层次低,有的原语抽象层次高.其中函数式.DSL是这几年十分热门的编程语言概念. 过程式抽象原语:变量 对象式抽象原语:对象 函数式抽象原语: ...
- [中英对照]Linux kernel coding style | Linux内核编码风格
Linux kernel coding style | Linux内核编码风格 This is a short document describing the preferred coding sty ...
- 如何进行Linux Kernel 开发
转自:http://www.cppblog.com/flyonok/archive/2011/04/15/144316.html 如何进行Linux Kernel 开发? (Take 3) 译者序:这 ...
- Linux Kernel Maintainers
http://en.wikipedia.org/wiki/Ingo_Molnár http://zh.wikipedia.org/wiki/英格·蒙內 Ingo Molnár Ingo Molnár, ...
随机推荐
- 140 - The 12th Zhejiang Provincial Collegiate Programming Contest(第二部分)
Floor Function Time Limit: 10 Seconds Memory Limit: 65536 KB a, b, c and d are all positive int ...
- JS的分号可以省掉吗?
摘要: JavaScript语言从设计之初就是考虑带分号的,使用不带分号的编码规则就要小心点啦. 背景 最近在项目中开始使用新的编码规范,一开始ESLint报一大堆错误,改得我想砸键盘,花了好些时间才 ...
- Python全栈学习_day009知识点
今日大纲: . 函数的初识 . 函数的返回值 . 函数的参数 1. 函数的初识 统计字符串s的总个数(不能用len) s='fkahfkahofijalkfkadhfkjadhf' count = f ...
- array.js
// “最后加” concat 连接两个或更多的数组,并返回结果. var a = ['a','b','c']; var b = ['x','y','z']; var c = a.concat(b,t ...
- 【代码笔记】Web-ionic-头部与底部
index代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> < ...
- JS--我发现,原来你是这样的JS:面向对象编程OOP[1]--(理解对象和对象属性类型)
一.介绍 老铁们,这次是JS的面向对象的编程OOP(虽然我没有对象,心累啊,但是可以自己创建啊,哈哈). JS高程里第六章的内容,这章内容在我看来是JS中很难理解的一部分.所以分成三篇博客来逐个理清. ...
- DNS协议总结
1.DNS用于根据域名返回ip地址. 2.一般情况下,DNS-server是通过在UDP协议与客户端之间交互的,UDP端口号是53. 特别注意.DNS有时会使用TCP 53端口与客户端进行交互,所以, ...
- Java String和Date的转换
String—>Date方法一: String dateString = "2016-01-08"; try { SimpleDateFormat sdf = new Sim ...
- 【Java入门提高篇】Day34 Java容器类详解(十五)WeakHashMap详解
源码详解系列均基于JDK8进行解析 说明 在Java容器详解系列文章的最后,介绍一个相对特殊的成员:WeakHashMap,从名字可以看出它是一个 Map.它的使用上跟HashMap并没有什么区别,所 ...
- ER模型试题
M公司为了便于开展和管理各项业务活动,提高公司的知名度和影响力,拟构建一个基于网络的会议策划系统. [需求分析结果] 该系统的部分功能及初步需求分析的结果如下 : (1)M公司旗下有业务部.策划部和其 ...