Browse Source

Merge branch 'bugfix_format' into bfgminer-2.9.x

Conflicts:
	configure.ac
Luke Dashjr 13 years ago
parent
commit
0723d45e19
13 changed files with 50 additions and 35 deletions
  1. 1 1
      adl.c
  2. 18 0
      configure.ac
  3. 6 6
      driver-bitforce.c
  4. 1 4
      driver-cairnsmore.c
  5. 2 2
      driver-x6500.c
  6. 3 3
      driver-ztex.c
  7. 1 1
      fpgautils.c
  8. 2 2
      libztex.c
  9. 2 2
      logging.h
  10. 9 9
      miner.c
  11. 1 1
      miner.h
  12. 3 3
      ocl.c
  13. 1 1
      util.c

+ 1 - 1
adl.c

@@ -1053,7 +1053,7 @@ static bool fan_autotune(int gpu, int temp, int fanpercent, int lasttemp, bool *
 
 
 	get_fanrange(gpu, &iMin, &iMax);
 	get_fanrange(gpu, &iMin, &iMax);
 	if (temp > ga->overtemp && fanpercent < iMax) {
 	if (temp > ga->overtemp && fanpercent < iMax) {
-		applog(LOG_WARNING, "Overheat detected on GPU %d, increasing fan to 100%", gpu);
+		applog(LOG_WARNING, "Overheat detected on GPU %d, increasing fan to 100%%", gpu);
 		newpercent = iMax;
 		newpercent = iMax;
 
 
 		cgpu->device_last_not_well = time(NULL);
 		cgpu->device_last_not_well = time(NULL);

+ 18 - 0
configure.ac

@@ -541,6 +541,24 @@ if test "x$found_endian" = "xno"; then
 fi
 fi
 
 
 
 
+AC_MSG_CHECKING([if GNU format attribute compiles])
+AC_TRY_COMPILE([
+	#define FORMAT_SYNTAX_CHECK(...) __attribute__(( format(__VA_ARGS__) ))
+	int myfunc(char *fmt, ...) FORMAT_SYNTAX_CHECK(printf, 1, 2);
+	int myfunc(char *fmt, ...) {
+		return 42;
+	}
+], [
+	myfunc("abc%d", 42);
+], [
+	AC_MSG_RESULT([yes])
+	AC_DEFINE_UNQUOTED([FORMAT_SYNTAX_CHECK(...)], [__attribute__(( format(__VA_ARGS__) ))], [Syntax of format-checking attribute])
+], [
+	AC_MSG_RESULT([no])
+	AC_DEFINE_UNQUOTED([FORMAT_SYNTAX_CHECK(...)], [])
+])
+
+
 if test "x$prefix" = xNONE; then
 if test "x$prefix" = xNONE; then
 	prefix=/usr/local
 	prefix=/usr/local
 fi
 fi

+ 6 - 6
driver-bitforce.c

@@ -30,7 +30,7 @@
 #define BITFORCE_CHECK_INTERVAL_MS 10
 #define BITFORCE_CHECK_INTERVAL_MS 10
 #define WORK_CHECK_INTERVAL_MS 50
 #define WORK_CHECK_INTERVAL_MS 50
 #define MAX_START_DELAY_US 100000
 #define MAX_START_DELAY_US 100000
-#define tv_to_ms(tval) (tval.tv_sec * 1000 + tval.tv_usec / 1000)
+#define tv_to_ms(tval) ((unsigned long)(tval.tv_sec * 1000 + tval.tv_usec / 1000))
 #define TIME_AVG_CONSTANT 8
 #define TIME_AVG_CONSTANT 8
 
 
 #define KNAME_WORK  "full work"
 #define KNAME_WORK  "full work"
@@ -449,8 +449,8 @@ static int64_t bitforce_get_result(struct thr_info *thr, struct work *work)
 		timersub(&now, &bitforce->work_start_tv, &elapsed);
 		timersub(&now, &bitforce->work_start_tv, &elapsed);
 
 
 		if (elapsed.tv_sec >= BITFORCE_LONG_TIMEOUT_S) {
 		if (elapsed.tv_sec >= BITFORCE_LONG_TIMEOUT_S) {
-			applog(LOG_ERR, "BFL%i: took %dms - longer than %dms", bitforce->device_id,
-				tv_to_ms(elapsed), BITFORCE_LONG_TIMEOUT_MS);
+			applog(LOG_ERR, "BFL%i: took %lums - longer than %lums", bitforce->device_id,
+				tv_to_ms(elapsed), (unsigned long)BITFORCE_LONG_TIMEOUT_MS);
 			return 0;
 			return 0;
 		}
 		}
 
 
@@ -465,8 +465,8 @@ static int64_t bitforce_get_result(struct thr_info *thr, struct work *work)
 	}
 	}
 
 
 	if (elapsed.tv_sec > BITFORCE_TIMEOUT_S) {
 	if (elapsed.tv_sec > BITFORCE_TIMEOUT_S) {
-		applog(LOG_ERR, "BFL%i: took %dms - longer than %dms", bitforce->device_id,
-			tv_to_ms(elapsed), BITFORCE_TIMEOUT_MS);
+		applog(LOG_ERR, "BFL%i: took %lums - longer than %lums", bitforce->device_id,
+			tv_to_ms(elapsed), (unsigned long)BITFORCE_TIMEOUT_MS);
 		bitforce->device_last_not_well = time(NULL);
 		bitforce->device_last_not_well = time(NULL);
 		bitforce->device_not_well_reason = REASON_DEV_OVER_HEAT;
 		bitforce->device_not_well_reason = REASON_DEV_OVER_HEAT;
 		bitforce->dev_over_heat_count++;
 		bitforce->dev_over_heat_count++;
@@ -589,7 +589,7 @@ commerr:
 		BFclose(bitforce->device_fd);
 		BFclose(bitforce->device_fd);
 		int fd = bitforce->device_fd = BFopen(bitforce->device_path);
 		int fd = bitforce->device_fd = BFopen(bitforce->device_path);
 		if (fd == -1) {
 		if (fd == -1) {
-			applog(LOG_ERR, "BFL%i: Error reopening");
+			applog(LOG_ERR, "BFL%i: Error reopening", bitforce->device_id);
 			return -1;
 			return -1;
 		}
 		}
 		/* empty read buffer */
 		/* empty read buffer */

+ 1 - 4
driver-cairnsmore.c

@@ -82,8 +82,6 @@ bool cairnsmore_supports_dynclock(int fd)
 {
 {
 	if (!cairnsmore_send_cmd(fd, 0, 1, true))
 	if (!cairnsmore_send_cmd(fd, 0, 1, true))
 		return false;
 		return false;
-	struct timeval tv_start, elapsed;
-	gettimeofday(&tv_start, NULL);
 	if (!cairnsmore_send_cmd(fd, 0, 1, true))
 	if (!cairnsmore_send_cmd(fd, 0, 1, true))
 		return false;
 		return false;
 
 
@@ -95,9 +93,8 @@ bool cairnsmore_supports_dynclock(int fd)
 			.work_restart_fd = -1,
 			.work_restart_fd = -1,
 		};
 		};
 		icarus_gets((unsigned char*)&nonce, fd, &tv_finish, &dummy, 1);
 		icarus_gets((unsigned char*)&nonce, fd, &tv_finish, &dummy, 1);
-		timersub(&tv_finish, &tv_start, &elapsed);
 	}
 	}
-	applog(LOG_DEBUG, "Cairnsmore dynclock detection... Got %08x in %d.%06ds", nonce, elapsed.tv_sec, elapsed.tv_usec);
+	applog(LOG_DEBUG, "Cairnsmore dynclock detection... Got %08x", nonce);
 	switch (nonce) {
 	switch (nonce) {
 		case 0x00949a6f:  // big    endian
 		case 0x00949a6f:  // big    endian
 		case 0x6f9a9400:  // little endian
 		case 0x6f9a9400:  // little endian

+ 2 - 2
driver-x6500.c

@@ -240,7 +240,7 @@ x6500_fpga_upload_bitstream(struct cgpu_info *x6500, struct jtag_port *jp1)
 	sleep(1);
 	sleep(1);
 	
 	
 	if (fread(buf, 32, 1, f) != 1)
 	if (fread(buf, 32, 1, f) != 1)
-		bailout2(LOG_ERR, "%s %u: File underrun programming %s (%d bytes left)", x6500->api->name, x6500->device_id, x6500->device_path, len);
+		bailout2(LOG_ERR, "%s %u: File underrun programming %s (%lu bytes left)", x6500->api->name, x6500->device_id, x6500->device_path, len);
 	jtag_swrite(jp, JTAG_REG_DR, buf, 256);
 	jtag_swrite(jp, JTAG_REG_DR, buf, 256);
 	len -= 32;
 	len -= 32;
 	
 	
@@ -258,7 +258,7 @@ x6500_fpga_upload_bitstream(struct cgpu_info *x6500, struct jtag_port *jp1)
 	while (len) {
 	while (len) {
 		buflen = len < 32 ? len : 32;
 		buflen = len < 32 ? len : 32;
 		if (fread(buf, buflen, 1, f) != 1)
 		if (fread(buf, buflen, 1, f) != 1)
-			bailout2(LOG_ERR, "%s %u: File underrun programming %s (%d bytes left)", x6500->api->name, x6500->device_id, x6500->device_path, len);
+			bailout2(LOG_ERR, "%s %u: File underrun programming %s (%lu bytes left)", x6500->api->name, x6500->device_id, x6500->device_path, len);
 		jtag_swrite_more(jp, buf, buflen * 8, len == (unsigned long)buflen);
 		jtag_swrite_more(jp, buf, buflen * 8, len == (unsigned long)buflen);
 		*pdone = 100 - ((len * 100) / flen);
 		*pdone = 100 - ((len * 100) / flen);
 		if (*pdone >= nextstatus)
 		if (*pdone >= nextstatus)

+ 3 - 3
driver-ztex.c

@@ -170,7 +170,7 @@ static bool ztex_checkNonce(struct libztex_device *ztex,
 	sha2(hash1, 32, hash2, false);
 	sha2(hash1, 32, hash2, false);
 	if (htobe32(hash2_32[7]) != ((hdata->hash7 + 0x5be0cd19) & 0xFFFFFFFF)) {
 	if (htobe32(hash2_32[7]) != ((hdata->hash7 + 0x5be0cd19) & 0xFFFFFFFF)) {
 		dclk_errorCount(&ztex->dclk, 1.0 / ztex->numNonces);
 		dclk_errorCount(&ztex->dclk, 1.0 / ztex->numNonces);
-		applog(LOG_DEBUG, "%s: checkNonce failed for %0.8X", ztex->repr, hdata->nonce);
+		applog(LOG_DEBUG, "%s: checkNonce failed for %08x", ztex->repr, hdata->nonce);
 		return false;
 		return false;
 	}
 	}
 	return true;
 	return true;
@@ -271,7 +271,7 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 			if (nonce > noncecnt)
 			if (nonce > noncecnt)
 				noncecnt = nonce;
 				noncecnt = nonce;
 			if (((nonce & 0x7fffffff) >> 4) < ((lastnonce[i] & 0x7fffffff) >> 4)) {
 			if (((nonce & 0x7fffffff) >> 4) < ((lastnonce[i] & 0x7fffffff) >> 4)) {
-				applog(LOG_DEBUG, "%s: overflow nonce=%0.8x lastnonce=%0.8x", ztex->repr, nonce, lastnonce[i]);
+				applog(LOG_DEBUG, "%s: overflow nonce=%08x lastnonce=%08x", ztex->repr, nonce, lastnonce[i]);
 				overflow = true;
 				overflow = true;
 			} else
 			} else
 				lastnonce[i] = nonce;
 				lastnonce[i] = nonce;
@@ -299,7 +299,7 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 						work->blk.nonce = 0xffffffff;
 						work->blk.nonce = 0xffffffff;
 						if ( (rv = test_nonce(work, nonce, false)) )
 						if ( (rv = test_nonce(work, nonce, false)) )
 						rv = submit_nonce(thr, work, nonce);
 						rv = submit_nonce(thr, work, nonce);
-						applog(LOG_DEBUG, "%s: submitted %0.8x (from N%dE%d) %d", ztex->repr, nonce, i, j, rv);
+						applog(LOG_DEBUG, "%s: submitted %08x (from N%dE%d) %d", ztex->repr, nonce, i, j, rv);
 					}
 					}
 				}
 				}
 			}
 			}

