Skip to content

LBR state is incorrect during nt!SwapContext #2288

@jdu2600

Description

@jdu2600

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions