forked from tpruvot/ccminer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sysinfos.cpp
94 lines (71 loc) · 1.23 KB
/
sysinfos.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* 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 double linux_cputemp(int core)
{
double 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 = (double)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 (float) 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;
}