Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Системное программирование и WinAPI > Параметры процессора


Автор: Kirk_Lee_Hammet 8.9.2006, 18:59
Народ помогите надо код проги которая определяет параметры процессора.
плиз очень надо... smile  smile 

Автор: _hunter 8.9.2006, 19:26
о каких параметрах идет разговор?

Автор: Kirk_Lee_Hammet 9.9.2006, 12:30
Название, частота, .....пять шесть любых параметров. Все что знаете.

Автор: 586 9.9.2006, 12:51
http://psv-cmos.narod.ru/cpuid.htm

Автор: Bishop 10.9.2006, 09:24
Kirk_Lee_Hammet
возможно, тебе будет достаточно сведений, хранящихся в реестре в разделе:
Код

HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor

Автор: Damarus 10.9.2006, 11:38
Цитата(Kirk_Lee_Hammet @  8.9.2006,  19:59 Найти цитируемый пост)
Народ помогите надо код проги которая определяет параметры процессора.плиз очень надо...    

В MSDN есть пример:
Код

// cpuid.cpp 
// processor: x86, x64
// Use the __cpuid intrinsic to get information about a CPU

#include <stdio.h>
#include <string.h>
#include <intrin.h>

const char* szFeatures[] =
{
    "x87 FPU On Chip",
    "Virtual-8086 Mode Enhancement",
    "Debugging Extensions",
    "Page Size Extensions",
    "Time Stamp Counter",
    "RDMSR and WRMSR Support",
    "Physical Address Extensions",
    "Machine Check Exception",
    "CMPXCHG8B Instruction",
    "APIC On Chip",
    "Unknown1",
    "SYSENTER and SYSEXIT",
    "Memory Type Range Registers",
    "PTE Global Bit",
    "Machine Check Architecture",
    "Conditional Move/Compare Instruction",
    "Page Attribute Table",
    "Page Size Extension",
    "Processor Serial Number",
    "CFLUSH Extension",
    "Unknown2",
    "Debug Store",
    "Thermal Monitor and Clock Ctrl",
    "MMX Technology",
    "FXSAVE/FXRSTOR",
    "SSE Extensions",
    "SSE2 Extensions",
    "Self Snoop",
    "Hyper-threading Technology",
    "Thermal Monitor",
    "Unknown4",
    "Pend. Brk. EN."
};

