Browse Source

ccminer: rename main file and switch to C++

There was a different behavior on linux and visual studio

That was making it hard to link functions correctly

That remove some ifdef / extern "C" requirements

note about x86 releases, x86 nvml.dll is not installed on Windows x64!
master
Tanguy Pruvot 10 years ago
parent
commit
e40a7a720c
  1. 3
      Makefile.am
  2. 18
      api.cpp
  3. 30
      ccminer.cpp
  4. 10
      ccminer.vcxproj
  5. 4
      ccminer.vcxproj.filters
  6. 2
      configure.ac
  7. 8
      cuda.cpp
  8. 12
      hashlog.cpp
  9. 105
      nvml.cpp
  10. 3
      stats.cpp
  11. 4
      util.cpp

3
Makefile.am

@ -17,7 +17,8 @@ bin_PROGRAMS = ccminer
ccminer_SOURCES = elist.h miner.h compat.h \ ccminer_SOURCES = elist.h miner.h compat.h \
compat/inttypes.h compat/stdbool.h compat/unistd.h \ compat/inttypes.h compat/stdbool.h compat/unistd.h \
compat/sys/time.h compat/getopt/getopt.h \ compat/sys/time.h compat/getopt/getopt.h \
cpu-miner.c util.c crc32.c hefty1.c scrypt.c \ crc32.c hefty1.c scrypt.c \
ccminer.cpp util.cpp \
api.cpp hashlog.cpp stats.cpp cuda.cpp \ api.cpp hashlog.cpp stats.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 \

18
api.cpp

