Browse Source

Merge branch '2014-benchmark' into bfgminer

Conflicts:
	bench_block.h
Luke Dashjr 12 years ago
parent
commit
6d728a818c
5 changed files with 68 additions and 122 deletions
  1. 0 1
      Makefile.am
  2. 0 39
      bench_block.h
  3. 5 12
      driver-cpu.c
  4. 62 70
      miner.c
  5. 1 0
      miner.h

+ 0 - 1
Makefile.am

@@ -143,7 +143,6 @@ bfgminer_SOURCES	+= \
 
 
 # the CPU portion extracted from original main.c
 # the CPU portion extracted from original main.c
 bfgminer_SOURCES += driver-cpu.h driver-cpu.c
 bfgminer_SOURCES += driver-cpu.h driver-cpu.c
-bfgminer_SOURCES += bench_block.h
 
 
 if HAVE_SSE2
 if HAVE_SSE2
 bfgminer_LDADD  += libsse2cpuminer.a
 bfgminer_LDADD  += libsse2cpuminer.a

+ 0 - 39
bench_block.h

@@ -1,39 +0,0 @@
-#ifndef BFG_BENCH_BLOCK_H
-#define BFG_BENCH_BLOCK_H
-
-	// Random work pulled from a pool
-        #define CGMINER_BENCHMARK_BLOCK                                                                         \
-                0x00, 0x00, 0x00, 0x01, 0x20, 0x00, 0xD8, 0x07, 0x17, 0xC9, 0x13, 0x6F, 0xDC, 0xBE, 0xDE, 0xB7, \
-                0xB2, 0x14, 0xEF, 0xD1, 0x72, 0x7F, 0xA3, 0x72, 0xB2, 0x5D, 0x88, 0xF0, 0x00, 0x00, 0x05, 0xAA, \
-                0x00, 0x00, 0x00, 0x00, 0x92, 0x8B, 0x4C, 0x77, 0xF5, 0xB2, 0xE6, 0x56, 0x96, 0x27, 0xE0, 0x66, \
-                0x3C, 0x5B, 0xDD, 0xDC, 0x88, 0x6A, 0x7D, 0x7C, 0x7B, 0x8C, 0xE4, 0x92, 0x38, 0x92, 0x58, 0x2E, \
-                0x18, 0x4D, 0x95, 0x9E, 0x4E, 0x44, 0xF1, 0x5F, 0x1A, 0x08, 0xE1, 0xE5, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, \
-                0x86, 0x7E, 0x3A, 0xAF, 0x37, 0x83, 0xAF, 0xA0, 0xB5, 0x33, 0x2C, 0x28, 0xED, 0xA9, 0x89, 0x3E, \
-                0x0A, 0xB6, 0x46, 0x81, 0xC2, 0x71, 0x4F, 0x34, 0x5A, 0x74, 0x89, 0x0E, 0x2B, 0x04, 0xB3, 0x16, \
-                0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \
-                0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0xF6, 0x09, 0x02, 0x00, 0x00, 0x00, 0x00, \
-                0x55, 0xF1, 0x44, 0x4E, 0x00, 0x00, 0x00, 0x00, 0x79, 0x63, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,                                                 \
-
-#endif

+ 5 - 12
driver-cpu.c

@@ -32,7 +32,6 @@
 #include "compat.h"
 #include "compat.h"
 #include "deviceapi.h"
 #include "deviceapi.h"
 #include "miner.h"
 #include "miner.h"
-#include "bench_block.h"
 #include "logging.h"
 #include "logging.h"
 #include "util.h"
 #include "util.h"
 #include "driver-cpu.h"
 #include "driver-cpu.h"
@@ -226,16 +225,10 @@ double bench_algo_stage3(
 	enum sha256_algos algo
 	enum sha256_algos algo
 )
 )
 {
 {
-	// Use a random work block pulled from a pool
-	static uint8_t bench_block[] = { CGMINER_BENCHMARK_BLOCK };
 	struct work work __attribute__((aligned(128)));
 	struct work work __attribute__((aligned(128)));
 	unsigned char hash1[64];
 	unsigned char hash1[64];
 
 
-	size_t bench_size = sizeof(work);
-	size_t work_size = sizeof(bench_block);
-	size_t min_size = (work_size < bench_size ? work_size : bench_size);
-	memset(&work, 0, sizeof(work));
-	memcpy(&work, &bench_block, min_size);
+	get_benchmark_work(&work);
 
 
 	static struct thr_info dummy;
 	static struct thr_info dummy;
 
 
@@ -258,7 +251,7 @@ double bench_algo_stage3(
 					work.target,
 					work.target,
 					max_nonce,
 					max_nonce,
 					&last_nonce,
 					&last_nonce,
-					work.blk.nonce
+					0
 				);
 				);
 			}
 			}
 	timer_set_now(&end);
 	timer_set_now(&end);
