1

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 を使用する必要があり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

何か間違っていますか?同じことを行うための他の簡単な方法はありますか。

ありがとう、シャラン

4

2 に答える 2

1

他のユーザーが述べたように、そのlockdepようなプロファイリングを行うことができます。LockdepLinux カーネルにすでに存在する (パッチは不要) 機能でdeadlocks、カーネル コード内を検出します。また、システム パフォーマンスの向上に役立つ可能性がある、ロック、待機時間、ホールド時間、ロック チェーンなどに関連するその他の重要な統計情報も提供します。

ドキュメントから:

「ロックバリデーターは何をしますか? 動的に発生するすべてのロック規則を「監視」してマップします (カーネルのスピンロック、rwlock、mutex、および rwsem の自然な使用によってトリガーされる)。ロック バリデータ サブシステムは、新しいロック シナリオを検出するたびに、既存のルール セットに対してこの新しいルールを検証します。この新しいルールが既存のルール セットと一致する場合、新しいルールは透過的に追加され、カーネルは通常どおり続行されます。新しいルールがデッドロック シナリオを作成する可能性がある場合、この条件が出力されます。」</p>

また、この投稿はその使用方法を示しています:デッドロック検出のために Linux カーネルで lockdep 機能を使用する方法

于 2014-03-14T05:51:35.860 に答える
0

ロックのプロファイリングも行っている lockdep の実装を見てください。

于 2013-01-14T12:37:00.700 に答える