1
0
mirror of https://github.com/gryf/wmtemp.git synced 2026-02-14 04:45:47 +01:00

New branch for nouveau driver

This commit is contained in:
2013-10-21 22:20:36 +02:00
parent fb2374178c
commit fc28caa211
2 changed files with 28 additions and 87 deletions

View File

@@ -9,14 +9,14 @@ OBJ = $(SRC:.c=.o)
CFLAGS = -Wall -O3 CFLAGS = -Wall -O3
LIB = -I/usr/include/NVCtrl/ -L/usr/X11R6/lib -lXpm -lXext -lX11 -lsensors -lXNVCtrl LIB = -L/usr/X11R6/lib -lXpm -lXext -lX11 -lsensors
INSTALL = /usr/bin/install INSTALL = /usr/bin/install
CC = gcc CC = gcc
all: $(OBJ) all: $(OBJ)
$(CC) $(CFLAGS) -o $(EXE) $(OBJ) $(LIB) $(CC) -o $(EXE) $(OBJ) $(LIB)
strip $(EXE) strip $(EXE)
$(OBJ): %.o : %.c $(OBJ): %.o : %.c

View File

@@ -4,8 +4,8 @@
* *
* version = 0.4 * version = 0.4
* *
* requirements: configured lm_sensors, sensor program and * requirements: configured lm_sensors, sensor program and nouveau
* nvidia-settings package *
* licence: gpl * licence: gpl
*/ */
@@ -18,66 +18,36 @@
#include <string.h> #include <string.h>
#include "../wmgeneral/wmgeneral.h" #include "../wmgeneral/wmgeneral.h"
#include "../wmgeneral/misc.h" #include "../wmgeneral/misc.h"
#include "../wmgeneral/misc.h"
#include "wmtempnv_master2.xpm" #include "wmtempnv_master2.xpm"
#include "wmtempnv_mask.xbm" #include "wmtempnv_mask.xbm"
#include <NVCtrl/NVCtrl.h>
#include <NVCtrl/NVCtrlLib.h>
#define MAXSTRLEN 8 #define MAXSTRLEN 8
#define TEMP 40 #define TEMP 40
#define TEMP_OVER 47 #define TEMP_OVER 47
#define GPU_T 70 #define GPU_T 70
#define GPU_T_OVER 85 #define GPU_T_OVER 85
#define MAXFNAME 50
void display_values(int, int, int); void display_values(int, int, int);
int get_temp(int core_number, Display*); int get_temp(int core_number);
int get_offset(int temp, int cpu); int get_offset(int temp, int cpu);
void display_help(char* progname);
int get_gpu_temp(char* path, Display *disp);
void read_file_into(char *filepath, int *output);
Display *display;
int main(int argc, char **argv){ int main(int argc, char **argv){
short got_path=0;
int temp1=0, temp2=0, temp3=0; int temp1=0, temp2=0, temp3=0;
/* offset is one of 0 (normal), 7 (alert), 14 (warning) */ /* offset is one of 0 (normal), 7 (alert), 14 (warning) */
int offset1=0, offset2=0, offset3=0; int offset1=0, offset2=0, offset3=0;
int counter = 0; int counter = 0;
char* path = "";
display = XOpenDisplay(NULL);
if (argc > 1) { openXwindow(argc, argv, wmtempnv_master2_xpm, wmtempnv_mask_bits, wmtempnv_mask_width, wmtempnv_mask_height);
if (argc > 2) {
display_help(argv[0]);
exit(2);
}
if (argc == 2 &&
(strcmp(argv[1], "--help") == 0 ||
strcmp(argv[1], "-h") == 0)) {
display_help(argv[0]);
exit(0);
}
got_path = 1;
path = argv[1];
}
openXwindow(argc, argv, wmtempnv_master2_xpm, wmtempnv_mask_bits,
wmtempnv_mask_width, wmtempnv_mask_height);
while(TRUE){ while(TRUE){
if (counter < 1){ if(counter==0){
counter = 5; temp1 = get_temp(0);
temp1 = get_temp(0, display);
offset1 = get_offset(temp1, 1); offset1 = get_offset(temp1, 1);
temp2 = get_temp(1, display); temp2 = get_temp(1);
offset2 = get_offset(temp2, 1); offset2 = get_offset(temp2, 1);
temp3 = get_gpu_temp(path, display); temp3 = get_temp(2) / 1000;
offset3 = get_offset(temp3, 0); offset3 = get_offset(temp3, 0);
counter = 200;
} }
// core 1 // core 1
@@ -98,7 +68,7 @@ int main(int argc, char **argv){
display_values(temp3, 28, offset3); display_values(temp3, 28, offset3);
RedrawWindow(); RedrawWindow();
counter--; counter--;
usleep(100000); usleep(5000);
} }
} }
@@ -137,55 +107,26 @@ void display_values(int temp, int offset, int offset2){
copyXPMArea(5 * num4, 65 + offset2, 5, 7, 51, 7 + offset); copyXPMArea(5 * num4, 65 + offset2, 5, 7, 51, 7 + offset);
} }
int get_temp(int core_number, Display *disp){ int get_temp(int core_number){
// Core temperature. argument is core number. // Core temperature. argument is core number. core no.2 is GPU
FILE *file; FILE *file;
char filename[MAXFNAME]; int core=0;
int core_temp = 0; char cmd[] = " ";
Bool res; if(core_number==2){
sprintf(cmd, "echo `cat /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/hwmon/hwmon0/temp1_input`");
snprintf(filename, MAXFNAME,
"/sys/bus/platform/devices/coretemp.0/temp%d_input",
core_number + 2);
read_file_into(filename, &core_temp);
return core_temp;
}
int get_gpu_temp(char* path, Display *disp){
// return GPU temperature. Argument is path in sysfs or empty string.
FILE *file;
char filename[MAXFNAME];
int gpu_temp = 0;
Bool res;
if (strcmp(path, "") == 0){
res = XNVCTRLQueryTargetAttribute(disp,
NV_CTRL_TARGET_TYPE_GPU, 0, 0,
NV_CTRL_GPU_CORE_TEMPERATURE, &gpu_temp);
if (res == False) gpu_temp = 0;
}else{ }else{
read_file_into(path, &gpu_temp); sprintf(cmd, "echo `sensors |grep 'Core %d'|cut -d ':' -f 2|cut -d '.' -f 1`", core_number);
} }
return gpu_temp; file = popen(cmd, "r");
} while (! feof(file)) {
char line[MAXSTRLEN + 1];
void read_file_into(char *filepath, int *output) { bzero(line, MAXSTRLEN + 1);
// Read an integer from the provided filepath and write it in the address fgets(line, MAXSTRLEN, file);
FILE *fp; if(line[0] != 0){
if((fp = fopen(filepath, "r")) != NULL){ sscanf(line, "%d", &core);
if(fscanf(fp, "%d", output) != EOF){
*output = *output / 1000;
fclose(fp);
} }
} }
} pclose(file);
void display_help(char* progname){ return core;
printf("Dockapp for monitoring CPU and Nvidia GPU temperatures.\n");
printf("Usage:\n\t%s [full path for temp in sysfs]\n\n", progname);
printf("As an optional parameter you can provide `temp_input' ");
printf("full path from sysfs,\ncorresponding to your gfx card ");
printf("to read temperature from. Otherwise\nfunctionality of ");
printf("nv-control will be used (package nvidia-settings).\n");
} }