Browse Source

cpu: Default to --algo auto

Luke Dashjr 12 years ago
parent
commit
564fa6ecb1
2 changed files with 16 additions and 14 deletions
  1. 14 14
      driver-cpu.c
  2. 2 0
      driver-cpu.h

+ 14 - 14
driver-cpu.c

@@ -166,6 +166,7 @@ const char *algo_names[] = {
 #ifdef WANT_SCRYPT
     [ALGO_SCRYPT] = "scrypt",
 #endif
+	[ALGO_AUTO] = "auto",
 };
 
 static const sha256_func sha256_funcs[] = {
@@ -201,15 +202,7 @@ static const sha256_func sha256_funcs[] = {
 
 
 #ifdef WANT_CPUMINE
-#if defined(WANT_X8664_SSE4) && defined(__SSE4_1__)
-enum sha256_algos opt_algo = ALGO_SSE4_64;
-#elif defined(WANT_X8664_SSE2) && defined(__SSE2__)
-enum sha256_algos opt_algo = ALGO_SSE2_64;
-#elif defined(WANT_X8632_SSE2) && defined(__SSE2__)
-enum sha256_algos opt_algo = ALGO_SSE2_32;
-#else
-enum sha256_algos opt_algo = ALGO_C;
-#endif
+enum sha256_algos opt_algo = ALGO_AUTO;
 bool opt_usecpu = false;
 static bool forced_n_threads;
 #endif
@@ -684,11 +677,6 @@ char *set_algo(const char *arg, enum sha256_algos *algo)
 	if (opt_scrypt)
 		return "Can only use scrypt algorithm";
 
-	if (!strcmp(arg, "auto")) {
-		*algo = pick_fastest_algo();
-		return NULL;
-	}
-
 	for (i = 0; i < ARRAY_SIZE(algo_names); i++) {
 		if (algo_names[i] && !strcmp(arg, algo_names[i])) {
 			*algo = i;
@@ -780,8 +768,15 @@ static void cpu_detect()
 	}
 }
 
+static pthread_mutex_t cpualgo_lock;
+
 static bool cpu_thread_prepare(struct thr_info *thr)
 {
+	struct cgpu_info *cgpu = thr->cgpu;
+	
+	if (!(cgpu->device_id || thr->device_thread || cgpu->proc_id))
+		mutex_init(&cpualgo_lock);
+	
 	thread_reportin(thr);
 
 	return true;
@@ -796,6 +791,11 @@ static bool cpu_thread_init(struct thr_info *thr)
 {
 	const int thr_id = thr->id;
 
+	mutex_lock(&cpualgo_lock);
+	if (opt_algo == ALGO_AUTO)
+		opt_algo = pick_fastest_algo();
+	mutex_unlock(&cpualgo_lock);
+
 	/* 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 */

+ 2 - 0
driver-cpu.h

@@ -49,6 +49,8 @@ enum sha256_algos {
 	ALGO_SSE4_64,		/* SSE4 for x86_64 */
 	ALGO_ALTIVEC_4WAY,	/* parallel Altivec */
 	ALGO_SCRYPT,		/* scrypt */
+	
+	ALGO_AUTO		/* autodetect */
 };
 
 extern const char *algo_names[];