8000 gluk's metabank2 by glukolog · Pull Request #357 · luke-jr/bfgminer · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

gluk's metabank2 #357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasio 8000 nally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: bfgminer
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ bfgminer_SOURCES += driver-bfsb.c
endif

if HAS_METABANK
bfgminer_SOURCES += driver-metabank.c tm_i2c.h tm_i2c.c
bfgminer_SOURCES += driver-metabank.c tm_i2cm.h tm_i2cm.c
#bfgminer_SOURCES += driver-metabank.c tm_i2c.h tm_i2c.c
endif

if HAS_LITTLEFURY
Expand Down
76 changes: 60 additions & 16 deletions driver-bitfury.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include "util.h"
#include "spidevc.h"

//#define MB2_Hgood 2800
#define MB2_Hgood 2650
BFG_REGISTER_DRIVER(bitfury_drv)

static
Expand Down Expand Up @@ -430,8 +432,19 @@ void bitfury_do_io(struct thr_info * const master_thr)

inp = rxbuf[j];

if (proc->deven == DEV_DISABLED) continue;

if (unlikely(bitfury->desync_counter == 99))
{
if (bitfury_init_oldbuf(proc, inp) == false)
{
if (bitfury->osc6_bits > 40) {
bitfury->osc6_bits--;
bitfury->force_reinit = true;
} else {
proc->deven = DEV_DISABLED;
}
}
bitfury_init_oldbuf(proc, inp);
goto out;
}
Expand All @@ -449,9 +462,11 @@ void bitfury_do_io(struct thr_info * const master_thr)
inc_hw_errors2(thr, NULL, NULL);
if (unlikely(++bitfury->desync_counter >= 4))
{
applog(LOG_WARNING, "%"PRIpreprv": Previous nonce mismatch (4th try), recalibrating",
proc->proc_repr);
if (bitfury->strange_counter > 50) proc->deven = DEV_DISABLED;
applog(LOG_WARNING, "%"PRIpreprv": Previous nonce mismatch (4th try), recalibrating %d",
proc->proc_repr, bitfury->strange_counter);
bitfury_init_oldbuf(proc, inp);
bitfury->strange_counter++;
continue;
}
applog(LOG_DEBUG, "%"PRIpreprv": Previous nonce mismatch, ignoring response",
Expand Down Expand Up @@ -489,27 +504,28 @@ void bitfury_do_io(struct thr_info * const master_thr)
int32_t cycles = counter - bitfury->counter1;
if (cyc 10000 les < 0)
cycles += 0x00400000;

if (cycles & 0x00200000)
{
long long unsigned int period;
double ns;
struct timeval d_time;

timersub(&(tv_now), &(bitfury->timer1), &d_time);
period = timeval_to_us(&d_time) * 1000ULL;
ns = (double)period / (double)(cycles);
bitfury->mhz = 1.0 / ns * 65.0 * 1000.0;
period = timeval_to_us(&d_time);
ns = (double)(cycles) / (double)period * 65.0;
if (ns < 350) bitfury->mhz = ns;

if (bitfury->mhz_best)
{
if (bitfury->mhz < bitfury->mhz_best / 2)
if (bitfury->mhz < bitfury->mhz_best / 3)
{
applog(LOG_WARNING, "%"PRIpreprv": Frequency drop over 50%% detected, reinitialising",
applog(LOG_WARNING, "%"PRIpreprv": Frequency drop over 33%% detected, reinitialising",
proc->proc_repr);
bitfury->force_reinit = true;
}
}

if ((int)bitfury->mhz > bitfury->mhz_best && bitfury->mhz_last > bitfury->mhz_best)
{
// mhz_best is the lowest of two sequential readings over the previous best
Expand All @@ -524,11 +540,12 @@ void bitfury_do_io(struct thr_info * const master_thr)
copy_time(&(bitfury->timer1), &tv_now);
}
}

if (tvp_stat->tv_sec == 0 && tvp_stat->tv_usec == 0) {
copy_time(tvp_stat, &tv_now);
copy_time(&bitfury->tv_stat_long, &tv_now);
}
#ifndef USE_METABANK2
if (c->osc6_max)
{
if (timer_elapsed(tvp_stat, &tv_now) >= 60)
Expand Down Expand Up @@ -568,7 +585,7 @@ void bitfury_do_io(struct thr_info * const master_thr)
}
}
}
#endif
if (n)
{
for (i = 0; i < n; ++i)
Expand Down Expand Up @@ -597,9 +614,8 @@ void bitfury_do_io(struct thr_info * const master_thr)
}
if (++bitfury->sample_tot >= 0x40 || bitfury->sample_hwe >= 8)
{
if (bitfury->sample_hwe >= 8)
{
applog(LOG_WARNING, "%"PRIpreprv": %d of the last %d results were bad, reinitialising",
if (bitfury->sample_hwe >= 8) {
applog(LOG_INFO, "%"PRIpreprv": %d of the last %d results were bad, reinitialising",
proc->proc_repr, bitfury->sample_hwe, bitfury->sample_tot);
bitfury_send_reinit(bitfury->spi, bitfury->slot, bitfury->fasync, bitfury->osc6_bits);
bitfury->desync_counter = 99;
Expand All @@ -609,7 +625,33 @@ void bitfury_do_io(struct thr_info * const master_thr)
}
bitfury->active = (bitfury->active + n) % 0x10;
}

#ifdef USE_METABANK2
if (timer_elapsed(tvp_stat, &tv_now) >= 10)
{
if (j == 0) {
struct bitfury_device *tbitfury;
int str_count = 0;
for (int k = 0; k < n_chips; ++k) {
tbitfury = procs[k]->device_data;
str_count += tbitfury->strange_counter;
}
applog(LOG_WARNING, "stranges=%d", str_count);
}
if (bitfury->strange_counter > 10 && bitfury->osc6_bits == c->osc6_min)
bitfury->osc6_bits -= 4;
if (bitfury->strange_counter > 3 && bitfury->osc6_bits > c->osc6_min)
bitfury_send_freq(bitfury->spi, bitfury->slot, bitfury->fasync, --bitfury->osc6_bits);
bitfury->strange_counter = 0;
copy_time(tvp_stat, &tv_now);
}
tvp_stat = &bitfury->tv_stat_long;
if (timer_elapsed(tvp_stat, &tv_now) >= 900)
{
if (bitfury->osc6_bits < c->osc6_max && (proc->total_mhashes / total_secs) < MB2_Hgood)
bitfury_send_freq(bitfury->spi, bitfury->slot, bitfury->fasync, ++bitfury->osc6_bits);
copy_time(tvp_stat, &tv_now);
}
#endif
memcpy(&oldbuf[0], &newbuf[n], 4 * (0x10 - n));
memcpy(&oldbuf[0x10 - n], &newbuf[0], 4 * n);
bitfury->oldjob = newjob;
Expand All @@ -625,8 +667,10 @@ void bitfury_do_io(struct thr_info * const master_thr)
bitfury->mhz_best = 0;
bitfury->force_reinit = false;
}
#ifndef USE_METABANK2
if (timer_elapsed(tvp_stat, &tv_now) >= 60)
copy_time(tvp_stat, &tv_now);
#endif
}