int main(int argc, char* argv[])
{
    char CPUString[0x20];
    char CPUBrandString[0x40];
    int CPUInfo[4] = {-1};
    int nSteppingID = 0;
    int nModel = 0;
    int nFamily = 0;
    int nProcessorType = 0;
    int nExtendedmodel = 0;
    int nExtendedfamily = 0;
    int nBrandIndex = 0;
    int nCLFLUSHcachelinesize = 0;
    int nAPICPhysicalID = 0;
    int nFeatureInfo = 0;
    int nCacheLineSize = 0;
    int nL2Associativity = 0;
    int nCacheSizeK = 0;
    int nRet = 0;
    unsigned    nIds, nExIds, i;
    bool    bSSE3NewInstructions = false;
    bool    bMONITOR_MWAIT = false;
    bool    bCPLQualifiedDebugStore = false;
    bool    bThermalMonitor2 = false;


    // __cpuid with an InfoType argument of 0 returns the number of
    // valid Ids in CPUInfo[0] and the CPU identification string in
    // the other three array elements. The CPU identification string is
    // not in linear order. The code below arranges the information 
    // in a human readable form.
    __cpuid(CPUInfo, 0);
    nIds = CPUInfo[0];
    memset(CPUString, 0, sizeof(CPUString));
    *((int*)CPUString) = CPUInfo[1];
    *((int*)(CPUString+4)) = CPUInfo[3];
    *((int*)(CPUString+8)) = CPUInfo[2];

    // Get the information associated with each valid Id
    for (i=0; i<=nIds; ++i)
    {
        __cpuid(CPUInfo, i);
        printf_s("\nFor InfoType %d\n", i); 
        printf_s("CPUInfo[0] = 0x%x\n", CPUInfo[0]);
        printf_s("CPUInfo[1] = 0x%x\n", CPUInfo[1]);
        printf_s("CPUInfo[2] = 0x%x\n", CPUInfo[2]);
        printf_s("CPUInfo[3] = 0x%x\n", CPUInfo[3]);

        // Interpret CPU feature information.
        if  (i == 1)
        {
            nSteppingID = CPUInfo[0] & 0xf;
            nModel = (CPUInfo[0] >> 4) & 0xf;
            nFamily = (CPUInfo[0] >> 8) & 0xf;
            nProcessorType = (CPUInfo[0] >> 12) & 0x3;
            nExtendedmodel = (CPUInfo[0] >> 16) & 0xf;
            nExtendedfamily = (CPUInfo[0] >> 20) & 0xff;
            nBrandIndex = CPUInfo[1] & 0xff;
            nCLFLUSHcachelinesize = ((CPUInfo[1] >> 8) & 0xff) * 8;
            nAPICPhysicalID = (CPUInfo[1] >> 24) & 0xff;
            bSSE3NewInstructions = (CPUInfo[2] & 0x1) || false;
            bMONITOR_MWAIT = (CPUInfo[2] & 0x8) || false;
            bCPLQualifiedDebugStore = (CPUInfo[2] & 0x10) || false;
            bThermalMonitor2 = (CPUInfo[2] & 0x100) || false;
            nFeatureInfo = CPUInfo[3];
        }
    }

    // Calling __cpuid with 0x80000000 as the InfoType argument
    // gets the number of valid extended IDs.
    __cpuid(CPUInfo, 0x80000000);
    nExIds = CPUInfo[0];
    memset(CPUBrandString, 0, sizeof(CPUBrandString));

    // Get the information associated with each extended ID.
    for (i=0x80000000; i<=nExIds; ++i)
    {
        __cpuid(CPUInfo, i);
        printf_s("\nFor InfoType %x\n", i); 
        printf_s("CPUInfo[0] = 0x%x\n", CPUInfo[0]);
        printf_s("CPUInfo[1] = 0x%x\n", CPUInfo[1]);
        printf_s("CPUInfo[2] = 0x%x\n", CPUInfo[2]);
        printf_s("CPUInfo[3] = 0x%x\n", CPUInfo[3]);

        // Interpret CPU brand string and cache information.
        if  (i == 0x80000002)
            memcpy(CPUBrandString, CPUInfo, sizeof(CPUInfo));
        else if  (i == 0x80000003)
            memcpy(CPUBrandString + 16, CPUInfo, sizeof(CPUInfo));
        else if  (i == 0x80000004)
            memcpy(CPUBrandString + 32, CPUInfo, sizeof(CPUInfo));
        else if  (i == 0x80000006)
        {
            nCacheLineSize = CPUInfo[2] & 0xff;
            nL2Associativity = (CPUInfo[2] >> 12) & 0xf;
            nCacheSizeK = (CPUInfo[2] >> 16) & 0xffff;
        }
    }

    // Display all the information in user-friendly format.

    printf_s("\n\nCPU String: %s\n", CPUString);

    if  (nIds >= 1)
    {
        if  (nSteppingID)
            printf_s("Stepping ID = %d\n", nSteppingID);
        if  (nModel)
            printf_s("Model = %d\n", nModel);
        if  (nFamily)
            printf_s("Family = %d\n", nFamily);
        if  (nProcessorType)
            printf_s("Processor Type = %d\n", nProcessorType);
        if  (nExtendedmodel)
            printf_s("Extended model = %d\n", nExtendedmodel);
        if  (nExtendedfamily)
            printf_s("Extended family = %d\n", nExtendedfamily);
        if  (nBrandIndex)
            printf_s("Brand Index = %d\n", nBrandIndex);
        if  (nCLFLUSHcachelinesize)
            printf_s("CLFLUSH cache line size = %d\n",
            nCLFLUSHcachelinesize);
        if  (nAPICPhysicalID)
            printf_s("APIC Physical ID = %d\n", nAPICPhysicalID);

        if  (nFeatureInfo || bSSE3NewInstructions ||
            bMONITOR_MWAIT || bCPLQualifiedDebugStore ||
            bThermalMonitor2)
        {
            printf_s("\nThe following features are supported:\n");

            if  (bSSE3NewInstructions)
                printf_s("\tSSE3 New Instructions\n");
            if  (bMONITOR_MWAIT)
                printf_s("\tMONITOR/MWAIT\n");
            if  (bCPLQualifiedDebugStore)
                printf_s("\tCPL Qualified Debug Store\n");
            if  (bThermalMonitor2)
                printf_s("\tThermal Monitor 2\n");

            i = 0;
            nIds = 1;
            while (i < (sizeof(szFeatures)/sizeof(const char*)))
            {
                if  (nFeatureInfo & nIds)
                {
                    printf_s("\t");
                    printf_s(szFeatures[i]);
                    printf_s("\n");
                }

                nIds <<= 1;
                ++i;
            }
        }
    }

    if  (nExIds >= 0x80000004)
        printf_s("\nCPU Brand String: %s\n", CPUBrandString);

    if  (nExIds >= 0x80000006)
    {
        printf_s("Cache Line Size = %d\n", nCacheLineSize);
        printf_s("L2 Associativity = %d\n", nL2Associativity);
        printf_s("Cache Size = %dK\n", nCacheSizeK);
    }

    return  nRet;
}


Автор: Kirk_Lee_Hammet 13.9.2006, 16:40
Большое всем спасибки. smile  smile 

