Browse Source

Revert "Windows' timer resolution is limited to 15ms accuracy. This was breaking dynamic intensity since it tries to measure below this."

https://bitcointalk.org/?topic=28402.msg1111967#msg1111967

This reverts commit 8fc2983614ce32d1aa9f8729dd69c8a60f212a36.
Luke Dashjr 13 years ago
parent
commit
00cd89b7ae
3 changed files with 10 additions and 28 deletions
  1. 8 18
      driver-opencl.c
  2. 2 4
      miner.h
  3. 0 6
      util.c

+ 8 - 18
driver-opencl.c

@@ -1741,7 +1741,6 @@ static int64_t opencl_scanhash(struct thr_info *thr, struct work *work,
 	_clState *clState = clStates[thr_id];
 	const cl_kernel *kernel = &clState->kernel;
 	const int dynamic_us = opt_dynamic_interval * 1000;
-	struct timeval tv_gpuend;
 	cl_bool blocking;
 
 	cl_int status;
@@ -1760,17 +1759,13 @@ static int64_t opencl_scanhash(struct thr_info *thr, struct work *work,
 		clFinish(clState->commandQueue);
 
 	if (gpu->dynamic) {
-		double gpu_us;
-
-		/* Windows returns the same time for gettimeofday due to its
-		 * 15ms timer resolution, so we must average the result over
-		 * at least 5 values that are actually different to get an
-		 * accurate result */
-		gpu->intervals++;
-		gettimeofday(&tv_gpuend, NULL);
-		gpu_us = us_tdiff(&tv_gpuend, &gpu->tv_gpumid);
-		if (gpu_us > 0 && ++gpu->hit > 4) {
-			gpu_us = us_tdiff(&tv_gpuend, &gpu->tv_gpustart) / gpu->intervals;
+		struct timeval diff;
+		suseconds_t gpu_us;
+
+		gettimeofday(&gpu->tv_gpuend, NULL);
+		timersub(&gpu->tv_gpuend, &gpu->tv_gpustart, &diff);
+		gpu_us = diff.tv_sec * 1000000 + diff.tv_usec;
+		if (likely(gpu_us >= 0)) {
 			gpu->gpu_us_average = (gpu->gpu_us_average + gpu_us * 0.63) / 1.63;
 
 			/* Try to not let the GPU be out for longer than 
@@ -1783,7 +1778,6 @@ static int64_t opencl_scanhash(struct thr_info *thr, struct work *work,
 				if (gpu->intensity < MAX_INTENSITY)
 					++gpu->intensity;
 			}
-			gpu->intervals = gpu->hit = 0;
 		}
 	}
 	set_threads_hashes(clState->vwidth, &threads, &hashes, globalThreads,
@@ -1819,11 +1813,7 @@ static int64_t opencl_scanhash(struct thr_info *thr, struct work *work,
 			clFinish(clState->commandQueue);
 	}
 
-	gettimeofday(&gpu->tv_gpumid, NULL);
-	if (!gpu->intervals) {
-		gpu->tv_gpustart.tv_sec = gpu->tv_gpumid.tv_sec;
-		gpu->tv_gpustart.tv_usec = gpu->tv_gpumid.tv_usec;
-	}
+	gettimeofday(&gpu->tv_gpustart, NULL);
 
 	if (clState->goffset) {
 		size_t global_work_offset[1];

+ 2 - 4
miner.h

@@ -404,10 +404,9 @@ struct cgpu_info {
 	int opt_tc, thread_concurrency;
 	int shaders;
 #endif
-	struct timeval tv_gpustart;
-	struct timeval tv_gpumid;
+	struct timeval tv_gpustart;;
+	struct timeval tv_gpuend;
 	double gpu_us_average;
-	int intervals, hit;
 #endif
 
 	float temp;
@@ -481,7 +480,6 @@ extern int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*s
 extern void thr_info_cancel(struct thr_info *thr);
 extern void thr_info_freeze(struct thr_info *thr);
 extern void nmsleep(unsigned int msecs);
-extern double us_tdiff(struct timeval *end, struct timeval *start);
 extern void rename_thr(const char* name);
 
 struct string_elist {

+ 0 - 6
util.c

@@ -719,12 +719,6 @@ void nmsleep(unsigned int msecs)
 	} while (ret == -1 && errno == EINTR);
 }
 
-/* Returns the microseconds difference between end and start times as a double */
-double us_tdiff(struct timeval *end, struct timeval *start)
-{
-	return end->tv_sec * 1000000 + end->tv_usec - start->tv_sec * 1000000 - start->tv_usec;
-}
-
 void rename_thr(const char* name) {
 #if defined(PR_SET_NAME)
 	// Only the first 15 characters are used (16 - NUL terminator)