Skip to content

Commit

Permalink
stratum: pool benchmark + new methods
Browse files Browse the repository at this point in the history
+ model/stepping cpu id to get the same vid on linux and windows
  • Loading branch information
tpruvot committed May 21, 2016
1 parent b693a9a commit fdeb220
Show file tree
Hide file tree
Showing 4 changed files with 306 additions and 5 deletions.
7 changes: 5 additions & 2 deletions cpu-miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ bool have_gbt = true;
bool allow_getwork = true;
bool want_stratum = true;
bool have_stratum = false;
bool opt_stratum_stats = false;
bool allow_mininginfo = true;
bool use_syslog = false;
bool use_colors = true;
Expand Down Expand Up @@ -2574,7 +2575,7 @@ static void *stratum_thread(void *userdata)

static void show_version_and_exit(void)
{
printf("\n built on " __DATE__
printf(" built on " __DATE__
#ifdef _MSC_VER
" with VC++ 2013\n");
#elif defined(__GNUC__)
Expand Down Expand Up @@ -2618,7 +2619,6 @@ static void show_version_and_exit(void)
#endif
#endif
"\n\n");

/* dependencies versions */
printf("%s\n", curl_version());
#ifdef JANSSON_VERSION
Expand Down Expand Up @@ -3307,6 +3307,9 @@ int main(int argc, char *argv[]) {
if (!thr->q)
return 1;

if (rpc_pass && rpc_user)
opt_stratum_stats = (strstr(rpc_pass, "stats") != NULL) || (strcmp(rpc_user, "benchmark") == 0);

/* start work I/O thread */
if (thread_create(thr, workio_thread)) {
applog(LOG_ERR, "work thread create failed");
Expand Down
14 changes: 13 additions & 1 deletion miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ enum {
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#endif

static inline bool is_windows(void) {
#ifdef WIN32
return 1;
#else
return 0;
#endif
}

#if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
#define WANT_BUILTIN_BSWAP
#else
Expand Down Expand Up @@ -274,13 +282,15 @@ extern bool opt_protocol;
extern bool opt_showdiff;
extern bool opt_quiet;
extern bool opt_redirect;
extern int opt_priority;
extern int opt_timeout;
extern bool want_longpoll;
extern bool have_longpoll;
extern bool have_gbt;
extern bool allow_getwork;
extern bool want_stratum;
extern bool have_stratum;
extern bool opt_stratum_stats;
extern char *opt_cert;
extern char *opt_proxy;
extern long opt_proxy_type;
Expand Down Expand Up @@ -357,7 +367,9 @@ void work_set_target_ratio(struct work* work, uint32_t* hash);

void get_currentalgo(char* buf, int sz);
bool has_aes_ni(void);
void bestcpu_feature(char *outbuf, int maxsz);
void cpu_bestfeature(char *outbuf, size_t maxsz);
void cpu_getname(char *outbuf, size_t maxsz);
void cpu_getmodelid(char *outbuf, size_t maxsz);
float cpu_temp(int core);

struct work {
Expand Down
80 changes: 78 additions & 2 deletions sysinfos.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ static uint32_t linux_cpufreq(int core)
if (!fscanf(fd, "%d", &freq))
return freq;

fclose(fd);
return freq;
}

Expand Down Expand Up @@ -110,6 +111,81 @@ int cpu_fanpercent()
return 0;
}

void cpu_getname(char *outbuf, size_t maxsz)
{
memset(outbuf, 0, maxsz);
#ifdef WIN32
// For the i7-5775C will output this :
// Intel64 Family 6 Model 71 Stepping 1, GenuineIntel
snprintf(outbuf, maxsz, "%s", getenv("PROCESSOR_IDENTIFIER"));
#else
// Intel(R) Xeon(R) CPU E3-1245 V2 @ 3.40GHz
FILE *fd = fopen("/proc/cpuinfo", "rb");
char *buf = NULL, *p, *eol;
size_t size = 0;
if (!fd) return;
while(getdelim(&buf, &size, 0, fd) != -1) {
if (buf && (p = strstr(buf, "model name\t")) && strstr(p, ":")) {
p = strstr(p, ":");
if (p) {
p += 2;
eol = strstr(p, "\n"); if (eol) *eol = '\0';
snprintf(outbuf, maxsz, "%s", p);
}
break;
}
}
free(buf);
fclose(fd);
#endif
}

void cpu_getmodelid(char *outbuf, size_t maxsz)
{
memset(outbuf, 0, maxsz);
#ifdef WIN32
// For the i7-5775C will output 6 r4701
snprintf(outbuf, maxsz, "%s:%s",
getenv("PROCESSOR_LEVEL"), getenv("PROCESSOR_REVISION")); // hexa
#else
FILE *fd = fopen("/proc/cpuinfo", "rb");
char *buf = NULL, *p, *eol;
int level = 0, cpufam = 0, model = 0, stepping = 0;
size_t size = 0;
if (!fd) return;
while(getdelim(&buf, &size, 0, fd) != -1) {
if (buf && (p = strstr(buf, "cpu family\t")) && strstr(p, ":")) {
p = strstr(p, ":");
if (p) {
p += 2;
cpufam = atoi(p);
}
}
if (buf && (p = strstr(buf, "model\t")) && strstr(p, ":")) {
p = strstr(p, ":");
if (p) {
p += 2;
model = atoi(p);
}
}
if (buf && (p = strstr(buf, "stepping\t")) && strstr(p, ":")) {
p = strstr(p, ":");
if (p) {
p += 2;
stepping = atoi(p);
}
}
if (level && cpufam) {
snprintf(outbuf, maxsz, "%x:%02x%02x", cpufam, model, stepping);
outbuf[maxsz-1] = '\0';
break;
}
}
free(buf);
fclose(fd);
#endif
}

#ifndef __arm__
static inline void cpuid(int functionnumber, int output[4]) {
#if defined (_MSC_VER) || defined (__INTEL_COMPILER)
Expand Down Expand Up @@ -163,7 +239,7 @@ bool has_aes_ni()
#endif
}

void bestcpu_feature(char *outbuf, int maxsz)
void cpu_bestfeature(char *outbuf, size_t maxsz)
{
#ifdef __arm__
sprintf(outbuf, "ARM");
Expand All @@ -175,7 +251,7 @@ void bestcpu_feature(char *outbuf, int maxsz)
if ((cpu_info[2] & AVX1_Flag) && (cpu_info_adv[1] & AVX2_Flag))
sprintf(outbuf, "AVX2");
else if (cpu_info[2] & AVX1_Flag)
sprintf(outbuf, "AVX1");
sprintf(outbuf, "AVX");
else if (cpu_info[2] & FMA3_Flag)
sprintf(outbuf, "FMA3");
else if (cpu_info[2] & XOP_Flag)
Expand Down
Loading

0 comments on commit fdeb220

Please sign in to comment.