Автор: bel_nikita 13.9.2006, 22:57
Вот, метода для измерение реальной частоты в реальном времени:
Код
FLOAT MeasureClockSpeed()
{
    DWORD            ticks;              // Microseconds elapsed during test
    DWORD            cycles;             // Clock cycles elapsed during test
    DWORD            stamp0, stamp1;     // Time Stamp Variable for beginning and end of test                                            
  DWORD         freq = 0;
    DWORD         freq2 =0;           // 2nd most current frequ. calc.
    DWORD         freq3 =0;           // 3rd most current frequ. calc.
    DWORD         total;              // Sum of previous three frequency calculations
    int           tries=0;            // Number of times a calculation has been made on this call
    LARGE_INTEGER t0,t1;              // Variables for High-Resolution Performance Counter reads                    
    LARGE_INTEGER count_freq;           // High Resolution Performance Counter frequency

    // Checks whether the high-resolution counter exists and returns an error if it does not exist.
    if (!QueryPerformanceFrequency( &count_freq ) ) return 0.0f;
  
  // Get a copy of the current thread and process priorities
#if !defined (PHARLAP)
  DWORD priority_class     = GetPriorityClass(GetCurrentProcess());
#endif
  int  thread_priority    = GetThreadPriority(GetCurrentThread());

  // Make this thread the highest possible priority so we get the best timing
#if !defined (PHARLAP)
  SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
#endif
  SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);

    // Compare elapsed time on the High-Resolution Counter with elapsed cycles on the Time Stamp Register.
    do 
    {
    // This do loop runs up to 20 times or until the average of the previous  three calculated
        // frequencies is within 1 MHz of each of the individual calculated frequencies. 
        // This resampling increases the accuracy of the results since outside factors could affect
        // this calculation            

        tries++;        //Increment number of times sampled on this call to cpuspeed
        freq3 = freq2;  //Shift frequencies back to make
        freq2 = freq;   //room for new frequency measurement
    
    //Get high-resolution performance counter time
    QueryPerformanceCounter(&t0);
    t1.LowPart  = t0.LowPart;        // Set Initial time
    t1.HighPart = t0.HighPart;

        // Loop until 50 ticks have passed since last read of hi-res counter.
        // This accounts for overhead later.
    while ( (DWORD)t1.LowPart - (DWORD)t0.LowPart<50)
    {
      QueryPerformanceCounter(&t1);
    }
    
    _asm
    {
      rdtsc
        mov stamp0, EAX
    }

        t0.LowPart  = t1.LowPart;     // Reset Initial 
        t0.HighPart = t1.HighPart;        // Time
    
    // Loop until 1000 ticks have passed since last read of hi-res counter.
    // This allows for elapsed time for sampling.
    while ((DWORD)t1.LowPart-(DWORD)t0.LowPart<1000 )
    {
      QueryPerformanceCounter(&t1);
    }
    
    _asm
    {
      rdtsc
        mov        stamp1, EAX
    }
    
    cycles = stamp1 - stamp0;
    ticks = (DWORD) t1.LowPart - (DWORD) t0.LowPart;    

        // Note that some seemingly arbitrary mulitplies and divides are done below.
        // This is to maintain a high level of precision without truncating the most 
        // significant data. 

        ticks = ticks * 100000;                
        ticks = ticks / ( count_freq.LowPart/10 );        
        
        if ( ticks%count_freq.LowPart > count_freq.LowPart/2 )
        {
      ticks++;            // Round up if necessary
    }
        
        freq = cycles/ticks;    // Cycles / us  = MHz
                                         
    if ( cycles%ticks > ticks/2 )
    {
      freq++;                // Round up if necessary
        }
    
    total = ( freq + freq2 + freq3 );
  } while (    (tries < 3 ) || (tries < 20) && (( abs( (int)(3 * freq -total) ) > 3 ) ||
        (abs( (int)(3 * freq2-total) ) > 3) || (abs( (int)(3 * freq3-total) > 3) ) ));
        
    if ( total / 3  !=  ( total + 1 ) / 3 )
  {
        total ++;                // Round up if necessary
    }

    // restore the thread priority
#if !defined (PHARLAP)
    SetPriorityClass(GetCurrentProcess(), priority_class);
#endif
    SetThreadPriority(GetCurrentThread(), thread_priority);
  
  //return float(total) / 3.0f;
  return float(total) / 3.01f;
}

Автор: Android80 27.9.2006, 16:26
To Damarus

а не подскажешь что еще нужно в этот код добавить, чтобы еще проверить наличие 3DNow и 3DNow Ext

Автор: Damarus 27.9.2006, 18:39
Цитата(Android80 @  27.9.2006,  17:26 Найти цитируемый пост)
а не подскажешь что еще нужно в этот код добавить, чтобы еще проверить наличие 3DNow и 3DNow Ext

Для 3DNow примерно так:
Код
int CPUInfo[4] = { -1 };
__cpuid(CPUInfo, 0x80000001);
if (CPUInfo[3] & 0x80000000)
    printf_s("3DNow! Extensions");

Для 3DNow Ext. примерно также, смотреть документацию по процессорам AMD.

PS. Это теоретически, т.к. проверить не на чем.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)