Browse Source

Merge branch 'bfgminer' into cointerra

Luke Dashjr 11 years ago
parent
commit
b57c3b50dc
6 changed files with 78 additions and 18 deletions
  1. 1 1
      deviceapi.c
  2. 1 1
      driver-opencl.c
  3. 13 9
      miner.c
  4. 1 1
      miner.h
  5. 58 6
      util.c
  6. 4 0
      util.h

+ 1 - 1
deviceapi.c

@@ -489,7 +489,7 @@ void cgpu_setup_control_requests(struct cgpu_info * const cgpu)
 {
 	mutex_init(&cgpu->device_mutex);
 	notifier_init(cgpu->thr[0]->mutex_request);
-	pthread_cond_init(&cgpu->device_cond, NULL);
+	pthread_cond_init(&cgpu->device_cond, bfg_condattr);
 }
 
 void cgpu_request_control(struct cgpu_info * const cgpu)

+ 1 - 1
driver-opencl.c

@@ -1283,7 +1283,7 @@ void *reinit_gpu(void *userdata)
 
 select_cgpu:
 	sel_cgpu =
-	cgpu = tq_pop(mythr->q, NULL);
+	cgpu = tq_pop(mythr->q);
 	if (!cgpu)
 		goto out;
 	

+ 13 - 9
miner.c

@@ -357,6 +357,8 @@ bool selecting_device;
 unsigned selected_device;
 #endif
 
+static int max_lpdigits;
+
 static char current_block[40];
 
 /* Protected by ch_lock */
@@ -1050,7 +1052,7 @@ struct pool *add_pool(void)
 	mutex_init(&pool->last_work_lock);
 	mutex_init(&pool->pool_lock);
 	mutex_init(&pool->pool_test_lock);
-	if (unlikely(pthread_cond_init(&pool->cr_cond, NULL)))
+	if (unlikely(pthread_cond_init(&pool->cr_cond, bfg_condattr)))
 		quit(1, "Failed to pthread_cond_init in add_pool");
 	cglock_init(&pool->data_lock);
 	mutex_init(&pool->stratum_lock);
