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, ...
随机推荐
- 在使用vue-cli中遇到的几个问题
前言:框架没有好坏之分,能解决需求就可以.之前没事用vue模仿过BOSS直聘App(纯属娱乐),实际工作中开发过一个后台管理系统,遇到过不少坑,终于闲下来稍微总结几个问题分享一下! 一.所遇到的问题( ...
- 分布式日志框架之ExceptionLess【二】:自行搭建帮助文档【译文】
原文地址:https://github.com/exceptionless/Exceptionless/wiki/Self-Hosting ExceptionLess自行托管环境搭建 一.测试环境 如 ...
- HTML命名规范
一.关于选择器的命名 W3C CSS2.1的 4.1.3 节中提到:标识符(包括选择器中的元素名,类和ID)只能包含字符[a- zA-Z0-9]和ISO 10646字符编码U+00A1及以上,再加 ...
- python基础之数据的三大结构
python的三大数据结构 1.顺序 2.分支 3.循环 # if语句联系# 如果age小于18岁,则打印信息“未成年”age = 17if age <= 18: print("未成年 ...
- switch和if语句
if :基本语法: 1.单分支语句 : if(条件){代码块}else{代码块} 2.多分支语句 :if(条件){代码块} else if(条件){代码块}else{代码块} * 不要忘记添加else ...
- 【代码笔记】Web-ionic-安装及第一个app
一,下载ionic v1.0.1版本,下载地址为:ionic-v1.0.1.zip. ionic 最新版本下载地址:http://ionicframework.com/docs/overview/#d ...
- [201804012]关于hugepages 3.txt
[201804012]关于hugepages 3.txt --//有一段时间我一直强调安装oracle一定要配置hugepage,因为现在的服务器内存越来越大,如果还使用4K的页面表,如果内存表占用内 ...
- Asp.net 中ViewState,cookie,session,application,cache的比较
Asp.net 中的状态管理维护包含ViewState,cookie,session,application,cache五种方式,以下是它们的一些比较: 1.存在于客户端还是服务端 客户端: view ...
- drop all database objects
/*Use this sql to drop all objects in a database.*/ -- Drop all SPdeclare @dropSp varchar(max)=''sel ...
- EF扩展 更新指定字段
using System.Data.Entity.Infrastructure; using System.Threading.Tasks; /// <summary> /// EF扩展 ...