Increase GPU timing resolution to microsecond and add sanity check to ensure times are positive.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
diff --git a/driver-opencl.c b/driver-opencl.c
index 0571a14..7ba0e26 100644
--- a/driver-opencl.c
+++ b/driver-opencl.c
@@ -1346,6 +1346,7 @@ static uint64_t opencl_scanhash(struct thr_info *thr, struct work *work,
struct cgpu_info *gpu = thr->cgpu;
_clState *clState = clStates[thr_id];
const cl_kernel *kernel = &clState->kernel;
+ const int dynamic_us = opt_dynamic_interval * 1000;
cl_int status;
size_t globalThreads[1];
@@ -1359,21 +1360,23 @@ static uint64_t opencl_scanhash(struct thr_info *thr, struct work *work,
if (gpu->dynamic) {
struct timeval diff;
- suseconds_t gpu_ms;
+ suseconds_t gpu_us;
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->gpu_ms_average > opt_dynamic_interval) {
- if (gpu->intensity > MIN_INTENSITY)
- --gpu->intensity;
- } else if (gpu->gpu_ms_average < (float)opt_dynamic_interval / 2) {
- if (gpu->intensity < MAX_INTENSITY)
- ++gpu->intensity;
+ gpu_us = diff.tv_sec * 1000 + 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
+ * opt_dynamic_interval in ms, but increase
+ * intensity when the system is idle in dynamic mode */
+ if (gpu->gpu_us_average > dynamic_us) {
+ if (gpu->intensity > MIN_INTENSITY)
+ --gpu->intensity;
+ } else if (gpu->gpu_us_average < dynamic_us / 2) {
+ if (gpu->intensity < MAX_INTENSITY)
+ ++gpu->intensity;
+ }
}
}
set_threads_hashes(clState->vwidth, &threads, &hashes, globalThreads,
diff --git a/miner.h b/miner.h
index 024bce6..5b44cee 100644
--- a/miner.h
+++ b/miner.h
@@ -345,7 +345,7 @@ struct cgpu_info {
struct timeval tv_gpustart;;
struct timeval tv_gpuend;
- double gpu_ms_average;
+ double gpu_us_average;
#endif
float temp;