커 널 타이머 timerlist 사용
3098 단어 Linux리 눅 스 커 널 학습
1.포 함 된 헤더 파일:linux/timer.h
2.데이터 형식:struct timerlist;
:
a. data: , , timer 。
b. expires: , linux jiffies 。
c. void (*function)(unsigned long): 。
3.주요 관련 API 함수:
a. init_timer(struct timer_list*): ;
b. add_timer(struct timer_list*): ;
c. mod_timer(struct timer_list *, unsigned long jiffier_timerout): jiffies_timerout;
d. timer_pending(struct timer_list *): , 1, 0;
e. del_timer(struct timer_list*): 。
4.시간 과 jiffies 의 변환 함수:
Linux jiffies Windows TickCount, , 。 250 jiffies , :HZ。 jiffies :
unsigned int jiffies_to_msecs(unsigned long);
unsigned int jiffies_to_usecs(unsigned long);
unsigned long msecs_to_jiffies(unsigned int);
unsigned long usecs_to_jiffies(unsigned int);
5.간단 한 예 사용:
:init_timer->[timer.expires=? & timer.function=?]->add_timer->[mod_timer]->del_timer.
#include
#include
#include
struct timer_list timer;
void timer_handler(unsigned long data) {
printk(KERN_INFO"timer pending:%d
", timer_pending(&timer));
mod_timer(&timer, jiffies+msecs_to_jiffies(1000));
printk(KERN_INFO"jiffies:%ld, data:%ld
", jiffies, data);
}
int timer_init(void) {
printk(KERN_INFO"%s jiffies:%ld
", __func__, jiffies);
printk(KERN_INFO"ji:%d,HZ:%d
", jiffies_to_msecs(250), HZ);
init_timer(&timer);
timer.data = 45;
timer.function = timer_handler;
timer.expires = jiffies + HZ;
add_timer(&timer);
printk(KERN_INFO"timer pending:%d
", timer_pending(&timer));
return 0;
}
void timer_exit(void) {
printk(KERN_INFO"%s jiffies:%ld
", __func__, jiffies);
del_timer(&timer);
}
module_init(timer_init);
module_exit(timer_exit);
MODULE_LICENSE("GPL");
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
바이너리 파일cat 또는tail, 터미널 디코딩 시 처리 방법cat으로 바이너리 파일을 보려고 할 때 코드가 엉망이 되어 식은땀이 났다. 웹에서 스크롤된 정보의 처리 방법과alias의 설정을 요약합니다. reset 명령을 사용하여 터미널을 재설정합니다.이렇게 하면 고치지 못하...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.