Browse Source

api: add cpu temp/freq (linux)

2upstream
Tanguy Pruvot 10 years ago
parent
commit
9a8b7ff0d7
  1. 2
      Makefile.am
  2. 15
      api.cpp
  3. 1
      ccminer.vcxproj
  4. 3
      ccminer.vcxproj.filters
  5. 94
      sysinfos.cpp

2
Makefile.am

@ -19,7 +19,7 @@ ccminer_SOURCES = elist.h miner.h compat.h \
compat/sys/time.h compat/getopt/getopt.h \ compat/sys/time.h compat/getopt/getopt.h \
crc32.c hefty1.c scrypt.c \ crc32.c hefty1.c scrypt.c \
ccminer.cpp util.cpp \ ccminer.cpp util.cpp \
api.cpp hashlog.cpp stats.cpp cuda.cpp \ api.cpp hashlog.cpp stats.cpp sysinfos.cpp cuda.cpp \
heavy/heavy.cu \ heavy/heavy.cu \
heavy/cuda_blake512.cu heavy/cuda_blake512.h \ heavy/cuda_blake512.cu heavy/cuda_blake512.h \
heavy/cuda_combine.cu heavy/cuda_combine.h \ heavy/cuda_combine.cu heavy/cuda_combine.h \

15
api.cpp

@ -108,6 +108,10 @@ extern uint32_t accepted_count;
extern uint32_t rejected_count; extern uint32_t rejected_count;
extern int device_map[8]; extern int device_map[8];
extern char *device_name[8]; extern char *device_name[8];
extern int num_cpus;
extern float cpu_temp(int);
extern uint32_t cpu_clock(int);
/***************************************************************/ /***************************************************************/
@ -246,13 +250,18 @@ static void gpuhwinfos(int gpu_id)
} }
/** /**
* To finish * CPU Infos
*/ */
static void cpuhwinfos() static void cpuhwinfos()
{ {
char buf[256]; char buf[256];
float temp = cpu_temp(0);
uint32_t clock = cpu_clock(0);
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), "CPU=|"); snprintf(buf, sizeof(buf), "CPUS=%d;TEMP=%.1f;FREQ=%d|",
num_cpus, temp, clock);
strcat(buffer, buf); strcat(buffer, buf);
} }
@ -277,8 +286,8 @@ static char *gethistory(char *params)
struct stats_data data[50]; struct stats_data data[50];
int thrid = params ? atoi(params) : -1; int thrid = params ? atoi(params) : -1;
char *p = buffer; char *p = buffer;
*buffer = '\0';
int records = stats_get_history(thrid, data, ARRAY_SIZE(data)); int records = stats_get_history(thrid, data, ARRAY_SIZE(data));
*buffer = '\0';
for (int i = 0; i < records; i++) { for (int i = 0; i < records; i++) {
time_t ts = data[i].tm_stat; time_t ts = data[i].tm_stat;
p += sprintf(p, "GPU=%d;H=%u;KHS=%.2f;DIFF=%.6f;" p += sprintf(p, "GPU=%d;H=%u;KHS=%.2f;DIFF=%.6f;"

1
ccminer.vcxproj

@ -247,6 +247,7 @@
<ClCompile Include="stats.cpp" /> <ClCompile Include="stats.cpp" />
<ClCompile Include="nvml.cpp" /> <ClCompile Include="nvml.cpp" />
<ClCompile Include="api.cpp" /> <ClCompile Include="api.cpp" />
<ClCompile Include="sysinfos.cpp" />
<ClCompile Include="crc32.c" /> <ClCompile Include="crc32.c" />
<ClCompile Include="hefty1.c" /> <ClCompile Include="hefty1.c" />
<ClCompile Include="myriadgroestl.cpp" /> <ClCompile Include="myriadgroestl.cpp" />

3
ccminer.vcxproj.filters

@ -201,6 +201,9 @@
<ClCompile Include="nvml.cpp"> <ClCompile Include="nvml.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="sysinfos.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="compat\jansson\memory.c"> <ClCompile Include="compat\jansson\memory.c">
<Filter>Source Files\jansson</Filter> <Filter>Source Files\jansson</Filter>
</ClCompile> </ClCompile>

94
sysinfos.cpp

@ -0,0 +1,94 @@
/**
* Unit to read cpu informations
*
* TODO: WMI implementation for windows
*
* tpruvot 2014
*/
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "miner.h"
#ifndef WIN32
#define HWMON_PATH \
"/sys/class/hwmon/hwmon1/device/temp1_input"
#define HWMON_ALT \
"/sys/class/hwmon/hwmon0/temp1_input"
static float linux_cputemp(int core)
{
float tc = 0.0;
FILE *fd = fopen(HWMON_PATH, "r");
uint32_t val = 0;
if (!fd)
fd = fopen(HWMON_ALT, "r");
if (!fd)
return tc;
if (fscanf(fd, "%d", &val))
tc = val / 1000.0;
fclose(fd);
return tc;
}
#define CPUFREQ_PATH \
"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq"
static uint32_t linux_cpufreq(int core)
{
FILE *fd = fopen(CPUFREQ_PATH, "r");
uint32_t freq = 0;
if (!fd)
return freq;
if (!fscanf(fd, "%d", &freq))
return freq;
return freq;
}
#else /* WIN32 */
static float win32_cputemp(int core)
{
// todo
return 0.0;
}
#endif /* !WIN32 */
/* exports */
float cpu_temp(int core)
{
#ifdef WIN32
return win32_cputemp(core);
#else
return linux_cputemp(core);
#endif
}
uint32_t cpu_clock(int core)
{
#ifdef WIN32
return 0;
#else
return linux_cpufreq(core);
#endif
}
int cpu_fanpercent()
{
return 0;
}
Loading…
Cancel
Save