Browse Source

Removed idle mode... again!?

Changed work_reset rate to every 100ms & use defines rather than numerics.
Change total sleep time to 4300ms after performance testing/measurement (now good to 916MH/s).
Changed timeout to 15s - Throttle time is 15s.
Added support for 'Busy' when submitting work.
Improved logging text to include device identifier.
Added a thread_enable api function, called when a thread is re-enabled.
... and removed useless re-init inside scanhash.
Use modminer introduced mutex.
nfactor-troky
Paul Sheppard 13 years ago
parent
commit
2384d0fbc6
  1. 16
      api.c
  2. 3
      cgminer.c
  3. 140
      driver-bitforce.c
  4. 4
      miner.h

16
api.c

@ -465,7 +465,7 @@ struct CODES { @@ -465,7 +465,7 @@ struct CODES {
{ SEVERITY_SUCC, MSG_GPUFAN, PARAM_BOTH, "Setting GPU %d fan to (%s) reported succeess" },
{ SEVERITY_ERR, MSG_MISFN, PARAM_NONE, "Missing save filename parameter" },
{ SEVERITY_ERR, MSG_BADFN, PARAM_STR, "Can't open or create save file '%s'" },
{ SEVERITY_ERR, MSG_SAVED, PARAM_STR, "Configuration saved to file '%s'" },
{ SEVERITY_SUCC, MSG_SAVED, PARAM_STR, "Configuration saved to file '%s'" },
{ SEVERITY_ERR, MSG_ACCDENY, PARAM_STR, "Access denied to '%s' command" },
{ SEVERITY_SUCC, MSG_ACCOK, PARAM_NONE, "Privileged access OK" },
{ SEVERITY_SUCC, MSG_ENAPOOL, PARAM_POOL, "Enabling pool %d:'%s'" },
@ -879,7 +879,7 @@ static void pgastatus(int pga, bool isjson) @@ -879,7 +879,7 @@ static void pgastatus(int pga, bool isjson)
cgpu->utility = cgpu->accepted / ( total_secs ? total_secs : 1 ) * 60;
if (cgpu->deven == DEV_ENABLED)
if (cgpu->deven != DEV_DISABLED)
enabled = (char *)YES;
else
enabled = (char *)NO;
@ -1092,7 +1092,7 @@ static void pgaenable(__maybe_unused SOCKETTYPE c, char *param, bool isjson) @@ -1092,7 +1092,7 @@ static void pgaenable(__maybe_unused SOCKETTYPE c, char *param, bool isjson)
struct cgpu_info *cgpu = devices[dev];
if (cgpu->deven == DEV_ENABLED) {
if (cgpu->deven != DEV_DISABLED) {
strcpy(io_buffer, message(MSG_PGALRENA, id, NULL, isjson));
return;
}
@ -1143,12 +1143,12 @@ static void pgadisable(__maybe_unused SOCKETTYPE c, char *param, bool isjson) @@ -1143,12 +1143,12 @@ static void pgadisable(__maybe_unused SOCKETTYPE c, char *param, bool isjson)
struct cgpu_info *cgpu = devices[dev];
if (cgpu->deven != DEV_ENABLED) {
if (cgpu->deven == DEV_DISABLED) {
strcpy(io_buffer, message(MSG_PGALRDIS, id, NULL, isjson));
return;
}
cgpu->deven = DEV_IDLE;
cgpu->deven = DEV_DISABLED;
strcpy(io_buffer, message(MSG_PGADIS, id, NULL, isjson));
}
@ -1979,12 +1979,13 @@ static void devdetails(__maybe_unused SOCKETTYPE c, __maybe_unused char *param, @@ -1979,12 +1979,13 @@ static void devdetails(__maybe_unused SOCKETTYPE c, __maybe_unused char *param,
void dosave(__maybe_unused SOCKETTYPE c, char *param, bool isjson)
{
char filename[PATH_MAX];
FILE *fcfg;
char *ptr;
if (param == NULL || *param == '\0') {
strcpy(io_buffer, message(MSG_MISFN, 0, NULL, isjson));
return;
default_save_file(filename);
param = filename;
}
fcfg = fopen(param, "w");
@ -2584,4 +2585,3 @@ die: @@ -2584,4 +2585,3 @@ die:
mutex_unlock(&quit_restart_lock);
}

3
cgminer.c

@ -3959,7 +3959,7 @@ void *miner_thread(void *userdata) @@ -3959,7 +3959,7 @@ void *miner_thread(void *userdata)
tv_lastupdate = tv_end;
}
if (unlikely(mythr->pause || cgpu->deven == DEV_DISABLED || cgpu->deven == DEV_RECOVER)) {
if (unlikely(mythr->pause || cgpu->deven != DEV_ENABLED)) {
applog(LOG_WARNING, "Thread %d being disabled", thr_id);
disabled:
mythr->rolling = mythr->cgpu->rolling = 0;
@ -3968,6 +3968,7 @@ disabled: @@ -3968,6 +3968,7 @@ disabled:
tq_pop(mythr->q, NULL); /* Ignore ping that's popped */
thread_reportin(mythr);
applog(LOG_WARNING, "Thread %d being re-enabled", thr_id);
if (api->thread_enable) api->thread_enable(mythr);
}
sdiff.tv_sec = sdiff.tv_usec = 0;

140
driver-bitforce.c

@ -20,9 +20,13 @@ @@ -20,9 +20,13 @@
#include "fpgautils.h"
#include "miner.h"
#define BITFORCE_SLEEP_US 4500000
#define BITFORCE_SLEEP_MS (BITFORCE_SLEEP_US/1000)
#define BITFORCE_TIMEOUT_MS 30000
/* @832MH/s wait time is ~4500ms
@864MH/s wait time is ~4430ms
-> @896MH/s wait time will be ~4350ms */
#define BITFORCE_SLEEP_MS 4300
#define BITFORCE_TIMEOUT_MS 15000
#define BITFORCE_CHECK_INTERVAL_MS 10
#define WORK_CHECK_INTERVAL_MS 100
struct device_api bitforce_api;
@ -44,7 +48,7 @@ static ssize_t BFwrite2(int fd, const void *buf, ssize_t bufLen) @@ -44,7 +48,7 @@ static ssize_t BFwrite2(int fd, const void *buf, ssize_t bufLen)
#define BFwrite(fd, buf, bufLen) do { \
if ((bufLen) != BFwrite2(fd, buf, bufLen)) { \
applog(LOG_ERR, "Error writing to BitForce (" #buf ")"); \
applog(LOG_ERR, "BFL: Error writing (" #buf ")"); \
return 0; \
} \
} while(0)
@ -58,18 +62,18 @@ static bool bitforce_detect_one(const char *devpath) @@ -58,18 +62,18 @@ static bool bitforce_detect_one(const char *devpath)
int fdDev = BFopen(devpath);
if (unlikely(fdDev == -1)) {
applog(LOG_ERR, "BitForce Detect: Failed to open %s", devpath);
applog(LOG_ERR, "BFL: Failed to open %s", devpath);
return false;
}
BFwrite(fdDev, "ZGX", 3);
BFgets(pdevbuf, sizeof(pdevbuf), fdDev);
if (unlikely(!pdevbuf[0])) {
applog(LOG_ERR, "Error reading from BitForce (ZGX)");
applog(LOG_ERR, "BFL: Error reading (ZGX)");
return 0;
}
BFclose(fdDev);
if (unlikely(!strstr(pdevbuf, "SHA256"))) {
applog(LOG_ERR, "BitForce Detect: Didn't recognise BitForce on %s", devpath);
applog(LOG_ERR, "BFL: Didn't recognise BitForce on %s", devpath);
return false;
}
@ -86,7 +90,7 @@ static bool bitforce_detect_one(const char *devpath) @@ -86,7 +90,7 @@ static bool bitforce_detect_one(const char *devpath)
bitforce->name = strdup(pdevbuf + 7);
}
mutex_init(&bitforce->dev_lock);
mutex_init(&bitforce->device_mutex);
return add_cgpu(bitforce);
}
@ -122,13 +126,13 @@ static bool bitforce_thread_prepare(struct thr_info *thr) @@ -122,13 +126,13 @@ static bool bitforce_thread_prepare(struct thr_info *thr)
int fdDev = BFopen(bitforce->device_path);
if (unlikely(-1 == fdDev)) {
applog(LOG_ERR, "Failed to open BitForce on %s", bitforce->device_path);
applog(LOG_ERR, "BFL%i: Failed to open %s", bitforce->device_id, bitforce->device_path);
return false;
}
bitforce->device_fd = fdDev;
applog(LOG_INFO, "Opened BitForce on %s", bitforce->device_path);
applog(LOG_INFO, "BFL%i: Opened %s", bitforce->device_id, bitforce->device_path);
gettimeofday(&now, NULL);
get_datestamp(bitforce->init, &now);
@ -142,30 +146,33 @@ static bool bitforce_init(struct cgpu_info *bitforce) @@ -142,30 +146,33 @@ static bool bitforce_init(struct cgpu_info *bitforce)
char pdevbuf[0x100];
char *s;
applog(LOG_DEBUG, "BFL%i: Re-initalizing", bitforce->device_id);
applog(LOG_INFO, "BFL%i: Re-initalizing", bitforce->device_id);
BFclose(fdDev);
if (fdDev) {
BFclose(fdDev);
bitforce->device_fd = 0;
}
fdDev = BFopen(devpath);
if (unlikely(fdDev == -1)) {
applog(LOG_ERR, "BitForce init: Failed to open %s", devpath);
applog(LOG_ERR, "BFL%i: Failed to open %s", bitforce->device_id, devpath);
return false;
}
bitforce->device_fd = fdDev;
mutex_lock(&bitforce->dev_lock);
mutex_lock(&bitforce->device_mutex);
BFwrite(fdDev, "ZGX", 3);
BFgets(pdevbuf, sizeof(pdevbuf), fdDev);
mutex_unlock(&bitforce->dev_lock);
mutex_unlock(&bitforce->device_mutex);
if (unlikely(!pdevbuf[0])) {
applog(LOG_ERR, "Error reading from BitForce (ZGX)");
applog(LOG_ERR, "BFL%i: Error reading (ZGX)", bitforce->device_id);
return false;
}
if (unlikely(!strstr(pdevbuf, "SHA256"))) {
applog(LOG_ERR, "BitForce init: Didn't recognise BitForce on %s", devpath);
applog(LOG_ERR, "BFL%i: Didn't recognise BitForce on %s", bitforce->device_id, devpath);
return false;
}
@ -184,13 +191,13 @@ static bool bitforce_get_temp(struct cgpu_info *bitforce) @@ -184,13 +191,13 @@ static bool bitforce_get_temp(struct cgpu_info *bitforce)
char pdevbuf[0x100];
char *s;
mutex_lock(&bitforce->dev_lock);
mutex_lock(&bitforce->device_mutex);
BFwrite(fdDev, "ZLX", 3);
BFgets(pdevbuf, sizeof(pdevbuf), fdDev);
mutex_unlock(&bitforce->dev_lock);
mutex_unlock(&bitforce->device_mutex);
if (unlikely(!pdevbuf[0])) {
applog(LOG_ERR, "Error reading temp from BitForce (ZLX)");
applog(LOG_ERR, "BFL%i: Error reading (ZLX)", bitforce->device_id);
return false;
}
if ((!strncasecmp(pdevbuf, "TEMP", 4)) && (s = strchr(pdevbuf + 4, ':'))) {
@ -198,7 +205,7 @@ static bool bitforce_get_temp(struct cgpu_info *bitforce) @@ -198,7 +205,7 @@ static bool bitforce_get_temp(struct cgpu_info *bitforce)
if (temp > 0) {
bitforce->temp = temp;
if (temp > bitforce->cutofftemp) {
applog(LOG_WARNING, "Hit thermal cutoff limit on %s %d, disabling!", bitforce->api->name, bitforce->device_id);
applog(LOG_WARNING, "BFL%i: Hit thermal cutoff limit, disabling!", bitforce->device_id);
bitforce->deven = DEV_RECOVER;
bitforce->device_last_not_well = time(NULL);
@ -218,17 +225,22 @@ static bool bitforce_send_work(struct thr_info *thr, struct work *work) @@ -218,17 +225,22 @@ static bool bitforce_send_work(struct thr_info *thr, struct work *work)
unsigned char ob[61] = ">>>>>>>>12345678901234567890123456789012123456789012>>>>>>>>";
char *s;
mutex_lock(&bitforce->dev_lock);
mutex_lock(&bitforce->device_mutex);
BFwrite(fdDev, "ZDX", 3);
BFgets(pdevbuf, sizeof(pdevbuf), fdDev);
if (unlikely(!pdevbuf[0])) {
applog(LOG_ERR, "Error reading from BitForce (ZDX)");
mutex_unlock(&bitforce->dev_lock);
applog(LOG_ERR, "BFL%i: Error reading (ZDX)", bitforce->device_id);
mutex_unlock(&bitforce->device_mutex);
return false;
}
if (unlikely(pdevbuf[0] != 'O' || pdevbuf[1] != 'K')) {
applog(LOG_ERR, "BitForce ZDX reports: %s", pdevbuf);
mutex_unlock(&bitforce->dev_lock);
if (pdevbuf[0] == 'B'){
applog(LOG_WARNING, "BFL%i: Throttling", bitforce->device_id);
mutex_unlock(&bitforce->device_mutex);
return true;
}
else if (unlikely(pdevbuf[0] != 'O' || pdevbuf[1] != 'K')) {
applog(LOG_ERR, "BFL%i: ZDX reports: %s", bitforce->device_id, pdevbuf);
mutex_unlock(&bitforce->device_mutex);
return false;
}
memcpy(ob + 8, work->midstate, 32);
@ -237,17 +249,17 @@ static bool bitforce_send_work(struct thr_info *thr, struct work *work) @@ -237,17 +249,17 @@ static bool bitforce_send_work(struct thr_info *thr, struct work *work)
BFwrite(fdDev, ob, 60);
if (opt_debug) {
s = bin2hex(ob + 8, 44);
applog(LOG_DEBUG, "BitForce block data: %s", s);
applog(LOG_DEBUG, "BFL%i: block data: %s", bitforce->device_id, s);
free(s);
}
BFgets(pdevbuf, sizeof(pdevbuf), fdDev);
mutex_unlock(&bitforce->dev_lock);
mutex_unlock(&bitforce->device_mutex);
if (unlikely(!pdevbuf[0])) {
applog(LOG_ERR, "Error reading from BitForce (block data)");
applog(LOG_ERR, "BFL%i: Error reading (block data)", bitforce->device_id);
return false;
}
if (unlikely(pdevbuf[0] != 'O' || pdevbuf[1] != 'K')) {
applog(LOG_ERR, "BitForce block data reports: %s", pdevbuf);
applog(LOG_ERR, "BFL%i: block data reports: %s", bitforce->device_id, pdevbuf);
return false;
}
return true;
@ -261,41 +273,39 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work) @@ -261,41 +273,39 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work)
char pdevbuf[0x100];
char *pnoncebuf;
uint32_t nonce;
int i;
unsigned int wait_ms = BITFORCE_SLEEP_MS;
i = BITFORCE_SLEEP_MS;
while (i < BITFORCE_TIMEOUT_MS) {
mutex_lock(&bitforce->dev_lock);
while (wait_ms < BITFORCE_TIMEOUT_MS) {
mutex_lock(&bitforce->device_mutex);
BFwrite(fdDev, "ZFX", 3);
BFgets(pdevbuf, sizeof(pdevbuf), fdDev);
mutex_unlock(&bitforce->dev_lock);
mutex_unlock(&bitforce->device_mutex);
if (unlikely(!pdevbuf[0])) {
applog(LOG_ERR, "Error reading from BitForce (ZFX)");
mutex_unlock(&bitforce->dev_lock);
applog(LOG_ERR, "BFL%i: Error reading (ZFX)", bitforce->device_id);
mutex_unlock(&bitforce->device_mutex);
return 0;
}
if (pdevbuf[0] != 'B')
break;
usleep(10000);
i += 10;
usleep(BITFORCE_CHECK_INTERVAL_MS*1000);
wait_ms += BITFORCE_CHECK_INTERVAL_MS;
}
if (i >= BITFORCE_TIMEOUT_MS) {
applog(LOG_ERR, "BitForce took longer than 30s");
if (wait_ms >= BITFORCE_TIMEOUT_MS) {
applog(LOG_ERR, "BFL%i took longer than 15s");
bitforce->device_last_not_well = time(NULL);
bitforce->device_not_well_reason = REASON_THREAD_ZERO_HASH;
bitforce->thread_zero_hash_count++;
return 1;
}
applog(LOG_DEBUG, "BitForce waited %dms until %s\n", i, pdevbuf);
applog(LOG_DEBUG, "BFL%i: waited %dms until %s\n", bitforce->device_id, wait_ms, pdevbuf);
work->blk.nonce = 0xffffffff;
if (pdevbuf[2] == '-')
return 0xffffffff; /* No valid nonce found */
else if (pdevbuf[0] == 'I')
return 1; /* Device idle */
else if (strncasecmp(pdevbuf, "NONCE-FOUND", 11)) {
applog(LOG_WARNING, "BitForce result reports: %s", pdevbuf);
applog(LOG_WARNING, "BFL%i: result reports: %s", bitforce->device_id, pdevbuf);
return 1;
}
@ -319,42 +329,34 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work) @@ -319,42 +329,34 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work)
static void bitforce_shutdown(struct thr_info *thr)
{
struct cgpu_info *bitforce = thr->cgpu;
int fdDev = bitforce->device_fd;
BFclose(fdDev);
BFclose(bitforce->device_fd);
bitforce->device_fd = 0;
}
#define CHECK_INTERVAL_MS 200
static void biforce_thread_enable(struct thr_info *thr)
{
struct cgpu_info *bitforce = thr->cgpu;
bitforce_init(bitforce);
}
static uint64_t bitforce_scanhash(struct thr_info *thr, struct work *work, uint64_t __maybe_unused max_nonce)
{
struct cgpu_info *bitforce = thr->cgpu;
bool dev_enabled = (bitforce->deven == DEV_ENABLED);
static enum dev_enable last_dev_state = DEV_ENABLED;
int wait_ms = 0;
if (bitforce->deven == DEV_DISABLED) {
bitforce_shutdown(thr);
return 1;
}
// if device has just gone from disabled to enabled, re-initialise it
if (last_dev_state == DEV_DISABLED && dev_enabled)
bitforce_init(bitforce);
last_dev_state = bitforce->deven;
unsigned int wait_ms = 0;
if (!bitforce_send_work(thr, work))
return 0;
while (wait_ms < BITFORCE_SLEEP_MS) {
usleep(CHECK_INTERVAL_MS * 1000);
wait_ms += CHECK_INTERVAL_MS;
usleep(WORK_CHECK_INTERVAL_MS*1000);
wait_ms += WORK_CHECK_INTERVAL_MS;
if (work_restart[thr->id].restart) {
applog(LOG_DEBUG, "BFL%i: New work detected, discarding current job", bitforce->device_id);
return 1; //we have discard all work; equivilent to 0 hashes done.
applog(LOG_DEBUG, "BFL%i: Work restart, discarding after %dms", bitforce->device_id, wait_ms);
return 1; //we have discarded all work; equivilent to 0 hashes done.
}
}
return bitforce_get_result(thr, work);
}
@ -367,9 +369,11 @@ struct device_api bitforce_api = { @@ -367,9 +369,11 @@ struct device_api bitforce_api = {
.dname = "bitforce",
.name = "BFL",
.api_detect = bitforce_detect,
.reinit_device = bitforce_init,
.get_statline_before = get_bitforce_statline_before,
.get_stats = bitforce_get_stats,
.thread_prepare = bitforce_thread_prepare,
.scanhash = bitforce_scanhash,
.thread_shutdown = bitforce_shutdown
.thread_shutdown = bitforce_shutdown,
.thread_enable = biforce_thread_enable
};

4
miner.h

@ -245,13 +245,13 @@ struct device_api { @@ -245,13 +245,13 @@ struct device_api {
bool (*prepare_work)(struct thr_info*, struct work*);
uint64_t (*scanhash)(struct thr_info*, struct work*, uint64_t);
void (*thread_shutdown)(struct thr_info*);
void (*thread_enable)(struct thr_info*);
};
enum dev_enable {
DEV_ENABLED,
DEV_DISABLED,
DEV_RECOVER,
DEV_IDLE,
};
enum cl_kernels {
@ -377,8 +377,6 @@ struct cgpu_info { @@ -377,8 +377,6 @@ struct cgpu_info {
int dev_thermal_cutoff_count;
struct cgminer_stats cgminer_stats;
pthread_mutex_t dev_lock;
};
extern bool add_cgpu(struct cgpu_info*);

Loading…
Cancel
Save