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, ...
随机推荐
- 【Tomcat】详解tomcat的连接数与线程池
前言 在使用tomcat时,经常会遇到连接数.线程数之类的配置问题,要真正理解这些概念,必须先了解Tomcat的连接器(Connector). Connector的主要功能,是接收连接请求,创建Req ...
- Mysql无法选取非聚合列
教程所示图片使用的是 github 仓库图片,网速过慢的朋友请移步>>> (原文)Mysql 无法选取非聚合列. 更多讨论或者错误提交,也请移步. 1. 前言 最近升级博客,给文章页 ...
- curl 发送 post 请求
curl -i -X POST -H 'Content-type':'application/json' -d '{"keyWord":"雅诗兰黛"," ...
- 关于python访问字典的方法
def stu( **kwargs): # 在函数体内对于kwargs的使用不用带星号 print("大家好,我为大家简单自我介绍以下:") print(type(kwargs)) ...
- 访问WEB-INF下的jsp页面
访问web-inf下的jsp文件, 1)使用springMVC,一般都会使用springMVC的视图解析器,大概会这样配置 <!--jsp视图解析器--> <bean class ...
- vue引入bootstrap——webpack
想要在vue中引入bootstrap,引入的时候需要按照如下的步骤进行. 1.引入jquery 2.引入bootstrap 阅读本文前,应该能够搭建环境,使用vue-cli进行项目的创建,可以参考 ...
- 测试思想-流程规范 SVN代码管理与版本控制
SVN代码管理与版本控制 by:授客 QQ:1033553122 欢迎加入软件性能测试交流群(QQ群):7156436 目录 一. 二. 三. 四. 五. 六. 七. 一. 创建根目录 创建一 ...
- 使用过AsyncTask、EventBus、Volley以及Retrofit,必须好好了解handler运行机制
我们都知道在UI线程中不能进行耗时操作,例如数据读写.网络请求.Android 4.0开始,在主线程中进行网络请求甚至会抛出Android.os.NetworkOnMainThreadExceptio ...
- Python中DataFrame关联
df = pd.merge( df, # 左 wzplbm, # 右 left_on = ['WZBM','ZBWZMC'], # 左DataFrame匹配列 right_on = ['WZPLBM' ...
- [20171220]toad plsql显示整形的bug.txt
[20171220]toad plsql显示整形的bug.txt --//下午有itpub网友反应,一个查询在sqlplus,pl/sql下不同.链接如下:--//http://www.itpub.n ...