Skip to content

Commit

Permalink
Merge branch 'bugfix_format' into bfgminer
Browse files Browse the repository at this point in the history
Conflicts:
	configure.ac
	driver-bitforce.c
	driver-ztex.c
	libztex.c
	miner.c
	util.c
  • Loading branch information
luke-jr committed Dec 24, 2012
2 parents 73c24bb + 2b3d385 commit 3ac7f71
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 34 deletions.
2 changes: 1 addition & 1 deletion adl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ static bool fan_autotune(int gpu, int temp, int fanpercent, int lasttemp, bool *

get_fanrange(gpu, &iMin, &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;

dev_error(cgpu, REASON_DEV_OVER_HEAT);
Expand Down
18 changes: 18 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,24 @@ if test "x$found_endian" = "xno"; then
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
prefix=/usr/local
fi
Expand Down
12 changes: 6 additions & 6 deletions driver-bitforce.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#define BITFORCE_CHECK_INTERVAL_MS 10
#define WORK_CHECK_INTERVAL_MS 50
#define MAX_START_DELAY_MS 100
#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 KNAME_WORK "full work"
Expand Down Expand Up @@ -447,8 +447,8 @@ static int64_t bitforce_get_result(struct thr_info *thr, struct work *work)
timersub(&now, &bitforce->work_start_tv, &elapsed);

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;
}

Expand All @@ -463,8 +463,8 @@ static int64_t bitforce_get_result(struct thr_info *thr, struct work *work)
}

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);
dev_error(bitforce, REASON_DEV_OVER_HEAT);
++bitforce->hw_errors;
++hw_errors;
Expand Down Expand Up @@ -583,7 +583,7 @@ static int64_t bitforce_scanhash(struct thr_info *thr, struct work *work, int64_
BFclose(bitforce->device_fd);
int fd = bitforce->device_fd = BFopen(bitforce->device_path);
if (fd == -1) {
applog(LOG_ERR, "BFL%i: Error reopening");
applog(LOG_ERR, "BFL%i: Error reopening", bitforce->device_id);
return -1;
}
/* empty read buffer */
Expand Down
5 changes: 1 addition & 4 deletions driver-cairnsmore.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ bool cairnsmore_supports_dynclock(int fd)
{
if (!cairnsmore_send_cmd(fd, 0, 1, true))
return false;
struct timeval tv_start, elapsed;
gettimeofday(&tv_start, NULL);
if (!cairnsmore_send_cmd(fd, 0, 1, true))
return false;

Expand All @@ -95,9 +93,8 @@ bool cairnsmore_supports_dynclock(int fd)
.work_restart_fd = -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) {
case 0x00949a6f: // big endian
case 0x6f9a9400: // little endian
Expand Down
4 changes: 2 additions & 2 deletions driver-x6500.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ x6500_fpga_upload_bitstream(struct cgpu_info *x6500, struct jtag_port *jp1)
sleep(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);
len -= 32;

Expand All @@ -258,7 +258,7 @@ x6500_fpga_upload_bitstream(struct cgpu_info *x6500, struct jtag_port *jp1)
while (len) {
buflen = len < 32 ? len : 32;
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);
*pdone = 100 - ((len * 100) / flen);
if (*pdone >= nextstatus)
Expand Down
6 changes: 3 additions & 3 deletions driver-ztex.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ static bool ztex_checkNonce(struct libztex_device *ztex,
sha2(hash1, 32, hash2, false);
if (htobe32(hash2_32[7]) != ((hdata->hash7 + 0x5be0cd19) & 0xFFFFFFFF)) {
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 true;
Expand Down Expand Up @@ -272,7 +272,7 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
if (nonce > noncecnt)
noncecnt = nonce;
if (((0xffffffff - nonce) < (nonce - lastnonce[i])) || nonce < lastnonce[i]) {
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;
} else
lastnonce[i] = nonce;
Expand Down Expand Up @@ -300,7 +300,7 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
work->blk.nonce = 0xffffffff;
if (test_nonce(work, nonce, false))
submit_nonce(thr, work, nonce);
applog(LOG_DEBUG, "%s: submitted %0.8x (from N%dE%d)", ztex->repr, nonce, i, j);
applog(LOG_DEBUG, "%s: submitted %08x (from N%dE%d)", ztex->repr, nonce, i, j);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion fpgautils.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ FILE *open_xilinx_bitstream(struct cgpu_info *cgpu, const char *fwfile, unsigned
if (fwusercode == 0xffffffff)
bailout(LOG_ERR, "%s %u: Firmware doesn't support user code",
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');
read_str("part number");
applog(LOG_DEBUG, " Part number: %s", buf);
Expand Down
2 changes: 1 addition & 1 deletion libztex.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static enum check_result libztex_checkDevice(struct libusb_device *dev)
}

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 CHECK_IS_NOT_ZTEX;
}

Expand Down
4 changes: 2 additions & 2 deletions logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ extern bool want_per_device_stats;
extern int opt_log_level;

/* 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 */
extern void log_error(const char *fmt, ...);
Expand Down
18 changes: 9 additions & 9 deletions miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -3382,11 +3382,10 @@ static void pool_died(struct pool *pool)

static bool stale_work(struct work *work, bool share)
{
struct timeval now;
time_t work_expiry;
unsigned work_expiry;
struct pool *pool;
uint32_t block_id;
int getwork_delay;
unsigned getwork_delay;

block_id = ((uint32_t*)work->data)[1];
pool = work->pool;
Expand All @@ -3399,7 +3398,7 @@ static bool stale_work(struct work *work, bool share)
else
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)
work_expiry = max_expiry;

Expand Down Expand Up @@ -3458,15 +3457,16 @@ static bool stale_work(struct work *work, bool share)
/* Factor in the average getwork delay of this pool, rounding it up to
* the nearest second */
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;
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;
}

Expand Down
2 changes: 1 addition & 1 deletion miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ extern void switch_pools(struct pool *selected);
extern void remove_pool(struct pool *pool);
extern void write_config(FILE *fcfg);
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 bool pool_tclear(struct pool *pool, bool *var);
extern struct thread_q *tq_new(void);
Expand Down
6 changes: 3 additions & 3 deletions ocl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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
* compiler to ensure we only load a binary that matches what would
Expand Down Expand Up @@ -680,7 +680,7 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
ma <<= 1;
if (ma < cgpu->max_alloc) {
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);
}
}
}
Expand Down Expand Up @@ -983,7 +983,7 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
/* Use the max alloc value which has been rounded to a power of
* 2 greater >= required amount earlier */
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);
} else
bufsize = cgpu->max_alloc;
Expand Down
2 changes: 1 addition & 1 deletion util.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ json_t *json_rpc_call_completed(CURL *curl, int rc, bool probe, int *rolltime, v
applog(LOG_INFO, "JSON decode failed(%d): %s", err.line, err.text);

if (opt_protocol)
applog(LOG_DEBUG, "JSON protocol response:\n%s", state->all_data.buf);
applog(LOG_DEBUG, "JSON protocol response:\n%s", (char*)state->all_data.buf);

goto err_out;
}
Expand Down

0 comments on commit 3ac7f71

Please sign in to comment.