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

來源:互聯網
上載者:User

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/), 謝謝。 <<

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.