个人在试验软中断的时候碰到一个编译问题,而明明知道这个问题是为什么,却不知道如何解决,所以请大家指点。
以下代码中是想通过软中断的使用步骤(分配索引、注册处理程序、触发软中断)触发并执行一个软中断。
(当然了,这只是一个试验,正常的软中断的使用场合多是在中断程序返回前)。
代码: 全选
1 #include <linux/module.h>
2 #include <linux/kernel.h>
3 #include <linux/interrupt.h>
4
5 void softirq_func(struct softirq_action *sa)
6 {
7 printk("%s, %d\n", __FUNCTION__, __LINE__);
8 }
9
10 static int mod_init(void)
11 {
12 unsigned long flags;
13
14 printk("%s ...\n", __FUNCTION__);
15 //MY_OWN_SOFTIRQ定义,我已在<linux/interrupt.h>的enum位置添加。 -----分配索引
16 //open_softirq(MY_OWN_SOFTIRQ, softirq_func, NULL); -----注册处理程序
17 //softirq_vec[MY_OWN_SOFTIRQ].action = softirq_func;//open_softirq没有导出,直接将open_softirq实现在这里。
18 //softirq_vec[MY_OWN_SOFTIRQ].data = NULL;
19
20 //raise_softirq(MY_OWN_SOFTIRQ); -----触发软中断
21 local_irq_save(flags);//raise_softirq函数没有导出,改用raise_softirq_irqoff的方式
22 printk("flags is %d\n", flags);
23 //raise_softirq_irqoff(MY_OWN_SOFTIRQ);
24 local_irq_restore(flags);
25
26 return 0;
27 }
28 static void mod_exit(void)
29 {
30 printk("%s ...\n", __FUNCTION__);
31 }
32 module_init(mod_init);
33 module_exit(mod_exit);
代码: 全选
make -C /lib/modules/2.6.23.1ubuntu810/build M=/root/Bottom_half modules
make[1]: 正在进入目录 `/usr/src/linux-2.6.23.1'
CC [M] /root/Bottom_half/mod.o
/root/Bottom_half/mod.c: 在函数‘mod_init’中:
/root/Bottom_half/mod.c:30: 错误: ‘softirq_vec’未声明(在此函数内第一次使用)
/root/Bottom_half/mod.c:30: 错误: (即使在一个函数内多次出现,每个未声明的标识符在其
/root/Bottom_half/mod.c:30: 错误: 所在的函数内也只报告一次。)
/root/Bottom_half/mod.c:35: 警告: 格式‘%d’需要类型‘int’,但实参 2 的类型为‘long unsigned int’
make[2]: *** [/root/Bottom_half/mod.o] 错误 1
make[1]: *** [_module_/root/Bottom_half] 错误 2
make[1]:正在离开目录 `/usr/src/linux-2.6.23.1'
make: *** [all] 错误 2
该如何是好?