mirror of https://github.com/GOSTSec/ccminer
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
1.2 KiB
95 lines
1.2 KiB
10 years ago
|
/**
|
||
|
* 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;
|
||
|
}
|
||
|
|