tasklet是通过软中断实现的,tasklet本身也是软中断。
关于tasklet更详细的知识,还是建议看一下《Linux内核设计与实现》
本贴子只介绍一下具体的流程。
驱动程序源码:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/kdev_t.h>
#include <linux/cdev.h>
#include <linux/kernel.h>
#include <linux/interrupt.h>
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("Adams");
static struct tasklet_struct my_tasklet;
static void tasklet_handler (unsigned long data)
{
printk(KERN_ALERT "tasklet_handler is running.\n");
}
static int hello_init(void)
{
printk(KERN_EMERG "HELLO WORLD enter!\n");
tasklet_init(&my_tasklet, tasklet_handler, 0);
tasklet_schedule(&my_tasklet);
return 0;
}
static void hello_exit(void)
{
printk(KERN_EMERG "HELLO WORLD exit!\n");
tasklet_kill(&my_tasklet);
}
module_init(hello_init);
module_exit(hello_exit);
运行结果:
~ # insmod tasklet_test.ko
[ 763.212947] HELLO WORLD enter!
[ 763.214601] tasklet_handler is running.
~ # rmmod tasklet_test
[ 768.270681] HELLO WORLD exit!
~ #
程序很简单。