microsoft / microsoft/perfview

LBR state is incorrect during nt!SwapContext

Open
#2,288 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
4.7k
Forks
775
Avg merge
5d 11h
Merged PRs (30d)
9

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by investigating the ordering of context switching, context-switch tracing, and LBR clearing in nt!SwapContext, using the PmcInterrupt and ContextSwitch observations in the issue. Done means LBR records and emitted ContextSwitch stacks are attributed to the correct process and thread, including events occurring during the swap sequence.

Written by the indexing model from the issue text.

Assessment

Domain
operating-systems, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.