Windows Server 2003 から CPU の情報を取得する関数として GetLogicalProcessorInformation function が導入されました。ちなみに Windows XP でも Service Pack 3 を適用すれば利用可能です。
名前に logical (論理) とついていますが、この function を利用して physical processor 数を取得することができます。
ただし、Windows Server 2003 環境では注意が必要です。
[KB932370] The number of physical hyperthreading-enabled processors or the number of physical multicore processors is incorrectly reported in Windows Server 2003
こちらで説明されているように Windows Server 2003 環境では physical processor 数を正確に取得できないことがあります。
試しに Windows Server 2003 Enterprise x64 Edition Service Pack 2 で MSDN の sample code を実行したところ、下記結果が返ってきました。
Core 2 Duo E6600 1 個搭載
Number of NUMA nodes: 1
Number of cores: 1
Number of physical packages: 0
Number of caches: 3
解消方法としては、KB932370 で提供されている hotfix を適用することになります。この hotfix は kernel module を変更し、この問題の修正だけでなく、他の kernel に修正も含まれていることに注意してください。Kernel に対する変更であるため、hotfix に問題が含まれる場合甚大な被害を被る可能性があります。置き換える対象の file version を注意深く確認し、この hotfix を適用することによって発生する既知の不具合がないか確認したほうがよいでしょう。
なお、この hotfix を適用すると GetLogicalProcessorInformation function だけではなく、WMI Win32_Processor class および Win32_ComputerSystem class に関する変更も行われています。
Class |
Property |
Before |
After |
Win32_ComputerSystem |
NumberOfProcessors |
Retun number of logical processors |
Retun number of physical processors |
|
NumberOfLogicalProcessors |
N/A |
Available |
Win32_Processor |
NumberOfCores |
N/A |
Available |
|
NumberOfLogicalProcessors |
N/A |
Available |
これらの変更は Windows Vista 以降の OS ではもちろん、Windows XP Service Pack 3 でも行われています。