@@ -472,9 +465,9 @@ static double bench_algo_stage2(
 		}
 		}
 
 
 		// Construct new command line based on that
 		// Construct new command line based on that
-		char *p = strlen(cmd_line) + cmd_line;
-		sprintf(p, " --bench-algo %d", algo);
-		SetEnvironmentVariable("BFGMINER_BENCH_ALGO", "1");
+		char buf[0x20];
+		snprintf(buf, sizeof(buf), "%d", algo);
+		SetEnvironmentVariable("BFGMINER_BENCH_ALGO", buf);
 
 
 		// Launch a debug copy of BFGMiner
 		// Launch a debug copy of BFGMiner
 		STARTUPINFO startup_info;
 		STARTUPINFO startup_info;

+ 62 - 70
miner.c

@@ -161,7 +161,6 @@ int opt_queue = 1;
 int opt_scantime = 60;
 int opt_scantime = 60;
 int opt_expiry = 120;
 int opt_expiry = 120;
 int opt_expiry_lp = 3600;
 int opt_expiry_lp = 3600;
-int opt_bench_algo = -1;
 unsigned long long global_hashrate;
 unsigned long long global_hashrate;
 static bool opt_unittest = false;
 static bool opt_unittest = false;
 unsigned long global_quota_gcd = 1;
 unsigned long global_quota_gcd = 1;
@@ -1967,11 +1966,6 @@ static struct opt_table opt_config_table[] = {
 			opt_set_bool, &opt_bfl_noncerange,
 			opt_set_bool, &opt_bfl_noncerange,
 			"Use nonce range on bitforce devices if supported"),
 			"Use nonce range on bitforce devices if supported"),
 #endif
 #endif
-#ifdef WANT_CPUMINE
-	OPT_WITH_ARG("--bench-algo",
-		     set_int_0_to_9999, opt_show_intval, &opt_bench_algo,
-		     opt_hidden),
-#endif
 #ifdef HAVE_CHROOT
 #ifdef HAVE_CHROOT
         OPT_WITH_ARG("--chroot-dir",
         OPT_WITH_ARG("--chroot-dir",
                      opt_set_charp, NULL, &chroot_dir,
                      opt_set_charp, NULL, &chroot_dir,
@@ -4585,7 +4579,28 @@ static void calc_diff(struct work *work, int known)
 	}
 	}
 }
 }
 
 
