B.10.4  Spin Lock Usage

Spin lock usage can be traced using a method similar to the pool-allocation logging. This facility is useful for finding code that returns without releasing a lock. A log of recent p_lock and v_lock activity is kept in the kernel data location StrmLockLogList, a circular buffer. The log can be dumped using the Windows NT kernel debugger commands:

    da streams!StrmLockLogList

    da

    da

    ...

 

Spin-lock tracing is not actually part of the strmdbg services. The “-l” switch displayed by the command line help of strmdbg turns on lock tracing only for streams.sys and has no effect on transport drivers. To make use of the spin lock tracing facility, you must include macros similar to the following in your code:

#if DBG

 

#define KeAcquireSpinLock(PSpinLock, POldIrql)                 \

    ( (TcpDebugBits & DBG_TCP_LOCKTRACE) ?                     \

           StrmAcquireSpinLock(PSpinLock, POldIrql, __LINE__, __FILE__) \

                                                               \

           StrmAcquireSpinLock(PSpinLock, POldIrql, 0, NULL)   \

    )

 

#define KeReleaseSpinLock(PSpinLock, OldIrql)                  \

    ( (TcpDebugBits & DBG_TCP_LOCKTRACE) ?                     \

           StrmReleaseSpinLock(PSpinLock, OldIrql, __LINE__, __FILE__)  \

                                                               \

           StrmReleaseSpinLock(PSpinLock, OldIrql, 0, NULL)    \

    )

 

#endif

 

The Strm..SpinLock functions export by STREAMS.SYS will log an operation if their fourth argument is nonNULL.