From 19b4d2b9dea36079ac5a3efe88df21bc5277e661 Mon Sep 17 00:00:00 2001 From: Paul Sheppard Date: Fri, 6 Jul 2012 11:57:53 -0700 Subject: [PATCH 01/10] More BFL tweaks. Add delay between closing and reopening port. Remove buffer clear in re-init Add kernel type (mini-rig or single) --- driver-bitforce.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/driver-bitforce.c b/driver-bitforce.c index 3cfd287c..6432d59a 100644 --- a/driver-bitforce.c +++ b/driver-bitforce.c @@ -88,8 +88,11 @@ static bool bitforce_detect_one(const char *devpath) if (opt_bfl_noncerange) { bitforce->nonce_range = true; bitforce->sleep_ms = BITFORCE_SLEEP_MS; - } else + bitforce->kname = "Mini-rig"; + } else { bitforce->sleep_ms = BITFORCE_SLEEP_MS * 5; + bitforce->kname = "Single"; + } if (likely((!memcmp(pdevbuf, ">>>ID: ", 7)) && (s = strstr(pdevbuf + 3, ">>>")))) { s[0] = '\0'; @@ -172,11 +175,11 @@ void bitforce_init(struct cgpu_info *bitforce) applog(LOG_WARNING, "BFL%i: Re-initalizing", bitforce->device_id); - biforce_clear_buffer(bitforce); - mutex_lock(&bitforce->device_mutex); - if (fdDev) + if (fdDev) { BFclose(fdDev); + sleep(5); + } bitforce->device_fd = 0; fdDev = BFopen(devpath); @@ -282,6 +285,7 @@ re_send: applog(LOG_WARNING, "BFL%i: Does not support nonce range, disabling", bitforce->device_id); bitforce->nonce_range = false; bitforce->sleep_ms *= 5; + bitforce->kname = "Single"; goto re_send; } applog(LOG_ERR, "BFL%i: Error: Send work reports: %s", bitforce->device_id, pdevbuf); From 953ecd9e6a3fff4c26d25197bcd90848c948fb91 Mon Sep 17 00:00:00 2001 From: Paul Sheppard Date: Sun, 8 Jul 2012 23:25:02 -0700 Subject: [PATCH 02/10] Change timeouts to time-vals for accuracy. --- driver-bitforce.c | 25 ++++++++++++++++++++----- miner.h | 1 + 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/driver-bitforce.c b/driver-bitforce.c index 276ffcf7..92315837 100644 --- a/driver-bitforce.c +++ b/driver-bitforce.c @@ -21,11 +21,14 @@ #include "miner.h" #define BITFORCE_SLEEP_MS 500 -#define BITFORCE_TIMEOUT_MS 10000 -#define BITFORCE_LONG_TIMEOUT_MS 15000 +#define BITFORCE_TIMEOUT_S 7 +#define BITFORCE_TIMEOUT_MS (BITFORCE_TIMEOUT_S * 1000) +#define BITFORCE_LONG_TIMEOUT_S 15 +#define BITFORCE_LONG_TIMEOUT_MS (BITFORCE_LONG_TIMEOUT_S * 1000) #define BITFORCE_CHECK_INTERVAL_MS 10 #define WORK_CHECK_INTERVAL_MS 50 #define MAX_START_DELAY_US 100000 +#define tv_to_ms(tval) (tval.tv_sec * 1000 + tval.tv_usec / 1000) struct device_api bitforce_api; @@ -332,6 +335,7 @@ re_send: return false; } + gettimeofday(&bitforce->work_start_tv, NULL); return true; } @@ -340,6 +344,8 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work) struct cgpu_info *bitforce = thr->cgpu; int fdDev = bitforce->device_fd; unsigned int delay_time_ms; + struct timeval elapsed; + struct timeval now; char pdevbuf[0x100]; char *pnoncebuf; uint32_t nonce; @@ -348,7 +354,7 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work) if (!fdDev) return 0; - while (bitforce->wait_ms < BITFORCE_LONG_TIMEOUT_MS) { + while (1) { if (unlikely(thr->work_restart)) return 1; @@ -357,6 +363,15 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work) BFgets(pdevbuf, sizeof(pdevbuf), fdDev); mutex_unlock(&bitforce->device_mutex); + gettimeofday(&now, NULL); + timersub(&now, &bitforce->work_start_tv, &elapsed); + + if (elapsed.tv_sec >= BITFORCE_LONG_TIMEOUT_S) { + applog(LOG_ERR, "BFL%i: took %dms - longer than %dms", bitforce->device_id, + tv_to_ms(elapsed), BITFORCE_LONG_TIMEOUT_MS); + return 0; + } + if (pdevbuf[0] && strncasecmp(pdevbuf, "B", 1)) /* BFL does not respond during throttling */ break; @@ -366,9 +381,9 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work) bitforce->wait_ms += delay_time_ms; } - if (bitforce->wait_ms >= BITFORCE_TIMEOUT_MS) { + if (elapsed.tv_sec > BITFORCE_TIMEOUT_S) { applog(LOG_ERR, "BFL%i: took %dms - longer than %dms", bitforce->device_id, - bitforce->wait_ms, BITFORCE_TIMEOUT_MS); + tv_to_ms(elapsed), BITFORCE_TIMEOUT_MS); bitforce->device_last_not_well = time(NULL); bitforce->device_not_well_reason = REASON_DEV_OVER_HEAT; bitforce->dev_over_heat_count++; diff --git a/miner.h b/miner.h index 50a1ca2a..4acb8f96 100644 --- a/miner.h +++ b/miner.h @@ -320,6 +320,7 @@ struct cgpu_info { int device_fd; }; #ifdef USE_BITFORCE + struct timeval work_start_tv; unsigned int wait_ms; unsigned int sleep_ms; uint32_t nonces; From 2dfe0d628e05763bce09c51420860ef4f2ea7919 Mon Sep 17 00:00:00 2001 From: Paul Sheppard Date: Mon, 9 Jul 2012 17:36:06 -0700 Subject: [PATCH 03/10] Remove bitforce_thread_init The delay thing does nothing useful... when long poll comes around, all threads restart at the same time anyway. --- driver-bitforce.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/driver-bitforce.c b/driver-bitforce.c index 92315837..365bf29f 100644 --- a/driver-bitforce.c +++ b/driver-bitforce.c @@ -510,20 +510,6 @@ static bool bitforce_get_stats(struct cgpu_info *bitforce) return bitforce_get_temp(bitforce); } -static bool bitforce_thread_init(struct thr_info *thr) -{ - struct cgpu_info *bitforce = thr->cgpu; - unsigned int wait; - - /* Pause each new thread a random time between 0-100ms - so the devices aren't making calls all at the same time. */ - wait = (rand() * MAX_START_DELAY_US)/RAND_MAX; - applog(LOG_DEBUG, "BFL%i: Delaying start by %dms", bitforce->device_id, wait / 1000); - usleep(wait); - - return true; -} - static struct api_data *bitforce_api_stats(struct cgpu_info *cgpu) { struct api_data *root = NULL; @@ -546,7 +532,6 @@ struct device_api bitforce_api = { .get_statline_before = get_bitforce_statline_before, .get_stats = bitforce_get_stats, .thread_prepare = bitforce_thread_prepare, - .thread_init = bitforce_thread_init, .scanhash = bitforce_scanhash, .thread_shutdown = bitforce_shutdown, .thread_enable = biforce_thread_enable From 3cc0aa76ad25d0ce580b9ec5db2c53eadf4d4a4e Mon Sep 17 00:00:00 2001 From: Paul Sheppard Date: Tue, 10 Jul 2012 15:34:01 -0700 Subject: [PATCH 04/10] Add average return time to api stats --- driver-bitforce.c | 9 ++++++++- miner.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/driver-bitforce.c b/driver-bitforce.c index 365bf29f..e87c3af4 100644 --- a/driver-bitforce.c +++ b/driver-bitforce.c @@ -29,6 +29,8 @@ #define WORK_CHECK_INTERVAL_MS 50 #define MAX_START_DELAY_US 100000 #define tv_to_ms(tval) (tval.tv_sec * 1000 + tval.tv_usec / 1000) +#define TIME_AVE_CONSTANT 16 +#define TIME_AVE_ROUND (TIME_AVE_CONSTANT/2) struct device_api bitforce_api; @@ -101,7 +103,7 @@ static bool bitforce_detect_one(const char *devpath) s[0] = '\0'; bitforce->name = strdup(pdevbuf + 7); } - + mutex_init(&bitforce->device_mutex); return add_cgpu(bitforce); @@ -407,6 +409,9 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work) if (delay_time_ms != bitforce->sleep_ms) applog(LOG_DEBUG, "BFL%i: Wait time changed to: %d", bitforce->device_id, bitforce->sleep_ms, bitforce->wait_ms); + + /* Work out the averge time taken. This method (pre mutiplier) maintains the fractional part accuracy */ + bitforce->ave_wait += (tv_to_ms(elapsed) * TIME_AVE_CONSTANT) - bitforce->ave_wait; } applog(LOG_DEBUG, "BFL%i: waited %dms until %s", bitforce->device_id, bitforce->wait_ms, pdevbuf); @@ -513,12 +518,14 @@ static bool bitforce_get_stats(struct cgpu_info *bitforce) static struct api_data *bitforce_api_stats(struct cgpu_info *cgpu) { struct api_data *root = NULL; + unsigned int ave_wait_ms = (cgpu->ave_wait + TIME_AVE_ROUND)/TIME_AVE_CONSTANT; /* Now remove the multiplier */ // Warning, access to these is not locked - but we don't really // care since hashing performance is way more important than // locking access to displaying API debug 'stats' // If locking becomes an issue for any of them, use copy_data=true also root = api_add_uint(root, "Sleep Time", &(cgpu->sleep_ms), false); + root = api_add_uint(root, "Ave Wait", &(ave_wait_ms), false); return root; } diff --git a/miner.h b/miner.h index 4acb8f96..39e96f92 100644 --- a/miner.h +++ b/miner.h @@ -321,6 +321,7 @@ struct cgpu_info { }; #ifdef USE_BITFORCE struct timeval work_start_tv; + unsigned int ave_wait; unsigned int wait_ms; unsigned int sleep_ms; uint32_t nonces; From 4dc1bf2319daf5d8eae3a486e2bbbaa3ed00c88b Mon Sep 17 00:00:00 2001 From: Paul Sheppard Date: Tue, 10 Jul 2012 15:40:45 -0700 Subject: [PATCH 05/10] Missed one nonce-range disabling. --- driver-bitforce.c | 1 + 1 file changed, 1 insertion(+) diff --git a/driver-bitforce.c b/driver-bitforce.c index 365bf29f..be266e28 100644 --- a/driver-bitforce.c +++ b/driver-bitforce.c @@ -432,6 +432,7 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work) bitforce->nonce_range = false; work->blk.nonce = 0xffffffff; bitforce->sleep_ms *= 5; + bitforce->kname = "Single"; } submit_nonce(thr, work, nonce); From 01a69ee45e15f2f6b225fa93e8ef15ce7427fd2e Mon Sep 17 00:00:00 2001 From: Paul Sheppard Date: Wed, 11 Jul 2012 08:07:39 -0700 Subject: [PATCH 06/10] Revert "Merge branch 'ave_time' of https://github.com/pshep/cgminer.git" This reverts commit 242e52cdf902aabd124e600a65b7d7140b11fef0, reversing changes made to 4dc1bf2319daf5d8eae3a486e2bbbaa3ed00c88b. --- driver-bitforce.c | 9 +-------- miner.h | 1 - 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/driver-bitforce.c b/driver-bitforce.c index 59d7427a..be266e28 100644 --- a/driver-bitforce.c +++ b/driver-bitforce.c @@ -29,8 +29,6 @@ #define WORK_CHECK_INTERVAL_MS 50 #define MAX_START_DELAY_US 100000 #define tv_to_ms(tval) (tval.tv_sec * 1000 + tval.tv_usec / 1000) -#define TIME_AVE_CONSTANT 16 -#define TIME_AVE_ROUND (TIME_AVE_CONSTANT/2) struct device_api bitforce_api; @@ -103,7 +101,7 @@ static bool bitforce_detect_one(const char *devpath) s[0] = '\0'; bitforce->name = strdup(pdevbuf + 7); } - + mutex_init(&bitforce->device_mutex); return add_cgpu(bitforce); @@ -409,9 +407,6 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work) if (delay_time_ms != bitforce->sleep_ms) applog(LOG_DEBUG, "BFL%i: Wait time changed to: %d", bitforce->device_id, bitforce->sleep_ms, bitforce->wait_ms); - - /* Work out the averge time taken. This method (pre mutiplier) maintains the fractional part accuracy */ - bitforce->ave_wait += (tv_to_ms(elapsed) * TIME_AVE_CONSTANT) - bitforce->ave_wait; } applog(LOG_DEBUG, "BFL%i: waited %dms until %s", bitforce->device_id, bitforce->wait_ms, pdevbuf); @@ -519,14 +514,12 @@ static bool bitforce_get_stats(struct cgpu_info *bitforce) static struct api_data *bitforce_api_stats(struct cgpu_info *cgpu) { struct api_data *root = NULL; - unsigned int ave_wait_ms = (cgpu->ave_wait + TIME_AVE_ROUND)/TIME_AVE_CONSTANT; /* Now remove the multiplier */ // Warning, access to these is not locked - but we don't really // care since hashing performance is way more important than // locking access to displaying API debug 'stats' // If locking becomes an issue for any of them, use copy_data=true also root = api_add_uint(root, "Sleep Time", &(cgpu->sleep_ms), false); - root = api_add_uint(root, "Ave Wait", &(ave_wait_ms), false); return root; } diff --git a/miner.h b/miner.h index 39e96f92..4acb8f96 100644 --- a/miner.h +++ b/miner.h @@ -321,7 +321,6 @@ struct cgpu_info { }; #ifdef USE_BITFORCE struct timeval work_start_tv; - unsigned int ave_wait; unsigned int wait_ms; unsigned int sleep_ms; uint32_t nonces; From 2c54522d7dee649a63e89705eda23e07505ada49 Mon Sep 17 00:00:00 2001 From: Paul Sheppard Date: Wed, 11 Jul 2012 08:11:53 -0700 Subject: [PATCH 07/10] Add average wait time to api stats --- driver-bitforce.c | 9 +++++++-- miner.h | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/driver-bitforce.c b/driver-bitforce.c index be266e28..8e41bb98 100644 --- a/driver-bitforce.c +++ b/driver-bitforce.c @@ -29,6 +29,7 @@ #define WORK_CHECK_INTERVAL_MS 50 #define MAX_START_DELAY_US 100000 #define tv_to_ms(tval) (tval.tv_sec * 1000 + tval.tv_usec / 1000) +#define TIME_AVE_CONSTANT 8 struct device_api bitforce_api; @@ -101,7 +102,7 @@ static bool bitforce_detect_one(const char *devpath) s[0] = '\0'; bitforce->name = strdup(pdevbuf + 7); } - + mutex_init(&bitforce->device_mutex); return add_cgpu(bitforce); @@ -407,6 +408,10 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work) if (delay_time_ms != bitforce->sleep_ms) applog(LOG_DEBUG, "BFL%i: Wait time changed to: %d", bitforce->device_id, bitforce->sleep_ms, bitforce->wait_ms); + + /* Work out the average time taken. Float for calculation, uint for display */ + bitforce->ave_wait_f += (tv_to_ms(elapsed) - bitforce->ave_wait_f) / TIME_AVE_CONSTANT; + bitforce->ave_wait_d = (unsigned int) (bitforce->ave_wait_f + 0.5); } applog(LOG_DEBUG, "BFL%i: waited %dms until %s", bitforce->device_id, bitforce->wait_ms, pdevbuf); @@ -432,7 +437,6 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work) bitforce->nonce_range = false; work->blk.nonce = 0xffffffff; bitforce->sleep_ms *= 5; - bitforce->kname = "Single"; } submit_nonce(thr, work, nonce); @@ -520,6 +524,7 @@ static struct api_data *bitforce_api_stats(struct cgpu_info *cgpu) // locking access to displaying API debug 'stats' // If locking becomes an issue for any of them, use copy_data=true also root = api_add_uint(root, "Sleep Time", &(cgpu->sleep_ms), false); + root = api_add_uint(root, "Ave Wait", &(cgpu->ave_wait_d), false); return root; } diff --git a/miner.h b/miner.h index 4acb8f96..fc8a1083 100644 --- a/miner.h +++ b/miner.h @@ -321,8 +321,11 @@ struct cgpu_info { }; #ifdef USE_BITFORCE struct timeval work_start_tv; + unsigned int ave_wait; unsigned int wait_ms; unsigned int sleep_ms; + double ave_wait_f; + unsigned int ave_wait_d; uint32_t nonces; bool nonce_range; #endif From c37a3f3007f98e50cb4fbabe87b1012d7eb8e6da Mon Sep 17 00:00:00 2001 From: Paul Sheppard Date: Wed, 11 Jul 2012 08:30:56 -0700 Subject: [PATCH 08/10] Put kname change for broken nonce-range back in --- driver-bitforce.c | 1 + 1 file changed, 1 insertion(+) diff --git a/driver-bitforce.c b/driver-bitforce.c index 8e41bb98..cc3317ff 100644 --- a/driver-bitforce.c +++ b/driver-bitforce.c @@ -437,6 +437,7 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work) bitforce->nonce_range = false; work->blk.nonce = 0xffffffff; bitforce->sleep_ms *= 5; + bitforce->kname = "Single"; } submit_nonce(thr, work, nonce); From 5f0a22d230650b990a66ffd418fc5113449133c1 Mon Sep 17 00:00:00 2001 From: Paul Sheppard Date: Wed, 11 Jul 2012 08:32:41 -0700 Subject: [PATCH 09/10] Remove superfluous ave_wait --- miner.h | 1 - 1 file changed, 1 deletion(-) diff --git a/miner.h b/miner.h index fc8a1083..1cfd943e 100644 --- a/miner.h +++ b/miner.h @@ -321,7 +321,6 @@ struct cgpu_info { }; #ifdef USE_BITFORCE struct timeval work_start_tv; - unsigned int ave_wait; unsigned int wait_ms; unsigned int sleep_ms; double ave_wait_f; From d4d5b28e5fa47a09e7d791a1c265ddee8ec13c24 Mon Sep 17 00:00:00 2001 From: Paul Sheppard Date: Wed, 11 Jul 2012 14:46:09 -0700 Subject: [PATCH 10/10] Abbrv. correction --- driver-bitforce.c | 8 ++++---- miner.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/driver-bitforce.c b/driver-bitforce.c index cc3317ff..9e4fc6f4 100644 --- a/driver-bitforce.c +++ b/driver-bitforce.c @@ -29,7 +29,7 @@ #define WORK_CHECK_INTERVAL_MS 50 #define MAX_START_DELAY_US 100000 #define tv_to_ms(tval) (tval.tv_sec * 1000 + tval.tv_usec / 1000) -#define TIME_AVE_CONSTANT 8 +#define TIME_AVG_CONSTANT 8 struct device_api bitforce_api; @@ -410,8 +410,8 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work) applog(LOG_DEBUG, "BFL%i: Wait time changed to: %d", bitforce->device_id, bitforce->sleep_ms, bitforce->wait_ms); /* Work out the average time taken. Float for calculation, uint for display */ - bitforce->ave_wait_f += (tv_to_ms(elapsed) - bitforce->ave_wait_f) / TIME_AVE_CONSTANT; - bitforce->ave_wait_d = (unsigned int) (bitforce->ave_wait_f + 0.5); + bitforce->avg_wait_f += (tv_to_ms(elapsed) - bitforce->avg_wait_f) / TIME_AVG_CONSTANT; + bitforce->avg_wait_d = (unsigned int) (bitforce->avg_wait_f + 0.5); } applog(LOG_DEBUG, "BFL%i: waited %dms until %s", bitforce->device_id, bitforce->wait_ms, pdevbuf); @@ -525,7 +525,7 @@ static struct api_data *bitforce_api_stats(struct cgpu_info *cgpu) // locking access to displaying API debug 'stats' // If locking becomes an issue for any of them, use copy_data=true also root = api_add_uint(root, "Sleep Time", &(cgpu->sleep_ms), false); - root = api_add_uint(root, "Ave Wait", &(cgpu->ave_wait_d), false); + root = api_add_uint(root, "Avg Wait", &(cgpu->avg_wait_d), false); return root; } diff --git a/miner.h b/miner.h index 1cfd943e..df4d431a 100644 --- a/miner.h +++ b/miner.h @@ -323,8 +323,8 @@ struct cgpu_info { struct timeval work_start_tv; unsigned int wait_ms; unsigned int sleep_ms; - double ave_wait_f; - unsigned int ave_wait_d; + double avg_wait_f; + unsigned int avg_wait_d; uint32_t nonces; bool nonce_range; #endif