概述
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.
最后
以上就是平常热狗为你收集整理的 Windows 7 对多核的支持的全部内容,希望文章能够帮你解决 Windows 7 对多核的支持所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复