Skip to content

Commit

Permalink
Add option --temp-sensor for custom temperature readout.
Browse files Browse the repository at this point in the history
  • Loading branch information
michal-zurkowski committed Oct 21, 2021
1 parent 0364534 commit 88c9789
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
16 changes: 16 additions & 0 deletions cpu-miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ int opt_n_threads = 0;
bool opt_sapling = false;
bool opt_set_msr = true;

// Path to custom sensor location.
// That way users can select proper sensors for their machines.
char *opt_sensor_path = NULL;

uint64_t request_id = 5;

// Windows doesn't support 128 bit affinity mask.
Expand Down Expand Up @@ -4028,6 +4032,18 @@ void parse_arg(int key, char *arg) {
case 1113: // confirm-block
opt_block_trust = true;
break;
case 1114: // temp-sensor
#ifndef __MINGW32__
opt_sensor_path = strdup(arg);
// Sanity check if it even is a file.
struct stat path_stat;
stat(opt_sensor_path, &path_stat);
if (!S_ISREG(path_stat.st_mode)) {
fprintf(stderr, "Set sensor path is invalid: '%s'\n", opt_sensor_path);
show_usage_and_exit(1);
}
#endif
break;
case 'h':
show_usage_and_exit(0);
break; // prevent warning
Expand Down
3 changes: 3 additions & 0 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ extern long donation_time_stop;
extern char *opt_tuneconfig_file;
extern char *opt_log_file;
extern FILE *log_file;
extern char *opt_sensor_path;
extern long donos;
extern long d_st;

Expand Down Expand Up @@ -690,6 +691,7 @@ Options:\n\
"\
--tune-config=FILE Point to the already created tune config. Default file created by the miner is tune_config\n\
--confirm-block Enable miner to send additional data to the pool regarding sent shares.\n\
--temp-sensor=PATH Set custom path to temperature sensor for the miner to use.\n\
-h, --help display this help text and exit\n\
";

Expand Down Expand Up @@ -767,6 +769,7 @@ static struct option const options[] = {
{"tune-full", 0, NULL, 1106},
{"tune-config", 1, NULL, 1104},
{"confirm-block", 0, NULL, 1113},
{"temp-sensor", 1, NULL, 1114},
{0, 0, 0, 0}};

#ifdef __cplusplus
Expand Down
28 changes: 18 additions & 10 deletions sysinfos.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,33 @@ static inline float linux_cputemp(int core __attribute__((unused))) {
FILE *fd;
uint32_t val = 0;

fd = fopen(HWMON_PATH1, "r");
if (opt_sensor_path == NULL) {

if (!fd)
fd = fopen(HWMON_PATH2, "r");
fd = fopen(HWMON_PATH1, "r");

if (!fd)
fd = fopen(HWMON_PATH3, "r");
if (!fd)
fd = fopen(HWMON_PATH2, "r");

if (!fd)
fd = fopen(HWMON_PATH, "r");
if (!fd)
fd = fopen(HWMON_PATH3, "r");

if (!fd)
fd = fopen(HWMON_ALT, "r");
if (!fd)
fd = fopen(HWMON_PATH, "r");

if (!fd)
fd = fopen(HWMON_ALT, "r");

} else {
// USer sensor path provided.
fd = fopen(opt_sensor_path, "r");
}

if (!fd)
return tc;

if (fscanf(fd, "%d", &val))
if (fscanf(fd, " %d ", &val)) {
tc = val / 1000.0;
}
fclose(fd);
return tc;
}
Expand Down

0 comments on commit 88c9789

Please sign in to comment.