timer_set_delay(&master_thr->tv_poll, &tv_now, 10000);
Expand Down
136 changes: 123 additions & 13 deletions driver-metabank.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* THE SOFTWARE.
*/

//#define HAS_METABANK2
#include "config.h"

#include <stdbool.h>
Expand All @@ -30,7 +31,29 @@
#include "driver-bitfury.h"
#include "libbitfury.h"
#include "spidevc.h"
#ifndef USE_METABANK2
#include "tm_i2c.h"
#else
#include "tm_i2cm.h"
#endif

/*
#define MB2_Hdiff 220
#define MB2_Vnorm 0.835
#define MB2_Vhigh 0.91
*/
#define MB2_Hdiff 205
#define MB2_Vnorm 0.79
#define MB2_Vhigh 0.82

static int renew_voltage = 1;
static struct timeval mb_stat[32];

typedef struct {
double temp;
double vc;
} slots_stat_struct;
static slots_stat_struct slots[32] = {0};

BFG_REGISTER_DRIVER(metabank_drv)

Expand Down Expand Up @@ -81,6 +104,7 @@ int metabank_autodetect()

for (i = 0; i < 32; i++) {
slot_on[i] = 0;
timer_set_now(&mb_stat[i]);
}
for (i = 0; i < 32; i++) {
int slot_detected = tm_i2c_detect(i) != -1;
Expand Down Expand Up @@ -120,20 +144,28 @@ int metabank_autodetect()
.drv = &metabank_drv,
.procs = chip_n,
.device_data = devicelist,
.cutofftemp = 50,
.cutofftemp = 80,
};
add_cgpu_slave(cgpu, prev_cgpu);

#ifdef USE_METABANK2
// ### Set all vltage to 0.835V ###
applog(LOG_INFO, "Set voltage!");
applog(LOG_WARNING, "Slot[%02d]: %.3f V %.1f C", i,
tm_i2c_set_voltage_abs(i, MB2_Vnorm), tm_i2c_gettemp(i));
#endif

proc_count += chip_n;
if (!proc1)
proc1 = cgpu;
prev_cgpu = cgpu;
}
else
} else {
slot_on[i] = 0;
free(port);
}
}
}

if (proc1)
proc1->threads = 1;

