vendor/github.com/shirou/gopsutil/v3/cpu/_smc.c
kern_return_t SMCGetKeyInfo(UInt32 key, SMCKeyData_keyInfo_t* keyInfo, io_connect_t conn)
{
    SMCKeyData_t inputStructure;
    SMCKeyData_t outputStructure;
    kern_return_t result = kIOReturnSuccess;
    int i = 0;
    
    OSSpinLockLock(&g_keyInfoSpinLock);
    
    for (; i < g_keyInfoCacheCount; ++i)
    {
        if (key == g_keyInfoCache[i].key)
        {
            *keyInfo = g_keyInfoCache[i].keyInfo;
            break;
        }
    }
    
    if (i == g_keyInfoCacheCount)
    {
        // Not in cache, must look it up.
        memset(&inputStructure, 0, sizeof(inputStructure));
        memset(&outputStructure, 0, sizeof(outputStructure));
        
        inputStructure.key = key;
        inputStructure.data8 = SMC_CMD_READ_KEYINFO;
        
        result = SMCCall2(KERNEL_INDEX_SMC, &inputStructure, &outputStructure, conn);
        if (result == kIOReturnSuccess)
        {
            *keyInfo = outputStructure.keyInfo;
            if (g_keyInfoCacheCount < KEY_INFO_CACHE_SIZE)
            {
                g_keyInfoCache[g_keyInfoCacheCount].key = key;
                g_keyInfoCache[g_keyInfoCacheCount].keyInfo = outputStructure.keyInfo;
                ++g_keyInfoCacheCount;
            }
        }
    }
    
    OSSpinLockUnlock(&g_keyInfoSpinLock);
    
    return result;
}
// Provides key info, using a cache to dramatically improve the energy impact of smcFanControl
Provides key info, using a cache to dramatically improve the energy impact of smcFanControl
Provides key info using a cache to dramatically improve the energy impact of smcFanControl
kern_return_t SMCGetKeyInfo(UInt32 key, SMCKeyData_keyInfo_t* keyInfo, io_connect_t conn)
{
    SMCKeyData_t inputStructure;
    SMCKeyData_t outputStructure;
    kern_return_t result = kIOReturnSuccess;
    int i = 0;
    OSSpinLockLock(&g_keyInfoSpinLock);
    for (; i < g_keyInfoCacheCount; ++i)
    {
        if (key == g_keyInfoCache[i].key)
        {
            *keyInfo = g_keyInfoCache[i].keyInfo;
            break;
        }
    }
    if (i == g_keyInfoCacheCount)
    {
        memset(&inputStructure, 0, sizeof(inputStructure));
        memset(&outputStructure, 0, sizeof(outputStructure));
        inputStructure.key = key;
        inputStructure.data8 = SMC_CMD_READ_KEYINFO;
        result = SMCCall2(KERNEL_INDEX_SMC, &inputStructure, &outputStructure, conn);
        if (result == kIOReturnSuccess)
        {
            *keyInfo = outputStructure.keyInfo;
            if (g_keyInfoCacheCount < KEY_INFO_CACHE_SIZE)
            {
                g_keyInfoCache[g_keyInfoCacheCount].key = key;
                g_keyInfoCache[g_keyInfoCacheCount].keyInfo = outputStructure.keyInfo;
                ++g_keyInfoCacheCount;
            }
        }
    }
    OSSpinLockUnlock(&g_keyInfoSpinLock);
    return result;
}
kern_return_t SMCGetKeyInfo ( UInt32 key , SMCKeyData_keyInfo_t * keyInfo , io_connect_t conn ) { SMCKeyData_t inputStructure ; SMCKeyData_t outputStructure ; kern_return_t result = kIOReturnSuccess ; int i = 0 ; OSSpinLockLock ( & g_keyInfoSpinLock ) ; for ( ; i < g_keyInfoCacheCount ; ++ i ) { if ( key == g_keyInfoCache [ i ] . key ) { * keyInfo = g_keyInfoCache [ i ] . keyInfo ; break ; } } if ( i == g_keyInfoCacheCount ) { memset ( & inputStructure , 0 , sizeof ( inputStructure ) ) ; memset ( & outputStructure , 0 , sizeof ( outputStructure ) ) ; inputStructure . key = key ; inputStructure . data8 = SMC_CMD_READ_KEYINFO ; result = SMCCall2 ( KERNEL_INDEX_SMC , & inputStructure , & outputStructure , conn ) ; if ( result == kIOReturnSuccess ) { * keyInfo = outputStructure . keyInfo ; if ( g_keyInfoCacheCount < KEY_INFO_CACHE_SIZE ) { g_keyInfoCache [ g_keyInfoCacheCount ] . key = key ; g_keyInfoCache [ g_keyInfoCacheCount ] . keyInfo = outputStructure . keyInfo ; ++ g_keyInfoCacheCount ; } } } OSSpinLockUnlock ( & g_keyInfoSpinLock ) ; return result ; }
Provides key info, using a cache to dramatically improve the energy impact of smcFanControl
Provides key info using a cache to dramatically improve the energy impact of smcFanControl
// Not in cache, must look it up.