-   Programming (
-   -   Facing dependencies issues when modifying spinlock (

sharan013 01-13-2013 01:54 PM

Facing dependencies issues when modifying spinlock

I want to modify spin_lock & spin_unlock API in spinlock.h of 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

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

#include percpu.h
which inturn

#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

, again I got the same issues of dependencies.

Heres what I have done so far in spinlock.h

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;                                                                   
        cpu = raw_smp_processor_id();                                               
static inline void spin_unlock(spinlock_t *lock)                                   
        int cpu ;                                                                   
        cpu = raw_smp_processor_id();                                               

And these are the warning/error I get


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-,
                from /usr/src/linux-,
                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 .


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