我已经替换系统调用表中的sys_open系统调用来实现统计系统。我必须使用什么锁? spin_lock_irqsave()函数冻结了系统。我在Linux 3.16.0-4-686-pae上使用Intel Core i3-4330。使用内核模块锁定系统调用
部分,但revelant代码:
static DEFINE_SPINLOCK(spin);
static int tally = 0;
static asmlinkage long my_sys_open(const char __user *filename, int flags, int mode)
{
unsigned long fl;
spin_lock_irqsave(&spin, fl); // system freeze
tally++;
spin_unlock_irqrestore(&spin, fl);
printk("sys_open used %i times\n", tally);
return old_sys_open(filename, flags, mode);
}
您没有使用'mutex_lock'的任何特定原因? http://www.hep.by/gnu/kernel/kernel-locking/API-mutex-lock.html – VAndrei
奇怪。你的代码看起来不错。你怎么知道冻结发生在'spin_lock_irqsave'?如果您注释掉锁定代码,它不会冻结?有没有其他的代码使用'spin'? –