perfview icon indicating copy to clipboard operation
perfview copied to clipboard

LBR state is incorrect during nt!SwapContext

Open jdu2600 opened this issue 3 months ago • 1 comments

I've been playing around with -LbrSources:PmcInterrupt -LbrFilters:StackMode data and about ~0.1% of the LBR records are attributed to the wrong process.

In my investigation of these misattributed LBR records, execution is always somewhere in nt!SwapContext Even worse, if I try to emit the LBR stacks for ContextSwitch events then these are 100% attributed to the wrong process.

The steps currently taken in SwapContext appear to be -

  1. Perform context swap - the LBR stack is now invalid for the current thread
  2. Trace context swap - the associated LBR event is always attributed to the wrong thread here
  3. Clear LBR stack - the (empty) LBR stack is now valid again

And any PmcInterrupt events occurring between 1 and 3 will be attributed to the wrong thread.

I would have thought that the tracing then clearing would need to occur immediately prior to the context swap -

  1. Trace context swap - the LBR stack is still valid here
  2. Clear LBR stack
  3. Perform context swap

jdu2600 avatar Aug 25 '25 04:08 jdu2600

@jakobbotsch, have you seen this before? I'll admit, I've really not used the LBR support.

brianrob avatar Aug 25 '25 22:08 brianrob