"); //-->
打开该选项,内核将捕获对未初始化自旋锁的操作,也会捕获两次解开同一锁的操作等其他错误。
2.2 捕获未初始化自旋锁 2.2.1实验代码://spinlock.c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/spinlock.h>
unsigned char aa;
spinlock_t SpinLockTest ;
static int spinlock_init(void)
{
int i;
unsigned long flags;
// spin_lock_init(&SpinLockTest);//进行未初始化自旋锁检测
spin_lock_irqsave(&SpinLockTest, flags);
aa =1;
spin_unlock_irqrestore(&SpinLockTest, flags);
printk(KERN_EMERG "\nHello\n");
return 0;
}
=======================================================================================
By 下家山 QQ 1209050967 上海松江文汇路928号258室 松江大学城 7/31/2012
上海索漫科技 http://www.xiajiashan.com 专注嵌入式(ARM7,Cortex-M0,Cortex-M3,ARM9,linux)培训
static void spinlock_exit(void)
{
printk(KERN_EMERG"\nGoodbye\n");
}
module_init(spinlock_init);
module_exit(spinlock_exit);
2.2.2 运行结果2.3.1 代码
//spinlock.c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/spinlock.h>
unsigned char aa;
spinlock_t SpinLockTest ;
static int spinlock_init(void)
{
int i;
unsigned long flags;
spin_lock_init(&SpinLockTest);
spin_lock_irqsave(&SpinLockTest, flags);
aa =1;
spin_unlock_irqrestore(&SpinLockTest, flags);
printk(KERN_EMERG "\nHello\n");
return 0;
}
static void spinlock_exit(void)
{
printk(KERN_EMERG"\nGoodbye\n");
}
=======================================================================================
By 下家山 QQ 1209050967 上海松江文汇路928号258室 松江大学城 7/31/2012
上海索漫科技 http://www.xiajiashan.com 专注嵌入式(ARM7,Cortex-M0,Cortex-M3,ARM9,linux)培训
module_init(spinlock_init);
module_exit(spinlock_exit);
2.3.2 运行结果 2.4 如果不打开spin_lock调试功能如果不打开spin_lock调试功能,则检测不到自旋锁未初始化错误。
2.4.1实验代码测试代码与2.2.1实验代码同。
2.4.2实验结果测试结果与2.3.2 运行结果同。
2.5 检测两次解开同一锁 2.5.1 关闭此功能即在”kernel hacking”中不选择“spinlock debugging”,看能否检测两次解开同一锁的错误。
●测试代码//spinlock.c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/spinlock.h>
unsigned char aa;
spinlock_t SpinLockTest ;
static int spinlock_init(void)
{
int i;
unsigned long flags;
spin_lock_init(&SpinLockTest);
spin_lock_irqsave(&SpinLockTest, flags);
aa =1;
spin_unlock_irqrestore(&SpinLockTest, flags);
spin_unlock_irqrestore(&SpinLockTest, flags);
printk(KERN_EMERG "\nHello\n");
return 0;
}
static void spinlock_exit(void)
{
printk(KERN_EMERG"\nGoodbye\n");
}
module_init(spinlock_init);
module_exit(spinlock_exit);
=======================================================================================
By 下家山 QQ 1209050967 上海松江文汇路928号258室 松江大学城 7/31/2012
上海索漫科技 http://www.xiajiashan.com 专注嵌入式(ARM7,Cortex-M0,Cortex-M3,ARM9,linux)培训
检测不到此错误!
2.5.2 打开此功能即在”kernel hacking”中选择“spinlock debugging”,看能否检测两次解开同一锁的错误。
●测试代码//spinlock.c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/spinlock.h>
unsigned char aa;
spinlock_t SpinLockTest ;
static int spinlock_init(void)
{
int i;
unsigned long flags;
spin_lock_init(&SpinLockTest);
spin_lock_irqsave(&SpinLockTest, flags);
aa =1;
spin_unlock_irqrestore(&SpinLockTest, flags);
spin_unlock_irqrestore(&SpinLockTest, flags);
printk(KERN_EMERG "\nHello\n");
return 0;
}
static void spinlock_exit(void)
{
printk(KERN_EMERG"\nGoodbye\n");
}
module_init(spinlock_init);
module_exit(spinlock_exit);
●运行结果检测到了此错误!
作者:下家山(请尊重原创, 转载请注明) http://www.xiajiashan.com,有什么问题可与我联系:ximenpiaoxue4016@sina.com*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。
eleaction01 阅读:4511