Browse Source

opencl: Use timeBeginPeriod on Windows to ensure gettimeofday has sufficient precision for dynamic intensity

Luke Dashjr 13 years ago
parent
commit
de73e0fcf4
4 changed files with 44 additions and 1 deletions
  1. 1 0
      Makefile.am
  2. 5 1
      configure.ac
  3. 37 0
      driver-opencl.c
  4. 1 0
      miner.c

+ 1 - 0
Makefile.am

@@ -23,6 +23,7 @@ bin_SCRIPTS	= *.cl
 bfgminer_LDFLAGS	= $(PTHREAD_FLAGS)
 bfgminer_LDFLAGS	= $(PTHREAD_FLAGS)
 bfgminer_LDADD	= $(DLOPEN_FLAGS) @LIBCURL_LIBS@ @JANSSON_LIBS@ @PTHREAD_LIBS@ \
 bfgminer_LDADD	= $(DLOPEN_FLAGS) @LIBCURL_LIBS@ @JANSSON_LIBS@ @PTHREAD_LIBS@ \
 		  @NCURSES_LIBS@ @PDCURSES_LIBS@ @WS2_LIBS@ \
 		  @NCURSES_LIBS@ @PDCURSES_LIBS@ @WS2_LIBS@ \
+		  @TIMER_LIBS@ \
 		  @UDEV_LIBS@ @USB_LIBS@ \
 		  @UDEV_LIBS@ @USB_LIBS@ \
 		  @MATH_LIBS@ lib/libgnu.a ccan/libccan.a
 		  @MATH_LIBS@ lib/libgnu.a ccan/libccan.a
 bfgminer_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib
 bfgminer_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib

+ 5 - 1
configure.ac

@@ -67,6 +67,7 @@ USB_LIBS=""
 USB_FLAGS=""
 USB_FLAGS=""
 DLOPEN_FLAGS="-ldl"
 DLOPEN_FLAGS="-ldl"
 WS2_LIBS=""
 WS2_LIBS=""
+TIMER_LIBS=""
 MATH_LIBS="-lm"
 MATH_LIBS="-lm"
 
 
 case $target in
 case $target in
@@ -85,6 +86,7 @@ case $target in
 	PTHREAD_FLAGS=""
 	PTHREAD_FLAGS=""
 	DLOPEN_FLAGS=""
 	DLOPEN_FLAGS=""
 	WS2_LIBS="-lws2_32"
 	WS2_LIBS="-lws2_32"
+	TIMER_LIBS="-lwinmm"
 	;;
 	;;
   *-*-mingw*)
   *-*-mingw*)
     have_x86_64=false
     have_x86_64=false
@@ -92,6 +94,7 @@ case $target in
     PTHREAD_FLAGS=""
     PTHREAD_FLAGS=""
     DLOPEN_FLAGS=""
     DLOPEN_FLAGS=""
     WS2_LIBS="-lws2_32"
     WS2_LIBS="-lws2_32"
+	TIMER_LIBS="-lwinmm"
     ;;
     ;;
   powerpc-*-darwin*)
   powerpc-*-darwin*)
     CFLAGS="$CFLAGS -faltivec"
     CFLAGS="$CFLAGS -faltivec"
@@ -356,6 +359,7 @@ AC_SUBST(PTHREAD_LIBS)
 AC_SUBST(NCURSES_LIBS)
 AC_SUBST(NCURSES_LIBS)
 AC_SUBST(PDCURSES_LIBS)
 AC_SUBST(PDCURSES_LIBS)
 AC_SUBST(WS2_LIBS)
 AC_SUBST(WS2_LIBS)
+AC_SUBST(TIMER_LIBS)
 AC_SUBST(MATH_LIBS)
 AC_SUBST(MATH_LIBS)
 AC_SUBST(UDEV_LIBS)
 AC_SUBST(UDEV_LIBS)
 AC_SUBST(USB_LIBS)
 AC_SUBST(USB_LIBS)
@@ -445,7 +449,7 @@ echo "Compilation............: make (or gmake)"
 echo "  CPPFLAGS.............: $CPPFLAGS"
 echo "  CPPFLAGS.............: $CPPFLAGS"
 echo "  CFLAGS...............: $CFLAGS"
 echo "  CFLAGS...............: $CFLAGS"
 echo "  LDFLAGS..............: $LDFLAGS $PTHREAD_FLAGS $USB_FLAGS"
 echo "  LDFLAGS..............: $LDFLAGS $PTHREAD_FLAGS $USB_FLAGS"
