How to take a snapshot of processor speed by individual cores in MHz

I would like to create an application that monitors and displays the frequencies of each core in the system processor for the user in MHz. I have seen other applications do this, like Piriform Speccy , so I know that this should be possible.

I tried to find a solution for, but I could not find it. Even this question , which was the closest coincidence that I could find, speaks of an anti-deception implementation in C ++ and does not offer a real solution, but it has one important conclusion that this article describes : "When power management technologies become more mundane on today's computers, the commonly used method of obtaining high-resolution CPU timings, the RDTSC command may not work as expected. " This idea is coming.

The closest I've seen is that the control object has MaxClockSpeed , but it responds to the speed of the processor rather than the processor cores.

There is also a CPUID System Information Monitoring Kit , but this is a development kit that costs money that I don’t have.

So ... back to the issue under discussion, how can I programmatically get the current snapshot of the base clock frequency? There must be a way.

PS With turbocharging and other technologies, core speed depends on speed. That is why I want to get this information as a snapshot of the current time. For monitoring purposes, such an application would be useful for the end user to make it easier for them to find out if their system is configured correctly, work correctly and allow them to control their system and see what performance is similar to load, etc. In addition, there is no harm in knowing how to obtain this data.

+4
1

CallNtPowerInformation. :

#include <NTstatus.h>
#define WIN32_NO_STATUS
#include <windows.h>
#include <Powrprof.h>
#include <iostream>

typedef struct _PROCESSOR_POWER_INFORMATION {
   ULONG  Number;
   ULONG  MaxMhz;
   ULONG  CurrentMhz;
   ULONG  MhzLimit;
   ULONG  MaxIdleState;
   ULONG  CurrentIdleState;
} PROCESSOR_POWER_INFORMATION, *PPROCESSOR_POWER_INFORMATION;

#pragma comment(lib, "Powrprof.lib")

int main()
{
   // get the number or processors 
   SYSTEM_INFO si = {0};
   ::GetSystemInfo(&si);
   // allocate buffer to get info for each processor
   const int size = si.dwNumberOfProcessors * sizeof(PROCESSOR_POWER_INFORMATION);
   LPBYTE pBuffer = new BYTE[size]; 

   NTSTATUS status = ::CallNtPowerInformation(ProcessorInformation, NULL, 0, pBuffer, size);
   if(STATUS_SUCCESS == status)
   {
      // list each processor frequency 
      PPROCESSOR_POWER_INFORMATION ppi = (PPROCESSOR_POWER_INFORMATION)pBuffer;
      for(DWORD nIndex = 0; nIndex < si.dwNumberOfProcessors; nIndex++)
      {
         std::cout << "Processor #" << ppi->Number << " frequency: " 
            << ppi->CurrentMhz << " MHz" << std::endl;
         ppi++;
      }
   }
   else
   {
      std::cout << "CallNtPowerInformation failed. Status: " << status << std::endl;
   }
   delete []pBuffer;
   system("pause");
   return status;
}
0

Source: https://habr.com/ru/post/1537517/


All Articles