Browse Source

Merge branch 'win64' into bfgminer

Luke Dashjr 13 years ago
parent
commit
5248737f93
17 changed files with 187 additions and 77 deletions
  1. 24 0
      compat.h
  2. 2 2
      driver-bitforce.c
  3. 4 0
      driver-icarus.c
  4. 4 0
      driver-opencl.c
  5. 4 0
      driver-x6500.c
  6. 2 0
      driver-ztex.c
  7. 2 0
      dynclock.c
  8. 1 1
      elist.h
  9. 5 1
      fpgautils.c
  10. 4 0
      ft232r.c
  11. 4 0
      jtag.c
  12. 4 2
      logging.c
  13. 85 56
      make-release
  14. 15 9
      miner.c
  15. 4 0
      miner.h
  16. 3 3
      ocl.c
  17. 20 3
      util.c

+ 24 - 0
compat.h

@@ -3,6 +3,10 @@
 
 #include "config.h"
 
+#ifdef WIN32
+#include <winsock2.h>
+#endif
+
 #include <stdbool.h>
 
 // NOTE: Nested preprocessor checks since the latter isn't defined at all without the former
@@ -49,6 +53,26 @@
    } while (0)
  #endif
 
+// localtime is thread-safe on Windows
+// We also use this with timeval.tv_sec, which is incorrectly smaller than time_t on Windows
+// Need to cast to time_t* to suppress warning - actual problem shouldn't be possible in practice
+#define localtime_r(timep, result)  (  \
+	memcpy(result,  \
+		(  \
+			(sizeof(*timep) == sizeof(time_t))  \
+			? localtime((time_t*)timep)  \
+			: localtime_convert(*timep)  \
+		),  \
+		sizeof(*result)  \
+	)  \
+)
+
+static inline
+struct tm *localtime_convert(time_t t)
+{
+	return localtime(&t);
+}
+
 static inline int nanosleep(const struct timespec *req, struct timespec *rem)
 {
 	struct timeval tstart;

+ 2 - 2
driver-bitforce.c

@@ -8,6 +8,8 @@
  * any later version.  See COPYING for more details.
  */
 
+#include "config.h"
+
 #include <limits.h>
 #include <pthread.h>
 #include <stdint.h>
@@ -16,8 +18,6 @@
 #include <sys/time.h>
 #include <unistd.h>
 
-#include "config.h"
-
 #include "compat.h"
 #include "miner.h"
 #include "fpgautils.h"

+ 4 - 0
driver-icarus.c

@@ -31,6 +31,10 @@
 
 #include "config.h"
 
+#ifdef WIN32
+#include <winsock2.h>
+#endif
+
 #include <limits.h>
 #include <pthread.h>
 #include <stdio.h>

+ 4 - 0
driver-opencl.c

@@ -11,6 +11,10 @@
 
 #include "config.h"
 
+#ifdef WIN32
+#include <winsock2.h>
+#endif
+
 #ifdef HAVE_CURSES
 #include <curses.h>
 #endif

+ 4 - 0
driver-x6500.c

@@ -9,6 +9,10 @@
 
 #include "config.h"
 
+#ifdef WIN32
+#include <winsock2.h>
+#endif
+
 #include <math.h>
 #include <sys/time.h>
 

+ 2 - 0
driver-ztex.c

@@ -24,6 +24,8 @@
  *   along with this program; if not, see http://www.gnu.org/licenses/.
 **/
 
+#include "config.h"
+
 #include <unistd.h>
 #include <sha2.h>
 

+ 2 - 0
dynclock.c

@@ -8,6 +8,8 @@
  * any later version.  See COPYING for more details.
  */
 
+#include "config.h"
+
 #include "dynclock.h"
 #include "miner.h"
 

+ 1 - 1
elist.h

@@ -181,7 +181,7 @@ static inline void list_splice_init(struct list_head *list,
  * @member:	the name of the list_struct within the struct.
  */
 #define list_entry(ptr, type, member) \
-	((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
+	((type *)((char *)(ptr)-(intptr_t)(&((type *)0)->member)))
 
 /**
  * list_for_each	-	iterate over a list

+ 5 - 1
fpgautils.c

@@ -10,6 +10,10 @@
 
 #include "config.h"
 
+#ifdef WIN32
+#include <winsock2.h>
+#endif
+
 #include <stdarg.h>
 #include <stdint.h>
 #include <stdlib.h>
@@ -661,7 +665,7 @@ int serial_open(const char *devpath, unsigned long baud, uint8_t timeout, bool p
 		PurgeComm(hSerial, PURGE_TXCLEAR);
 	}
 
-	return _open_osfhandle((LONG)hSerial, 0);
+	return _open_osfhandle((intptr_t)hSerial, 0);
 #else
 	int fdDev = open(devpath, O_RDWR | O_CLOEXEC | O_NOCTTY);
 

+ 4 - 0
ft232r.c

@@ -9,6 +9,10 @@
 
 #include "config.h"
 
+#ifdef WIN32
+#include <winsock2.h>
+#endif
+
 #include <errno.h>
 #include <stdbool.h>
 #include <stdint.h>

+ 4 - 0
jtag.c

@@ -11,6 +11,10 @@
 
 #include "config.h"
 
+#ifdef WIN32
+#include <winsock2.h>
+#endif
+
 #include <stdbool.h>
 #include <stdint.h>
 #include <stdlib.h>

+ 4 - 2
logging.c

@@ -11,6 +11,7 @@
 
 #include <unistd.h>
 
+#include "compat.h"
 #include "logging.h"
 #include "miner.h"
 
@@ -92,11 +93,12 @@ static void log_generic(int prio, const char *fmt, va_list ap)
 		char *f;
 		int len;
 		struct timeval tv = {0, 0};
-		struct tm *tm;
+		struct tm _tm;
+		struct tm *tm = &_tm;
 
 		gettimeofday(&tv, NULL);
 
-		tm = localtime(&tv.tv_sec);
+		localtime_r(&tv.tv_sec, tm);
 
 		len = 40 + strlen(fmt) + 22;
 		f = alloca(len);

+ 85 - 56
make-release

@@ -6,28 +6,22 @@ tag="$1"; shift
 sw="$1"; shift || true
 [ -n "$sw" ] || sw="$tag"
 
+builds=(win32 win64)
+
+win32_machine='i686-pc-mingw32'
+win32_CFLAGS='-march=i686'
+
+win64_machine='x86_64-w64-mingw32'
+win64_CFLAGS=''
+
 IDIR="$PWD"
-ZIPNAME="${sw}-win32"
-OUTDIR="$PWD/w32zip/$ZIPNAME"
-TMPDIR="${OUTDIR}-tmp"
+OUTDIR="$PWD"
+TMPROOT="$PWD/make-release-tmp"
+TMPDIR="${TMPROOT}/${sw}-tmp"
 
-set -e
-mkdir -v "$OUTDIR"
-dlls='
-	pdcurses.dll
-	libcurl-4.dll
-	pthreadGC2.dll
-	libjansson-4.dll
-	libusb-1.0.dll
-	zlib1.dll
-'
-cp -v \
-	-L \
-	$dlls \
-	"$OUTDIR/"
-for dll in $dlls; do
-	i686-pc-mingw32-strip "$OUTDIR/$dll"
-done
+mkdir -vp "$TMPDIR"
+
+# Source release
 git branch TMP "$tag"
 git clone . "$TMPDIR" -b TMP --depth 1
 git branch -D TMP
@@ -43,42 +37,77 @@ NOSUBMODULES=1 \
 NOCONFIGURE=1 \
 ./autogen.sh
 cd ..
-zip -r "$IDIR/${sw}.zip" "$sw"
-tar cjvpf "$IDIR/${sw}.tbz2" "$sw"
+zip -r "$OUTDIR/${sw}.zip" "$sw"
+tar cjvpf "$OUTDIR/${sw}.tbz2" "$sw"
 SRCDIR="$TMPDIR/$sw"
-for txt in AUTHORS COPYING NEWS README API-README FPGA-README SCRYPT-README; do
-	sed 's/$/\r/' <"$txt" >"$OUTDIR/${txt}.txt"
+
+dlls='
+	pdcurses.dll
+	libcurl-4.dll
+	pthreadGC2.dll
+	libjansson-4.dll
+	libusb-1.0.dll
+	zlib1.dll
+'
+docs='
+	AUTHORS
+	COPYING
+	NEWS
+	README
+	API-README
+	FPGA-README
+	SCRYPT-README
+'
+for build in "${builds[@]}"; do
+	PKGNAME="${sw}-${build}"
+	PKGDIR="$TMPDIR/$PKGNAME"
+	cd "$TMPDIR"
+	mkdir -vp "$PKGDIR"
+	for v in machine CFLAGS; do
+		eval "${v}"="$(eval echo "\${${build}_${v}}")"
+	done
+	libdir="/usr/$machine/usr/bin/$dll"
+	for dll in $dlls; do
+		libdir="/usr/$machine/usr/lib"
+		[ -e "$libdir/$dll" ] ||
+			libdir="/usr/$machine/usr/bin"
+		cp -v -L "$libdir/$dll" "$PKGDIR"
+		"$machine"-strip "$PKGDIR/$dll"
+	done
+	for doc in $docs; do
+		sed 's/$/\r/' <"$doc" >"$PKGDIR/${doc}.txt"
+	done
+	cp -av "bitstreams" "$PKGDIR/"
+	
+	NOCONFIGURE=1 \
+	./autogen.sh
+	./configure \
+		--prefix='C:\\Program Files\\BFGMiner\\' \
+		CFLAGS="${CFLAGS} -Wall" \
+		--disable-cpumining \
+		--enable-opencl \
+		--enable-adl \
+		--enable-bitforce \
+		--enable-icarus \
+		--enable-modminer \
+		--enable-ztex \
+		--enable-scrypt \
+		--host="$machine"
+	make $MAKEOPTS
+	"$machine"-strip \
+		libblkmaker/.libs/*.dll \
+		*.exe
+	cp -v \
+		*.exe \
+		libblkmaker/.libs/*.dll \
+		*.cl \
+		example.conf \
+		windows-build.txt \
+		API.class \
+		miner.php \
+		"$PKGDIR/"
+	make clean
+	cd "$PKGDIR/.."
+	zip -r "$OUTDIR/$PKGNAME.zip" "$PKGNAME"
 done
-cp -av "bitstreams" "$OUTDIR/"
-NOCONFIGURE=1 \
-./autogen.sh
-./configure \
-	--prefix='C:\\Program Files\\BFGMiner\' \
-	CFLAGS='-march=i686 -Wall' \
-	--disable-cpumining \
-	--enable-opencl \
-	--enable-adl \
-	--enable-bitforce \
-	--enable-icarus \
-	--enable-modminer \
-	--enable-ztex \
-	--enable-scrypt \
-	--build=i686-pc-linux-gnu \
-	--host=i686-pc-mingw32
-make -j4
-i686-pc-mingw32-strip \
-	libblkmaker/.libs/*.dll \
-	bfgminer.exe
-cp -v \
-	bfgminer.exe \
-	libblkmaker/.libs/*.dll \
-	*.cl \
-	example.conf \
-	windows-build.txt \
-	API.class \
-	miner.php \
-	"$OUTDIR/" -v
-cd "$OUTDIR"
-cd ..
-zip -r "$IDIR/${ZIPNAME}.zip" "${ZIPNAME}"
 cd "$IDIR"

+ 15 - 9
miner.c

@@ -345,7 +345,7 @@ static bool should_run(void)
 		return true;
 
 	gettimeofday(&tv, NULL);
-	tm = *localtime(&tv.tv_sec);
+	localtime_r(&tv.tv_sec, &tm);
 
 	// NOTE: This is delicately balanced so that should_run is always false if schedstart==schedstop
 	if (time_before(&schedstop.tm, &schedstart.tm))
@@ -362,9 +362,10 @@ static bool should_run(void)
 
 void get_datestamp(char *f, struct timeval *tv)
 {
-	struct tm *tm;
+	struct tm _tm;
+	struct tm *tm = &_tm;
 
-	tm = localtime(&tv->tv_sec);
+	localtime_r(&tv->tv_sec, tm);
 	sprintf(f, "[%d-%02d-%02d %02d:%02d:%02d]",
 		tm->tm_year + 1900,
 		tm->tm_mon + 1,
@@ -376,9 +377,10 @@ void get_datestamp(char *f, struct timeval *tv)
 
 void get_timestamp(char *f, struct timeval *tv)
 {
-	struct tm *tm;
+	struct tm _tm;
+	struct tm *tm = &_tm;
 
-	tm = localtime(&tv->tv_sec);
+	localtime_r(&tv->tv_sec, tm);
 	sprintf(f, "[%02d:%02d:%02d]",
 		tm->tm_hour,
 		tm->tm_min,
@@ -2727,7 +2729,9 @@ static bool submit_upstream_work_completed(struct work *work, bool resubmit, str
 
 		if (opt_worktime) {
 			char workclone[20];
+			struct tm _tm;
 			struct tm *tm, tm_getwork, tm_submit_reply;
+			tm = &_tm;
 			double getwork_time = tdiff((struct timeval *)&(work->tv_getwork_reply),
 							(struct timeval *)&(work->tv_getwork));
 			double getwork_to_work = tdiff((struct timeval *)&(work->tv_work_start),
@@ -2739,9 +2743,9 @@ static bool submit_upstream_work_completed(struct work *work, bool resubmit, str
 			double submit_time = tdiff(&tv_submit_reply, ptv_submit);
 			int diffplaces = 3;
 
-			tm = localtime(&(work->tv_getwork.tv_sec));
+			localtime_r(&(work->tv_getwork.tv_sec), tm);
 			memcpy(&tm_getwork, tm, sizeof(struct tm));
-			tm = localtime(&(tv_submit_reply.tv_sec));
+			localtime_r(&(tv_submit_reply.tv_sec), tm);
 			memcpy(&tm_submit_reply, tm, sizeof(struct tm));
 
 			if (work->clone) {
@@ -3155,8 +3159,10 @@ void kill_work(void)
 
 static
 #ifdef WIN32
+#ifndef _WIN64
 const
 #endif
+#endif
 char **initial_args;
 
 static void clean_up(void);
@@ -8092,9 +8098,9 @@ begin_bench:
 	gettimeofday(&total_tv_end, NULL);
 	miner_started = total_tv_start;
 	if (schedstart.tm.tm_sec)
-		schedstart.tm = *localtime(&miner_started.tv_sec);
+		localtime_r(&miner_started.tv_sec, &schedstart.tm);
 	if (schedstop.tm.tm_sec)
-		schedstop .tm = *localtime(&miner_started.tv_sec);
+		localtime_r(&miner_started.tv_sec, &schedstop .tm);
 	get_datestamp(datestamp, &total_tv_start);
 
 	// Start threads

+ 4 - 0
miner.h

@@ -3,6 +3,10 @@
 
 #include "config.h"
 
+#ifdef WIN32
+#include <winsock2.h>
+#endif
+
 #include <stdbool.h>
 #include <stdint.h>
 #include <sys/time.h>

+ 3 - 3
ocl.c

@@ -667,7 +667,7 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
 					cgpu->thread_concurrency = cgpu->shaders * 5;
 			}
 				
-			applog(LOG_DEBUG, "GPU %d: selecting thread concurrency of %u",gpu,  cgpu->thread_concurrency);
+			applog(LOG_DEBUG, "GPU %u: selecting thread concurrency of %lu", gpu,  (unsigned long)cgpu->thread_concurrency);
 		} else
 			cgpu->thread_concurrency = cgpu->opt_tc;
 
@@ -985,10 +985,10 @@ built:
 		 * 2 greater >= required amount earlier */
 		if (bufsize > cgpu->max_alloc) {
 			applog(LOG_WARNING, "Maximum buffer memory device %d supports says %lu", gpu, (unsigned long)cgpu->max_alloc);
-			applog(LOG_WARNING, "Your scrypt settings come to %u", bufsize);
+			applog(LOG_WARNING, "Your scrypt settings come to %lu", (unsigned long)bufsize);
 		} else
 			bufsize = cgpu->max_alloc;
-		applog(LOG_DEBUG, "Creating scrypt buffer sized %d", bufsize);
+		applog(LOG_DEBUG, "Creating scrypt buffer sized %ld", (unsigned long)bufsize);
 		clState->padbufsize = bufsize;
 
 		/* This buffer is weird and might work to some degree even if

+ 20 - 3
util.c

@@ -445,7 +445,7 @@ void json_rpc_call_async(CURL *curl, const char *url,
 	if (likely(global_hashrate)) {
 		char ghashrate[255];
 
-		sprintf(ghashrate, "X-Mining-Hashrate: %llu", global_hashrate);
+		sprintf(ghashrate, "X-Mining-Hashrate: %"PRIu64, (uint64_t)global_hashrate);
 		headers = curl_slist_append(headers, ghashrate);
 	}
 
@@ -1095,7 +1095,7 @@ static void recalloc_sock(struct pool *pool, size_t len)
 	if (new < pool->sockbuf_size)
 		return;
 	new = new + (RBUFSIZE - (new % RBUFSIZE));
-	applog(LOG_DEBUG, "Recallocing pool sockbuf to %d", new);
+	applog(LOG_DEBUG, "Recallocing pool sockbuf to %lu", (unsigned long)new);
 	pool->sockbuf = realloc(pool->sockbuf, new);
 	if (!pool->sockbuf)
 		quit(1, "Failed to realloc pool sockbuf in recalloc_sock");
@@ -1491,6 +1491,14 @@ out:
 	return ret;
 }
 
+curl_socket_t grab_socket_opensocket_cb(void *clientp, curlsocktype purpose, struct curl_sockaddr *addr)
+{
+	struct pool *pool = clientp;
+	curl_socket_t sck = socket(addr->family, addr->socktype, addr->protocol);
+	pool->sock = sck;
+	return sck;
+}
+
 bool initiate_stratum(struct pool *pool)
 {
 	json_t *val = NULL, *res_val, *err_val;
@@ -1540,6 +1548,10 @@ bool initiate_stratum(struct pool *pool)
 	curl_easy_setopt(curl, CURLOPT_DEBUGDATA, (void *)pool);
 	curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
 
+	// CURLINFO_LASTSOCKET is broken on Win64 (which has a wider SOCKET type than curl_easy_getinfo returns), so we use this hack for now
+	curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, grab_socket_opensocket_cb);
+	curl_easy_setopt(curl, CURLOPT_OPENSOCKETDATA, pool);
+	
 	curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_TRY);
 	if (pool->rpc_proxy) {
 		curl_easy_setopt(curl, CURLOPT_PROXY, pool->rpc_proxy);
@@ -1553,7 +1565,12 @@ bool initiate_stratum(struct pool *pool)
 		applog(LOG_INFO, "Stratum connect failed to pool %d: %s", pool->pool_no, curl_err_str);
 		goto out;
 	}
-	curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, (long *)&pool->sock);
+	if (pool->sock == INVSOCK)
+	{
+		curl_easy_cleanup(curl);
+		applog(LOG_ERR, "Stratum connect succeeded, but technical problem extracting socket (pool %u)", pool->pool_no);
+		goto out;
+	}
 	keep_sockalive(pool->sock);
 
 	pool->cgminer_pool_stats.times_sent++;