-static void get_benchmark_work(struct work *work)
+static
+void setup_benchmark_pool()
+{
+	struct pool *pool;
+	
+	want_longpoll = false;
+	
+	// Temporarily disable opt_benchmark to avoid auto-removal
+	opt_benchmark = false;
+	pool = add_pool();
+	opt_benchmark = true;
+	
+	pool->rpc_url = malloc(255);
+	strcpy(pool->rpc_url, "Benchmark");
+	pool->rpc_user = pool->rpc_url;
+	pool->rpc_pass = pool->rpc_url;
+	enable_pool(pool);
+	pool->idle = false;
+	successful_connect = true;
+}
+
+void get_benchmark_work(struct work *work)
 {
 {
 	static uint32_t blkhdr[20];
 	static uint32_t blkhdr[20];
 	for (int i = 18; i >= 0; --i)
 	for (int i = 18; i >= 0; --i)
@@ -11323,16 +11338,46 @@ int main(int argc, char *argv[])
 	strcpy(cgminer_path, dirname(s));
 	strcpy(cgminer_path, dirname(s));
 	free(s);
 	free(s);
 	strcat(cgminer_path, "/");
 	strcat(cgminer_path, "/");
-#ifdef WANT_CPUMINE
-	// Hack to make cgminer silent when called recursively on WIN32
-	int skip_to_bench = 0;
-	#if defined(WIN32)
+fprintf(stderr, ">>>\n");fflush(stderr);
+#if defined(WANT_CPUMINE) && defined(WIN32)
+	{
 		char buf[32];
 		char buf[32];
-		if (GetEnvironmentVariable("BFGMINER_BENCH_ALGO", buf, 16))
-			skip_to_bench = 1;
-		if (GetEnvironmentVariable("CGMINER_BENCH_ALGO", buf, 16))
-			skip_to_bench = 1;
-	#endif // defined(WIN32)
+		int gev = GetEnvironmentVariable("BFGMINER_BENCH_ALGO", buf, sizeof(buf));
+		if (gev > 0 && gev < sizeof(buf))
+		{
+			setup_benchmark_pool();
+			double rate = bench_algo_stage3(atoi(buf));
+			
+			// Write result to shared memory for parent
+			char unique_name[64];
+			
+			if (GetEnvironmentVariable("BFGMINER_SHARED_MEM", unique_name, 32))
+			{
+				HANDLE map_handle = CreateFileMapping(
+					INVALID_HANDLE_VALUE,   // use paging file
+					NULL,                   // default security attributes
+					PAGE_READWRITE,         // read/write access
+					0,                      // size: high 32-bits
+					4096,                   // size: low 32-bits
+					unique_name             // name of map object
+				);
+				if (NULL != map_handle) {
+					void *shared_mem = MapViewOfFile(
+						map_handle,     // object to map view of
+						FILE_MAP_WRITE, // read/write access
+						0,              // high offset:  map from
+						0,              // low offset:   beginning
+						0               // default: map entire file
+					);
+					if (NULL != shared_mem)
+						CopyMemory(shared_mem, &rate, sizeof(rate));
+					(void)UnmapViewOfFile(shared_mem);
+				}
+				(void)CloseHandle(map_handle);
+			}
+			exit(0);
+		}
+	}
 #endif
 #endif
 
 
 	devcursor = 8;
 	devcursor = 8;
@@ -11428,25 +11473,10 @@ int main(int argc, char *argv[])
 	raise_fd_limits();
 	raise_fd_limits();
 	
 	
 	if (opt_benchmark) {
 	if (opt_benchmark) {
-		struct pool *pool;
-		
 		while (total_pools)
 		while (total_pools)
 			remove_pool(pools[0]);
 			remove_pool(pools[0]);
 
 
-		want_longpoll = false;
-		
-		// Temporarily disable opt_benchmark to avoid auto-removal
-		opt_benchmark = false;
-		pool = add_pool();
-		opt_benchmark = true;
-		
-		pool->rpc_url = malloc(255);
-		strcpy(pool->rpc_url, "Benchmark");
-		pool->rpc_user = pool->rpc_url;
-		pool->rpc_pass = pool->rpc_url;
-		enable_pool(pool);
-		pool->idle = false;
-		successful_connect = true;
+		setup_benchmark_pool();
 	}
 	}
 	
 	
 	if (opt_unittest) {
 	if (opt_unittest) {
@@ -11505,45 +11535,7 @@ int main(int argc, char *argv[])
 #ifdef USE_SCRYPT
 #ifdef USE_SCRYPT
 	if (opt_scrypt)
 	if (opt_scrypt)
 		set_scrypt_algo(&opt_algo);
 		set_scrypt_algo(&opt_algo);
-	else
-#endif
-	if (0 <= opt_bench_algo) {
-		double rate = bench_algo_stage3(opt_bench_algo);
-
-		if (!skip_to_bench)
-			printf("%.5f (%s)\n", rate, algo_names[opt_bench_algo]);
-		else {
-			// Write result to shared memory for parent
-#if defined(WIN32)
-				char unique_name[64];
-
-				if (GetEnvironmentVariable("BFGMINER_SHARED_MEM", unique_name, 32) || GetEnvironmentVariable("CGMINER_SHARED_MEM", unique_name, 32)) {
-					HANDLE map_handle = CreateFileMapping(
-						INVALID_HANDLE_VALUE,   // use paging file
-						NULL,                   // default security attributes
-						PAGE_READWRITE,         // read/write access
-						0,                      // size: high 32-bits
-						4096,			// size: low 32-bits
-						unique_name		// name of map object
-					);
-					if (NULL != map_handle) {
-						void *shared_mem = MapViewOfFile(
-							map_handle,	// object to map view of
-							FILE_MAP_WRITE, // read/write access
-							0,              // high offset:  map from
-							0,              // low offset:   beginning
-							0		// default: map entire file
-						);
-						if (NULL != shared_mem)
-							CopyMemory(shared_mem, &rate, sizeof(rate));
-						(void)UnmapViewOfFile(shared_mem);
-					}
-					(void)CloseHandle(map_handle);
-				}
 #endif
 #endif
-		}
-		exit(0);
-	}
 #endif
 #endif
 
 
 	bfg_devapi_init();
 	bfg_devapi_init();

+ 1 - 0
miner.h

@@ -1342,6 +1342,7 @@ struct work {
 
 
 extern void get_datestamp(char *, size_t, time_t);
 extern void get_datestamp(char *, size_t, time_t);
 #define get_now_datestamp(buf, bufsz)  get_datestamp(buf, bufsz, INVALID_TIMESTAMP)
 #define get_now_datestamp(buf, bufsz)  get_datestamp(buf, bufsz, INVALID_TIMESTAMP)
+extern void get_benchmark_work(struct work *);
 extern void stratum_work_cpy(struct stratum_work *dst, const struct stratum_work *src);
 extern void stratum_work_cpy(struct stratum_work *dst, const struct stratum_work *src);
 extern void stratum_work_clean(struct stratum_work *);
 extern void stratum_work_clean(struct stratum_work *);
 extern void gen_stratum_work2(struct work *, struct stratum_work *, const char *nonce1);
 extern void gen_stratum_work2(struct work *, struct stratum_work *, const char *nonce1);