@@ -3763,7 +3765,7 @@ void get_statline3(char *buf, size_t bufsz, struct cgpu_info *cgpu, bool for_cur
 	if (for_curses)
 	{
 		if (opt_show_procs)
-			snprintf(buf, bufsz, " %"PRIprepr": ", cgpu->proc_repr);
+			snprintf(buf, bufsz, " %*s: ", -(5 + max_lpdigits), cgpu->proc_repr);
 		else
 			snprintf(buf, bufsz, " %s: ", cgpu->dev_repr);
 	}
@@ -4202,7 +4204,7 @@ one_workable_pool: ;
 	{
 		int offset = 8 /* device */ + 5 /* temperature */ + 1 /* padding space */;
 		if (opt_show_procs && !opt_compact)
-			++offset;  // proc letter
+			offset += max_lpdigits;  // proc letter(s)
 		if (have_unicode_degrees)
 			++offset;  // degrees symbol
 		mvwadd_wch(statuswin, 6, offset, WACS_PLUS);
@@ -8292,7 +8294,7 @@ static void hashmeter(int thr_id, struct timeval *diff,
 		
 		divx = 7;
 		if (opt_show_procs && !opt_compact)
-			++divx;
+			divx += max_lpdigits;
 		
 		if (bad)
 		{
@@ -9156,7 +9158,6 @@ static struct work *hash_pop(void)
 {
 	struct work *work = NULL, *tmp;
 	int hc;
-	struct timespec ts;
 
 retry:
 	mutex_lock(stgd_lock);
@@ -9174,9 +9175,9 @@ retry:
 			staged_full = false;  // Let it fill up before triggering an underrun again
 			no_work = true;
 		}
-		ts = (struct timespec){ .tv_sec = opt_log_interval, };
 		pthread_cond_signal(&gws_cond);
-		if (ETIMEDOUT == pthread_cond_timedwait(&getq->cond, stgd_lock, &ts))
+		const struct timeval tv = { .tv_sec = opt_log_interval, };
+		if (ETIMEDOUT == bfg_cond_timedwait(&getq->cond, stgd_lock, &tv))
 		{
 			run_cmd(cmd_idle);
 			pthread_cond_signal(&gws_cond);
@@ -11479,6 +11480,9 @@ void renumber_cgpu(struct cgpu_info *cgpu)
 		for (int i = lpcount; i > 26 && lpdigits < 3; i /= 26)
 			++lpdigits;
 		
+		if (lpdigits > max_lpdigits)
+			max_lpdigits = lpdigits;
+		
 		memset(&cgpu->proc_repr[5], 'a', lpdigits);
 		cgpu->proc_repr[5 + lpdigits] = '\0';
 		ns = strlen(cgpu->proc_repr_ns);
@@ -12337,10 +12341,10 @@ int main(int argc, char *argv[])
 	rwlock_init(&devices_lock);
 
 	mutex_init(&lp_lock);
-	if (unlikely(pthread_cond_init(&lp_cond, NULL)))
+	if (unlikely(pthread_cond_init(&lp_cond, bfg_condattr)))
 		quit(1, "Failed to pthread_cond_init lp_cond");
 
-	if (unlikely(pthread_cond_init(&gws_cond, NULL)))
+	if (unlikely(pthread_cond_init(&gws_cond, bfg_condattr)))
 		quit(1, "Failed to pthread_cond_init gws_cond");
 
 	notifier_init(submit_waiting_notifier);

+ 1 - 1
miner.h

@@ -1512,7 +1512,7 @@ extern bool pool_may_redirect_to(struct pool *, const char *uri);
 extern struct thread_q *tq_new(void);
 extern void tq_free(struct thread_q *tq);
 extern bool tq_push(struct thread_q *tq, void *data);
-extern void *tq_pop(struct thread_q *tq, const struct timespec *abstime);
+extern void *tq_pop(struct thread_q *);
 extern void tq_freeze(struct thread_q *tq);
 extern void tq_thaw(struct thread_q *tq);
 extern bool successful_connect;

+ 58 - 6
util.c

@@ -882,7 +882,7 @@ struct thread_q *tq_new(void)
 		return NULL;
 
 	pthread_mutex_init(&tq->mutex, NULL);
-	pthread_cond_init(&tq->cond, NULL);
+	pthread_cond_init(&tq->cond, bfg_condattr);
 
 	return tq;
 }
@@ -948,7 +948,7 @@ bool tq_push(struct thread_q *tq, void *data)
 	return rc;
 }
 
-void *tq_pop(struct thread_q *tq, const struct timespec *abstime)
+void *tq_pop(struct thread_q * const tq)
 {
 	struct tq_ent *ent;
 	void *rval = NULL;
@@ -958,10 +958,7 @@ void *tq_pop(struct thread_q *tq, const struct timespec *abstime)
 	if (tq->q)
 		goto pop;
 
-	if (abstime)
-		rc = pthread_cond_timedwait(&tq->cond, &tq->mutex, abstime);
-	else
-		rc = pthread_cond_wait(&tq->cond, &tq->mutex);
+	rc = pthread_cond_wait(&tq->cond, &tq->mutex);
 	if (rc)
 		goto out;
 	if (!tq->q)
@@ -1188,6 +1185,7 @@ void _now_is_not_set(__maybe_unused struct timeval *tv)
 void (*timer_set_now)(struct timeval *tv) = _now_is_not_set;
 void (*cgsleep_us_r)(cgtimer_t *, int64_t) = _cgsleep_us_r_nanosleep;
 
+static clockid_t bfg_timedwait_clk;
 #ifdef HAVE_CLOCK_GETTIME_MONOTONIC
 static clockid_t bfg_timer_clk;
 
@@ -1233,6 +1231,60 @@ bool _bfg_try_clock_gettime(clockid_t clk)
 }
 #endif
 
+int bfg_cond_timedwait(pthread_cond_t * restrict cond, pthread_mutex_t * restrict mutex, const struct timeval *tvp)
+{
+	struct timespec ts;
+	clock_gettime(bfg_timedwait_clk, &ts);
+	ts.tv_sec += tvp->tv_sec;
+	ts.tv_nsec += (long)tvp->tv_usec * 1000;
+	if (ts.tv_nsec > 1000000000L)
+	{
+		++ts.tv_sec;
+		ts.tv_nsec -= 1000000000L;
+	}
+	return pthread_cond_timedwait(cond, mutex, &ts);
+}
+
+pthread_condattr_t *bfg_condattr_()
+{
+	static pthread_condattr_t attr;
+	static bool initialized;
+	
+	if (unlikely(!initialized))
+	{
+		pthread_condattr_init(&attr);
+#ifdef HAVE_CLOCK_GETTIME_MONOTONIC
+#ifdef HAVE_CLOCK_GETTIME_MONOTONIC_RAW
+		if (!pthread_condattr_setclock(&attr, CLOCK_MONOTONIC_RAW))
+		{
+			applog(LOG_DEBUG, "Timers: Using %s for cond timedwait", "CLOCK_MONOTONIC_RAW");
+			bfg_timedwait_clk = CLOCK_MONOTONIC_RAW;
+		}
+		else
+#endif
+		if (!pthread_condattr_setclock(&attr, CLOCK_MONOTONIC))
+		{
+			applog(LOG_DEBUG, "Timers: Using %s for cond timedwait", "CLOCK_MONOTONIC");
+			bfg_timedwait_clk = CLOCK_MONOTONIC;
+		}
+		else
+#endif
+		if (!pthread_condattr_setclock(&attr, CLOCK_REALTIME))
+		{
+			applog(LOG_DEBUG, "Timers: Using %s for cond timedwait", "CLOCK_REALTIME");
+			bfg_timedwait_clk = CLOCK_REALTIME;
+		}
+		else
+		{
+			applog(LOG_DEBUG, "Timers: Cannot find a clock for cond timedwait");
+			return NULL;
+		}
+		initialized = true;
+	}
+	
+	return &attr;
+}
+
 static
 void bfg_init_time()
 {

+ 4 - 0
util.h

@@ -224,6 +224,10 @@ int cgtimer_to_ms(cgtimer_t *cgt)
 	return (cgt->tv_sec * 1000) + (cgt->tv_usec / 1000);
 }
 
+extern int bfg_cond_timedwait(pthread_cond_t * restrict, pthread_mutex_t * restrict, const struct timeval *);
+extern pthread_condattr_t *bfg_condattr_();
+#define bfg_condattr (bfg_condattr_())
+
 #define cgtimer_sub(a, b, res)  timersub(a, b, res)
 double us_tdiff(struct timeval *end, struct timeval *start);
 double tdiff(struct timeval *end, struct timeval *start);