Querying for Processor performance counter data on XP binds the calling thread to the current CPU

Support for Windows XP has ended

Microsoft ended support for Windows XP on April 8, 2014. This change has affected your software updates and security options. Learn what this means for you and how to stay protected.

This article has been archived. It is offered "as is" and will no longer be updated.
Source: Microsoft Support
RAPID PUBLISHING
RAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.
Action
An application performs either a Global query or a specific query for Processor performance counter data.
Result
After the query, the calling thread will only run on a single processor, even if there are multiple processors available for the thread to be scheduled on.
Cause


This is a known issue in the products listed below.

When an application queries for processor information from the system, many metrics are collected and aggregated in the returned data.  One of the metrics is CPU idle time.  When collecting this, the system sets the affinity of the requesting thread.  It does not, however, reset the affinity of the thread after finishing collecting the idle time data, causing the thread to be affinitized to the processor.
Resolution
To workaround this issue, the application can reset the affinity of the thread after querying for processor performance counter data.  If the application is using native Win32 APIs, it can use the SetThreadAffinityMask API.  If the application is using the .NET Framework, it can use the System.Diagnostics.ProcessThread.ProcessorAffinity property to do this.  See the More Information section of this article for references on these APIs.
More Information
SetThreadAffinityMask Function
     http://msdn.microsoft.com/en-us/library/ms686247(VS.85).aspx

System.Diagnostics.ProcessThread.ProcessorAffinity property  
     http://msdn.microsoft.com/en-us/library/system.diagnostics.processthread.processoraffinity.aspx 
DISCLAIMER
MICROSOFT AND/OR ITS SUPPLIERS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY, RELIABILITY OR ACCURACY OF THE INFORMATION CONTAINED IN THE DOCUMENTS AND RELATED GRAPHICS PUBLISHED ON THIS WEBSITE (THE “MATERIALS”) FOR ANY PURPOSE. THE MATERIALS MAY INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS AND MAY BE REVISED AT ANY TIME WITHOUT NOTICE.

TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.
Properties

Article ID: 971565 - Last Review: 01/14/2015 10:48:06 - Revision: 1.0

  • Microsoft Windows XP Professional
  • Microsoft Windows XP Home Edition
  • kbnosurvey kbarchive kbrapidpub kbnomt KB971565
Feedback