LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Facing dependencies issues when modifying spinlock (http://www.linuxquestions.org/questions/programming-9/facing-dependencies-issues-when-modifying-spinlock-4175445427/)

sharan013 01-13-2013 01:54 PM

Facing dependencies issues when modifying spinlock
 
Hi,

I want to modify spin_lock & spin_unlock API in spinlock.h of 2.6.36.4. I want to add a counter for each core so that every time a lock is taken on a core, its counter in incremented and decremented when spin_lock is called. At any point of time I can get lock_depth of each core.

I tried doing this by adding a per CPU variable. using
Code:

DECLARE_PER_CPU(int, crnt_lck_depth)
but to do this I had to
Code:

#include percpu.h
which inturn
Code:

#includes spinlock.h
.

So I did a work around by creating an array and writing into respective index, but to do this I needed the executing thread's cpu using
Code:

cpu_id
, again I got the same issues of dependencies.

Heres what I have done so far in spinlock.h
Code:

static int ctr_lock_depth[24];                                                     
EXPORT_SYMBOL(ctr_lock_depth);//ctr_depth is used by other 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]--;                                                     
}

And these are the warning/error I get

Code:

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

Am getting anything wrong? Is there any other simpler way to do the same .

Thanks,
Sharan


All times are GMT -5. The time now is 11:07 AM.