+ 1 - 1
fpgautils.c

@@ -713,7 +713,7 @@ FILE *open_xilinx_bitstream(struct cgpu_info *cgpu, const char *fwfile, unsigned
 	if (fwusercode == 0xffffffff)
 	if (fwusercode == 0xffffffff)
 		bailout(LOG_ERR, "%s %u: Firmware doesn't support user code",
 		bailout(LOG_ERR, "%s %u: Firmware doesn't support user code",
 		        cgpu->api->name, cgpu->device_id);
 		        cgpu->api->name, cgpu->device_id);
-	applog(LOG_DEBUG, "  Version: %u, build %u", (fwusercode >> 8) & 0xff, fwusercode & 0xff);
+	applog(LOG_DEBUG, "  Version: %u, build %u", (unsigned)((fwusercode >> 8) & 0xff), (unsigned)(fwusercode & 0xff));
 	check_magic('b');
 	check_magic('b');
 	read_str("part number");
 	read_str("part number");
 	applog(LOG_DEBUG, "  Part number: %s", buf);
 	applog(LOG_DEBUG, "  Part number: %s", buf);

+ 2 - 2
libztex.c

@@ -59,7 +59,7 @@ static bool libztex_checkDevice(struct libusb_device *dev)
 		return false;
 		return false;
 	}
 	}
 	if (!(desc.idVendor == LIBZTEX_IDVENDOR && desc.idProduct == LIBZTEX_IDPRODUCT)) {
 	if (!(desc.idVendor == LIBZTEX_IDVENDOR && desc.idProduct == LIBZTEX_IDPRODUCT)) {
-		applog(LOG_DEBUG, "Not a ZTEX device %0.4x:%0.4x", desc.idVendor, desc.idProduct);
+		applog(LOG_DEBUG, "Not a ZTEX device %04x:%04x", desc.idVendor, desc.idProduct);
 		return false;
 		return false;
 	}
 	}
 	return true;
 	return true;
