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

61 lines
1.9 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-25 15:23:00 +08:00
#include "detection/temps/temps_apple.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-25 15:23:00 +08:00
static double detectCpuTemp(const FFstrbuf* cpuName)
{
2023-08-07 10:15:08 +08:00
double result = 0;
2022-09-25 15:23:00 +08:00
2023-08-07 10:15:08 +08:00
const char* error = NULL;
2022-09-25 15:23:00 +08:00
if(ffStrbufStartsWithS(cpuName, "Apple M1"))
2023-08-07 10:15:08 +08:00
error = ffDetectCoreTemps(FF_TEMP_CPU_M1X, &result);
2022-09-25 15:23:00 +08:00
else if(ffStrbufStartsWithS(cpuName, "Apple M2"))
2023-08-07 10:15:08 +08:00
error = ffDetectCoreTemps(FF_TEMP_CPU_M2X, &result);
else // PPC?
error = ffDetectCoreTemps(FF_TEMP_CPU_X64, &result);
2022-09-25 15:23:00 +08:00
2023-08-07 10:15:08 +08:00
if(error)
2022-09-25 15:23:00 +08:00
return FF_CPU_TEMP_UNSET;
return result;
}
const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
2022-09-04 22:20:12 +02:00
{
2023-06-12 09:56:03 +08:00
if (ffSysctlGetString("machdep.cpu.brand_string", &cpu->name) != NULL)
return "sysctlbyname(machdep.cpu.brand_string) failed";
2022-12-17 11:39:10 +08:00
ffSysctlGetString("machdep.cpu.vendor", &cpu->vendor);
2022-09-04 14:12:04 -07:00
2022-12-17 11:39:10 +08:00
cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.physicalcpu_max", 1);
if(cpu->coresPhysical == 1)
cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.physicalcpu", 1);
2022-09-04 14:12:04 -07:00
2022-12-17 11:39:10 +08:00
cpu->coresLogical = (uint16_t) ffSysctlGetInt("hw.logicalcpu_max", 1);
if(cpu->coresLogical == 1)
cpu->coresLogical = (uint16_t) ffSysctlGetInt("hw.ncpu", 1);
2022-09-04 14:12:04 -07:00
2022-12-17 11:39:10 +08:00
cpu->coresOnline = (uint16_t) ffSysctlGetInt("hw.logicalcpu", 1);
if(cpu->coresOnline == 1)
cpu->coresOnline = (uint16_t) ffSysctlGetInt("hw.activecpu", 1);
2022-09-04 22:20:12 +02:00
2022-12-17 11:39:10 +08: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
2023-08-07 10:15:08 +08:00
cpu->temperature = options->temp ? detectCpuTemp(&cpu->name) : FF_CPU_TEMP_UNSET;
2023-06-12 09:56:03 +08:00
return NULL;
2022-09-04 22:20:12 +02:00
}