[Windows編程] Windows 7 對多核的支持

Windows 7 和 Windows Server 2008 R2 一個重要更新是增強了對多核的支持。 現已可以支持超過64個邏輯處理器(也就是所謂的“核”),並且引入了NUMA 技術, 大幅度提高多核運算的性能。

 

傳統的多核運算是使用SMP(Symmetric Multi-Processor )模式:將多個處理器與一個集中的存儲器和I/O總線相連。所有處理器只能訪問同一個物理存儲器,因此SMP系統有時也被稱爲一致存儲器訪問(UMA)結構體系,一致性意指無論在什麼時候,處理器只能爲內存的每個數據保持或共享唯一一個數值。很顯然,SMP的缺點是可伸縮性有限,因爲在存儲器和I/O接口達到飽和的時候,增加處理器並不能獲得更高的性能。

 

NUMA模式是一種分佈式存儲器訪問方式,處理器可以同時訪問不同的存儲器地址,大幅度提高並行性。 NUMA模式下,處理器被劃分成多個"節點"(node), 每個節點被分配有的本地存儲器空間。 所有節點中的處理器都可以訪問全部的系統物理存儲器,但是訪問本節點內的存儲器所需要的時間,比訪問某些遠程節點內的存儲器所花的時間要少得多。

 

在開發Windows7 上的多線程程序的時候, 應該把進程內所有的線程都安排到同一個節點,可以大大提高性能。 新的Windows 7 API 函數 SetProcessAffinityMask  可以實現這個功能。

 

如果你的程序使用內存比較頻繁, 應該在進程所在節點的本地存儲器空間分配內存,以避免跨節點存儲器訪問的開銷。 Windows API VirtualAllocExNuma  可以實現這個功能。

 

以下是Windows 7/ WIndows Server2 2008R2 新增加的多核支持API函數

 

CreateRemoteThreadEx
Creates a thread that runs in the virtual address space of another process and optionally specifies extended attributes such as processor group affinity.

GetActiveProcessorCount
Returns the number of active processors in a processor group or in the system.

GetActiveProcessorGroupCount
Returns the number of active processor groups in the system.

GetCurrentProcessorNumberEx
Retrieves the processor group and number of the logical processor in which the calling thread is running.

GetLogicalProcessorInformationEx
Retrieves information about the relationships of logical processors and related hardware.

GetMaximumProcessorCount
Returns the maximum number of logical processors that a processor group or the system can support.

GetMaximumProcessorGroupCount
Returns the maximum number of processor groups that the system supports.

GetNumaAvailableMemoryNodeEx
Retrieves the amount of memory that is available in the specified node as a USHORT value.

GetNumaNodeNumberFromHandle
Retrieves the NUMA node associated with the underlying device for a file handle.

GetNumaNodeProcessorMaskEx
Retrieves the processor mask for the specified NUMA node as a USHORT value.

GetNumaProcessorNodeEx
Retrieves the node number of the specified logical processor as a USHORT value.

GetNumaProximityNodeEx
Retrieves the node number as a USHORT value for the specified proximity identifier.

GetProcessGroupAffinity
Retrieves the processor group affinity of the specified process.

GetProcessorSystemCycleTime
Retrieves the cycle time each processor in the specified group spent executing deferred procedure calls (DPCs) and interrupt service routines (ISRs).

GetThreadGroupAffinity
Retrieves the processor group affinity of the specified thread.

GetThreadIdealProcessorEx
Retrieves the processor number of the ideal processor for the specified thread.

QueryIdleProcessorCycleTimeEx
Retrieves the accumulated cycle time for the idle thread on each logical processor in the specified processor group.

SetThreadGroupAffinity
Sets the processor group affinity for the specified thread.

SetThreadIdealProcessorEx
Sets the ideal processor for the specified thread and optionally retrieves the previous ideal processor.

以下是新的線程池 API 函數


QueryThreadpoolStackInformation
Retrieves the stack reserve and commit sizes for threads in the specified thread pool.

SetThreadpoolCallbackPersistent
Specifies that the callback should run on a persistent thread.

SetThreadpoolCallbackPriority
Specifies the priority of a callback function relative to other work items in the same thread pool.

SetThreadpoolStackInformation
Sets the stack reserve and commit sizes for new threads in the specified thread pool.

 

 

 >> 原創文章的版權屬於作者,轉載請註明出處和作者信息(http://blog.csdn.net/WinGeek/), 謝謝。 <<

發佈了160 篇原創文章 · 獲贊 8 · 訪問量 90萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章