Browse Source

Handle a default config file (ccminer.conf)

This allow to "debug" easily in visual studio (without project changes)

Prepare version 1.5.3, update README
master
Tanguy Pruvot 10 years ago
parent
commit
5dd2534df9
  1. 7
      README.txt
  2. 19
      ccminer.conf
  3. 43
      ccminer.cpp
  4. 30
      compat.h
  5. 2
      configure.ac
  6. 6
      cpuminer-config.h
  7. 18
      example-cfg.json
  8. 13
      miner.h
  9. BIN
      res/ccminer.rc
  10. 28
      util.cpp

7
README.txt

@ -1,5 +1,5 @@
ccMiner release 1.5.2-tpruvot (24 Jan 2015) - "Happy new Year!" ccMiner release 1.5.3-tpruvot (11 Feb 2015) - "Default Config"
--------------------------------------------------------------- ---------------------------------------------------------------
*************************************************************** ***************************************************************
@ -175,6 +175,11 @@ features.
>>> RELEASE HISTORY <<< >>> RELEASE HISTORY <<<
Feb. 11th 2015 v1.5.3
Fix anime algo
Allow a default config file in user or ccminer folder
SM 2.1 windows binary (lyra2 and blake/blakecoin for the moment)
Jan. 24th 2015 v1.5.2 Jan. 24th 2015 v1.5.2
Allow per device intensity, example: -i 20,19.5 Allow per device intensity, example: -i 20,19.5
Add process CPU priority and affinity mask parameters Add process CPU priority and affinity mask parameters

19
ccminer.conf

@ -0,0 +1,19 @@
{
"_comment1" : "Possible keys are the long options (ccminer --help)",
"_comment2" : "todo: support /* comments */",
"algo" : "blake",
"intensity": 19,
"api-bind": "127.0.0.1:4068",
"statsavg": 20,
"quiet" : false,
"debug" : false,
"protocol" : false,
"cpu-priority" : 3,
"url" : "stratum+tcp://stratum.eu.miners-pool.eu:8421",
"user" : "ShGCAFrspnLDo414EzUyJm4k5Qr2Kkrmvh",
"pass" : "x"
}

43
ccminer.cpp

