Browse Source

Replace cgpu.min_nonce_diff with drv.drv_min_nonce_diff(cgpu, malgo)

Luke Dashjr 11 years ago
parent
commit
0f24272964
12 changed files with 73 additions and 57 deletions
  1. 18 0
      deviceapi.c
  2. 3 0
      deviceapi.h
  3. 7 1
      driver-cointerra.c
  4. 1 4
      driver-cpu.c
  5. 1 13
      driver-dualminer.c
  6. 1 16
      driver-gridseed.c
  7. 1 2
      driver-opencl.c
  8. 7 1
      driver-proxy.c
  9. 8 5
      driver-titan.c
  10. 1 2
      driver-zeusminer.c
  11. 20 8
      miner.c
  12. 5 5
      miner.h

+ 18 - 0
deviceapi.c

@@ -86,6 +86,24 @@ void bfg_devapi_init()
 }
 
 
+float common_sha256d_and_scrypt_min_nonce_diff(struct cgpu_info * const proc, const struct mining_algorithm * const malgo)
+{
+	switch (malgo->algo)
+	{
+		case POW_SCRYPT:
+			return 1./0x10000;
+		case POW_SHA256D:
+			return 1.;
+		default:
+			return -1.;
+	}
+}
+
+float common_scrypt_min_nonce_diff(struct cgpu_info * const proc, const struct mining_algorithm * const malgo)
+{
+	return (malgo->algo == POW_SCRYPT) ? (1./0x10000) : -1.;
+}
+
 bool hashes_done(struct thr_info *thr, int64_t hashes, struct timeval *tvp_hashes, uint32_t *max_nonce)
 {
 	struct cgpu_info *cgpu = thr->cgpu;

+ 3 - 0
deviceapi.h

@@ -42,6 +42,9 @@ extern void _bfg_register_driver(const struct device_drv *);
 
 extern bool bfg_need_detect_rescan;
 
+extern float common_sha256d_and_scrypt_min_nonce_diff(struct cgpu_info *, const struct mining_algorithm *);
+extern float common_scrypt_min_nonce_diff(struct cgpu_info *, const struct mining_algorithm *);
+
 extern void request_work(struct thr_info *);
 extern struct work *get_work(struct thr_info *);
 extern bool hashes_done(struct thr_info *, int64_t hashes, struct timeval *tvp_hashes, uint32_t *max_nonce);

+ 7 - 1
driver-cointerra.c

@@ -272,6 +272,12 @@ bool cointerra_wait_for_info(struct cointerra_info * const ctainfo, struct lowl_
 	return true;
 }
 
+static
+float cointerra_min_nonce_diff(struct cgpu_info * const proc, const struct mining_algorithm * const malgo)
+{
+	return (malgo->algo == POW_SHA256D) ? CTA_INIT_DIFF : -1.;
+}
+
 static
 bool cointerra_lowl_probe(const struct lowlevel_device_info * const info)
 {
@@ -316,7 +322,6 @@ bool cointerra_lowl_probe(const struct lowlevel_device_info * const info)
 		.dev_product = maybe_strdup(info->product),
 		.dev_serial = maybe_strdup(info->serial),
 		.deven = DEV_ENABLED,
-		.min_nonce_diff = CTA_INIT_DIFF,
 	};
 	const bool rv = add_cgpu(dev);
 	applog(LOG_INFO, "%s: Successfully set up %s",
@@ -1357,6 +1362,7 @@ static const struct bfg_set_device_definition cointerra_set_device_funcs[] = {
 struct device_drv cointerra_drv = {
 	.dname = "cointerra",
 	.name = "CTA",
+	.drv_min_nonce_diff = cointerra_min_nonce_diff,
 	.lowl_match = cointerra_lowl_match,
 	.lowl_probe = cointerra_lowl_probe,
 	.thread_init = cta_prepare,

+ 1 - 4
driver-cpu.c

@@ -805,9 +805,6 @@ static bool cpu_thread_init(struct thr_info *thr)
 
 	cgpu->kname = algo_names[opt_algo];
 	
-	if (opt_algo == ALGO_SCRYPT)
-		cgpu->min_nonce_diff = 1./0x10000;
-	
 	/* Set worker threads to nice 19 and then preferentially to SCHED_IDLE
 	 * and if that fails, then SCHED_BATCH. No need for this to be an
 	 * error if it fails */
@@ -867,7 +864,7 @@ struct device_drv cpu_drv = {
 	.dname = "cpu",
 	.name = "CPU",
 	.probe_priority = 120,
-	.supported_algos = POW_SHA256D | POW_SCRYPT,
+	.drv_min_nonce_diff = common_sha256d_and_scrypt_min_nonce_diff,
 	.drv_detect = cpu_detect,
 	.thread_prepare = cpu_thread_prepare,
 	.can_limit_work = cpu_can_limit_work,

+ 1 - 13
driver-dualminer.c

@@ -107,17 +107,6 @@ void dualminer_init_hashrate(struct cgpu_info * const cgpu)
 		info->Hs = DUALMINER_SCRYPT_DM_HASH_TIME;
 }
 
-static
-bool dualminer_init(struct thr_info * const thr)
-{
-	struct cgpu_info * const cgpu = thr->cgpu;
-	
-	if (opt_scrypt)
-		cgpu->min_nonce_diff = 1./0x10000;
-	
-	return icarus_init(thr);
-}
-
 // runs when job starts and the device has been reset (or first run)
 static
 void dualminer_init_firstrun(struct cgpu_info *icarus)
@@ -329,9 +318,8 @@ void dualminer_drv_init()
 	dualminer_drv = icarus_drv;
 	dualminer_drv.dname = "dualminer";
 	dualminer_drv.name = "DMU";
-	dualminer_drv.supported_algos = POW_SCRYPT | POW_SHA256D;
+	dualminer_drv.drv_min_nonce_diff = common_sha256d_and_scrypt_min_nonce_diff;
 	dualminer_drv.lowl_probe = dualminer_lowl_probe;
-	dualminer_drv.thread_init = dualminer_init;
 	dualminer_drv.thread_shutdown = dualminer_thread_shutdown;
 	dualminer_drv.job_prepare = dualminer_job_prepare;
 	dualminer_drv.set_device = dualminer_set_device;

+ 1 - 16
driver-gridseed.c

@@ -215,24 +215,12 @@ bool gridseed_lowl_probe(const struct lowlevel_device_info * const info)
  * setup & shutdown
  */
 
-static
-bool gridseed_thread_prepare(struct thr_info *thr)
-{
-	thr->cgpu_data = calloc(1, sizeof(*thr->cgpu_data));
-	
-	struct cgpu_info *device = thr->cgpu;
-	device->min_nonce_diff = 1./0x10000;
-
-	return true;
-}
-
 static
 void gridseed_thread_shutdown(struct thr_info *thr)
 {
 	struct cgpu_info *device = thr->cgpu;
 
 	gc3355_close(device->device_fd);
-	free(thr->cgpu_data);
 }
 
 /*
@@ -446,14 +434,11 @@ struct device_drv gridseed_drv =
 	// metadata
 	.dname = "gridseed",
 	.name = "GSD",
-	.supported_algos = POW_SCRYPT,
+	.drv_min_nonce_diff = common_scrypt_min_nonce_diff,
 	
 	// detect device
 	.lowl_probe = gridseed_lowl_probe,
 	
-	// initialize device
-	.thread_prepare = gridseed_thread_prepare,
-	
 	// specify mining type - scanhash
 	.minerloop = minerloop_scanhash,
 	

+ 1 - 2
driver-opencl.c

@@ -1647,7 +1647,6 @@ static bool opencl_thread_init(struct thr_info *thr)
 #ifdef USE_SCRYPT
 		case KL_SCRYPT:
 			thrdata->queue_kernel_parameters = &queue_scrypt_kernel;
-			gpu->min_nonce_diff = 1./0x10000;
 			break;
 #endif
 		default:
@@ -1869,7 +1868,7 @@ struct device_drv opencl_api = {
 	.dname = "opencl",
 	.name = "OCL",
 	.probe_priority = 110,
-	.supported_algos = POW_SHA256D | POW_SCRYPT,
+	.drv_min_nonce_diff = common_sha256d_and_scrypt_min_nonce_diff,
 	.drv_detect = opencl_detect,
 	.reinit_device = reinit_opencl_device,
 	.watchdog = opencl_watchdog,

+ 7 - 1
driver-proxy.c

@@ -70,6 +70,12 @@ void *prune_worklog_thread(void *userdata)
 	return NULL;
 }
 
+static
+float proxy_min_nonce_diff(struct cgpu_info * const proc, const struct mining_algorithm * const malgo)
+{
+	return minimum_pdiff;
+}
+
 static
 void proxy_first_client(struct cgpu_info *cgpu)
 {
@@ -99,7 +105,6 @@ struct proxy_client *proxy_find_or_create_client(const char *username)
 			.threads = 0,
 			.device_data = client,
 			.device_path = user,
-			.min_nonce_diff = minimum_pdiff,
 		};
 		timer_set_now(&cgpu->cgminer_stats.start_tv);
 		if (unlikely(!create_new_cgpus(add_cgpu_live, cgpu)))
@@ -170,6 +175,7 @@ static const struct bfg_set_device_definition proxy_set_device_funcs[] = {
 struct device_drv proxy_drv = {
 	.dname = "proxy",
 	.name = "PXY",
+	.drv_min_nonce_diff = proxy_min_nonce_diff,
 #ifdef HAVE_CURSES
 	.proc_wlogprint_status = proxy_wlogprint_status,
 #endif

+ 8 - 5
driver-titan.c

@@ -296,6 +296,12 @@ static bool configure_one_die(struct knc_titan_info *knc, int asic, int die)
 	return true;
 }
 
+static
+float titan_min_nonce_diff(struct cgpu_info * const proc, const struct mining_algorithm * const malgo)
+{
+	return (malgo->algo == POW_SCRYPT) ? DEFAULT_DIFF_FILTERING_FLOAT : -1.;
+}
+
 static bool knc_titan_init(struct thr_info * const thr)
 {
 	const int max_cores = KNC_TITAN_CORES_PER_ASIC;
@@ -308,7 +314,6 @@ static bool knc_titan_init(struct thr_info * const thr)
 	int asic_cores[KNC_TITAN_MAX_ASICS] = {0};
 
 	for (proc = cgpu; proc; ) {
-		proc->min_nonce_diff = DEFAULT_DIFF_FILTERING_FLOAT;
 		if (proc->device != proc) {
 			applog(LOG_WARNING, "%"PRIpreprv": Extra processor?", proc->proc_repr);
 			proc = proc->next_proc;
@@ -430,9 +435,7 @@ static bool die_reconfigure(struct knc_titan_info * const knc, int asic, int die
 
 static bool knc_titan_prepare_work(struct thr_info *thr, struct work *work)
 {
-	struct cgpu_info * const cgpu = thr->cgpu;
-
-	work->nonce_diff = cgpu->min_nonce_diff;
+	work->nonce_diff = DEFAULT_DIFF_FILTERING_FLOAT;
 	return true;
 }
 
@@ -792,7 +795,7 @@ struct device_drv knc_titan_drv =
 	/* metadata */
 	.dname = "titan",
 	.name = "KNC",
-	.supported_algos = POW_SCRYPT,
+	.drv_min_nonce_diff = titan_min_nonce_diff,
 	.drv_detect = knc_titan_detect,
 
 	.thread_init = knc_titan_init,

+ 1 - 2
driver-zeusminer.c

@@ -219,7 +219,6 @@ bool zeusminer_thread_init(struct thr_info * const thr)
 {
 	struct cgpu_info * const device = thr->cgpu;
 	
-	device->min_nonce_diff = 1./0x10000;
 	device->set_device_funcs = zeusminer_set_device_funcs_live;
 	
 	return icarus_init(thr);
@@ -320,7 +319,7 @@ void zeusminer_drv_init()
 	// metadata
 	zeusminer_drv.dname = "zeusminer";
 	zeusminer_drv.name = "ZUS";
-	zeusminer_drv.supported_algos = POW_SCRYPT;
+	zeusminer_drv.drv_min_nonce_diff = common_scrypt_min_nonce_diff;
 	
 	// detect device
 	zeusminer_drv.lowl_probe = zeusminer_lowl_probe;

+ 20 - 8
miner.c

@@ -510,6 +510,14 @@ static void applog_and_exit(const char *fmt, ...)
 	exit(1);
 }
 
+static
+float drv_min_nonce_diff(const struct device_drv * const drv, struct cgpu_info * const proc, const struct mining_algorithm * const malgo)
+{
+	if (drv->drv_min_nonce_diff)
+		return drv->drv_min_nonce_diff(proc, malgo);
+	return (malgo->algo == POW_SHA256D) ? 1. : -1.;
+}
+
 char *devpath_to_devid(const char *devpath)
 {
 #ifndef WIN32
@@ -10059,12 +10067,13 @@ struct work *get_work(struct thr_info *thr)
 	
 	if (work->work_difficulty < 1)
 	{
-		if (unlikely(work->work_difficulty < cgpu->min_nonce_diff))
+		const float min_nonce_diff = drv_min_nonce_diff(cgpu->drv, cgpu, work_mining_algorithm(work));
+		if (unlikely(work->work_difficulty < min_nonce_diff))
 		{
-			if (cgpu->min_nonce_diff - work->work_difficulty > 1./0x10000000)
+			if (min_nonce_diff - work->work_difficulty > 1./0x10000000)
 				applog(LOG_WARNING, "%"PRIpreprv": Using work with lower difficulty than device supports",
 				       cgpu->proc_repr);
-			work->nonce_diff = cgpu->min_nonce_diff;
+			work->nonce_diff = min_nonce_diff;
 		}
 		else
 			work->nonce_diff = work->work_difficulty;
@@ -11994,11 +12003,15 @@ static bool my_blkmaker_sha256_callback(void *digest, const void *buffer, size_t
 }
 
 static
-int drv_algo_check(const struct device_drv * const drv)
+bool drv_algo_check(const struct device_drv * const drv)
 {
-	const int algomatch = opt_scrypt ? POW_SCRYPT : POW_SHA256D;
-	const supported_algos_t algos = drv->supported_algos ?: POW_SHA256D;
-	return (algos & algomatch);
+	struct mining_goal_info *goal, *tmpgoal;
+	HASH_ITER(hh, mining_goals, goal, tmpgoal)
+	{
+		if (drv_min_nonce_diff(drv, NULL, goal->malgo) >= 0)
+			return true;
+	}
+	return false;
 }
 
 #ifndef HAVE_PTHREAD_CANCEL
@@ -12091,7 +12104,6 @@ void allocate_cgpu(struct cgpu_info *cgpu, unsigned int *kp)
 	}
 
 	cgpu->max_hashes = 0;
-	BFGINIT(cgpu->min_nonce_diff, 1);
 	
 	BFGINIT(cgpu->cutofftemp, opt_cutofftemp);
 	BFGINIT(cgpu->targettemp, cgpu->cutofftemp - 6);

+ 5 - 5
miner.h

@@ -280,7 +280,6 @@ enum pow_algorithm {
 	POW_SHA256D = 1,
 	POW_SCRYPT  = 2,
 };
-typedef uint8_t supported_algos_t;
 
 struct api_data;
 struct thr_info;
@@ -295,15 +294,19 @@ enum bfg_probe_result_flags_values {
 extern unsigned *_bfg_probe_result_flags();
 #define bfg_probe_result_flags (*_bfg_probe_result_flags())
 
+struct mining_algorithm;
+
 struct device_drv {
 	const char *dname;
 	const char *name;
 	int8_t probe_priority;
 	bool lowl_probe_by_name_only;
-	supported_algos_t supported_algos;
 
 	// DRV-global functions
 	void (*drv_init)();
+	// drv_min_nonce_diff's proc may be NULL
+	// drv_min_nonce_diff should return negative if algorithm is not supported
+	float (*drv_min_nonce_diff)(struct cgpu_info *proc, const struct mining_algorithm *);
 	void (*drv_detect)();
 	bool (*lowl_match)(const struct lowlevel_device_info *);
 	bool (*lowl_probe)(const struct lowlevel_device_info *);
@@ -570,9 +573,6 @@ struct cgpu_info {
 
 	bool disable_watchdog;
 	bool shutdown;
-	
-	// Lowest difficulty supported for finding nonces
-	float min_nonce_diff;
 };
 
 extern void renumber_cgpu(struct cgpu_info *);