Files
fastfetch/src/detection/cpu/cpu_apple.c
T

42 lines
1.3 KiB
C
Raw Normal View History

2022-09-04 22:20:12 +02:00
#include "cpu.h"
2022-09-19 21:31:50 +02:00
#include "common/sysctl.h"
2022-09-04 14:12:04 -07:00
static double getFrequency(const char* propName)
{
2022-09-19 21:31:50 +02:00
double herz = (double) ffSysctlGetInt64(propName, 0);
2022-09-04 14:12:04 -07:00
if(herz <= 0.0)
return herz;
herz /= 1000.0; //to KHz
herz /= 1000.0; //to MHz
return herz / 1000.0; //to GHz
}
2022-09-04 22:20:12 +02:00
2022-09-21 17:26:10 +02:00
void ffDetectCPUImpl(FFCPUResult* cpu, bool cached)
2022-09-04 22:20:12 +02:00
{
2022-09-21 17:26:10 +02:00
//TODO find a way to detect this
cpu->temperature = FF_CPU_TEMP_UNSET;
if(cached)
return;
2022-09-04 14:12:04 -07:00
2022-09-21 17:26:10 +02:00
ffSysctlGetString("machdep.cpu.brand_string", &cpu->name);
2022-09-19 21:31:50 +02:00
ffSysctlGetString("machdep.cpu.vendor", &cpu->vendor);
2022-09-04 14:12:04 -07:00
2022-09-19 21:31:50 +02:00
cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.physicalcpu_max", 1);
2022-09-04 14:12:04 -07:00
if(cpu->coresPhysical == 1)
2022-09-19 21:31:50 +02:00
cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.physicalcpu", 1);
2022-09-04 14:12:04 -07:00
2022-09-19 21:31:50 +02:00
cpu->coresLogical = (uint16_t) ffSysctlGetInt("hw.logicalcpu_max", 1);
2022-09-04 14:12:04 -07:00
if(cpu->coresLogical == 1)
2022-09-19 21:31:50 +02:00
cpu->coresLogical = (uint16_t) ffSysctlGetInt("hw.ncpu", 1);
2022-09-04 22:20:12 +02:00
2022-09-19 21:31:50 +02:00
cpu->coresOnline = (uint16_t) ffSysctlGetInt("hw.logicalcpu", 1);
2022-09-04 14:12:04 -07:00
if(cpu->coresOnline == 1)
2022-09-19 21:31:50 +02:00
cpu->coresOnline = (uint16_t) ffSysctlGetInt("hw.activecpu", 1);
2022-09-04 22:20:12 +02:00
2022-09-04 14:12:04 -07:00
cpu->frequencyMin = getFrequency("hw.cpufrequency_min");
cpu->frequencyMax = getFrequency("hw.cpufrequency_max");
if(cpu->frequencyMax == 0.0)
cpu->frequencyMax = getFrequency("hw.cpufrequency");
2022-09-04 22:20:12 +02:00
}