-echo "  LDADD................: $DLOPEN_FLAGS $LIBCURL_LIBS $JANSSON_LIBS $PTHREAD_LIBS $NCURSES_LIBS $PDCURSES_LIBS $WS2_LIBS $MATH_LIBS $UDEV_LIBS $USB_LIBS"
+echo "  LDADD................: $DLOPEN_FLAGS $LIBCURL_LIBS $JANSSON_LIBS $PTHREAD_LIBS $NCURSES_LIBS $PDCURSES_LIBS $WS2_LIBS $TIMER_LIBS $MATH_LIBS $UDEV_LIBS $USB_LIBS"
 echo
 echo
 echo "Installation...........: make install (as root if needed, with 'su' or 'sudo')"
 echo "Installation...........: make install (as root if needed, with 'su' or 'sudo')"
 echo "  prefix...............: $prefix"
 echo "  prefix...............: $prefix"

+ 37 - 0
driver-opencl.c

@@ -749,6 +749,21 @@ struct cgpu_info *cpus;
 
 
 #ifdef HAVE_OPENCL
 #ifdef HAVE_OPENCL
 
 
+#ifdef WIN32
+static UINT timeperiod_set;
+#endif
+
+void opencl_dynamic_cleanup() {
+#ifdef WIN32
+	if (timeperiod_set) {
+		timeEndPeriod(timeperiod_set);
+		timeperiod_set = 0;
+	}
+#endif
+}
+
+extern int opt_dynamic_interval;
+
 /* In dynamic mode, only the first thread of each device will be in use.
 /* In dynamic mode, only the first thread of each device will be in use.
  * This potentially could start a thread that was stopped with the start-stop
  * This potentially could start a thread that was stopped with the start-stop
  * options if one were to disable dynamic from the menu on a paused GPU */
  * options if one were to disable dynamic from the menu on a paused GPU */
@@ -756,10 +771,18 @@ void pause_dynamic_threads(int gpu)
 {
 {
 	struct cgpu_info *cgpu = &gpus[gpu];
 	struct cgpu_info *cgpu = &gpus[gpu];
 	int i;
 	int i;
+#ifdef WIN32
+	bool any_dynamic = false;
+#endif
 
 
 	for (i = 1; i < cgpu->threads; i++) {
 	for (i = 1; i < cgpu->threads; i++) {
 		struct thr_info *thr = &thr_info[i];
 		struct thr_info *thr = &thr_info[i];
 
 
+#ifdef WIN32
+		if (cgpu->dynamic)
+			any_dynamic = true;
+#endif
+
 		if (!thr->pause && cgpu->dynamic) {
 		if (!thr->pause && cgpu->dynamic) {
 			applog(LOG_WARNING, "Disabling extra threads due to dynamic mode.");
 			applog(LOG_WARNING, "Disabling extra threads due to dynamic mode.");
 			applog(LOG_WARNING, "Tune dynamic intensity with --gpu-dyninterval");
 			applog(LOG_WARNING, "Tune dynamic intensity with --gpu-dyninterval");
@@ -769,6 +792,20 @@ void pause_dynamic_threads(int gpu)
 		if (!cgpu->dynamic && cgpu->deven != DEV_DISABLED)
 		if (!cgpu->dynamic && cgpu->deven != DEV_DISABLED)
 			tq_push(thr->q, &ping);
 			tq_push(thr->q, &ping);
 	}
 	}
+
+#ifdef WIN32
+	if (any_dynamic) {
+		if (!timeperiod_set) {
+			timeperiod_set = opt_dynamic_interval > 3 ? (opt_dynamic_interval / 2) : 1;
+			if (TIMERR_NOERROR != timeBeginPeriod(timeperiod_set))
+				timeperiod_set = 0;
+		}
+	} else {
+		if (timeperiod_set) {
+			opencl_dynamic_cleanup();
+		}
+	}
+#endif
 }
 }
 
 
 
 

+ 1 - 0
miner.c

@@ -4653,6 +4653,7 @@ static void clean_up(void)
 {
 {
 #ifdef HAVE_OPENCL
 #ifdef HAVE_OPENCL
 	clear_adl(nDevs);
 	clear_adl(nDevs);
+	opencl_dynamic_cleanup();
 #endif
 #endif
 #ifdef HAVE_LIBUSB
 #ifdef HAVE_LIBUSB
         libusb_exit(NULL);
         libusb_exit(NULL);