how to use GetLogicalProcessorInformation, win32api, under using csharp

  • Thread starter Thread starter ti
  • Start date Start date
T

ti

Hello all,

Does anyone have any idea that how to use
GetLogicalProcessorInformation, win32api, under using csharp?
http://msdn2.microsoft.com/en-us/library/ms683194.aspx

For me, one of the most difficult things is how to define
SYSTEM_LOGICAL_PROCESSOR_INFORMATION structures and how to cast it to
the win32api.


Using
StructLayout(LayoutKind.Explicit)
[FieldOffset(0)]...



I've been trying but it's very difficult for me.

Best Regards,
TI
 
public class ProcessorInfo
{
private string manufacturer = null;
private UInt32 clockSpeed;
private UInt16 family;
private string version;
private string processorId = null;

public static void ConsoleOutput()
{
ProcessorInfo info = ProcessorInfo.Get();
Console.WriteLine("\nProcessor information:");
Console.WriteLine("----------------------");
Console.WriteLine("Manufacturer: {0}", info.manufacturer);
Console.WriteLine("ClockSpeed: {0}", info.clockSpeed);
Console.WriteLine("Family: {0}", info.family);
Console.WriteLine("Version: {0}", info.version);
Console.WriteLine("ProcessorId: {0}", info.processorId);
Console.WriteLine("\n");
}

public static ProcessorInfo Get()
{
ProcessorInfo output = new ProcessorInfo();
ManagementObjectSearcher searcher = new
ManagementObjectSearcher("SELECT * FROM Win32_Processor");
foreach (ManagementObject wmi_CPU in searcher.Get())
{
output.manufacturer = wmi_CPU["Manufacturer"].ToString();
output.clockSpeed = (UInt32) wmi_CPU["MaxClockSpeed"];
output.family = (UInt16) wmi_CPU["Family"];
output.version = wmi_CPU["Version"].ToString();
output.processorId = wmi_CPU["ProcessorId"].ToString();
break;
}

return output;
}

public string Manufacturer
{
get { return manufacturer; }
}

public UInt32 ClockSpeed
{
get { return clockSpeed; }
}

public UInt16 Family
{
get { return family; }
}

public string Version
{
get { return version; }
}

public string ProcessorId
{
get { return processorId; }
}
}
 
Thanks Miroslav.

But I think I need to use GetLogicalProcessorInformation().
Because WMI doesn't give me necessary information as far as I checked.

I'd like to know about the relationship between processor-cores like
below examples.

1. whether core-a and core-b share the same L2-cache.
2. whether core-a, core-b, core-c and core-d are in the same
die(physical processor chip).

I believe one of the best ways is to use
GetLogicalProcessorInformation().


I assume the environment is Vista or future release of windows.
And the necessary platforms are x86, x64 and Itanium, so I guess I
also can't use __cpuid().

Best Regards,
TI
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top