Expand All @@ -159,9 +191,15 @@ bool metabank_init(struct thr_info *thr)
proc->device_data = bitfury;
bitfury->spi->cgpu = proc;
bitfury_init_chip(proc);
#ifndef USE_METABANK2
bitfury->osc6_bits = 53;
bitfury_send_reinit(bitfury->spi, bitfury->slot, bitfury->fasync, bitfury->osc6_bits);
bitfury_init_freq_stat(&bitfury->chip_stat, 52, 56);
#else
bitfury->osc6_bits = 56;
bitfury_send_reinit(bitfury->spi, bitfury->slot, bitfury->fasync, bitfury->osc6_bits);
bitfury_init_freq_stat(&bitfury->chip_stat, 54, 56);
#endif

if (proc->proc_id == proc->procs - 1)
free(devicelist);
Expand All @@ -180,16 +218,87 @@ static void metabank_shutdown(struct thr_info *thr)

static bool metabank_get_stats(struct cgpu_info *cgpu)
{
struct bitfury_device * const bitfury = cgpu->device_data;
struct bitfury_device * bitfury = cgpu->device_data;
float t;

t = tm_i2c_gettemp(bitfury->slot) * 0.1;

if (t < -27) //Sometimes tm_i2c_gettemp() returns strange result, ignoring it.
return false;

cgpu->temp = t;

struct timeval now;
struct cgpu_info *proc, *cproc;
unsigned slot = bitfury->slot;
slots_stat_struct *stat = &slots[bitfury->slot];

timer_set_now(&now);
if (timer_elapsed(&mb_stat[slot], &now) >= 10)
{
copy_time(&mb_stat[slot], &now);
slot = bitfury->slot;
t = tm_i2c_gettemp(slot);
if (t < -27 || t > 250) //Sometimes tm_i2c_gettemp() returns strange result, ignoring it.
return false;
cgpu->temp = t;

#ifndef USE_METABANK2
bitfury->volt = tm_i2c_getcore0(slot);
stat->temp = t;
stat->vc = bitfury->volt;
#else
if (t > 75) // Drop Down voltage
{
tm_i2c_set_vid(slot, 0);
applog(LOG_WARNING, "-----=====!!!!! Slot %u set low voltage !!!!!=====-----", slot);
}
bitfury->volt = (slot & 1) ? tm_i2c_getcore1(slot) : tm_i2c_getcore0(slot);
stat->temp = t;
stat->vc = bitfury->volt;

if (stat->vc < 0.74 && !renew_voltage && t > 0 && t < 50 && timer_elapsed(&bitfury->tv_stat_long, &now) < 60) { // No overheat return voltage
renew_voltage = 1;
applog(LOG_WARNING, "Restore voltage after overheat");
proc = cgpu->device;
slot = 99;
while(proc) {
bitfury = (struct bitfury_device *) proc->device_data;
if (bitfury->slot != slot) {
slot = bitfury->slot;
applog(LOG_WARNING, "%s slot[%02d]: %.3f V %.1f C",
proc->dev_repr, slot, tm_i2c_set_voltage_abs(slot, MB2_Vnorm), tm_i2c_gettemp(slot));
}
proc = proc->next_proc;
}
}

if (renew_voltage && timer_elapsed(&bitfury->tv_stat_long, &now) > 660) { // set new voltage after 15 min
int count = 0;
double mhz;
applog(LOG_WARNING, "Set new voltage!");
proc = cgpu->device;
while(proc) {
cproc = proc;
mhz = 0;
count = proc->procs;
for(int i = 0; i < cproc->procs; i++) {
bitfury = (struct bitfury_device *) proc->device_data;
if (bitfury->mhz > 150)
mhz += bitfury->mhz;
else
count--;
proc = proc->next_proc;
}
mhz /= (double)count;
if (mhz < MB2_Hdiff) {
applog(LOG_WARNING, "Dev : %s slot[%u]=(%.0f, %d) new voltage: %.3f V\t%.1f C",
cproc->dev_repr, bitfury->slot, mhz, count, tm_i2c_set_voltage_abs(bitfury->slot, MB2_Vhigh), tm_i2c_gettemp(bitfury->slot));
} else {
applog(LOG_WARNING, "Dev : %s slot[%u]=(%.0f, %d) no changes",
cproc->dev_repr, bitfury->slot, mhz, count);
}
};
renew_voltage = 0;
}
#endif
} else {
cgpu->temp = stat->temp;
bitfury->volt = stat->vc;
}

return true;
}

Expand All @@ -215,6 +324,7 @@ static struct api_data *metabank_api_extra_device_status(struct cgpu_info *cgpu)

vc0 = tm_i2c_getcore0(bitfury->slot);
vc1 = tm_i2c_getcore1(bitfury->slot);
bitfury->volt = (bitfury->slot & 1) ? vc1 : vc0;

root = api_add_volts(root, "Slot VC0", &vc0, true);
root = api_add_volts(root, "Slot VC1", &vc1, true);
Expand Down
Loading
0