中斷中的限制:
copy_from_usr(),
copy_to_usr(),
get_usr(),
put_usr()
Cannot sleep in an interrupt
handlr:
wait_event()
kmalloc(SIZE,GFP_KERNEL)->kmalloc(SIZE,GFP_ATOMIC),
down()->down_trylock()
Jiffies 一瞬間的意思(最小的時間單位)
The number of clock ricks since booy-up.
從開機之後開始跳,linux的最小單位
Each timer interrupt increased by 1.
unsigned long volatile.
無號長整數
HZ(1s鐘多少個jiffies 250 or 1000)
Tick rate,the frequency of system timer
HZ is the number of jiffies in a second.
Compare with jiffies
1. Wrap safe jiffies < x
time_before(jiffies,x)
2 Wrap safe jiffies > x
time_before(jiffies,x)
3 Wrap safe jiffies <<=x
time_before(jiffies,x)
4 Wrap safe jiffies >= x
time_before(jiffies,x)
practice
Time Unit
#include <linux/kernel.h> // for kernel alert
#include <linux/module.h>
#include <linux/init.h> // for __init and __exit
#include <linux/delay.h> // for mdelay, udelay
#include <linux/sched.h> // for jiffies
static int __init time_unit_init(void)
{
unsigned long jiffies_a, jiffies_b;
jiffies_a= jiffies; //目前系統時間
jiffies_b= jiffies + HZ/10 ; // HZ/10 等於 1/10 秒
printk("<1> jiffies: %lu\n", jiffies_a);
printk("<1> HZ:%d, jiffies_b:jiffies+HZ/10:%lu\n", HZ, jiffies_b );
mdelay(100); //DELAY 0.1 S
if( time_before(jiffies, jiffies_b) )
printk(" jiffies:%lu < jiffies_b :%lu\n", jiffies, jiffies_b);
else
printk(" jiffies:%lu >= jiffies_b:%lu\n", jiffies, jiffies_b);
return 0;
}
static void __exit time_unit_exit(void)
{
printk("<1>Bye Bye, jiffies:%lu\n", jiffies);
}
module_init(time_unit_init);
module_exit(time_unit_exit);
![](https://imageproxy.pixnet.cc/imgproxy?url=https://pic.pimg.tw/sheratea/1453600975-3879413120_n.png)