网站首页  词典首页

请输入您要查询的函数:

 

术语 getlogicalprocessorinformation
释义 GetLogicalProcessorInformation
语法:
C++
BOOL WINAPI GetLogicalProcessorInformation(
__out PSYSTEM_LOGICAL_PROCESSOR_INFORMATION Buffer,
__inout PDWORD ReturnLength
);
GetLogicalProcessorInformation功能
获取信息的逻辑处理器和相关硬件。
要检索有关逻辑处理器和相关硬件,包括处理器组,使用GetLogicalProcessorInformationEx函数的信息。
参数
缓冲区[out]
A到接收缓冲区的SYSTEM_LOGICAL_PROCESSOR_INFORMATION结构的数组指针。如果函数失败,这个缓冲区的内容是不确定的。
ReturnLength [ in , out ]
在输入,指定缓冲区的长度所指向的缓冲区,以字节。如果缓冲区足够大,以包含所有数据,此函数成功,ReturnLength设置为返回的字节数。如果缓冲区不够大,包含的所有数据,函数失败,GetLastError返回ERROR_INSUFFICIENT_BUFFER,并ReturnLength设置为缓冲区的长度必须包含的所有数据。如果该函数一个错误比ERROR_INSUFFICIENT_BUFFER其他失败的ReturnLength值是不确定的。
返回值
如果函数成功,返回值为TRUE和至少一个SYSTEM_LOGICAL_PROCESSOR_INFORMATION结构写入到输出缓冲区。
如果函数失败,返回值为FALSE。为了获得更多错误信息,调用GetLastError。
备注
GetLogicalProcessorInformation可用于获取有关逻辑处理器之间的系统关系的信息,包括:
即是一个NUMA节点部分逻辑处理器。
逻辑处理器共享资源。这方面的一个类型的资源共享方案将超线程的例子。
您的应用程序可以使用此信息时affinitizing您的线程和进程以最佳的平台,或确定为牌照用途的逻辑和物理处理器的数量优势的硬件性能。
在SYSTEM_LOGICAL_PROCESSOR_INFORMATION结构中的每个缓冲区返回包含以下内容:
逻辑处理器关联掩码,这表明该结构中的信息适用于逻辑处理器。
一种类型的逻辑处理器面具LOGICAL_PROCESSOR_RELATIONSHIP,这表明逻辑处理器之间在面具的关系。应用程序调用该函数必须准备应付未来更多的指标值。
请注意,在其中的结构是在缓冲区内可能会更改与此函数调用顺序。
该SYSTEM_LOGICAL_PROCESSOR_INFORMATION结构的大小不等的处理器架构和Windows版本。为此,应用程序应该首先调用此函数来获得所需的缓冲区大小,然后动态分配缓冲区的内存。
在超过64个逻辑处理器,GetLogicalProcessorInformation函数检索有关处理器组调用线程的当前分配处理器逻辑处理器信息系统。使用GetLogicalProcessorInformationEx函数来检索有关系统上的所有处理器团体处理器的信息。
实例
下面的C + +示例使用GetLogicalProcessorInformation函数来显示有关当前系统处理器的信息。由于GetLogicalProcessorInformation并非所有系统目前,本示例使用GetProcAddress函数,而不是直接调用GetLogicalProcessorInformation。
这个例子报道了积极的处理器内核的数量。这个例子也报道了NUMA的节点,物理包数,缓存和系统支持这一信息。有关更多信息,看到的SYSTEM_LOGICAL_PROCESSOR_INFORMATION结构的关系成员的说明。
Windows Server 2003中,Windows XP专业x64版和Windows XP SP3的:这个例子的报告,而不是积极的处理器内核数量的物理处理器的数量。
#include
#include
#include
#include
typedef BOOL (WINAPI *LPFN_GLPI)(
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION,
PDWORD);

