LDD3 tasklet 使用

tasklet机制及API注解就不写了,测试代码如下:

#include <linux/init.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/fs.h>
#include <linux/kdev_t.h>
#include <linux/cdev.h>
#include <linux/kernel.h>
#include <linux/interrupt.h> 

#define switch 0//是否使用宏定义
void tasklets_function(unsigned long sign);

#if switch
 static DECLARE_TASKLET(my_tasklet,tasklets_function,3);
#else
 static struct tasklet_struct my_tasklet; 
#endif
 void tasklets_function(unsigned long sign)
{
 printk(KERN_EMERG"tasklet out %ld\n",sign);
}
 
static void tasklets_init(void)
{
#if !switch
  tasklet_init(&my_tasklet, tasklets_function, 0);
#endif
  tasklet_schedule(&my_tasklet);
}

static void tasklets_exit(void)
{
 tasklet_kill(&my_tasklet);
 printk(KERN_EMERG"GOOBYE,WORLD\t\n");

}

module_init(tasklets_init);
module_exit(tasklets_exit);
MODULE_LICENSE("Dual BSD/GPL");

 测试方法及结果如下:

[root@localhost tasklet]# insmod tasklet.ko
[root@localhost tasklet]#
Message from syslogd@ at Mon Aug 13 14:19:33 2012 ...
localhost kernel: tasklet out 3
[root@localhost tasklet]#

打开switch开关后:

[root@localhost tasklet]# insmod tasklet.ko
[root@localhost tasklet]#
Message from syslogd@ at Mon Aug 13 14:18:49 2012 ...
localhost kernel: tasklet out 0
[root@localhost tasklet]#

发布了29 篇原创文章 · 获赞 19 · 访问量 10万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章