Added the ability to read some CPU and other temperature sensors.
This commit is contained in:
+87
-14
@@ -15,8 +15,10 @@
|
||||
|
||||
#include "icx3.h"
|
||||
#include "evga-card.h"
|
||||
#include "board-sensors.h"
|
||||
|
||||
#define MAX_GPUS 16
|
||||
#define MAX_BOARD_SENSORS 256
|
||||
#define HEADER_COLOR_START "\x1b[36m"
|
||||
#define HEADER_COLOR_END "\x1b[39m"
|
||||
|
||||
@@ -38,21 +40,25 @@ static const char helpstring[] = "Available options:\n"
|
||||
"--watch N : Keep printing output every N seconds\n"
|
||||
"--overwrite : Overwrite previously displayed info with --watch and --compact instead of continuously logging\n"
|
||||
"--color : Print headers in color in --compact mode for better readability\n"
|
||||
"--no-reasons : Do not query NVML for clocks reasons (can cause stuttering)\n";
|
||||
"--no-reasons : Do not query NVML for clock reasons (can cause stuttering)\n"
|
||||
"--board : Also print temperatures from the CPU, motherboard, and other sensors";
|
||||
|
||||
void print_gpu_info(int gpu_num, struct card_info gpus[], int compact, int no_reasons);
|
||||
void print_board_info(struct hwmon_avail_sensor *board_sensors, int num_sensors, int compact);
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
struct card_info gpus[MAX_GPUS];
|
||||
int gpu_count;
|
||||
struct hwmon_avail_sensor board_sensors[MAX_BOARD_SENSORS];
|
||||
int gpu_count, board_sensor_count;
|
||||
int print_info = 0;
|
||||
int compact = 0;
|
||||
int gpu_num = -1; /* Card to control */
|
||||
int i2c_bus = -1;
|
||||
int overwrite = 0;
|
||||
int no_reasons = 0;
|
||||
unsigned int watch = 0;
|
||||
int compact = 0;
|
||||
int gpu_num = -1; /* Card to control */
|
||||
int i2c_bus = -1; /* Specific i2c bus to probe instead of all */
|
||||
int overwrite = 0; /* Overwrite printed console info in compact mode */
|
||||
int no_reasons = 0; /* Don't probe or display NVML clock reasons */
|
||||
unsigned int watch = 0; /* Refresh display every this many seconds */
|
||||
int print_board_sensors = 0; /* Print CPU/motherbord/other sensors as well */
|
||||
char *fan_speed[ICX3_MAX_FANS] = {NULL};
|
||||
|
||||
/* Input parsing */
|
||||
@@ -114,6 +120,8 @@ int main (int argc, char **argv)
|
||||
header_end = HEADER_COLOR_END;
|
||||
} else if (strcmp(argv[i], "--no-reasons") == 0) {
|
||||
no_reasons = 1;
|
||||
} else if (strcmp(argv[i], "--board") == 0) {
|
||||
print_board_sensors = 1;
|
||||
} else {
|
||||
printf(helpstring);
|
||||
return 0;
|
||||
@@ -133,8 +141,10 @@ int main (int argc, char **argv)
|
||||
if (overwrite && !compact)
|
||||
overwrite = 0;
|
||||
|
||||
/* Scan for supported GPUs */
|
||||
gpu_count = find_evga_gpu_i2cs(gpus, MAX_GPUS, i2c_bus);
|
||||
|
||||
/* Check for no GPUs found or other errors */
|
||||
if (gpu_count == -1) {
|
||||
printf("Error scanning I2C devices\n");
|
||||
return -1;
|
||||
@@ -142,12 +152,15 @@ int main (int argc, char **argv)
|
||||
printf("No supported GPUs found.\nAre you root or do you have udev access to i2c devices?\nDo you need to run `modprobe i2c-dev`?\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Check for invalid GPUs */
|
||||
if (gpu_num > gpu_count - 1) {
|
||||
printf("Invalid GPU number specified (%d, max %d)\n", gpu_num, gpu_count - 1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Scan for motherboard/CPU/other sensors */
|
||||
if (print_board_sensors)
|
||||
board_sensor_count = find_board_sensors(board_sensors, MAX_BOARD_SENSORS);
|
||||
|
||||
/* execute fan commands */
|
||||
if (gpu_num == -1) {
|
||||
@@ -183,6 +196,9 @@ int main (int argc, char **argv)
|
||||
if (overwrite)
|
||||
printf("\x1b[K"); /* Clear current console line */
|
||||
|
||||
if (print_board_sensors)
|
||||
print_board_info(board_sensors, board_sensor_count, compact);
|
||||
|
||||
if (gpu_num == -1) {
|
||||
/* No GPU specified on command line, loop over all supported GPUs */
|
||||
for (int i = 0; i < gpu_count; i++){
|
||||
@@ -199,8 +215,8 @@ int main (int argc, char **argv)
|
||||
|
||||
if (overwrite && compact) {
|
||||
printf("\x1b[1G"); /* Move cursor back to column 1 */
|
||||
if (gpu_count > 1)
|
||||
printf("\x1b[%dA", gpu_count-1); /* Move cursor back up to the top of gpu list */
|
||||
if (gpu_count > 1 || print_board_sensors)
|
||||
printf("\x1b[%dA", gpu_count-1+print_board_sensors); /* Move cursor back up to the top of gpu list */
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
@@ -213,7 +229,64 @@ int main (int argc, char **argv)
|
||||
#endif
|
||||
}
|
||||
|
||||
void print_gpu_info(int gpu_num, struct card_info *gpu, int compact, int no_reasons) {
|
||||
void print_board_info(struct hwmon_avail_sensor *board_sensors, int num_sensors, int compact)
|
||||
{
|
||||
int printed_sensors = 0;
|
||||
int current_sort_index = 0;
|
||||
float current_reading = 0.0;
|
||||
int good_reading = 0;
|
||||
/* These allow us to 'summarize' units and categories by only printing them when they change */
|
||||
char *last_short_name = NULL;
|
||||
char *last_units = NULL;
|
||||
|
||||
while (printed_sensors < num_sensors) {
|
||||
for (int i=0; i < num_sensors; i++){
|
||||
/* Loop over all sensors, but only output those with the current sort index so they come out sort of sorted
|
||||
Duplicates (e.g.) multiple NVMe will come out in whatever sort of order the directory listing happened to */
|
||||
if (board_sensors[i].sort_index == current_sort_index) {
|
||||
printed_sensors++;
|
||||
good_reading = get_sensor_reading(&board_sensors[i], ¤t_reading);
|
||||
|
||||
if (!good_reading)
|
||||
continue;
|
||||
|
||||
if (compact) {
|
||||
/* Print units if needed */
|
||||
if (last_units != NULL && strcmp(board_sensors[i].sensor_info->units, last_units))
|
||||
printf("%s", last_units);
|
||||
|
||||
/* Print new section header if needed */
|
||||
if (last_short_name == NULL || strcmp(board_sensors[i].sensor_info->short_name, last_short_name)) {
|
||||
if (last_short_name != NULL) /* Spacer for all headings not the first one */
|
||||
printf(" ");
|
||||
printf("%s%s%s", header_start, board_sensors[i].sensor_info->short_name, header_end);
|
||||
}
|
||||
printf(" %3.0f", current_reading);
|
||||
|
||||
last_short_name = board_sensors[i].sensor_info->short_name;
|
||||
last_units = board_sensors[i].sensor_info->units;
|
||||
|
||||
} else {
|
||||
printf("%s%s: %+.1f%s\n",
|
||||
board_sensors[i].sensor_info->name_prefix,
|
||||
board_sensors[i].sensor_name,
|
||||
current_reading,
|
||||
board_sensors[i].sensor_info->units);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
current_sort_index++;
|
||||
}
|
||||
|
||||
if (compact && last_units != NULL)
|
||||
printf("%s", last_units);
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void print_gpu_info(int gpu_num, struct card_info *gpu, int compact, int no_reasons)
|
||||
{
|
||||
if (compact) {
|
||||
/* One line per GPU */
|
||||
printf("%s#%d FAN%s", header_start, gpu_num, header_end);
|
||||
@@ -268,8 +341,8 @@ void print_gpu_info(int gpu_num, struct card_info *gpu, int compact, int no_reas
|
||||
printf("VRAM: +%.0f°C\n", get_vram_temp(gpu)); /* Print the VRAM temp before the rest of the memory sensors */
|
||||
#endif
|
||||
printf("%s: %+.1f°C\n",
|
||||
icx3_temp_sensor_names[i],
|
||||
icx_temp_sensors[i]);
|
||||
icx3_temp_sensor_names[i],
|
||||
icx_temp_sensors[i]);
|
||||
}
|
||||
|
||||
#ifdef USE_LIBPCI
|
||||
|
||||
Reference in New Issue
Block a user