构建Linux内核时编译错误

时间:2018-03-27 06:03:19

标签: linux compilation linux-kernel

我正在研究4.9.89版本的linux内核源码中的自旋锁代码。 在对“include / linux / spinlock.h”和“include / linux / spinlock_types.h”进行了一些修改之后,我构建了内核。 但是有些错误发生如下:

./include/linux/seqlock.h:406:2: error: unknown type name ‘spinlock_t’
  spinlock_t lock;
  ^
./include/linux/seqlock.h: In function ‘write_seqlock’:
./include/linux/seqlock.h:448:2: error: implicit declaration of function ‘spin_lock’ [-Werror=implicit-function-declaration]
  spin_lock(&sl->lock);
  ^
./include/linux/seqlock.h: In function ‘write_sequnlock’:
./include/linux/seqlock.h:455:2: error: implicit declaration of function ‘spin_unlock’ [-Werror=implicit-function-declaration]
  spin_unlock(&sl->lock);
  ^
./include/linux/seqlock.h: In function ‘write_seqlock_bh’:
./include/linux/seqlock.h:460:2: error: implicit declaration of function ‘spin_lock_bh’ [-Werror=implicit-function-declaration]
  spin_lock_bh(&sl->lock);
  ^
./include/linux/seqlock.h: In function ‘write_sequnlock_bh’:
./include/linux/seqlock.h:467:2: error: implicit declaration of function ‘spin_unlock_bh’ [-Werror=implicit-function-declaration]
  spin_unlock_bh(&sl->lock);
  ^
./include/linux/seqlock.h: In function ‘write_seqlock_irq’:
./include/linux/seqlock.h:472:2: error: implicit declaration of function ‘spin_lock_irq’ [-Werror=implicit-function-declaration]
  spin_lock_irq(&sl->lock);
  ^
./include/linux/seqlock.h: In function ‘write_sequnlock_irq’:
./include/linux/seqlock.h:479:2: error: implicit declaration of function ‘spin_unlock_irq’ [-Werror=implicit-function-declaration]
  spin_unlock_irq(&sl->lock);
  ^
./include/linux/seqlock.h: In function ‘__write_seqlock_irqsave’:
./include/linux/seqlock.h:486:2: error: implicit declaration of function ‘spin_lock_irqsave’ [-Werror=implicit-function-declaration]
  spin_lock_irqsave(&sl->lock, flags);
  ^
./include/linux/seqlock.h: In function ‘write_sequnlock_irqrestore’:
./include/linux/seqlock.h:498:2: error: implicit declaration of function ‘spin_unlock_irqrestore’ [-Werror=implicit-function-declaration]
  spin_unlock_irqrestore(&sl->lock, flags);

我的代码中没有发现任何奇怪的东西,我被困在这里。 我在内核源代码中所做的是我尝试仅估计锁定保持时间和锁定等待时间:

// function modifications
static __always_inline void spin_lock(spinlock_t *lock)
{
    struct timeval start, end;
    do_gettimeofday(&start);

    raw_spin_lock(&lock->rlock);

    do_gettimeofday(&end);
    atomic_add(&waiting_time, (end.tv_usec - start.tv_usec));
    lock->holding_time = end.tv_usec;
}
static __always_inline void spin_unlock(spinlock_t *lock)
{
    struct timeval end;

    raw_spin_unlock(&lock->rlock);

    do_gettimeofday(&end);
    atomic_add(&holding_time, (end.tv_usec - lock->holding_time));
}
// macro modification
#define spin_lock_nested(lock, subclass)            \
do {                                \
    struct timeval start, end;  \
    do_gettimeofday(&start);    \
    raw_spin_lock_nested(spinlock_check(lock), subclass);   \
    do_gettimeofday(&end);  \
    atomic_add(&waiting_time, (end.tv_usec - start.tv_usec));   \
    lock->holding_time = end.tv_usec;   \
} while (0)
// I added 2 atomic values to cumulate the lock time values in spinlock.h file
atomic_t waiting_time;
atomic_t holding_time;

// I added an unsigned int value (holding_time) to estimate lock holding time in spinlock struct
typedef struct spinlock {
    union {
        struct raw_spinlock rlock;

#ifdef CONFIG_DEBUG_LOCK_ALLOC
# define LOCK_PADSIZE (offsetof(struct raw_spinlock, dep_map))
        struct {
            u8 __padding[LOCK_PADSIZE];
            struct lockdep_map dep_map;
        };
#endif
    };
    unsigned int holding_time;
} spinlock_t;

为什么会出现错误? 我在等你帮忙。 谢谢!

0 个答案:

没有答案