Skip to content

Commit 968133e

Browse files
Ati Sharmagaul
authored andcommitted
Add support for many processors (not just cores)
* Add support for many processors (not just cores) Add an outer loop in mbpfan.c:retrieve_sensors to loop over all coretemp directories. Also increase hard-coded limits from 10 to 12 or 16 since the temp endpoints are sometimes indexed that high. For example, this is required for supporting a Mac Pro with two processors of 16 cores, requiring /sys/devices/platform/coretemp.0/hwmon/hwmon0/temp{1..12} /sys/devices/platform/coretemp.1/hwmon/hwmon1/temp{1..12} This solves issue #152 "Mac pro with two processors".
1 parent 1716d9d commit 968133e

File tree

2 files changed

+64
-51
lines changed

2 files changed

+64
-51
lines changed

src/mbpfan.c

Lines changed: 62 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Modifications (2012) by Ismail Khatib <ikhatib@gmail.com>
66
* Modifications (2012-present) by Daniel Graziotin <daniel@ineed.coffee> [CURRENT MAINTAINER]
77
* Modifications (2017-present) by Robert Musial <rmusial@fastmail.com>
8+
* Modifications (2018-present) by Ati Sharma <ati.sharma@gmail.com>
89
*
910
* This program is free software: you can redistribute it and/or modify
1011
* it under the terms of the GNU General Public License as published by
@@ -18,7 +19,8 @@
1819
*
1920
*
2021
* Notes:
21-
* Assumes any number of processors and fans (max. 10)
22+
* Assumes any number of processors, cores and fans (max. 6, 16, 12
23+
* as defined in NUM_PROCESSORS, NUM_HWMONS, NUM_TEMP_INPUTS and NUM_FANS)
2224
* It uses only the temperatures from the processors as input.
2325
* Requires coretemp and applesmc kernel modules to be loaded.
2426
* Requires root use
@@ -58,6 +60,12 @@ int low_temp = 63; // try ranges 55-63
5860
int high_temp = 66; // try ranges 58-66
5961
int max_temp = 86; // do not set it > 90
6062

63+
// maximum number of processors etc supported
64+
#define NUM_PROCESSORS 6
65+
#define NUM_HWMONS 12
66+
#define NUM_TEMP_INPUTS 16
67+
#define NUM_FANS 10
68+
6169
int polling_interval = 7;
6270

6371
t_sensors* sensors = NULL;
@@ -102,9 +110,9 @@ bool is_modern_sensors_path()
102110

103111
int counter;
104112

