Skip to content

Commit

Permalink
Temps (macOS): support Apple M3
Browse files Browse the repository at this point in the history
  • Loading branch information
CarterLi committed Dec 8, 2023
1 parent 4925222 commit f20b6d4
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Features:
* Improve performance of detecting rpm and pkg package count (Packages, Linux / FreeBSD)
* Support Apple M3X temperature detection (CPU / GPU, macOS)

# 2.3.4

Expand Down
14 changes: 10 additions & 4 deletions src/detection/cpu/cpu_apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ static double detectCpuTemp(const FFstrbuf* cpuName)
double result = 0;

const char* error = NULL;
if(ffStrbufStartsWithS(cpuName, "Apple M1"))
error = ffDetectCoreTemps(FF_TEMP_CPU_M1X, &result);
else if(ffStrbufStartsWithS(cpuName, "Apple M2"))
error = ffDetectCoreTemps(FF_TEMP_CPU_M2X, &result);
if (ffStrbufStartsWithS(cpuName, "Apple M"))
{
switch (strtol(cpuName->chars + strlen("Apple M"), NULL, 10))
{
case 1: error = ffDetectCoreTemps(FF_TEMP_CPU_M1X, &result); break;
case 2: error = ffDetectCoreTemps(FF_TEMP_CPU_M2X, &result); break;
case 3: error = ffDetectCoreTemps(FF_TEMP_CPU_M3X, &result); break;
default: error = "Unsupported Apple Silicon CPU";
}
}
else // PPC?
error = ffDetectCoreTemps(FF_TEMP_CPU_X64, &result);

Expand Down
22 changes: 14 additions & 8 deletions src/detection/gpu/gpu_apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,26 @@
static double detectGpuTemp(const FFstrbuf* gpuName)
{
double result = 0;
const char* error;
const char* error = NULL;

if(ffStrbufStartsWithS(gpuName, "Apple M1"))
error = ffDetectCoreTemps(FF_TEMP_GPU_M1X, &result);
else if(ffStrbufStartsWithS(gpuName, "Apple M2"))
error = ffDetectCoreTemps(FF_TEMP_GPU_M2X, &result);
else if(ffStrbufStartsWithS(gpuName, "Intel"))
if (ffStrbufStartsWithS(gpuName, "Apple M"))
{
switch (strtol(gpuName->chars + strlen("Apple M"), NULL, 10))
{
case 1: error = ffDetectCoreTemps(FF_TEMP_GPU_M1X, &result); break;
case 2: error = ffDetectCoreTemps(FF_TEMP_GPU_M2X, &result); break;
case 3: error = ffDetectCoreTemps(FF_TEMP_GPU_M3X, &result); break;
default: error = "Unsupported Apple Silicon GPU";
}
}
else if (ffStrbufStartsWithS(gpuName, "Intel"))
error = ffDetectCoreTemps(FF_TEMP_GPU_INTEL, &result);
else if(ffStrbufStartsWithS(gpuName, "Radeon") || ffStrbufStartsWithS(gpuName, "AMD"))
else if (ffStrbufStartsWithS(gpuName, "Radeon") || ffStrbufStartsWithS(gpuName, "AMD"))
error = ffDetectCoreTemps(FF_TEMP_GPU_AMD, &result);
else
error = ffDetectCoreTemps(FF_TEMP_GPU_UNKNOWN, &result);

if(error)
if (error)
return FF_GPU_TEMP_UNSET;

return result;
Expand Down
36 changes: 35 additions & 1 deletion src/detection/temps/temps_apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,25 @@ const char *ffDetectCoreTemps(enum FFTempType type, double *result)
count += detectTemp(conn, "Tp09", result); // CPU core 8
break;

case FF_TEMP_CPU_M3X:
count += detectTemp(conn, "Te05", result); // CPU efficiency core 1
count += detectTemp(conn, "Te0L", result); // CPU efficiency core 2
count += detectTemp(conn, "Te0P", result); // CPU efficiency core 3
count += detectTemp(conn, "Te0S", result); // CPU efficiency core 4
count += detectTemp(conn, "Tf04", result); // CPU performance core 1
count += detectTemp(conn, "Tf09", result); // CPU performance core 2
count += detectTemp(conn, "Tf0A", result); // CPU performance core 3
count += detectTemp(conn, "Tf0B", result); // CPU performance core 4
count += detectTemp(conn, "Tf0D", result); // CPU performance core 5
count += detectTemp(conn, "Tf0E", result); // CPU performance core 6
count += detectTemp(conn, "Tf44", result); // CPU performance core 7
count += detectTemp(conn, "Tf49", result); // CPU performance core 8
count += detectTemp(conn, "Tf4A", result); // CPU performance core 9
count += detectTemp(conn, "Tf4B", result); // CPU performance core 10
count += detectTemp(conn, "Tf4D", result); // CPU performance core 11
count += detectTemp(conn, "Tf4E", result); // CPU performance core 12
break;

case FF_TEMP_GPU_INTEL:
count += detectTemp(conn, "TCGC", result); // GPU Intel Graphics
goto gpu_unknown;
Expand All @@ -359,12 +378,27 @@ const char *ffDetectCoreTemps(enum FFTempType type, double *result)
count += detectTemp(conn, "Tg0j", result); // GPU 2
break;

case FF_TEMP_GPU_M3X:
count += detectTemp(conn, "Tf14", result); // GPU 1
count += detectTemp(conn, "Tf18", result); // GPU 2
count += detectTemp(conn, "Tf19", result); // GPU 3
count += detectTemp(conn, "Tf1A", result); // GPU 4
count += detectTemp(conn, "Tf24", result); // GPU 5
count += detectTemp(conn, "Tf28", result); // GPU 6
count += detectTemp(conn, "Tf29", result); // GPU 7
count += detectTemp(conn, "Tf2A", result); // GPU 8
break;

case FF_TEMP_BATTERY:
count += detectTemp(conn, "TB1T", result); // Battery
count += detectTemp(conn, "TB2T", result); // Battery
break;

case FF_TEMP_MEMORY:
count += detectTemp(conn, "Tm02", result); // Memory
count += detectTemp(conn, "Tm02", result); // Memory 1
count += detectTemp(conn, "Tm06", result); // Memory 2
count += detectTemp(conn, "Tm08", result); // Memory 3
count += detectTemp(conn, "Tm09", result); // Memory 4
break;
}

Expand Down
2 changes: 2 additions & 0 deletions src/detection/temps/temps_apple.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ enum FFTempType
FF_TEMP_CPU_X64,
FF_TEMP_CPU_M1X,
FF_TEMP_CPU_M2X,
FF_TEMP_CPU_M3X,

FF_TEMP_GPU_INTEL,
FF_TEMP_GPU_AMD,
FF_TEMP_GPU_UNKNOWN,
FF_TEMP_GPU_M1X,
FF_TEMP_GPU_M2X,
FF_TEMP_GPU_M3X,

FF_TEMP_BATTERY,

Expand Down

0 comments on commit f20b6d4

Please sign in to comment.