@@ -442,7 +442,7 @@ int libztex_prepare_device(struct libusb_device *dev, struct libztex_device** zt
 	// Check vendorId and productId
 	// Check vendorId and productId
 	if (!(newdev->descriptor.idVendor == LIBZTEX_IDVENDOR &&
 	if (!(newdev->descriptor.idVendor == LIBZTEX_IDVENDOR &&
 	    newdev->descriptor.idProduct == LIBZTEX_IDPRODUCT)) {
 	    newdev->descriptor.idProduct == LIBZTEX_IDPRODUCT)) {
-		applog(LOG_ERR, "Not a ztex device? %0.4X, %0.4X", newdev->descriptor.idVendor, newdev->descriptor.idProduct);
+		applog(LOG_ERR, "Not a ztex device? %04x, %04x", newdev->descriptor.idVendor, newdev->descriptor.idProduct);
 		return 1;
 		return 1;
 	}
 	}
 
 

+ 2 - 2
logging.h

@@ -28,8 +28,8 @@ extern bool want_per_device_stats;
 extern int opt_log_level;
 extern int opt_log_level;
 
 
 /* low-level logging functions with priority parameter */
 /* low-level logging functions with priority parameter */
-extern void vapplog(int prio, const char *fmt, va_list ap);
-extern void applog(int prio, const char *fmt, ...);
+extern void vapplog(int prio, const char *fmt, va_list ap) FORMAT_SYNTAX_CHECK(printf, 2, 0);
+extern void applog(int prio, const char *fmt, ...) FORMAT_SYNTAX_CHECK(printf, 2, 3);
 
 
 /* high-level logging functions with implicit priority */
 /* high-level logging functions with implicit priority */
 extern void log_error(const char *fmt, ...);
 extern void log_error(const char *fmt, ...);

+ 9 - 9
miner.c

@@ -3490,11 +3490,10 @@ static bool workio_get_work(struct workio_cmd *wc)
 
 
 static bool stale_work(struct work *work, bool share)
 static bool stale_work(struct work *work, bool share)
 {
 {
-	struct timeval now;
-	time_t work_expiry;
+	unsigned work_expiry;
 	struct pool *pool;
 	struct pool *pool;
 	uint32_t block_id;
 	uint32_t block_id;
-	int getwork_delay;
+	unsigned getwork_delay;
 
 
 	block_id = ((uint32_t*)work->data)[1];
 	block_id = ((uint32_t*)work->data)[1];
 	pool = work->pool;
 	pool = work->pool;
@@ -3507,7 +3506,7 @@ static bool stale_work(struct work *work, bool share)
 	else
 	else
 		work_expiry = opt_expiry;
 		work_expiry = opt_expiry;
 
 
-	int max_expiry = (have_longpoll ? opt_expiry_lp : opt_expiry);
+	unsigned max_expiry = (have_longpoll ? opt_expiry_lp : opt_expiry);
 	if (work_expiry > max_expiry)
 	if (work_expiry > max_expiry)
 		work_expiry = max_expiry;
 		work_expiry = max_expiry;
 
 
@@ -3553,15 +3552,16 @@ static bool stale_work(struct work *work, bool share)
 	/* Factor in the average getwork delay of this pool, rounding it up to
 	/* Factor in the average getwork delay of this pool, rounding it up to
 	 * the nearest second */
 	 * the nearest second */
 	getwork_delay = pool->cgminer_pool_stats.getwork_wait_rolling * 5 + 1;
 	getwork_delay = pool->cgminer_pool_stats.getwork_wait_rolling * 5 + 1;
-	work_expiry -= getwork_delay;
-	if (unlikely(work_expiry < 5))
+	if (unlikely(work_expiry <= getwork_delay + 5))
 		work_expiry = 5;
 		work_expiry = 5;
+	else
+		work_expiry -= getwork_delay;
 
 
 	}
 	}
 
 
-	gettimeofday(&now, NULL);
-	if ((now.tv_sec - work->tv_staged.tv_sec) >= work_expiry) {
-		applog(LOG_DEBUG, "%s stale due to expiry (%d - %d >= %d)", share?"Share":"Work", now.tv_sec, work->tv_staged.tv_sec, work_expiry);
+	double elapsed_since_staged = difftime(time(NULL), work->tv_staged.tv_sec);
+	if (elapsed_since_staged > work_expiry) {
+		applog(LOG_DEBUG, "%s stale due to expiry (%.0f >= %u)", share?"Share":"Work", elapsed_since_staged, work_expiry);
 		return true;
 		return true;
 	}
 	}
 
 

+ 1 - 1
miner.h

@@ -1068,7 +1068,7 @@ extern void switch_pools(struct pool *selected);
 extern void remove_pool(struct pool *pool);
 extern void remove_pool(struct pool *pool);
 extern void write_config(FILE *fcfg);
 extern void write_config(FILE *fcfg);
 extern void default_save_file(char *filename);
 extern void default_save_file(char *filename);
-extern bool log_curses_only(int prio, const char *f, va_list ap);
+extern bool log_curses_only(int prio, const char *f, va_list ap) FORMAT_SYNTAX_CHECK(printf, 2, 0);
 extern void clear_logwin(void);
 extern void clear_logwin(void);
 extern bool pool_tclear(struct pool *pool, bool *var);
 extern bool pool_tclear(struct pool *pool, bool *var);
 extern struct thread_q *tq_new(void);
 extern struct thread_q *tq_new(void);

+ 3 - 3
ocl.c

@@ -546,7 +546,7 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
 		applog(LOG_ERR, "Error %d: Failed to clGetDeviceInfo when trying to get CL_DEVICE_MAX_MEM_ALLOC_SIZE", status);
 		applog(LOG_ERR, "Error %d: Failed to clGetDeviceInfo when trying to get CL_DEVICE_MAX_MEM_ALLOC_SIZE", status);
 		return NULL;
 		return NULL;
 	}
 	}