// Helper function to count set bits in the processor mask.
DWORD CountSetBits(ULONG_PTR bitMask)
{
DWORD LSHIFT = sizeof(ULONG_PTR)*8 - 1;
DWORD bitSetCount = 0;
ULONG_PTR bitTest = (ULONG_PTR)1 << LSHIFT;
DWORD i;

for (i = 0; i <= LSHIFT; ++i)
{
bitSetCount += ((bitMask & bitTest)?1:0);
bitTest/=2;
}
return bitSetCount;
}
int _cdecl _tmain ()
{
LPFN_GLPI glpi;
BOOL done = FALSE;
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION buffer = NULL;
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION ptr = NULL;
DWORD returnLength = 0;
DWORD logicalProcessorCount = 0;
DWORD numaNodeCount = 0;
DWORD processorCoreCount = 0;
DWORD processorL1CacheCount = 0;
DWORD processorL2CacheCount = 0;
DWORD processorL3CacheCount = 0;
DWORD processorPackageCount = 0;
DWORD byteOffset = 0;
PCACHE_DESCRIPTOR Cache;
glpi = (LPFN_GLPI) GetProcAddress(
GetModuleHandle(TEXT("kernel32")),
"GetLogicalProcessorInformation");
if (NULL == glpi)
{
_tprintf(TEXT("\\nGetLogicalProcessorInformation is not supported.\\n"));
return (1);
}
while (!done)
{
DWORD rc = glpi(buffer, &returnLength);
if (FALSE == rc)
{
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
if (buffer)
free(buffer);
buffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)malloc(
returnLength);
if (NULL == buffer)
{
_tprintf(TEXT("\\nError: Allocation failure\\n"));
return (2);
}
}
else
{
_tprintf(TEXT("\\nError %d\\n"), GetLastError());
return (3);
}
}
else
{
done = TRUE;
}
}
ptr = buffer;
while (byteOffset + sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION) <= returnLength)
{
switch (ptr->Relationship)
{
case RelationNumaNode:
// Non-NUMA systems report a single record of this type.
numaNodeCount++;
break;
case RelationProcessorCore:
processorCoreCount++;
// A hyperthreaded core supplies more than one logical processor.
logicalProcessorCount += CountSetBits(ptr->ProcessorMask);
break;
case RelationCache:
// Cache data is in ptr->Cache, one CACHE_DESCRIPTOR structure for each cache.
Cache = &ptr->Cache;
if (Cache->Level == 1)
{
processorL1CacheCount++;
}
else if (Cache->Level == 2)
{
processorL2CacheCount++;
}
else if (Cache->Level == 3)
{
processorL3CacheCount++;
}
break;
case RelationProcessorPackage:
// Logical processors share a physical package.
processorPackageCount++;
break;
default:
_tprintf(TEXT("\\nError: Unsupported LOGICAL_PROCESSOR_RELATIONSHIP value.\\n"));
break;
}
byteOffset += sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
ptr++;
}
_tprintf(TEXT("\\nGetLogicalProcessorInformation results:\\n"));
_tprintf(TEXT("Number of NUMA nodes: %d\\n"),
numaNodeCount);
_tprintf(TEXT("Number of physical processor packages: %d\\n"),
processorPackageCount);
_tprintf(TEXT("Number of processor cores: %d\\n"),
processorCoreCount);
_tprintf(TEXT("Number of logical processors: %d\\n"),
logicalProcessorCount);
_tprintf(TEXT("Number of processor L1/L2/L3 caches: %d/%d/%d\\n"),
processorL1CacheCount,
processorL2CacheCount,
processorL3CacheCount);

free(buffer);
return 0;
}
要求:
最低支持clientWindows Vista中,Windows XP专业x64版,Windows XP中带有SP3
最低支持serverWindows服务器2003
HeaderWinbase.h(头文件:winuser.h)
LibraryKernel32.lib
DLLKernel32.dll
参见
GetLogicalProcessorInformationEx
LOGICAL_PROCESSOR_RELATIONSHIP
进程和线程函数
SYSTEM_LOGICAL_PROCESSOR_INFORMATION
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==GetLogicalProcessorInformation Function
Retrieves information about logical processors and related hardware.
To retrieve information about logical processors and related hardware, including processor groups, use the GetLogicalProcessorInformationEx function.
Syntax
C++
BOOL WINAPI GetLogicalProcessorInformation(
__out PSYSTEM_LOGICAL_PROCESSOR_INFORMATION Buffer,
__inout PDWORD ReturnLength
);
Parameters
Buffer [out]
A pointer to a buffer that receives an array of SYSTEM_LOGICAL_PROCESSOR_INFORMATION structures. If the function fails, the contents of this buffer are undefined.
ReturnLength [in, out]
On input, specifies the length of the buffer pointed to by Buffer, in bytes. If the buffer is large enough to contain all of the data, this function succeeds and ReturnLength is set to the number of bytes returned. If the buffer is not large enough to contain all of the data, the function fails, GetLastError returns ERROR_INSUFFICIENT_BUFFER, and ReturnLength is set to the buffer length required to contain all of the data. If the function fails with an error other than ERROR_INSUFFICIENT_BUFFER, the value of ReturnLength is undefined.
Return Value
If the function succeeds, the return value is TRUE and at least one SYSTEM_LOGICAL_PROCESSOR_INFORMATION structure is written to the output buffer.
If the function fails, the return value is FALSE. To get extended error information, call GetLastError.
Remarks
GetLogicalProcessorInformation can be used to get information about the relationship between logical processors in the system, including:
The logical processors that are part of a NUMA node.
The logical processors that share resources. An example of this type of resource sharing would be hyperthreading scenarios.
Your application can use this information when affinitizing your threads and processes to take best advantage of the hardware properties of the platform, or to determine the number of logical and physical processors for licensing purposes.
Each of the SYSTEM_LOGICAL_PROCESSOR_INFORMATION structures returned in the buffer contains the following:
A logical processor affinity mask, which indicates the logical processors that the information in the structure applies to.
A logical processor mask of type LOGICAL_PROCESSOR_RELATIONSHIP , which indicates the relationship between the logical processors in the mask. Applications calling this function must be prepared to handle additional indicator values in the future.
Note that the order in which the structures are returned in the buffer may change between calls to this function.
The size of the SYSTEM_LOGICAL_PROCESSOR_INFORMATION structure varies between processor architectures and versions of Windows. For this reason, applications should first call this function to obtain the required buffer size, then dynamically allocate memory for the buffer.
On systems with more than 64 logical processors, the GetLogicalProcessorInformation function retrieves logical processor information about processors in the processor group to which the calling thread is currently assigned. Use the GetLogicalProcessorInformationEx function to retrieve information about processors in all processor groups on the system.
Examples
The following C++ example uses the GetLogicalProcessorInformation function to display information about processors on the current system. Because GetLogicalProcessorInformation is not present on all systems, this example uses the GetProcAddress function instead of calling GetLogicalProcessorInformation directly.
This example reports the number of active processor cores. This example also reports the number of NUMA nodes, physical packages, and caches on systems that support this information. For more information, see the description of the Relationship member of the SYSTEM_LOGICAL_PROCESSOR_INFORMATION structure.
Windows Server 2003, Windows XP Professional x64 Edition, and Windows XP with SP3: This example reports the number of physical processors rather than the number of active processor cores.

