make it more or less work with 'warning_level=everything'
This commit is contained in:
@@ -3,8 +3,8 @@
|
|||||||
|
|
||||||
#include <libusb-1.0/libusb.h>
|
#include <libusb-1.0/libusb.h>
|
||||||
|
|
||||||
#define AIO_USB_VID 0x1b1c
|
#define AIO_USB_VID 0x1b1cU
|
||||||
#define AIO_USB_PID 0x0c13
|
#define AIO_USB_PID 0x0c13U
|
||||||
|
|
||||||
#define AIO_COLOR_CYAN { 0, 255, 255 }
|
#define AIO_COLOR_CYAN { 0, 255, 255 }
|
||||||
#define AIO_COLOR_WHITE { 255, 255, 255 }
|
#define AIO_COLOR_WHITE { 255, 255, 255 }
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
// roughly converts fan speed to duty
|
// roughly converts fan speed to duty
|
||||||
#define SPD2DTY(spd) MAX(0, MIN(spd * 100 / max_fan_speed, 100))
|
#define SPD2DTY(spd) MAX(0, MIN(spd * 100 / max_fan_speed, 100))
|
||||||
|
|
||||||
enum aio_pump_mode_t : uint8_t {
|
enum aio_pump_mode_t {
|
||||||
QUIET,
|
QUIET,
|
||||||
BALANCED,
|
BALANCED,
|
||||||
EXTREME
|
EXTREME
|
||||||
@@ -48,6 +48,7 @@ struct aio_t {
|
|||||||
float t_b;
|
float t_b;
|
||||||
uint16_t pump_speed;
|
uint16_t pump_speed;
|
||||||
uint16_t fan_speed[2];
|
uint16_t fan_speed[2];
|
||||||
|
uint8_t _padding[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
void aio_detect(struct aio_t *aio, float t_quiet, float t_balanced);
|
void aio_detect(struct aio_t *aio, float t_quiet, float t_balanced);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ struct cpu_sensors_t {
|
|||||||
int16_t tdie;
|
int16_t tdie;
|
||||||
int16_t tctl;
|
int16_t tctl;
|
||||||
int16_t tccd1;
|
int16_t tccd1;
|
||||||
// double pcore;
|
double pcore;
|
||||||
// double psoc;
|
// double psoc;
|
||||||
float ptotal;
|
float ptotal;
|
||||||
// double vcore;
|
// double vcore;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
struct time_date_t {
|
struct time_date_t {
|
||||||
char date[12];
|
char date[12];
|
||||||
char time[9];
|
char time[12];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct memory_t {
|
struct memory_t {
|
||||||
@@ -26,9 +26,10 @@ struct network_t {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct syssensors_t {
|
struct syssensors_t {
|
||||||
|
char hwmon[64];
|
||||||
// uint16_t fan_speed[1]; // just one fan (pump) we monitor
|
// uint16_t fan_speed[1]; // just one fan (pump) we monitor
|
||||||
int16_t t_sensor; // ntc temp sensor
|
int16_t t_sensor; // ntc temp sensor
|
||||||
char hwmon[64];
|
uint8_t _padding[6];
|
||||||
};
|
};
|
||||||
|
|
||||||
void sys_get_time(struct time_date_t *td);
|
void sys_get_time(struct time_date_t *td);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||||
#define P_BYTES(bytes, start) pretty_bytes((bytes), (start), (char[16]){0}, 16)
|
#define P_BYTES(bytes, start) pretty_bytes((bytes), (start), (char[16]){0}, 16)
|
||||||
#define P_NUM(num) pretty_num((num), (char[8]){0}, 8)
|
#define P_NUM(num) pretty_num((num), (char[16]){0}, 16)
|
||||||
|
|
||||||
int get_instance_lock(void);
|
int get_instance_lock(void);
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ project(
|
|||||||
default_options : [
|
default_options : [
|
||||||
'prefix=/home/drath/.local',
|
'prefix=/home/drath/.local',
|
||||||
'c_std=c23',
|
'c_std=c23',
|
||||||
'warning_level=3', # -> -Wall -Wextra -Wpedantic, also try =everything
|
'warning_level=everything', # -> -Wall -Wextra -Wpedantic, also try =everything
|
||||||
'werror=true', # -> -Werror
|
'werror=true', # -> -Werror
|
||||||
'buildtype=release', # -> -O3, no debug
|
'buildtype=release', # -> -O3, no debug
|
||||||
],
|
],
|
||||||
@@ -32,6 +32,12 @@ executable(
|
|||||||
c_args : [
|
c_args : [
|
||||||
'-D_GNU_SOURCE',
|
'-D_GNU_SOURCE',
|
||||||
'-D_POSIX_C_SOURCE=200809L',
|
'-D_POSIX_C_SOURCE=200809L',
|
||||||
|
'-Wno-c++-compat',
|
||||||
|
'-Wno-format-truncation',
|
||||||
|
'-Wno-conversion',
|
||||||
|
'-Wno-arith-conversion',
|
||||||
|
'-Wno-cast-align', # casting char array to gpu_metrics
|
||||||
|
'-Wno-padded'
|
||||||
],
|
],
|
||||||
install : true,
|
install : true,
|
||||||
)
|
)
|
||||||
@@ -37,7 +37,8 @@ void cpu_update(struct cpu_sensors_t *c) {
|
|||||||
clock_gettime(CLOCK_MONOTONIC, &curr.ts);
|
clock_gettime(CLOCK_MONOTONIC, &curr.ts);
|
||||||
fast_read_num_u64("/sys/class/powercap/intel-rapl:0/", "energy_uj", buf, &curr.energy, 1);
|
fast_read_num_u64("/sys/class/powercap/intel-rapl:0/", "energy_uj", buf, &curr.energy, 1);
|
||||||
|
|
||||||
c->ptotal = (float)(curr.energy - prev.energy) / (float)timespec_diff_us(&curr.ts, &prev.ts);
|
const uint64_t tdiff_us = timespec_diff_us(&curr.ts, &prev.ts);
|
||||||
|
c->ptotal = (float)(curr.energy - prev.energy) / (float)tdiff_us;
|
||||||
prev = curr;
|
prev = curr;
|
||||||
if (c->ptotal > 500.0f || c->ptotal < 0.0f)
|
if (c->ptotal > 500.0f || c->ptotal < 0.0f)
|
||||||
c->ptotal = 0.0f;
|
c->ptotal = 0.0f;
|
||||||
|
|||||||
@@ -9,6 +9,10 @@
|
|||||||
constexpr char rel_metrics_path[] = "/../../gpu_metrics"; // gpu_metrics path relative to hwmon path
|
constexpr char rel_metrics_path[] = "/../../gpu_metrics"; // gpu_metrics path relative to hwmon path
|
||||||
constexpr uint16_t max_metrics_length = 512; // length of the metrics buffer
|
constexpr uint16_t max_metrics_length = 512; // length of the metrics buffer
|
||||||
|
|
||||||
|
void fill_missing_metrics(struct gpu_sensors_t *g);
|
||||||
|
void update_from_fs(struct gpu_sensors_t *g);
|
||||||
|
void update_from_metrics(struct gpu_sensors_t *g);
|
||||||
|
|
||||||
void gpu_detect(struct gpu_sensors_t *t, const char *pci) {
|
void gpu_detect(struct gpu_sensors_t *t, const char *pci) {
|
||||||
snprintf(t->hwmon, sizeof(t->hwmon), "/sys/bus/pci/devices/%s/hwmon", pci);
|
snprintf(t->hwmon, sizeof(t->hwmon), "/sys/bus/pci/devices/%s/hwmon", pci);
|
||||||
const int ret = get_hwmon_dir(t->hwmon, sizeof(t->hwmon));
|
const int ret = get_hwmon_dir(t->hwmon, sizeof(t->hwmon));
|
||||||
@@ -60,7 +64,7 @@ void update_from_metrics(struct gpu_sensors_t *g) {
|
|||||||
|
|
||||||
switch (header->format_revision * 10 + header->content_revision) {
|
switch (header->format_revision * 10 + header->content_revision) {
|
||||||
|
|
||||||
/* rx5700xt, rx7800xtx rx9070xt */
|
/* rx5700xt, rx7800xt, rx9070xt */
|
||||||
case 13: {
|
case 13: {
|
||||||
const struct gpu_metrics_v1_3 *metrics = (struct gpu_metrics_v1_3 *)raw_metrics;
|
const struct gpu_metrics_v1_3 *metrics = (struct gpu_metrics_v1_3 *)raw_metrics;
|
||||||
g->usage_core = metrics->average_gfx_activity;
|
g->usage_core = metrics->average_gfx_activity;
|
||||||
|
|||||||
@@ -10,6 +10,9 @@
|
|||||||
|
|
||||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||||
|
|
||||||
|
int lcd_open(struct lcd_t *lcd, bool reopen);
|
||||||
|
void lcd_write(struct lcd_t *lcd, const uint8_t *cmdbuf, uint16_t len);
|
||||||
|
|
||||||
int lcd_open(struct lcd_t *lcd, const bool reopen) {
|
int lcd_open(struct lcd_t *lcd, const bool reopen) {
|
||||||
applog(LOG_INF, "Opening serial port at %s", lcd->port);
|
applog(LOG_INF, "Opening serial port at %s", lcd->port);
|
||||||
if (lcd->fd <= 0 || reopen)
|
if (lcd->fd <= 0 || reopen)
|
||||||
@@ -55,7 +58,7 @@ void lcd_set_backlight(struct lcd_t *lcd, const bool enabled) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void lcd_set_cursor(struct lcd_t *lcd, const uint8_t row, const uint8_t col) {
|
void lcd_set_cursor(struct lcd_t *lcd, const uint8_t row, const uint8_t col) {
|
||||||
const uint8_t cmdbuf[] = {254, 71, (col + 1), (row + 1)};
|
const uint8_t cmdbuf[] = {254, 71, col + 1, row + 1};
|
||||||
lcd_write(lcd, cmdbuf, sizeof(cmdbuf));
|
lcd_write(lcd, cmdbuf, sizeof(cmdbuf));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,13 +87,13 @@ void lcd_writef(struct lcd_t *lcd, const uint8_t x, const uint8_t y, const char
|
|||||||
char tmp[LCD_COLS + 1];
|
char tmp[LCD_COLS + 1];
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
uint8_t len = vsnprintf(tmp, sizeof(tmp), fmt, ap); // print fmt and ap to a temporary buffer
|
int len = vsnprintf(tmp, sizeof(tmp), fmt, ap); // print fmt and ap to a temporary buffer
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
len = MIN(len, LCD_COLS - x);
|
len = MIN(len, LCD_COLS - x);
|
||||||
int pos = 4 + x + (LCD_COLS * (y % 2)); // skip 4 bytes to leave room for set cursor command
|
int pos = 4 + x + (LCD_COLS * (y % 2)); // skip 4 bytes to leave room for set cursor command
|
||||||
if (y >= 2)
|
if (y >= 2)
|
||||||
pos += 2 * LCD_COLS + 4; // if we're writing to disp2, skip another 4 bytes for set cursor command and 2*40 bytes of disp 1
|
pos += 2 * LCD_COLS + 4; // if we're writing to disp2, skip another 4 bytes for set cursor command and 2*40 bytes of disp 1
|
||||||
memcpy(lcd->writebuf.text + pos, tmp, len); // copy to lcd writebuffer address + whatever pos is
|
memcpy(lcd->writebuf.text + pos, tmp, (size_t)len); // copy to lcd writebuffer address + whatever pos is
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void lcd_clear_buf(struct lcd_t *lcd) {
|
inline void lcd_clear_buf(struct lcd_t *lcd) {
|
||||||
|
|||||||
15
src/main.c
15
src/main.c
@@ -22,13 +22,13 @@ static constexpr char cpu_pcidev[] = "0000:00:18.3";
|
|||||||
static constexpr char gpu_pcidev[] = "0000:0a:00.0";
|
static constexpr char gpu_pcidev[] = "0000:0a:00.0";
|
||||||
|
|
||||||
struct control_t {
|
struct control_t {
|
||||||
atomic_bool g_running;
|
|
||||||
pthread_mutex_t sensors_mtx;
|
pthread_mutex_t sensors_mtx;
|
||||||
pthread_cond_t sensors_ready;
|
pthread_cond_t sensors_ready;
|
||||||
|
atomic_bool g_running;
|
||||||
|
uint8_t _padding[7];
|
||||||
} control;
|
} control;
|
||||||
|
|
||||||
struct sensors_t { // NOLINT yes it is
|
struct sensors_t { // NOLINT yes it is
|
||||||
struct time_date_t td;
|
|
||||||
struct memory_t ram;
|
struct memory_t ram;
|
||||||
struct disk_t home;
|
struct disk_t home;
|
||||||
struct disk_t gry;
|
struct disk_t gry;
|
||||||
@@ -37,6 +37,7 @@ struct sensors_t { // NOLINT yes it is
|
|||||||
struct cpu_sensors_t cpu;
|
struct cpu_sensors_t cpu;
|
||||||
struct gpu_sensors_t gpu;
|
struct gpu_sensors_t gpu;
|
||||||
struct aio_t aio;
|
struct aio_t aio;
|
||||||
|
struct time_date_t td;
|
||||||
double loadavg[3];
|
double loadavg[3];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -139,23 +140,23 @@ static void *display_thread(void *arg) {
|
|||||||
|
|
||||||
lcd_writef(&lcd, 0, 1, "%d/%d%c", sensors->cpu.tctl, sensors->cpu.tccd1, 0);
|
lcd_writef(&lcd, 0, 1, "%d/%d%c", sensors->cpu.tctl, sensors->cpu.tccd1, 0);
|
||||||
lcd_writef(&lcd, 7, 1, "%s", P_BYTES(sensors->ram.used, 0));
|
lcd_writef(&lcd, 7, 1, "%s", P_BYTES(sensors->ram.used, 0));
|
||||||
lcd_writef(&lcd, 13, 1, "%.1f%c", sensors->aio.water_temp, 0);
|
lcd_writef(&lcd, 13, 1, "%.1f%c", (double)sensors->aio.water_temp, 0);
|
||||||
lcd_writef(&lcd, 18, 1, "%3d%c", sensors->sys.t_sensor, 0);
|
lcd_writef(&lcd, 18, 1, "%3d%c", sensors->sys.t_sensor, 0);
|
||||||
lcd_writef(&lcd, 28, 1, "%4s%c", gpudelta, 0);
|
lcd_writef(&lcd, 28, 1, "%4s%c", gpudelta, 0);
|
||||||
lcd_writef(&lcd, 25 - gpu_pos, 1, "%6s", P_BYTES(sensors->gpu.vram_used, 1));
|
lcd_writef(&lcd, 25 - gpu_pos, 1, "%6s", P_BYTES(sensors->gpu.vram_used, 1));
|
||||||
lcd_writef(&lcd, 34, 1, "%d/%d%c", sensors->gpu.temp_edge, sensors->gpu.temp_hotspot, 0);
|
lcd_writef(&lcd, 34, 1, "%d/%d%c", sensors->gpu.temp_edge, sensors->gpu.temp_hotspot, 0);
|
||||||
|
|
||||||
lcd_writef(&lcd, 0, 2, "%.0fW", sensors->cpu.ptotal);
|
lcd_writef(&lcd, 0, 2, "%.0fW", (double)sensors->cpu.ptotal);
|
||||||
lcd_writef(&lcd, 5, 2, "%dR", avg_fan_speed);
|
lcd_writef(&lcd, 5, 2, "%dR", avg_fan_speed);
|
||||||
lcd_writef(&lcd, 12, 2, "%5s%c", P_BYTES(sensors->net.upload, 1), 3);
|
lcd_writef(&lcd, 12, 2, "%5s%c", P_BYTES(sensors->net.upload, 1), 3);
|
||||||
lcd_writef(&lcd, 19, 2, "%c%s", 4, P_BYTES(sensors->net.download, 1));
|
lcd_writef(&lcd, 19, 2, "%c%s", 4, P_BYTES(sensors->net.download, 1));
|
||||||
lcd_writef(&lcd, 26, 2, "%4dR", sensors->gpu.fan_speed);
|
lcd_writef(&lcd, 26, 2, "%4dR", sensors->gpu.fan_speed);
|
||||||
lcd_writef(&lcd, 32, 2, "%3d/%3dW", sensors->gpu.power_avg, sensors->gpu.power_cap);
|
lcd_writef(&lcd, 32, 2, "%3d/%3dW", sensors->gpu.power_avg, sensors->gpu.power_cap);
|
||||||
|
|
||||||
lcd_writef(&lcd, 0, 3, "%dMHz", sensors->cpu.avg_freq);
|
lcd_writef(&lcd, 0, 3, "%uMHz", sensors->cpu.avg_freq);
|
||||||
lcd_writef(&lcd, 8, 3, "%4dR-%c", sensors->aio.pump_speed, modes[sensors->aio.pump_mode]);
|
lcd_writef(&lcd, 8, 3, "%4dR-%c", sensors->aio.pump_speed, modes[sensors->aio.pump_mode]);
|
||||||
lcd_writef(&lcd, 21, 3, "%12s", gpuclock);
|
lcd_writef(&lcd, 21, 3, "%12s", gpuclock);
|
||||||
lcd_writef(&lcd, 34, 3, "%.3fV", sensors->gpu.vcore);
|
lcd_writef(&lcd, 34, 3, "%.3fV", (double)sensors->gpu.vcore);
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&control.sensors_mtx); // unlock sensor struct
|
pthread_mutex_unlock(&control.sensors_mtx); // unlock sensor struct
|
||||||
@@ -173,7 +174,7 @@ static void *display_thread(void *arg) {
|
|||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
applog(LOG_START, "linuxSmartie starting");
|
applog(LOG_START, "linuxSmartie starting");
|
||||||
applog(LOG_DBG, "Compiled on %s %s with %s", __DATE__, __TIME__, C_STD);
|
applog(LOG_DBG, "Compiled with %s", C_STD);
|
||||||
|
|
||||||
/* see if another instance is up, quit if it is */
|
/* see if another instance is up, quit if it is */
|
||||||
if (get_instance_lock() < 0)
|
if (get_instance_lock() < 0)
|
||||||
|
|||||||
@@ -63,7 +63,8 @@ void sys_get_network(struct network_t *network) {
|
|||||||
clock_gettime(CLOCK_MONOTONIC, ¤t.ts);
|
clock_gettime(CLOCK_MONOTONIC, ¤t.ts);
|
||||||
fast_read_num_u64(path, "rx_bytes", buf, ¤t.rx, 1);
|
fast_read_num_u64(path, "rx_bytes", buf, ¤t.rx, 1);
|
||||||
fast_read_num_u64(path, "tx_bytes", buf, ¤t.tx, 1);
|
fast_read_num_u64(path, "tx_bytes", buf, ¤t.tx, 1);
|
||||||
const double diff_s = (double)timespec_diff_us(¤t.ts, &prev.ts) / 1000000.0;
|
const uint64_t diff_us = timespec_diff_us(¤t.ts, &prev.ts);
|
||||||
|
const double diff_s = (double)diff_us / 1000000.0;
|
||||||
network->download = (uint32_t)((double)(current.rx - prev.rx) / diff_s);
|
network->download = (uint32_t)((double)(current.rx - prev.rx) / diff_s);
|
||||||
network->upload = (uint32_t)((double)(current.tx - prev.tx) / diff_s);
|
network->upload = (uint32_t)((double)(current.tx - prev.tx) / diff_s);
|
||||||
prev = current;
|
prev = current;
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ inline void timespec_add_ms(struct timespec *ts, const uint16_t ms) {
|
|||||||
inline uint64_t timespec_diff_us(const struct timespec *a, const struct timespec *b) {
|
inline uint64_t timespec_diff_us(const struct timespec *a, const struct timespec *b) {
|
||||||
const int64_t sec = a->tv_sec - b->tv_sec;
|
const int64_t sec = a->tv_sec - b->tv_sec;
|
||||||
const int64_t nsec = a->tv_nsec - b->tv_nsec;
|
const int64_t nsec = a->tv_nsec - b->tv_nsec;
|
||||||
return sec * 1000000LL + nsec / 1000LL;
|
return sec * 1000000ULL + nsec / 1000ULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline char *pretty_num(const double num, char *buf, const size_t bufsz) {
|
inline char *pretty_num(const double num, char *buf, const size_t bufsz) {
|
||||||
@@ -108,12 +108,12 @@ inline void fast_read_num_u64(const char *dir, const char *file, char *buf, uint
|
|||||||
|
|
||||||
inline void fast_read_num_u16(const char *dir, const char *file, char *buf, uint16_t *result, const uint32_t divider) {
|
inline void fast_read_num_u16(const char *dir, const char *file, char *buf, uint16_t *result, const uint32_t divider) {
|
||||||
read_file(dir, file, buf, 32);
|
read_file(dir, file, buf, 32);
|
||||||
*result = strtol(buf, nullptr, 10) / divider;
|
*result = (uint16_t)strtol(buf, nullptr, 10) / divider;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void fast_read_num_u8(const char *dir, const char *file, char *buf, uint8_t *result, const uint32_t divider) {
|
inline void fast_read_num_u8(const char *dir, const char *file, char *buf, uint8_t *result, const uint32_t divider) {
|
||||||
read_file(dir, file, buf, 32);
|
read_file(dir, file, buf, 32);
|
||||||
*result = strtol(buf, nullptr, 10) / divider;
|
*result = (uint8_t)strtol(buf, nullptr, 10) / divider;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void fast_read_num_i16(const char *dir, const char *file, char *buf, int16_t *result, const uint32_t divider) {
|
inline void fast_read_num_i16(const char *dir, const char *file, char *buf, int16_t *result, const uint32_t divider) {
|
||||||
@@ -123,5 +123,6 @@ inline void fast_read_num_i16(const char *dir, const char *file, char *buf, int1
|
|||||||
|
|
||||||
inline void fast_read_num_f(const char *dir, const char *file, char *buf, float *result, const uint32_t divider) {
|
inline void fast_read_num_f(const char *dir, const char *file, char *buf, float *result, const uint32_t divider) {
|
||||||
read_file(dir, file, buf, 32);
|
read_file(dir, file, buf, 32);
|
||||||
*result = (float)strtoull(buf, nullptr, 10) / (float)divider;
|
const uint64_t val = strtoull(buf, nullptr, 10);
|
||||||
|
*result = (float)val / (float)divider;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user