Пример #1
0
// IsCefSupported: Check if Core Effectiver Frequency is supported by the CPU
bool IsCefSupported()
{
#define CPUID_FnThermalAndPowerManagement 6
#define CPUID_FnThermalAndPowerManagement_ECX_EffFreq  (1 << 0)
#define ECX_OFFSET 2
    bool result = false;
    AMDTInt32 cpuInfo[4] = { -1 };

    getCpuid(CPUID_FnThermalAndPowerManagement, cpuInfo); // vendor information

    // Effective Frequency is supported
    result = (cpuInfo[ECX_OFFSET] & CPUID_FnThermalAndPowerManagement_ECX_EffFreq) != 0;
    return result;
}
Пример #2
0
// GetCpuFamilyDetails: Read Cpu family, model id and wheather it is a AMD platform from CPU id instruction
AMDTResult GetCpuFamilyDetails(AMDTUInt32* pFamily, AMDTUInt32* pModel, bool* pIsAmd)
{
    AMDTInt32 cpuInfo[4] = { -1 };
    char vendorId[20];
    bool isAmd = false;
    AMDTUInt32 family;
    AMDTUInt32 model;

    if (nullptr == pFamily || nullptr == pModel || nullptr == pIsAmd)
    {
        return AMDT_ERROR_INVALIDARG;
    }

    getCpuid(0, cpuInfo); // vendor information
    memcpy(vendorId, &cpuInfo[1], 4);
    memcpy(vendorId + 4, &cpuInfo[3], 4);
    memcpy(vendorId + 8, &cpuInfo[2], 4);
    vendorId[12] = '\0';

    if (0 == strcmp(vendorId, "AuthenticAMD"))
    {
        isAmd = true;
    }

    // read the family and model details
    memset(cpuInfo, 0, sizeof(cpuInfo));
    getCpuid(1, cpuInfo);

    // Family is an 8-bit value and is defined as:
    // Family[7:0] = ({0000b,BaseFamily[3:0]} + ExtFamily[7:0]).
    family = (cpuInfo[0] & CPU_BASE_FAMILY_MASK) >> 8;

    if (CPU_FAMILY_EXTENDED == family)
    {
        family += (cpuInfo[0] & CPU_EXT_FAMILY_MASK) >> 20;
    }
// Handler get cpuid and other system information from current platform
int handlerInPlatform(char* parm)
    {
    // first message for platform mode
    (*routines[OUTTEXT])("Get platform data...\n");    // Handler console/file
    int retCpuid = 0, retRdtsc = 0, retXcr0 = 0;
    char sup[] = "supported";
    char nsup[] = "not supported";
    char err[] = "error";
    char *s1 = nsup, *s2 = nsup;
    char temp[MAX_STRING];
    // cpuid
    retCpuid = getCpuid(pointerBinary, MAX_BINARY);
    if (retCpuid <= 0)
        {
        snprintf(temp, MAX_BINARY, "CPUID not supported or locked\n");
        }
    else if (retCpuid > MAX_ENTRIES)
        {
        snprintf(temp, MAX_BINARY, "CPUID functions count too big\n");
        }
    else
        {
        pointerBinary += retCpuid * BINARY_ENTRY;
        // rdtsc
        retRdtsc = getRdtsc(pointerBinary);
        // analysing status, default pointers "not supported"
        if      (retRdtsc > 0) { s1 = sup; pointerBinary += BINARY_ENTRY; }
        else if (retRdtsc < 0) s1 = err;
        // xcr0
        retXcr0 = getXcr0(pointerBinary);
        // analysing status, default pointers "not supported"
        if      (retXcr0 > 0)  { s2 = sup; pointerBinary += BINARY_ENTRY; }
        else if (retXcr0 < 0)  s2 = err;
        // print
        snprintf(temp, MAX_BINARY, 
                 "%s%d%s%s%s%s\n",
                 "CPUID functions supported: ", retCpuid,
                 ", TSC ", s1,
                 ", XCR0 control ", s2 );
        }
    // summary string
    (*routines[OUTTEXT])(temp);   // Handler console/file
    }