Thread Affinity Control for Accurate Call Stack Sampling

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing sampling technologies struggle to accurately capture the full execution context of interrupted threads due to thread migration issues in multiprocessor systems, leading to incomplete or inaccurate call stack reports.

Innovation Solution

The solution involves generating an interrupt, capturing information with an interrupt handler, setting the affinity of the interrupted thread to run only on a specific processor, and retrieving the call stack using a sampler thread that runs on the same processor, ensuring the thread does not migrate during sampling, and then restoring its original affinity after data collection.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Measurement precision

If a separate sampler thread is used to retrieve the interrupted thread's call stack, then the call stack can be obtained, but the interrupted thread may migrate to a different processor making the sampled data inaccurate

Engineering Contradiction:
Improvecall stack sampling accuracyVSAvoidthread execution context consistency
Core Design Contradiction:
Measurement precisionVSReliability

Solution Approach 1:

The patent introduces an interrupt handler as an intermediary between the interrupted thread and the sampler thread. The interrupt handler captures the thread's execution context (instruction pointer, stack pointer) at the moment of interruption and passes it to the sampler thread, ensuring accuracy without requiring the thread to remain on the same processor

Inventive Principle:
Principle #24Intermediary (Mediator)

Solution Approach 2:

The patent performs preliminary capture of the thread's execution context in the interrupt handler before the sampler thread retrieves the call stack. By recording the instruction pointer and stack pointer at interruption time, the system ensures the sampled data reflects the thread's state at that moment, even if the thread migrates afterward

Inventive Principle:
Principle #10Preliminary action

2Measurement precision

If thread migration is prevented by setting affinity during sampling, then accurate call stack data can be captured, but system performance may degrade due to restricted thread scheduling

Engineering Contradiction:
Improvecall stack sampling accuracyVSAvoidsystem throughput
Core Design Contradiction:
Measurement precisionVSProductivity

Solution Approach 1:

The patent applies thread affinity restriction only partially - only to the specific interrupted thread during the brief sampling window, not to all threads in the system. This localized application minimizes the impact on overall system throughput while ensuring accurate sampling for the target thread

Inventive Principle:
Principle #16Partial or excessive action

Solution Approach 2:

The patent implements sampling as a periodic interrupt-driven operation rather than a continuous process. The affinity restriction is applied only during these periodic sampling intervals, allowing the thread to migrate freely during normal execution, thus minimizing performance impact while maintaining sampling accuracy

Inventive Principle:
Principle #19Periodic action

3Loss of information

If the full execution context is recorded at interrupt time, then complete call stack information is available, but the data collection overhead increases

Engineering Contradiction:
Improveexecution context completenessVSAvoidsampling overhead
Core Design Contradiction:
Loss of informationVSLoss of time

Solution Approach 1:

The patent extracts only the essential execution context information (instruction pointer, stack pointer, register state) at interrupt time, rather than recording the entire execution context. This selective extraction provides sufficient information for accurate call stack reconstruction while minimizing the overhead of data collection

Inventive Principle:
Principle #2Taking out (Extraction)

Data Source

PatentUS8843684B2Performing call stack sampling by setting affinity of target thread to a current process to prevent target thread migration
Publication Date: 2014.09.23 INTERNATIONAL BUSINESS MACHINE CORPORATION
  • US8843684B2 patent drawing
  • US8843684B2 patent drawing
  • US8843684B2 patent drawing

AI summary

A sample is generated based on an event. Further, an interrupt handler captures information for an interrupted thread on a current processor. In addition, an affinity of the interrupted thread is set such that the interrupted thread runs only on the current processor without being able to migrate to a different processor. A sampler thread that runs on the current processor retrieves a call stack associated with the interrupted thread after the affinity of the interrupted thread has been set to the current processor. The affinity of the interrupted thread is restored after the call stack has been retrieved.