aboutsummaryrefslogtreecommitdiff
path: root/src/zenmonitor.c
diff options
context:
space:
mode:
authorOndrej Čerman2019-06-15 16:51:21 +0200
committerOndrej Čerman2019-06-15 16:51:21 +0200
commit37fc68ca76571bbb1ccf8c21ea159e5273bcde4a (patch)
tree352b1cde0b3b331f10cd38538315df1197615019 /src/zenmonitor.c
parentafdd058cfb2e06dee04a373ab98b380e4e3e5ad9 (diff)
New version - code rewritten to c, added GTK3 gui, added Core and Package Power monitoring via MSR
Diffstat (limited to 'src/zenmonitor.c')
-rw-r--r--src/zenmonitor.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/zenmonitor.c b/src/zenmonitor.c
new file mode 100644
index 0000000..5fe042a
--- /dev/null
+++ b/src/zenmonitor.c
@@ -0,0 +1,57 @@
+#include <gtk/gtk.h>
+#include <cpuid.h>
+#include "zenmonitor.h"
+#include "zenpower.h"
+#include "msr.h"
+#include "gui.h"
+
+#define AMD_STRING "AuthenticAMD"
+#define ZEN_FAMILY 0x17
+
+gboolean check_zen() {
+ unsigned int eax = 0, ebx = 0, ecx = 0, edx = 0, ext_family;
+ char vendor[13];
+
+ __get_cpuid(0, &eax, &ebx, &ecx, &edx);
+
+ memcpy(vendor, &ebx, 4);
+ memcpy(vendor+4, &edx, 4);
+ memcpy(vendor+8, &ecx, 4);
+ vendor[12] = 0;
+
+ if (strcmp(vendor, AMD_STRING) != 0){
+ return FALSE;
+ }
+
+ __get_cpuid(1, &eax, &ebx, &ecx, &edx);
+
+ ext_family = ((eax >> 8) & 0xF) + ((eax >> 20) & 0xFF);
+ if (ext_family != ZEN_FAMILY){
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static SensorSource sensor_sources[] = {
+ { "zenpower", zenpower_init, zenpower_get_sensors, zenpower_update, FALSE, NULL },
+ { "msr", msr_init, msr_get_sensors, msr_update, FALSE, NULL },
+ { NULL }
+};
+
+SensorInit *sensor_init_new() {
+ return g_new0(SensorInit, 1);
+}
+
+void sensor_init_free(SensorInit *s) {
+ if (s) {
+ g_free(s->label);
+ g_free(s);
+ }
+}
+
+int main (int argc, char *argv[])
+{
+ gtk_init(&argc, &argv);
+ start_gui(sensor_sources);
+}