@ -114,8 +114,6 @@ extern uint32_t rejected_count;
static void gpustatus(int thr_id) static void gpustatus(int thr_id)
{ {
char buf[MYBUFSIZ]; char buf[MYBUFSIZ];
float gt;
int gp, gf;
if (thr_id >= 0 && thr_id < gpu_threads) { if (thr_id >= 0 && thr_id < gpu_threads) {
struct cgpu_info *cgpu = &thr_info[thr_id].gpu; struct cgpu_info *cgpu = &thr_info[thr_id].gpu;
@ -125,16 +123,12 @@ static void gpustatus(int thr_id)
#ifdef USE_WRAPNVML #ifdef USE_WRAPNVML
// todo // todo
if (1 || cgpu->has_monitoring) { if (1 || cgpu->has_monitoring) {
gf = gpu_fanpercent(cgpu); cgpu->gpu_temp = gpu_temp(cgpu);
gt = gpu_temp(cgpu); cgpu->gpu_fan = gpu_fanpercent(cgpu);
gp = gpu_power(cgpu); cgpu->gpu_power = gpu_power(cgpu);
// gpu_clock(cgpu); //cgpu->gpu_clock = gpu_clock(cgpu);
} }
else
#endif #endif
{
gt = 0.0; gf = gp = 0;
}
// todo: can be 0 if set by algo (auto) // todo: can be 0 if set by algo (auto)
if (opt_intensity == 0 && opt_work_size) { if (opt_intensity == 0 && opt_work_size) {
@ -155,7 +149,7 @@ static void gpustatus(int thr_id)
sprintf(buf, "GPU=%d;TEMP=%.1f;FAN=%d;POWER=%d;KHS=%.2f;" sprintf(buf, "GPU=%d;TEMP=%.1f;FAN=%d;POWER=%d;KHS=%.2f;"
"HWF=%d;I=%d|", "HWF=%d;I=%d|",
thr_id, gt, gf, gp, cgpu->khashes, thr_id, cgpu->gpu_temp, cgpu->gpu_fan, cgpu->gpu_power, cgpu->khashes,
cgpu->hw_errors, cgpu->intensity); cgpu->hw_errors, cgpu->intensity);
strcat(buffer, buf); strcat(buffer, buf);
@ -174,7 +168,7 @@ static char *getsummary(char *params)
*buffer = '\0'; *buffer = '\0';
sprintf(buffer, "NAME=%s;VER=%s;API=%s;" sprintf(buffer, "NAME=%s;VER=%s;API=%s;"
"ALGO=%s;KHS=%.2f;ACC=%d;REJ=%d;ACCMN=%.3f;UPTIME=%.1f|", "ALGO=%s;KHS=%.2f;ACC=%d;REJ=%d;ACCMN=%.3f;UPTIME=%.0f|",
PACKAGE_NAME, PACKAGE_VERSION, APIVERSION, PACKAGE_NAME, PACKAGE_VERSION, APIVERSION,
algo, (double)global_hashrate / 1000.0, algo, (double)global_hashrate / 1000.0,
accepted_count, rejected_count, accepted_count, rejected_count,

30
cpu-miner.c → ccminer.cpp

@ -9,7 +9,6 @@
*/ */
#include "cpuminer-config.h" #include "cpuminer-config.h"
#define _GNU_SOURCE
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -56,21 +55,15 @@ BOOL WINAPI ConsoleHandler(DWORD);
#define HEAVYCOIN_BLKHDR_SZ 84 #define HEAVYCOIN_BLKHDR_SZ 84
#define MNR_BLKHDR_SZ 80 #define MNR_BLKHDR_SZ 80
// from cuda.cu // from cuda.cpp
#ifdef __cplusplus
extern "C"
{
#endif
int cuda_num_devices(); int cuda_num_devices();
void cuda_devicenames(); void cuda_devicenames();
void cuda_devicereset(); void cuda_devicereset();
int cuda_finddevice(char *name); int cuda_finddevice(char *name);
#ifdef __cplusplus
}
#endif
#ifdef USE_WRAPNVML #ifdef USE_WRAPNVML
#include "nvml.h" #include "nvml.h"
wrap_nvml_handle *hnvml = NULL;
#endif #endif
#ifdef __linux /* Linux specific policy and affinity management */ #ifdef __linux /* Linux specific policy and affinity management */
@ -247,10 +240,6 @@ uint32_t opt_work_size = 0; /* default */
char *opt_api_allow = "127.0.0.1"; /* 0.0.0.0 for all ips */ char *opt_api_allow = "127.0.0.1"; /* 0.0.0.0 for all ips */
int opt_api_listen = 4068; /* 0 to disable */ int opt_api_listen = 4068; /* 0 to disable */
#ifdef USE_WRAPNVML
wrap_nvml_handle *nvmlh = NULL;
#endif
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
#include <getopt.h> #include <getopt.h>
#else #else
@ -429,8 +418,8 @@ void proper_exit(int reason)
timeEndPeriod(1); // else never executed timeEndPeriod(1); // else never executed
#endif #endif
#ifdef USE_WRAPNVML #ifdef USE_WRAPNVML
if (nvmlh) if (hnvml)
wrap_nvml_destroy(nvmlh); wrap_nvml_destroy(hnvml);
#endif #endif
exit(reason); exit(reason);
} }
@ -463,11 +452,11 @@ static bool work_decode(const json_t *val, struct work *work)
if (unlikely(!jobj_binary(val, "data", work->data, sizeof(work->data)))) { if (unlikely(!jobj_binary(val, "data", work->data, sizeof(work->data)))) {
applog(LOG_ERR, "JSON inval data"); applog(LOG_ERR, "JSON inval data");
goto err_out; return false;
} }
if (unlikely(!jobj_binary(val, "target", work->target, sizeof(work->target)))) { if (unlikely(!jobj_binary(val, "target", work->target, sizeof(work->target)))) {
applog(LOG_ERR, "JSON inval target"); applog(LOG_ERR, "JSON inval target");
goto err_out; return false;
} }
if (opt_algo == ALGO_HEAVY) { if (opt_algo == ALGO_HEAVY) {
if (unlikely(!jobj_binary(val, "maxvote", &work->maxvote, sizeof(work->maxvote)))) { if (unlikely(!jobj_binary(val, "maxvote", &work->maxvote, sizeof(work->maxvote)))) {
@ -494,9 +483,6 @@ static bool work_decode(const json_t *val, struct work *work)
cbin2hex(work->job_id, (const char*)&work->data[17], 4); cbin2hex(work->job_id, (const char*)&work->data[17], 4);
return true; return true;
err_out:
return false;
} }
/** /**
@ -2140,8 +2126,8 @@ int main(int argc, char *argv[])
} }
#ifdef USE_WRAPNVML #ifdef USE_WRAPNVML
nvmlh = wrap_nvml_create(); hnvml = wrap_nvml_create();
if (nvmlh) { if (hnvml) {
// todo: link threads info gpu // todo: link threads info gpu
applog(LOG_INFO, "NVML GPU monitoring enabled."); applog(LOG_INFO, "NVML GPU monitoring enabled.");
} else { } else {

10
ccminer.vcxproj

@ -230,18 +230,18 @@
<ClCompile Include="compat\jansson\utf.c" /> <ClCompile Include="compat\jansson\utf.c" />
<ClCompile Include="compat\jansson\value.c" /> <ClCompile Include="compat\jansson\value.c" />
<ClCompile Include="compat\winansi.c" /> <ClCompile Include="compat\winansi.c" />
<ClCompile Include="cpu-miner.c"> <ClCompile Include="ccminer.cpp">
<AdditionalOptions>/Tp %(AdditionalOptions)</AdditionalOptions>
<TreatWChar_tAsBuiltInType>false</TreatWChar_tAsBuiltInType> <TreatWChar_tAsBuiltInType>false</TreatWChar_tAsBuiltInType>
<Optimization Condition="'$(Configuration)'=='Release'">Full</Optimization> <Optimization Condition="'$(Configuration)'=='Release'">Full</Optimization>
</ClCompile> </ClCompile>
<ClCompile Include="crc32.c" /> <ClCompile Include="util.cpp" />
<ClCompile Include="fuguecoin.cpp" /> <ClCompile Include="fuguecoin.cpp" />
<ClCompile Include="groestlcoin.cpp" /> <ClCompile Include="groestlcoin.cpp" />
<ClCompile Include="hashlog.cpp" /> <ClCompile Include="hashlog.cpp" />
<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="crc32.c" />
<ClCompile Include="hefty1.c" /> <ClCompile Include="hefty1.c" />
<ClCompile Include="myriadgroestl.cpp" /> <ClCompile Include="myriadgroestl.cpp" />
<ClCompile Include="scrypt.c"> <ClCompile Include="scrypt.c">
@ -274,10 +274,6 @@
<ClCompile Include="sph\hamsi.c" /> <ClCompile Include="sph\hamsi.c" />
<ClCompile Include="sph\hamsi_helper.c" /> <ClCompile Include="sph\hamsi_helper.c" />
<ClCompile Include="sph\whirlpool.c" /> <ClCompile Include="sph\whirlpool.c" />
<ClCompile Include="util.c">
<AdditionalOptions>/Tp %(AdditionalOptions)</AdditionalOptions>
<Optimization Condition="'$(Configuration)'=='Release'">Full</Optimization>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="compat.h" /> <ClInclude Include="compat.h" />

4
ccminer.vcxproj.filters

@ -93,10 +93,10 @@
<ClCompile Include="compat\gettimeofday.c"> <ClCompile Include="compat\gettimeofday.c">
<Filter>Source Files\gettimeofday</Filter> <Filter>Source Files\gettimeofday</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="util.c"> <ClCompile Include="util.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="cpu-miner.c"> <ClCompile Include="ccminer.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="crc32.c"> <ClCompile Include="crc32.c">

2
configure.ac

@ -2,7 +2,7 @@ AC_INIT([ccminer], [1.4.9])
AC_PREREQ([2.59c]) AC_PREREQ([2.59c])
AC_CANONICAL_SYSTEM AC_CANONICAL_SYSTEM
AC_CONFIG_SRCDIR([cpu-miner.c]) AC_CONFIG_SRCDIR([ccminer.cpp])
AM_INIT_AUTOMAKE([foreign subdir-objects]) AM_INIT_AUTOMAKE([foreign subdir-objects])
AC_CONFIG_HEADERS([cpuminer-config.h]) AC_CONFIG_HEADERS([cpuminer-config.h])

8
cuda.cpp

@ -27,7 +27,7 @@ extern int device_map[8];
extern int device_sm[8]; extern int device_sm[8];
// CUDA Devices on the System // CUDA Devices on the System
extern "C" int cuda_num_devices() int cuda_num_devices()
{ {
int version; int version;
cudaError_t err = cudaDriverGetVersion(&version); cudaError_t err = cudaDriverGetVersion(&version);
@ -54,7 +54,7 @@ extern "C" int cuda_num_devices()
return GPU_N; return GPU_N;
} }
extern "C" void cuda_devicenames() void cuda_devicenames()
{ {
cudaError_t err; cudaError_t err;
int GPU_N; int GPU_N;
@ -76,7 +76,7 @@ extern "C" void cuda_devicenames()
} }
// Can't be called directly in cpu-miner.c // Can't be called directly in cpu-miner.c
extern "C" void cuda_devicereset() void cuda_devicereset()
{ {
cudaDeviceReset(); cudaDeviceReset();
} }
@ -103,7 +103,7 @@ static bool substringsearch(const char *haystack, const char *needle, int &match
} }
// CUDA Gerät nach Namen finden (gibt Geräte-Index zurück oder -1) // CUDA Gerät nach Namen finden (gibt Geräte-Index zurück oder -1)
extern "C" int cuda_finddevice(char *name) int cuda_finddevice(char *name)
{ {
int num = cuda_num_devices(); int num = cuda_num_devices();
int match = 0; int match = 0;

12
hashlog.cpp

@ -63,8 +63,7 @@ extern "C" uint32_t hashlog_already_submittted(char* jobid, uint32_t nonce)
extern "C" void hashlog_remember_submit(char* jobid, uint32_t nonce, uint32_t scanned_from) extern "C" void hashlog_remember_submit(char* jobid, uint32_t nonce, uint32_t scanned_from)
{ {
uint64_t njobid = hextouint(jobid); uint64_t njobid = hextouint(jobid);
uint64_t keyall = (njobid << 32); uint64_t key = (njobid << 32) + nonce;
uint64_t key = keyall + nonce;
hashlog_data data; hashlog_data data;
memset(&data, 0, sizeof(data)); memset(&data, 0, sizeof(data));
@ -80,12 +79,12 @@ extern "C" void hashlog_remember_submit(char* jobid, uint32_t nonce, uint32_t sc
extern "C" void hashlog_remember_scan_range(char* jobid, uint32_t scanned_from, uint32_t scanned_to) extern "C" void hashlog_remember_scan_range(char* jobid, uint32_t scanned_from, uint32_t scanned_to)
{ {
uint64_t njobid = hextouint(jobid); uint64_t njobid = hextouint(jobid);
uint64_t keyall = (njobid << 32); uint64_t key = (njobid << 32);
uint64_t range = hashlog_get_scan_range(jobid); uint64_t range = hashlog_get_scan_range(jobid);
hashlog_data data; hashlog_data data;
// global scan range of a job // global scan range of a job
data = tlastshares[keyall]; data = tlastshares[key];
if (range == 0) { if (range == 0) {
memset(&data, 0, sizeof(data)); memset(&data, 0, sizeof(data));
} else { } else {
@ -110,7 +109,7 @@ extern "C" void hashlog_remember_scan_range(char* jobid, uint32_t scanned_from,
data.tm_upd = (uint32_t) time(NULL); data.tm_upd = (uint32_t) time(NULL);
tlastshares[keyall] = data; tlastshares[key] = data;
/* applog(LOG_BLUE, "job %s range : %x %x -> %x %x", jobid, /* applog(LOG_BLUE, "job %s range : %x %x -> %x %x", jobid,
scanned_from, scanned_to, data.scanned_from, data.scanned_to); */ scanned_from, scanned_to, data.scanned_from, data.scanned_to); */
} }
@ -124,13 +123,14 @@ extern "C" uint64_t hashlog_get_scan_range(char* jobid)
uint64_t ret = 0; uint64_t ret = 0;
uint64_t njobid = hextouint(jobid); uint64_t njobid = hextouint(jobid);
uint64_t keypfx = (njobid << 32); uint64_t keypfx = (njobid << 32);
uint64_t keymsk = (0xffffffffULL << 32);
hashlog_data data; hashlog_data data;
data.scanned_from = 0; data.scanned_from = 0;
data.scanned_to = 0; data.scanned_to = 0;
std::map<uint64_t, hashlog_data>::iterator i = tlastshares.begin(); std::map<uint64_t, hashlog_data>::iterator i = tlastshares.begin();
while (i != tlastshares.end()) { while (i != tlastshares.end()) {
if ((keypfx & i->first) == keypfx && i->second.scanned_to > ret) { if ((keymsk & i->first) == keypfx && i->second.scanned_to > ret) {
if (i->second.scanned_to > data.scanned_to) if (i->second.scanned_to > data.scanned_to)
data.scanned_to = i->second.scanned_to; data.scanned_to = i->second.scanned_to;
if (i->second.scanned_from < data.scanned_from || data.scanned_from == 0) if (i->second.scanned_from < data.scanned_from || data.scanned_from == 0)

105
nvml.cpp

@ -19,7 +19,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <string.h>
#ifndef _MSC_VER #ifndef _MSC_VER
#include <libgen.h> #include <libgen.h>
#endif #endif
@ -28,13 +28,21 @@
#include "cuda_runtime.h" #include "cuda_runtime.h"
#include "nvml.h" #include "nvml.h"
extern wrap_nvml_handle *hnvml;
extern int device_map[8];
/* /*
* Wrappers to emulate dlopen() on other systems like Windows * Wrappers to emulate dlopen() on other systems like Windows
*/ */
#if defined(_MSC_VER) || defined(_WIN32) || defined(_WIN64) #if defined(_MSC_VER) || defined(_WIN32) || defined(_WIN64)
#include <windows.h> #include <windows.h>
static void *wrap_dlopen(const char *filename) { static void *wrap_dlopen(const char *filename) {
return (void *)LoadLibrary(filename); HMODULE h = LoadLibrary(filename);
if (!h && opt_debug) {
applog(LOG_DEBUG, "dlopen(%d): failed to load %s",
GetLastError(), filename);
}
return (void*)h;
} }
static void *wrap_dlsym(void *h, const char *sym) { static void *wrap_dlsym(void *h, const char *sym) {
return (void *)GetProcAddress((HINSTANCE)h, sym); return (void *)GetProcAddress((HINSTANCE)h, sym);
@ -46,9 +54,16 @@
#else #else
/* assume we can use dlopen itself... */ /* assume we can use dlopen itself... */
#include <dlfcn.h> #include <dlfcn.h>
#include <errno.h>
static void *wrap_dlopen(const char *filename) { static void *wrap_dlopen(const char *filename) {
return dlopen(filename, RTLD_NOW); void *h = dlopen(filename, RTLD_NOW);
if (h == NULL && opt_debug) {
applog(LOG_DEBUG, "dlopen(%d): failed to load %s",
errno, filename);
}
return (void*)h;
} }
static void *wrap_dlsym(void *h, const char *sym) { static void *wrap_dlsym(void *h, const char *sym) {
return dlsym(h, sym); return dlsym(h, sym);
} }
@ -57,7 +72,7 @@
} }
#endif #endif
#if defined(__cplusplus) #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -66,51 +81,27 @@ wrap_nvml_handle * wrap_nvml_create()
int i=0; int i=0;
wrap_nvml_handle *nvmlh = NULL; wrap_nvml_handle *nvmlh = NULL;
/* #if defined(WIN32)
* We use hard-coded library installation locations for the time being... /* Windows (do not use slashes, else ExpandEnvironmentStrings will mix them) */
* No idea where or if libnvidia-ml.so is installed on MacOS X, a #define libnvidia_ml "%PROGRAMFILES%\\NVIDIA Corporation\\NVSMI\\nvml.dll"
* deep scouring of the filesystem on one of the Mac CUDA build boxes
* I used turned up nothing, so for now it's not going to work on OSX.
*/
#if defined(_WIN64)
/* 64-bit Windows */
#define libnvidia_ml "%PROGRAMFILES%/NVIDIA Corporation/NVSMI/nvml.dll"
#elif defined(_WIN32) || defined(_MSC_VER)
/* 32-bit Windows */
#define libnvidia_ml "%PROGRAMFILES%/NVIDIA Corporation/NVSMI/nvml.dll"
#elif defined(__linux) && (defined(__i386__) || defined(__ARM_ARCH_7A__))
/* 32-bit linux assumed */
#define libnvidia_ml "/usr/lib32/libnvidia-ml.so"
#elif defined(__linux)
/* 64-bit linux assumed */
#define libnvidia_ml "/usr/lib/libnvidia-ml.so"
#else #else
#error "Unrecognized platform: need NVML DLL path for this platform..." /* linux assumed */
#define libnvidia_ml "libnvidia-ml.so"
#endif #endif
#if WIN32
char tmp[512]; char tmp[512];
ExpandEnvironmentStringsA(libnvidia_ml, tmp, sizeof(tmp)); #ifdef WIN32
ExpandEnvironmentStrings(libnvidia_ml, tmp, sizeof(tmp));
#else #else
char tmp[512] = libnvidia_ml; strcpy(tmp, libnvidia_ml);
#endif #endif
void *nvml_dll = wrap_dlopen(tmp); void *nvml_dll = wrap_dlopen(tmp);
if (nvml_dll == NULL) { if (nvml_dll == NULL) {
#ifdef WIN32 #ifdef WIN32
char lib[] = "nvml.dll"; nvml_dll = wrap_dlopen("nvml.dll");
#else if (nvml_dll == NULL)
char lib[64] = { '\0' };
snprintf(lib, sizeof(lib), "%s", basename(tmp));
/* try dlopen without path, here /usr/lib/nvidia-340/libnvidia-ml.so */
#endif #endif
nvml_dll = wrap_dlopen(lib);
if (opt_debug)
applog(LOG_DEBUG, "dlopen: %s=%p", lib, nvml_dll);
}
if (nvml_dll == NULL) {
if (opt_debug)
applog(LOG_DEBUG, "dlopen(%d): failed to load %s", errno, tmp);
return NULL; return NULL;
} }
@ -120,9 +111,10 @@ wrap_nvml_handle * wrap_nvml_create()
nvmlh->nvmlInit = (wrap_nvmlReturn_t (*)(void)) nvmlh->nvmlInit = (wrap_nvmlReturn_t (*)(void))
wrap_dlsym(nvmlh->nvml_dll, "nvmlInit_v2"); wrap_dlsym(nvmlh->nvml_dll, "nvmlInit_v2");
if (!nvmlh->nvmlInit) if (!nvmlh->nvmlInit) {
nvmlh->nvmlInit = (wrap_nvmlReturn_t (*)(void)) nvmlh->nvmlInit = (wrap_nvmlReturn_t (*)(void))
wrap_dlsym(nvmlh->nvml_dll, "nvmlInit"); wrap_dlsym(nvmlh->nvml_dll, "nvmlInit");
}
nvmlh->nvmlDeviceGetCount = (wrap_nvmlReturn_t (*)(int *)) nvmlh->nvmlDeviceGetCount = (wrap_nvmlReturn_t (*)(int *))
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetCount_v2"); wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetCount_v2");
nvmlh->nvmlDeviceGetHandleByIndex = (wrap_nvmlReturn_t (*)(int, wrap_nvmlDevice_t *)) nvmlh->nvmlDeviceGetHandleByIndex = (wrap_nvmlReturn_t (*)(int, wrap_nvmlDevice_t *))
@ -153,11 +145,10 @@ wrap_nvml_handle * wrap_nvml_create()
nvmlh->nvmlDeviceGetPciInfo == NULL || nvmlh->nvmlDeviceGetPciInfo == NULL ||
nvmlh->nvmlDeviceGetName == NULL || nvmlh->nvmlDeviceGetName == NULL ||
nvmlh->nvmlDeviceGetTemperature == NULL || nvmlh->nvmlDeviceGetTemperature == NULL ||
nvmlh->nvmlDeviceGetFanSpeed == NULL || nvmlh->nvmlDeviceGetFanSpeed == NULL)
nvmlh->nvmlDeviceGetPowerUsage == NULL)
{ {
if (opt_debug) if (opt_debug)
applog(LOG_DEBUG, "Failed to obtain all required NVML function pointers"); applog(LOG_DEBUG, "Failed to obtain required NVML function pointers");
wrap_dlclose(nvmlh->nvml_dll); wrap_dlclose(nvmlh->nvml_dll);
free(nvmlh); free(nvmlh);
return NULL; return NULL;
@ -342,14 +333,11 @@ int wrap_nvml_destroy(wrap_nvml_handle *nvmlh)
/* api functions */ /* api functions */
extern wrap_nvml_handle *nvmlh;
extern int device_map[8];
unsigned int gpu_fanpercent(struct cgpu_info *gpu) unsigned int gpu_fanpercent(struct cgpu_info *gpu)
{ {
unsigned int pct = 0; unsigned int pct = 0;
if (nvmlh) { if (hnvml) {
wrap_nvml_get_fanpcnt(nvmlh, device_map[gpu->thr_id], &pct); wrap_nvml_get_fanpcnt(hnvml, device_map[gpu->thr_id], &pct);
} }
return pct; return pct;
} }
@ -357,9 +345,9 @@ unsigned int gpu_fanpercent(struct cgpu_info *gpu)
double gpu_temp(struct cgpu_info *gpu) double gpu_temp(struct cgpu_info *gpu)
{ {
double tc = 0.0; double tc = 0.0;
if (nvmlh) { if (hnvml) {
unsigned int tmp = 0; unsigned int tmp = 0;
wrap_nvml_get_tempC(nvmlh, device_map[gpu->thr_id], &tmp); wrap_nvml_get_tempC(hnvml, device_map[gpu->thr_id], &tmp);
tc = (double) tmp; tc = (double) tmp;
} }
return tc; return tc;
@ -368,8 +356,8 @@ double gpu_temp(struct cgpu_info *gpu)
unsigned int gpu_clock(struct cgpu_info *gpu) unsigned int gpu_clock(struct cgpu_info *gpu)
{ {
unsigned int freq = 0; unsigned int freq = 0;
if (nvmlh) { if (hnvml) {
wrap_nvml_get_clock(nvmlh, device_map[gpu->thr_id], NVML_CLOCK_SM, &freq); wrap_nvml_get_clock(hnvml, device_map[gpu->thr_id], NVML_CLOCK_SM, &freq);
} }
return freq; return freq;
} }
@ -377,8 +365,8 @@ unsigned int gpu_clock(struct cgpu_info *gpu)
unsigned int gpu_power(struct cgpu_info *gpu) unsigned int gpu_power(struct cgpu_info *gpu)
{ {
unsigned int mw = 0; unsigned int mw = 0;
if (nvmlh) { if (hnvml) {
wrap_nvml_get_power_usage(nvmlh, device_map[gpu->thr_id], &mw); wrap_nvml_get_power_usage(hnvml, device_map[gpu->thr_id], &mw);
} }
return mw; return mw;
} }
@ -386,9 +374,8 @@ unsigned int gpu_power(struct cgpu_info *gpu)
int gpu_pstate(struct cgpu_info *gpu) int gpu_pstate(struct cgpu_info *gpu)
{ {
int pstate = 0; int pstate = 0;
if (nvmlh) { if (hnvml) {
wrap_nvml_get_pstate(nvmlh, device_map[gpu->thr_id], &pstate); wrap_nvml_get_pstate(hnvml, device_map[gpu->thr_id], &pstate);
//gpu->gpu_pstate = pstate;
} }
return pstate; return pstate;
} }
@ -433,7 +420,7 @@ int gpu_pstate(struct cgpu_info *gpu)
* nvmlDeviceGetFanSpeed * nvmlDeviceGetFanSpeed
nvmlDeviceGetGpuOperationMode nvmlDeviceGetGpuOperationMode
nvmlDeviceGetHandleByIndex nvmlDeviceGetHandleByIndex
nvmlDeviceGetHandleByIndex_v2 * nvmlDeviceGetHandleByIndex_v2
nvmlDeviceGetHandleByPciBusId nvmlDeviceGetHandleByPciBusId
nvmlDeviceGetHandleByPciBusId_v2 nvmlDeviceGetHandleByPciBusId_v2
nvmlDeviceGetHandleBySerial nvmlDeviceGetHandleBySerial
@ -450,7 +437,7 @@ int gpu_pstate(struct cgpu_info *gpu)
nvmlDeviceGetMinorNumber nvmlDeviceGetMinorNumber
nvmlDeviceGetMultiGpuBoard nvmlDeviceGetMultiGpuBoard
nvmlDeviceGetName nvmlDeviceGetName
nvmlDeviceGetPciInfo * nvmlDeviceGetPciInfo
nvmlDeviceGetPciInfo_v2 nvmlDeviceGetPciInfo_v2
* nvmlDeviceGetPerformanceState * nvmlDeviceGetPerformanceState
nvmlDeviceGetPersistenceMode nvmlDeviceGetPersistenceMode
@ -476,4 +463,4 @@ int gpu_pstate(struct cgpu_info *gpu)
nvmlDeviceGetVbiosVersion nvmlDeviceGetVbiosVersion
nvmlDeviceGetViolationStatus nvmlDeviceGetViolationStatus
*/ */

3
stats.cpp

@ -72,13 +72,14 @@ extern "C" double stats_get_speed(int thr_id)
{ {
uint64_t thr = (0xff && thr_id); uint64_t thr = (0xff && thr_id);
uint64_t keypfx = (thr << 56); uint64_t keypfx = (thr << 56);
uint64_t keymsk = (0xffULL << 56);
double speed = 0.0; double speed = 0.0;
int records = 0; int records = 0;
std::map<uint64_t, stats_data>::reverse_iterator i = tlastscans.rbegin(); std::map<uint64_t, stats_data>::reverse_iterator i = tlastscans.rbegin();
while (i != tlastscans.rend() && records < opt_statsavg) { while (i != tlastscans.rend() && records < opt_statsavg) {
if (!i->second.ignored) if (!i->second.ignored)
if (thr_id == -1 || (keypfx & i->first) == keypfx) { if (thr_id == -1 || (keymsk & i->first) == keypfx) {
if (i->second.hashcount > 1000) { if (i->second.hashcount > 1000) {
speed += i->second.hashrate; speed += i->second.hashrate;
records++; records++;

4
util.c → util.cpp

@ -90,7 +90,7 @@ void applog(int prio, const char *fmt, ...)
va_copy(ap2, ap); va_copy(ap2, ap);
len = vsnprintf(NULL, 0, fmt, ap2) + 1; len = vsnprintf(NULL, 0, fmt, ap2) + 1;
va_end(ap2); va_end(ap2);
buf = alloca(len); buf = (char*) alloca(len);
if (vsnprintf(buf, len, fmt, ap) >= 0) if (vsnprintf(buf, len, fmt, ap) >= 0)
syslog(prio, "%s", buf); syslog(prio, "%s", buf);
} }
@ -1473,7 +1473,7 @@ extern void applog_compare_hash(uchar *hash, uchar *hash2)
char s[256] = ""; char s[256] = "";
int len = 0; int len = 0;
for (int i=0; i < 32; i += 4) { for (int i=0; i < 32; i += 4) {
char *color = memcmp(hash+i, hash2+i, 4) ? CL_WHT : CL_GRY; const char *color = memcmp(hash+i, hash2+i, 4) ? CL_WHT : CL_GRY;
len += sprintf(s+len, "%s%02x%02x%02x%02x " CL_GRY, color, len += sprintf(s+len, "%s%02x%02x%02x%02x " CL_GRY, color,
hash[i], hash[i+1], hash[i+2], hash[i+3]); hash[i], hash[i+1], hash[i+2], hash[i+3]);
s[len] = '\0'; s[len] = '\0';
Loading…
Cancel
Save