doing sth

This commit is contained in:
2026-05-05 17:49:37 +02:00
parent 6c8739ecd5
commit 110c012587
4 changed files with 81 additions and 0 deletions

27
include/cpu.h Normal file
View File

@@ -0,0 +1,27 @@
#ifndef CPU_H
#define CPU_H
#include <stdint.h>
enum cpu_module_t : uint8_t {
unknown,
k10temp,
zenpower
};
struct cpu_sensors_t {
enum cpu_module_t module;
uint8_t num_cores;
int16_t tdie;
int16_t tctl;
int16_t tccd1;
// double pcore;
// double psoc;
float ptotal;
// double vcore;
// double vsoc;
uint32_t avg_freq;
char hwmon[128];
};
#endif

9
include/utils.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef UTILS_H
#define UTILS_H
#define fastReadNum(path, buf, result_ptr, div) \
_Generic((result_ptr), \
uint64_t*: _fRN_u64, \
)(path, buf, sizeof(buf), result_ptr, div)
#endif

8
src/cpu.c Normal file
View File

@@ -0,0 +1,8 @@
#include "cpu.h"
#include <stdio.h>
void cpu_detect(struct cpu_sensors_t* t, const char* pci_dev) {
char path[128];
snprintf(path, sizeof(path), "/sys/bus/pci/devices/%s/hwmon", pci_dev);
}

37
src/utils.c Normal file
View File

@@ -0,0 +1,37 @@
#include <fcntl.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include "log.h"
#include <glob.h>
#include "utils.h"
inline bool file_exists(const char* path) {
return access(path, F_OK) == 0;
}
int get_hwmon_dir(char* path) {
glob_t g;
if (glob(path, 0, NULL, &g) == 0) {
}
}
/* read n bytes from path into buffer */
inline ssize_t read_file(const char* path, char* buffer, const ssize_t n) {
const int fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd < 0) {
applog(LOG_ERR, "Error reading %s", path);
return 0;
}
const ssize_t len = read(fd, buffer, n);
if (len >= 0) buffer[len] = '\0';
close(fd);
return len;
}
inline void _fRN_u64(const char* path, char* buf, uint64_t* result, const uint16_t divider) {
read_file(path, buf, 24); // wont ever be longer than 24 chars right? potential bug
*result = strtoull(buf, NULL, 10) / divider;
}