-	applog(LOG_DEBUG, "Max mem alloc size is %u", cgpu->max_alloc);
+	applog(LOG_DEBUG, "Max mem alloc size is %lu", (unsigned long)cgpu->max_alloc);
 
 
 	/* Create binary filename based on parameters passed to opencl
 	/* Create binary filename based on parameters passed to opencl
 	 * compiler to ensure we only load a binary that matches what would
 	 * compiler to ensure we only load a binary that matches what would
@@ -680,7 +680,7 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
 				ma <<= 1;
 				ma <<= 1;
 			if (ma < cgpu->max_alloc) {
 			if (ma < cgpu->max_alloc) {
 				cgpu->max_alloc = ma;
 				cgpu->max_alloc = ma;
-				applog(LOG_DEBUG, "Max alloc decreased to %lu", cgpu->max_alloc);
+				applog(LOG_DEBUG, "Max alloc decreased to %lu", (unsigned long)cgpu->max_alloc);
 			}
 			}
 		}
 		}
 	}
 	}
@@ -984,7 +984,7 @@ built:
 		/* Use the max alloc value which has been rounded to a power of
 		/* Use the max alloc value which has been rounded to a power of
 		 * 2 greater >= required amount earlier */
 		 * 2 greater >= required amount earlier */
 		if (bufsize > cgpu->max_alloc) {
 		if (bufsize > cgpu->max_alloc) {
-			applog(LOG_WARNING, "Maximum buffer memory device %d supports says %u", gpu, 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 %u", bufsize);
 		} else
 		} else
 			bufsize = cgpu->max_alloc;
 			bufsize = cgpu->max_alloc;

+ 1 - 1
util.c

@@ -457,7 +457,7 @@ json_t *json_rpc_call(CURL *curl, const char *url,
 		applog(LOG_INFO, "JSON decode failed(%d): %s", err.line, err.text);
 		applog(LOG_INFO, "JSON decode failed(%d): %s", err.line, err.text);
 
 
 		if (opt_protocol)
 		if (opt_protocol)
-			applog(LOG_DEBUG, "JSON protocol response:\n%s", all_data.buf);
+			applog(LOG_DEBUG, "JSON protocol response:\n%s", (char*)all_data.buf);
 
 
 		goto err_out;
 		goto err_out;
 	}
 	}