我想在 2.6.36.4 的 spinlock.h 中修改 spin_lock & spin_unlock API。我想为每个核心添加一个计数器,以便每次在核心上获取锁时,它的计数器在调用 spin_lock 时递增和递减。在任何时候,我都可以获得每个核心的 lock_depth。
我尝试通过添加每个 CPU 变量来做到这一点。使用DECLARE_PER_CPU(int, crnt_lck_depth)
但要做到这一点,我不得不#include percpu.h
反过来#includes spinlock.h
所以我通过创建一个数组并写入相应的索引来解决这个问题,但要做到这一点,我需要执行线程的 cpu using cpu_id()
,我再次遇到了相同的依赖问题。
这是我到目前为止在 spinlock.h 中所做的
static int ctr_lock_depth[24];
EXPORT_SYMBOL(ctr_lock_depth);//ctr_depth is used by my module
/* from smp.h */
extern int raw_smp_processor_id(void);
static inline void spin_lock(spinlock_t *lock)
{
int cpu;
raw_spin_lock(&lock->rlock);
cpu = raw_smp_processor_id();
ctr_lock_depth[cpu]++;
}
static inline void spin_unlock(spinlock_t *lock)
{
int cpu ;
raw_spin_unlock(&lock->rlock);
cpu = raw_smp_processor_id();
ctr_lock_depth[cpu]--;
}
这些是我得到的警告/错误
include/linux/spinlock.h:292:1: warning: data definition has no type or storage class
include/linux/spinlock.h:292:1: warning: type defaults to ‘int’ in declaration of ‘EXPORT_SYMBOL’
include/linux/spinlock.h:292:1: warning: parameter names (without types) in function declaration
include/linux/timex.h:76:17: error: field ‘time’ has incomplete type
In file included from include/linux/ktime.h:25:0,
from include/linux/timer.h:5,
from include/linux/workqueue.h:8,
from include/linux/pm.h:25,
from /usr/src/linux-2.6.36.4.kvm-rr/arch/x86/include/asm/apic.h:6,
from /usr/src/linux-2.6.36.4.kvm-rr/arch/x86/include/asm/smp.h:13,
from include/linux/spinlock.h:62,
from include/linux/seqlock.h:29,
from include/linux/time.h:8,
from include/linux/stat.h:60,
from include/linux/module.h:10,
from include/linux/crypto.h:21,
from arch/x86/kernel/asm-offsets_64.c:8,
from arch/x86/kernel/asm-offsets.c:4:
include/linux/jiffies.h:257:10: warning: "NSEC_PER_SEC" is not defined
include/linux/ktime.h:84:6: error: ‘NSEC_PER_SEC’ undeclared (first use in this function)
include/linux/time.h:240:23: error: conflicting types for ‘ns_to_timeval’
include/linux/ktime.h:294:22: note: previous implicit declaration of ‘ns_to_timeval’ was here
有什么不对吗?有没有其他更简单的方法来做同样的事情。
谢谢, 莎朗