From 6bd5139cfc686c23acc7fc3b398d08d0a6010ff3 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Wed, 23 Oct 2013 20:34:50 +1100 Subject: [PATCH 1/8] Implement a mutex_destroy function. --- miner.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/miner.h b/miner.h index 915d7f87..b53497fc 100644 --- a/miner.h +++ b/miner.h @@ -885,6 +885,13 @@ static inline void _mutex_init(pthread_mutex_t *lock, const char *file, const ch INITLOCK(lock, CGLOCK_MUTEX, file, func, line); } +static inline void mutex_destroy(pthread_mutex_t *lock) +{ + /* Ignore return code. This only invalidates the mutex on linux but + * releases resources on windows. */ + pthread_mutex_destroy(lock); +} + static inline void _rwlock_init(pthread_rwlock_t *lock, const char *file, const char *func, const int line) { if (unlikely(pthread_rwlock_init(lock, NULL))) From de4ad515e05f3943333169cf888ecd0562eab7c0 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Wed, 23 Oct 2013 20:37:10 +1100 Subject: [PATCH 2/8] Implement a rwlock_destroy function. --- miner.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/miner.h b/miner.h index b53497fc..e29fb78a 100644 --- a/miner.h +++ b/miner.h @@ -899,6 +899,11 @@ static inline void _rwlock_init(pthread_rwlock_t *lock, const char *file, const INITLOCK(lock, CGLOCK_RW, file, func, line); } +static inline void rwlock_destroy(pthread_rwlock_t *lock) +{ + pthread_rwlock_destroy(lock); +} + static inline void _cglock_init(cglock_t *lock, const char *file, const char *func, const int line) { _mutex_init(&lock->mutex, file, func, line); From d2719e312fd8c50cbe301c8af7bac2acb5f7b175 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Wed, 23 Oct 2013 20:38:15 +1100 Subject: [PATCH 3/8] Implement a cglock_destroy function. --- miner.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/miner.h b/miner.h index e29fb78a..4e3b5a17 100644 --- a/miner.h +++ b/miner.h @@ -910,6 +910,12 @@ static inline void _cglock_init(cglock_t *lock, const char *file, const char *fu _rwlock_init(&lock->rwlock, file, func, line); } +static inline void cglock_destroy(cglock_t *lock) +{ + rwlock_destroy(&lock->rwlock); + mutex_destroy(&lock->mutex); +} + /* Read lock variant of cglock. Cannot be promoted. */ static inline void _cg_rlock(cglock_t *lock, const char *file, const char *func, const int line) { From 05478b59375e7c8a156661f8ecb8b91a44bafff1 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Wed, 23 Oct 2013 21:19:03 +1100 Subject: [PATCH 4/8] Convert opencl to need to be explicitly enabled during build with --enable-opencl --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 49c1d3b6..43a610aa 100644 --- a/configure.ac +++ b/configure.ac @@ -135,10 +135,10 @@ if test -n "$CGMINER_SDK"; then LDFLAGS="-L$CGMINER_SDK/lib/$target $LDFLAGS" fi -opencl="yes" +opencl="no" AC_ARG_ENABLE([opencl], - [AC_HELP_STRING([--disable-opencl],[Override detection and disable building with opencl])], + [AC_HELP_STRING([--enable-opencl],[Enable support for GPU mining with opencl])], [opencl=$enableval] ) if test "x$opencl" != xno; then From 9fa8e920c70e9caeb3e04a99bdfcbe1eb9882cee Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Wed, 23 Oct 2013 21:29:42 +1100 Subject: [PATCH 5/8] Modify Makefile to only include opencl related code when configured in. --- Makefile.am | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile.am b/Makefile.am index a9fb44b1..0d141ebd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,8 +22,6 @@ INCLUDES = $(PTHREAD_FLAGS) -fno-strict-aliasing $(JANSSON_INCLUDES) $(USBUTILS_ bin_PROGRAMS = cgminer -bin_SCRIPTS = $(top_srcdir)/*.cl - cgminer_LDFLAGS = $(PTHREAD_FLAGS) cgminer_LDADD = $(DLOPEN_FLAGS) @LIBCURL_LIBS@ @JANSSON_LIBS@ @PTHREAD_LIBS@ \ @OPENCL_LIBS@ @NCURSES_LIBS@ @PDCURSES_LIBS@ @WS2_LIBS@ \ @@ -47,11 +45,10 @@ cgminer_SOURCES += elist.h miner.h compat.h bench_block.h \ cgminer_SOURCES += logging.c -# GPU sources, TODO: make them selectable -# the GPU portion extracted from original main.c -cgminer_SOURCES += driver-opencl.h driver-opencl.c +if HAVE_OPENCL +bin_SCRIPTS = $(top_srcdir)/*.cl -# the original GPU related sources, unchanged +cgminer_SOURCES += driver-opencl.h driver-opencl.c cgminer_SOURCES += ocl.c ocl.h findnonce.c findnonce.h cgminer_SOURCES += adl.c adl.h adl_functions.h cgminer_SOURCES += *.cl @@ -60,6 +57,9 @@ if HAS_SCRYPT cgminer_SOURCES += scrypt.c scrypt.h endif +endif + + if NEED_FPGAUTILS cgminer_SOURCES += fpgautils.c fpgautils.h endif From ed16f32d8f2d46810bd65b8d910a6aa6bbd5c449 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Wed, 23 Oct 2013 22:24:58 +1100 Subject: [PATCH 6/8] Enable dynamic linking against system libusb --with-system-libusb --- configure.ac | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index 43a610aa..9782bab4 100644 --- a/configure.ac +++ b/configure.ac @@ -333,16 +333,35 @@ AM_CONDITIONAL([HAVE_CURSES], [test x$curses = xyes]) AM_CONDITIONAL([HAVE_WINDOWS], [test x$have_win32 = xtrue]) AM_CONDITIONAL([HAVE_x86_64], [test x$have_x86_64 = xtrue]) -AC_CONFIG_SUBDIRS([compat/libusb-1.0]) if test "x$want_usbutils" != xfalse; then + dlibusb="no" AC_DEFINE([USE_USBUTILS], [1], [Defined to 1 if usbutils support required]) - LIBUSB_LIBS="compat/libusb-1.0/libusb/.libs/libusb-1.0.a" - if test "x$have_linux" = "xtrue"; then - PKG_CHECK_MODULES([UDEV], [libudev], LIBUSB_LIBS+=" -ludev", [AC_MSG_ERROR([Missing required libudev dev])]) - fi - if test "x$have_darwin" = "xtrue"; then - LIBUSB_LIBS+=" -lobjc" - LDFLAGS+=" -framework CoreFoundation -framework IOKit" + AC_ARG_WITH([system-libusb], + [AC_HELP_STRING([--with-system-libusb],[Compile against dynamic system libusb (default use included static libusb)])], + [dlibusb=$withval] + ) + + if test "x$dlibusb" != xno; then + case $target in + *-*-freebsd*) + LIBUSB_LIBS="-lusb" + LIBUSB_CFLAGS="" + AC_DEFINE(HAVE_LIBUSB, 1, [Define if you have libusb-1.0]) + ;; + *) + PKG_CHECK_MODULES(LIBUSB, libusb-1.0, [AC_DEFINE(HAVE_LIBUSB, 1, [Define if you have libusb-1.0])], [AC_MSG_ERROR([Could not find usb library - please install libusb-1.0])]) + ;; + esac + else + AC_CONFIG_SUBDIRS([compat/libusb-1.0]) + LIBUSB_LIBS="compat/libusb-1.0/libusb/.libs/libusb-1.0.a" + if test "x$have_linux" = "xtrue"; then + LIBUSB_LIBS+=" -ludev" + fi + if test "x$have_darwin" = "xtrue"; then + LIBUSB_LIBS+=" -lobjc" + LDFLAGS+=" -framework CoreFoundation -framework IOKit" + fi fi else LIBUSB_LIBS="" From e76421320e4b6b98e3f96aca4126ff9bc62b5eb9 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Wed, 23 Oct 2013 22:31:00 +1100 Subject: [PATCH 7/8] Minor opencl build corrections. --- Makefile.am | 2 +- cgminer.c | 2 ++ configure.ac | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 0d141ebd..0e03d2d1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -45,7 +45,7 @@ cgminer_SOURCES += elist.h miner.h compat.h bench_block.h \ cgminer_SOURCES += logging.c -if HAVE_OPENCL +if HAS_OPENCL bin_SCRIPTS = $(top_srcdir)/*.cl cgminer_SOURCES += driver-opencl.h driver-opencl.c diff --git a/cgminer.c b/cgminer.c index 0b85ddfb..293163fd 100644 --- a/cgminer.c +++ b/cgminer.c @@ -4968,8 +4968,10 @@ static void *input_thread(void __maybe_unused *userdata) display_pools(); else if (!strncasecmp(&input, "s", 1)) set_options(); +#if HAVE_OPENCL else if (have_opencl && !strncasecmp(&input, "g", 1)) manage_gpu(); +#endif if (opt_realquiet) { disable_curses(); break; diff --git a/configure.ac b/configure.ac index 9782bab4..8a505da2 100644 --- a/configure.ac +++ b/configure.ac @@ -171,6 +171,7 @@ else OPENCL_FLAGS="" OPENCL_LIBS="" fi +AM_CONDITIONAL([HAS_OPENCL], [test x$opencl = xyes]) has_winpthread=false if test "x$have_win32" = xtrue; then From 4f7b6fe4c3b810307bda2c78a57d25406976fad9 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Wed, 23 Oct 2013 22:40:13 +1100 Subject: [PATCH 8/8] Avoid entering static libusb directory if --with-system-libusb is enabled. --- compat/Makefile.am | 2 ++ configure.ac | 2 ++ 2 files changed, 4 insertions(+) diff --git a/compat/Makefile.am b/compat/Makefile.am index 4ed10f82..4cd32d2a 100644 --- a/compat/Makefile.am +++ b/compat/Makefile.am @@ -2,5 +2,7 @@ SUBDIRS = jansson-2.5 if WANT_USBUTILS +if WANT_STATIC_LIBUSB SUBDIRS += libusb-1.0 endif +endif diff --git a/configure.ac b/configure.ac index 8a505da2..f6fa7859 100644 --- a/configure.ac +++ b/configure.ac @@ -368,6 +368,8 @@ else LIBUSB_LIBS="" fi +AM_CONDITIONAL([WANT_STATIC_LIBUSB], [test x$dlibusb = xno]) + AC_CONFIG_SUBDIRS([compat/jansson-2.5]) JANSSON_LIBS="compat/jansson-2.5/src/.libs/libjansson.a"