【发布时间】:2015-06-27 17:14:26
【问题描述】:
我已经替换了系统调用表中的 sys_open 系统调用来实现一个计数系统。我必须使用什么锁? spin_lock_irqsave() 函数冻结系统。我在 Linux 3.16.0-4-686-pae 上使用 Intel Core i3-4330。
部分但相关的代码:
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”的任何特殊原因? hep.by/gnu/kernel/kernel-locking/API-mutex-lock.html
-
奇怪。你的代码看起来不错。你怎么知道
spin_lock_irqsave发生了冻结?如果您注释掉锁定代码,它不会冻结?有没有其他代码使用spin?
标签: c linux linux-kernel kernel kernel-module