105-
for (counter = 0; counter < 10; counter++) {
113+
for (counter = 0; counter < NUM_HWMONS; counter++) {
106114
int temp;
107-
for (temp = 1; temp < 10; ++temp) {
115+
for (temp = 1; temp < NUM_TEMP_INPUTS; ++temp) {
108116
char *path = smprintf("/sys/devices/platform/coretemp.0/hwmon/hwmon%d/temp%d_input", counter, temp);
109117
int res = access(path, R_OK);
110118
free(path);
@@ -127,6 +135,9 @@ t_sensors *retrieve_sensors()
127135
char *path = NULL;
128136
char *path_begin = NULL;
129137

138+
const char *path_end = "_input";
139+
int sensors_found = 0;
140+
130141
if (!is_modern_sensors_path()) {
131142
if(verbose) {
132143
printf("Using legacy sensor path for kernel < 3.15.0\n");
@@ -148,71 +159,72 @@ t_sensors *retrieve_sensors()
148159
}
149160
}
150161

151-
path_begin = strdup("/sys/devices/platform/coretemp.0/hwmon/hwmon");
162+
// loop over up to 6 processors
163+
int processor;
164+
for (processor = 0; processor < NUM_PROCESSORS; processor++) {
152165

153-
int counter;
154-
for (counter = 0; counter < 10; counter++) {
166+
path_begin = smprintf("/sys/devices/platform/coretemp.%d/hwmon/hwmon", processor);
155167

156-
char hwmon_path[strlen(path_begin)+2];
168+
int counter;
169+
for (counter = 0; counter < NUM_HWMONS; counter++) {
157170

158-
sprintf(hwmon_path, "%s%d", path_begin, counter);
171+
char hwmon_path[strlen(path_begin)+2];
159172

160-
int res = access(hwmon_path, R_OK);
161-
if (res == 0) {
173+
sprintf(hwmon_path, "%s%d", path_begin, counter);
162174

163-
free(path_begin);
164-
path_begin = smprintf("%s/temp", hwmon_path);
175+
int res = access(hwmon_path, R_OK);
176+
if (res == 0) {
165177

166-
if(verbose) {
167-
printf("Found hwmon path at %s\n", path_begin);
178+
free(path_begin);
179+
path_begin = smprintf("%s/temp", hwmon_path);
168180

169-
if(daemonize) {
170-
syslog(LOG_INFO, "Found hwmon path at %s\n", path_begin);
171-
}
181+
if(verbose) {
182+
printf("Found hwmon path at %s\n", path_begin);
172183

173-
}
184+
if(daemonize) {
185+
syslog(LOG_INFO, "Found hwmon path at %s\n", path_begin);
186+
}
174187

175-
break;
176-
}
177-
}
178-
}
188+
}
179189

180-
const char *path_end = "_input";
190+
break;
191+
}
192+
}
181193

182-
int sensors_found = 0;
194+
int core = 0;
195+
for(core = 0; core<NUM_TEMP_INPUTS; core++) {
196+
path = smprintf("%s%d%s", path_begin, core, path_end);
183197

184-
int counter = 0;
185-
for(counter = 0; counter<10; counter++) {
186-
path = smprintf("%s%d%s", path_begin, counter, path_end);
198+
FILE *file = fopen(path, "r");
187199

188-
FILE *file = fopen(path, "r");
200+
if(file != NULL) {
201+
s = (t_sensors *) malloc( sizeof( t_sensors ) );
202+
s->path = strdup(path);
203+
fscanf(file, "%d", &s->temperature);
189204

190-
if(file != NULL) {
191-
s = (t_sensors *) malloc( sizeof( t_sensors ) );
192-
s->path = strdup(path);
193-
fscanf(file, "%d", &s->temperature);
205+
if (sensors_head == NULL) {
206+
sensors_head = s;
207+
sensors_head->next = NULL;
194208

195-
if (sensors_head == NULL) {
196-
sensors_head = s;
197-
sensors_head->next = NULL;
209+
} else {
210+
t_sensors *tmp = sensors_head;
198211

199-
} else {
200-
t_sensors *tmp = sensors_head;
201-
202-
while (tmp->next != NULL) {
203-
tmp = tmp->next;
204-
}
212+
while (tmp->next != NULL) {
213+
tmp = tmp->next;
214+
}
205215

206-
tmp->next = s;
207-
tmp->next->next = NULL;
208-
}
216+
tmp->next = s;
217+
tmp->next->next = NULL;
218+
}
209219

210-
s->file = file;
211-
sensors_found++;
212-
}
220+
s->file = file;
221+
sensors_found++;
222+
}
213223

214-
free(path);
215-
path = NULL;
224+
free(path);
225+
path = NULL;
226+
}
227+
}
216228
}
217229

218230
if(verbose) {
@@ -252,7 +264,7 @@ t_fans *retrieve_fans()
252264
int counter = 0;
253265
int fans_found = 0;
254266

255-
for(counter = 0; counter<10; counter++) {
267+
for(counter = 0; counter<NUM_FANS; counter++) {
256268

257269
path_output = smprintf("%s%d%s", path_begin, counter, path_output_end);
258270
path_manual = smprintf("%s%d%s", path_begin, counter, path_man_end);

src/mbpfan.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ void retrieve_settings(const char* settings_path);
5959

6060
/**
6161
* Detect the sensors in /sys/devices/platform/coretemp.0/temp
62+
* and /sys/devices/platform/coretemp.1/temp etc
6263
* Return a linked list of t_sensors (first temperature detected)
6364
*/
6465
t_sensors *retrieve_sensors();
@@ -103,4 +104,4 @@ unsigned short get_temp(t_sensors* sensors);
103104
*/
104105
void mbpfan();
105106

106-
#endif
107+
#endif

0 commit comments

Comments
 (0)