Commit eaf1505381ff72f02a49d268a35656d9db88d2e2

Con Kolivas 2012-06-25T13:31:52

Dynamic intensity for GPUs should be calculated on a per device basis. Clean up the code to only calculate it if required as well.

diff --git a/driver-opencl.c b/driver-opencl.c
index 9dbaef1..2d6f975 100644
--- a/driver-opencl.c
+++ b/driver-opencl.c
@@ -1350,34 +1350,32 @@ static uint64_t opencl_scanhash(struct thr_info *thr, struct work *work,
 	_clState *clState = clStates[thr_id];
 	const cl_kernel *kernel = &clState->kernel;
 
-	double gpu_ms_average = 7;
 	cl_int status;
-
 	size_t globalThreads[1];
 	size_t localThreads[1] = { clState->wsize };
 	unsigned int threads;
 	unsigned int hashes;
 
-
-	struct timeval tv_gpustart, tv_gpuend, diff;
-	suseconds_t gpu_us;
-
-	gettimeofday(&tv_gpustart, NULL);
-	timeval_subtract(&diff, &tv_gpustart, &tv_gpuend);
+	gettimeofday(&gpu->tv_gpustart, NULL);
 	/* This finish flushes the readbuffer set with CL_FALSE later */
 	clFinish(clState->commandQueue);
-	gettimeofday(&tv_gpuend, NULL);
-	timeval_subtract(&diff, &tv_gpuend, &tv_gpustart);
-	gpu_us = diff.tv_sec * 1000000 + diff.tv_usec;
-	decay_time(&gpu_ms_average, gpu_us / 1000);
+	gettimeofday(&gpu->tv_gpuend, NULL);
+
 	if (gpu->dynamic) {
+		struct timeval diff;
+		suseconds_t gpu_ms;
+
+		timersub(&gpu->tv_gpuend, &gpu->tv_gpustart, &diff);
+		gpu_ms = diff.tv_sec * 1000 + diff.tv_usec / 1000;
+		gpu->gpu_ms_average = (gpu->gpu_ms_average + gpu_ms * 0.63) / 1.63;
+
 		/* Try to not let the GPU be out for longer than 6ms, but
 		 * increase intensity when the system is idle, unless
 		 * dynamic is disabled. */
-		if (gpu_ms_average > opt_dynamic_interval) {
+		if (gpu->gpu_ms_average > opt_dynamic_interval) {
 			if (gpu->intensity > MIN_INTENSITY)
 				--gpu->intensity;
-		} else if (gpu_ms_average < ((opt_dynamic_interval / 2) ? : 1)) {
+		} else if (gpu->gpu_ms_average < ((opt_dynamic_interval / 2) ? : 1)) {
 			if (gpu->intensity < MAX_INTENSITY)
 				++gpu->intensity;
 		}
diff --git a/miner.h b/miner.h
index 9eb1b6d..78d3b80 100644
--- a/miner.h
+++ b/miner.h
@@ -342,6 +342,10 @@ struct cgpu_info {
 	cl_uint vwidth;
 	size_t work_size;
 	enum cl_kernels kernel;
+
+	struct timeval tv_gpustart;;
+	struct timeval tv_gpuend;
+	double gpu_ms_average;
 #endif
 
 	float temp;