我想修改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
這inturn #includes spinlock.h
所以我做了一個變通通過創建一個數組,並寫入相應的指標,而要做到這一點,我使用cpu_id()
需要執行的線程的CPU,我再次得到了相同的依賴問題。
繼承人什麼我在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
我得到什麼錯?有沒有其他更簡單的方法來做同樣的事情?
感謝, 夏朗