Browse Source

bitfury: Use dynclock to adjust osc6_bits

Luke Dashjr 12 years ago
parent
commit
8386ac8dec
6 changed files with 51 additions and 4 deletions
  1. 1 0
      configure.ac
  2. 1 2
      driver-bfsb.c
  3. 42 0
      driver-bitfury.c
  4. 1 0
      driver-bitfury.h
  5. 1 2
      driver-metabank.c
  6. 5 0
      libbitfury.h

+ 1 - 0
configure.ac

@@ -462,6 +462,7 @@ AC_ARG_ENABLE([bitfury],
 	)
 if test "x$bitfury" = xyes; then
 	AC_DEFINE([USE_BITFURY], [1], [Defined to 1 if Bitfury support is wanted])
+	need_dynclock=yes
 fi
 AM_CONDITIONAL([HAS_BITFURY], [test x$bitfury = xyes])
 

+ 1 - 2
driver-bfsb.c

@@ -153,8 +153,7 @@ bool bfsb_init(struct thr_info *thr)
 		proc->device_data = bitfury;
 		bitfury->spi->cgpu = proc;
 		bitfury_init_oldbuf(proc);
-		bitfury->osc6_bits = 54;
-		send_reinit(bitfury->spi, bitfury->slot, bitfury->fasync, bitfury->osc6_bits);
+		bitfury_init_dclk(proc, 54, 55);
 	}
 	
 	free(devicelist);

+ 42 - 0
driver-bitfury.c

@@ -28,6 +28,7 @@
 #include <sha2.h>
 
 #include "deviceapi.h"
+#include "dynclock.h"
 #include "libbitfury.h"
 #include "util.h"
 #include "spidevc.h"
@@ -76,6 +77,21 @@ static void bitfury_detect(void)
 }
 
 
+static
+bool bitfury_change_osc6_bits(struct thr_info *thr, int multiplier)
+{
+	struct cgpu_info * const cgpu = thr->cgpu;
+	struct bitfury_device * const bitfury = cgpu->device_data;
+	uint8_t old_bits = bitfury->osc6_bits;
+	
+	bitfury->osc6_bits = multiplier;
+	send_reinit(bitfury->spi, bitfury->slot, bitfury->fasync, bitfury->osc6_bits);
+	bitfury->dclk.freqM = multiplier;
+	dclk_msg_freqchange(cgpu->proc_repr, old_bits, bitfury->osc6_bits, NULL);
+	
+	return true;
+}
+
 void *bitfury_just_io(struct bitfury_device * const bitfury)
 {
 	struct spi_port * const spi = bitfury->spi;
@@ -104,6 +120,17 @@ void bitfury_debug_nonce_array(const struct cgpu_info * const proc, const char *
 	       proc->proc_repr, msg, s, (unsigned long)inp[0x10]);
 }
 
+void bitfury_init_dclk(struct cgpu_info * const proc, uint8_t def, uint8_t max)
+{
+	struct bitfury_device * const bitfury = proc->device_data;
+	
+	dclk_prepare(&bitfury->dclk);
+	bitfury->dclk.freqMDefault = def;
+	bitfury->dclk.freqM = bitfury->dclk.freqMDefault;
+	bitfury_change_osc6_bits(proc->thr[0], bitfury->dclk.freqM);
+	bitfury->dclk.freqMaxM = max;
+}
+
 bool bitfury_init_oldbuf(struct cgpu_info * const proc)
 {
 	struct bitfury_device * const bitfury = proc->device_data;
@@ -518,8 +545,23 @@ void bitfury_do_io(struct thr_info *thr)
 				submit_nonce(thr, thr->prev_work, nonce);
 			}
 			else
+			{
 				inc_hw_errors(thr, thr->work, nonce);
+				++bitfury->dclk_hwe;
+			}
+			if (++bitfury->dclk_tot >= 0x10)
+			{
+				double errrate = (double)bitfury->dclk_hwe / (double)bitfury->dclk_tot;
+				applog(LOG_DEBUG, "%"PRIpreprv": DynClock: %d of %d results were bad",
+				       proc->proc_repr, bitfury->dclk_hwe, bitfury->dclk_tot);
+				dclk_gotNonces(&bitfury->dclk);
+				dclk_errorCount(&bitfury->dclk, errrate);
+				dclk_preUpdate(&bitfury->dclk);
+				dclk_updateFreq(&bitfury->dclk, bitfury_change_osc6_bits, thr);
+				bitfury->dclk_tot = bitfury->dclk_hwe = 0;
+			}
 		}
+		
 		bitfury->active = (bitfury->active + n) % 0x10;
 	}
 	

+ 1 - 0
driver-bitfury.h

@@ -8,6 +8,7 @@
 
 extern bool bitfury_prepare(struct thr_info *);
 extern bool bitfury_init_oldbuf(struct cgpu_info *);
+extern void bitfury_init_dclk(struct cgpu_info *, uint8_t def, uint8_t max);
 
 extern int64_t bitfury_scanHash(struct thr_info *);
 

+ 1 - 2
driver-metabank.c

@@ -149,8 +149,7 @@ bool metabank_init(struct thr_info *thr)
 		proc->device_data = bitfury;
 		bitfury->spi->cgpu = proc;
 		bitfury_init_oldbuf(proc);
-		bitfury->osc6_bits = 54;
-		send_reinit(bitfury->spi, bitfury->slot, bitfury->fasync, bitfury->osc6_bits);
+		bitfury_init_dclk(proc, 54, 55);
 		
 		if (proc->proc_id == proc->procs - 1)
 			free(devicelist);

+ 5 - 0
libbitfury.h

@@ -1,6 +1,7 @@
 #ifndef __LIBBITFURY_H__
 #define __LIBBITFURY_H__
 
+#include "dynclock.h"
 #include "miner.h"
 #include "spidevc.h"
 
@@ -57,6 +58,10 @@ struct bitfury_device {
 	
 	time_t short_out_t;
 	time_t long_out_t;
+	
+	struct dclk_data dclk;
+	int dclk_hwe;
+	int dclk_tot;
 };
 
 extern void libbitfury_sendHashData1(int chip_id, struct bitfury_device *, struct thr_info *);