#include
#include
#include
#include
typedef BOOL (WINAPI *LPFN_GLPI)(
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION,
PDWORD);

// Helper function to count set bits in the processor mask.
DWORD CountSetBits(ULONG_PTR bitMask)
{
DWORD LSHIFT = sizeof(ULONG_PTR)*8 - 1;
DWORD bitSetCount = 0;
ULONG_PTR bitTest = (ULONG_PTR)1 << LSHIFT;
DWORD i;

for (i = 0; i <= LSHIFT; ++i)
{
bitSetCount += ((bitMask & bitTest)?1:0);
bitTest/=2;
}
return bitSetCount;
}
int _cdecl _tmain ()
{
LPFN_GLPI glpi;
BOOL done = FALSE;
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION buffer = NULL;
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION ptr = NULL;
DWORD returnLength = 0;
DWORD logicalProcessorCount = 0;
DWORD numaNodeCount = 0;
DWORD processorCoreCount = 0;
DWORD processorL1CacheCount = 0;
DWORD processorL2CacheCount = 0;
DWORD processorL3CacheCount = 0;
DWORD processorPackageCount = 0;
DWORD byteOffset = 0;
PCACHE_DESCRIPTOR Cache;
glpi = (LPFN_GLPI) GetProcAddress(
GetModuleHandle(TEXT("kernel32")),
"GetLogicalProcessorInformation");
if (NULL == glpi)
{
_tprintf(TEXT("\\nGetLogicalProcessorInformation is not supported.\\n"));
return (1);
}
while (!done)
{
DWORD rc = glpi(buffer, &returnLength);
if (FALSE == rc)
{
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
if (buffer)
free(buffer);
buffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)malloc(
returnLength);
if (NULL == buffer)
{
_tprintf(TEXT("\\nError: Allocation failure\\n"));
return (2);
}
}
else
{
_tprintf(TEXT("\\nError %d\\n"), GetLastError());
return (3);
}
}
else
{
done = TRUE;
}
}
ptr = buffer;
while (byteOffset + sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION) <= returnLength)
{
switch (ptr->Relationship)
{
case RelationNumaNode:
// Non-NUMA systems report a single record of this type.
numaNodeCount++;
break;
case RelationProcessorCore:
processorCoreCount++;
// A hyperthreaded core supplies more than one logical processor.
logicalProcessorCount += CountSetBits(ptr->ProcessorMask);
break;
case RelationCache:
// Cache data is in ptr->Cache, one CACHE_DESCRIPTOR structure for each cache.
Cache = &ptr->Cache;
if (Cache->Level == 1)
{
processorL1CacheCount++;
}
else if (Cache->Level == 2)
{
processorL2CacheCount++;
}
else if (Cache->Level == 3)
{
processorL3CacheCount++;
}
break;
case RelationProcessorPackage:
// Logical processors share a physical package.
processorPackageCount++;
break;
default:
_tprintf(TEXT("\\nError: Unsupported LOGICAL_PROCESSOR_RELATIONSHIP value.\\n"));
break;
}
byteOffset += sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
ptr++;
}
_tprintf(TEXT("\\nGetLogicalProcessorInformation results:\\n"));
_tprintf(TEXT("Number of NUMA nodes: %d\\n"),
numaNodeCount);
_tprintf(TEXT("Number of physical processor packages: %d\\n"),
processorPackageCount);
_tprintf(TEXT("Number of processor cores: %d\\n"),
processorCoreCount);
_tprintf(TEXT("Number of logical processors: %d\\n"),
logicalProcessorCount);
_tprintf(TEXT("Number of processor L1/L2/L3 caches: %d/%d/%d\\n"),
processorL1CacheCount,
processorL2CacheCount,
processorL3CacheCount);

free(buffer);
return 0;
}

Requirements
Minimum supported clientWindows Vista, Windows XP Professional x64 Edition, Windows XP with SP3
Minimum supported serverWindows Server 2003
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
See Also
GetLogicalProcessorInformationEx
LOGICAL_PROCESSOR_RELATIONSHIP
Process and Thread Functions
SYSTEM_LOGICAL_PROCESSOR_INFORMATION
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/ms683194(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 13:21:52