@ -172,9 +172,9 @@ short device_map[MAX_GPUS] = { 0 };
long device_sm[MAX_GPUS] = { 0 }; long device_sm[MAX_GPUS] = { 0 };
uint32_t gpus_intensity[MAX_GPUS] = { 0 }; uint32_t gpus_intensity[MAX_GPUS] = { 0 };
char *rpc_user = NULL; char *rpc_user = NULL;
static char *rpc_url;
static char *rpc_userpass;
static char *rpc_pass; static char *rpc_pass;
static char *rpc_userpass = NULL;
static char *rpc_url;
static char *short_url = NULL; static char *short_url = NULL;
char *opt_cert; char *opt_cert;
char *opt_proxy; char *opt_proxy;
@ -364,6 +364,7 @@ static inline void drop_policy(void) {
sched_setscheduler(0, SCHED_BATCH, &param); sched_setscheduler(0, SCHED_BATCH, &param);
#endif #endif
} }
static void affine_to_cpu_mask(int id, uint8_t mask) { static void affine_to_cpu_mask(int id, uint8_t mask) {
cpu_set_t set; cpu_set_t set;
CPU_ZERO(&set); CPU_ZERO(&set);
@ -1125,7 +1126,7 @@ static void *miner_thread(void *userdata)
applog(LOG_DEBUG, "Thread %d priority %d (nice %d)", applog(LOG_DEBUG, "Thread %d priority %d (nice %d)",
thr_id, opt_priority, prio); thr_id, opt_priority, prio);
#endif #endif
int ret = setpriority(PRIO_PROCESS, 0, prio); setpriority(PRIO_PROCESS, 0, prio);
if (opt_priority == 0) { if (opt_priority == 0) {
drop_policy(); drop_policy();
} }
@ -1830,7 +1831,7 @@ static void parse_arg(int key, char *arg)
if (v < 0 || v > 31) if (v < 0 || v > 31)
show_usage_and_exit(1); show_usage_and_exit(1);
{ {
int n = 0, adds = 0; int n = 0;
int ngpus = cuda_num_devices(); int ngpus = cuda_num_devices();
char * pch = strtok(arg,","); char * pch = strtok(arg,",");
if (pch == NULL) { if (pch == NULL) {
@ -1842,13 +1843,14 @@ static void parse_arg(int key, char *arg)
d = atof(pch); d = atof(pch);
v = (uint32_t) d; v = (uint32_t) d;
if (v > 7) { /* 0 = default */ if (v > 7) { /* 0 = default */
gpus_intensity[n] = (1 << v);
if ((d - v) > 0.0) { if ((d - v) > 0.0) {
adds = (uint32_t) floor((d - v) * (1 << (v-8))) * 256; int adds = (uint32_t)floor((d - v) * (1 << (v - 8))) * 256;
gpus_intensity[n] += adds; gpus_intensity[n] = (1 << v) + adds;
applog(LOG_INFO, "Adding %u threads to intensity %u, %u cuda threads", applog(LOG_INFO, "Adding %u threads to intensity %u, %u cuda threads",
adds, v, gpus_intensity[n]); adds, v, gpus_intensity[n]);
} else { }
else if (gpus_intensity[n] != (1 << v)) {
gpus_intensity[n] = (1 << v);
applog(LOG_INFO, "Intensity set to %u, %u cuda threads", applog(LOG_INFO, "Intensity set to %u, %u cuda threads",
v, gpus_intensity[n]); v, gpus_intensity[n]);
} }
@ -1903,7 +1905,7 @@ static void parse_arg(int key, char *arg)
break; break;
case 't': case 't':
v = atoi(arg); v = atoi(arg);
if (v < 1 || v > 9999) /* sanity check */ if (v < 0 || v > 9999) /* sanity check */
show_usage_and_exit(1); show_usage_and_exit(1);
opt_n_threads = v; opt_n_threads = v;
break; break;
@ -2207,12 +2209,12 @@ int main(int argc, char *argv[])
int i; int i;
printf("*** ccminer " PACKAGE_VERSION " for nVidia GPUs by tpruvot@github ***\n"); printf("*** ccminer " PACKAGE_VERSION " for nVidia GPUs by tpruvot@github ***\n");
#ifdef WIN32 #ifdef _MSC_VER
printf("\tBuilt with VC++ 2013 and nVidia CUDA SDK 6.5\n\n"); printf(" Built with VC++ 2013 and nVidia CUDA SDK 6.5\n\n");
#else #else
printf("\tBuilt with the nVidia CUDA SDK 6.5\n\n"); printf(" Built with the nVidia CUDA SDK 6.5\n\n");
#endif #endif
printf(" Based on pooler cpuminer 2.3.2\n"); printf(" Originally based on pooler cpuminer,\n");
printf(" CUDA support by Christian Buchner and Christian H.\n"); printf(" CUDA support by Christian Buchner and Christian H.\n");
printf(" Include some of djm34 additions and sp optimisations\n\n"); printf(" Include some of djm34 additions and sp optimisations\n\n");
@ -2220,6 +2222,7 @@ int main(int argc, char *argv[])
rpc_user = strdup(""); rpc_user = strdup("");
rpc_pass = strdup(""); rpc_pass = strdup("");
rpc_url = strdup("");
pthread_mutex_init(&applog_lock, NULL); pthread_mutex_init(&applog_lock, NULL);
@ -2252,7 +2255,19 @@ int main(int argc, char *argv[])
/* parse command line */ /* parse command line */
parse_cmdline(argc, argv); parse_cmdline(argc, argv);
if (!opt_benchmark && !rpc_url) { if (!opt_benchmark && !strlen(rpc_url)) {
// try default config file (user then binary folder)
char defconfig[MAX_PATH] = { 0 };
get_defconfig_path(defconfig, MAX_PATH, argv[0]);
if (strlen(defconfig)) {
if (opt_debug)
applog(LOG_DEBUG, "Using config %s", defconfig);
parse_arg('c', defconfig);
parse_cmdline(argc, argv);
}
}
if (!opt_benchmark && !strlen(rpc_url)) {
fprintf(stderr, "%s: no URL supplied\n", argv[0]); fprintf(stderr, "%s: no URL supplied\n", argv[0]);
show_usage_and_exit(1); show_usage_and_exit(1);
} }

30
compat.h

@ -42,9 +42,37 @@ static __inline int setpriority(int which, int who, int prio)
} }
#ifdef _MSC_VER #ifdef _MSC_VER
#define __func__ __FUNCTION__ #define snprintf(...) _snprintf(__VA_ARGS__)
#define strdup(...) _strdup(__VA_ARGS__)
#define strncasecmp(x,y,z) _strnicmp(x,y,z)
#define strcasecmp(x,y) _stricmp(x,y)
typedef int ssize_t;
#include <stdlib.h>
static __inline char * dirname(char *file) {
char buffer[_MAX_PATH] = { 0 };
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
_splitpath_s(file, drive, _MAX_DRIVE, dir, _MAX_DIR, fname, _MAX_FNAME, ext, _MAX_EXT);
sprintf(buffer, "%s%s", drive, dir);
return strdup(buffer);
}
#endif #endif
#endif /* WIN32 */ #endif /* WIN32 */
#ifdef _MSC_VER
# define __func__ __FUNCTION__
# define __thread __declspec(thread)
# define _ALIGN(x) __declspec(align(x))
#else
# define _ALIGN(x) __attribute__ ((aligned(x)))
#endif
#ifndef WIN32
#define MAX_PATH PATH_MAX
#endif
#endif /* __COMPAT_H__ */ #endif /* __COMPAT_H__ */

2
configure.ac

@ -1,4 +1,4 @@
AC_INIT([ccminer], [1.5-git]) AC_INIT([ccminer], [1.5.3])
AC_PREREQ([2.59c]) AC_PREREQ([2.59c])
AC_CANONICAL_SYSTEM AC_CANONICAL_SYSTEM

6
cpuminer-config.h

@ -156,7 +156,7 @@
#define PACKAGE_NAME "ccminer" #define PACKAGE_NAME "ccminer"
/* Define to the full name and version of this package. */ /* Define to the full name and version of this package. */
#define PACKAGE_STRING "ccminer 1.5-git" #define PACKAGE_STRING "ccminer 1.5.3"
/* Define to the one symbol short name of this package. */ /* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "ccminer" #define PACKAGE_TARNAME "ccminer"
@ -165,7 +165,7 @@
#define PACKAGE_URL "" #define PACKAGE_URL ""
/* Define to the version of this package. */ /* Define to the version of this package. */
#define PACKAGE_VERSION "1.5-git" #define PACKAGE_VERSION "1.5.3"
/* If using the C implementation of alloca, define if you know the /* If using the C implementation of alloca, define if you know the
direction of stack growth for your system; otherwise it will be direction of stack growth for your system; otherwise it will be
@ -188,7 +188,7 @@
#define USE_XOP 1 #define USE_XOP 1
/* Version number of package */ /* Version number of package */
#define VERSION "1.5-git" #define VERSION "1.5.3"
/* Define curl_free() as free() if our version of curl lacks curl_free. */ /* Define curl_free() as free() if our version of curl lacks curl_free. */
/* #undef curl_free */ /* #undef curl_free */

18
example-cfg.json

@ -1,18 +0,0 @@
{
"_comment" : "todo: support /* comments */",
"algo" : "blake",
"intensity": 19,
"diff": 0.5,
"api-bind": "0.0.0.0:4068",
"statsavg": 20,
"quiet" : false,
"debug" : false,
"protocol": false,
"url" : "stratum+tcp://www.hashharder.com:9585",
"user" : "NaEcVrdzoCWHUYXb7X8QoafoKS9UV69Yk4",
"pass" : "ccminer"
}

13
miner.h

@ -14,12 +14,7 @@ extern "C" {
#include <jansson.h> #include <jansson.h>
#include <curl/curl.h> #include <curl/curl.h>
#ifdef WIN32 #ifdef _MSC_VER
#define snprintf(...) _snprintf(__VA_ARGS__)
#define strdup(x) _strdup(x)
#define strncasecmp(x,y,z) _strnicmp(x,y,z)
#define strcasecmp(x,y) _stricmp(x,y)
typedef int ssize_t;
#undef HAVE_ALLOCA_H #undef HAVE_ALLOCA_H
#undef HAVE_SYSLOG_H #undef HAVE_SYSLOG_H
#endif #endif
@ -69,11 +64,8 @@ typedef char * va_list;
#endif #endif
#if defined(__CUDA_ARCH__) && __CUDA_ARCH__ > 0 #if defined(__CUDA_ARCH__) && __CUDA_ARCH__ > 0
# undef _ALIGN
# define _ALIGN(x) __align__(x) # define _ALIGN(x) __align__(x)
#elif _MSC_VER
# define _ALIGN(x) __declspec(align(x))
#else
# define _ALIGN(x) __attribute__ ((aligned(x)))
#endif #endif
#ifdef HAVE_SYSLOG_H #ifdef HAVE_SYSLOG_H
@ -526,6 +518,7 @@ extern uint32_t gpus_intensity[MAX_GPUS];
#define CL_WHT "\x1B[01;37m" /* white */ #define CL_WHT "\x1B[01;37m" /* white */
extern void applog(int prio, const char *fmt, ...); extern void applog(int prio, const char *fmt, ...);
void get_defconfig_path(char *out, size_t bufsize, char *argv0);
extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass, extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
const char *rpc_req, bool, bool, int *); const char *rpc_req, bool, bool, int *);
extern void cbin2hex(char *out, const char *in, size_t len); extern void cbin2hex(char *out, const char *in, size_t len);

BIN
res/ccminer.rc

Binary file not shown.

28
util.cpp

@ -21,6 +21,7 @@
#include <unistd.h> #include <unistd.h>
#include <jansson.h> #include <jansson.h>
#include <curl/curl.h> #include <curl/curl.h>
#include <sys/stat.h>
#include <time.h> #include <time.h>
#ifdef WIN32 #ifdef WIN32
#include "compat/winansi.h" #include "compat/winansi.h"
@ -145,6 +146,33 @@ void applog(int prio, const char *fmt, ...)
va_end(ap); va_end(ap);
} }
/* Get default config.json path (system specific) */
void get_defconfig_path(char *out, size_t bufsize, char *argv0)
{
char *cmd = strdup(argv0);
char *dir = dirname(cmd);
const char *sep = strstr(dir, "\\") ? "\\" : "/";
struct stat info;
#ifdef WIN32
snprintf(out, bufsize, "%s\\ccminer\\ccminer.conf\0", getenv("APPDATA"));
#else
snprintf(out, bufsize, "%s\\.ccminer\\ccminer.conf", getenv("HOME"));
#endif
if (dir && stat(out, &info) != 0) {
// binary folder if not present in user folder
snprintf(out, bufsize, "%s%sccminer.conf\0", dir, sep);
}
if (stat(out, &info) != 0) {
out[0] = '\0';
return;
}
out[bufsize - 1] = '\0';
free(cmd);
#ifdef WIN32
if (dir) free(dir);
#endif
}
static void databuf_free(struct data_buffer *db) static void databuf_free(struct data_buffer *db)
{ {
if (!db) if (!db)

Loading…
Cancel
Save