Browse Source

Make pthread conditional timeouts handle all bulk usb transfer timeouts performing libusb_cancel_transfer, disabling timeouts within libusb itself.

nfactor-troky
Con Kolivas 11 years ago
parent
commit
b537976036
  1. 1
      api.c
  2. 1
      miner.h
  3. 22
      usbutils.c

1
api.c

@ -3141,7 +3141,6 @@ static int itemstats(struct io_data *io_data, int i, char *id, struct cgminer_st @@ -3141,7 +3141,6 @@ static int itemstats(struct io_data *io_data, int i, char *id, struct cgminer_st
}
root = api_add_string(root, "USB tmo", details, true);
root = api_add_int(root, "USB cancellations", &cgpu->usb_cancels, false);
#endif
}

1
miner.h

@ -472,7 +472,6 @@ struct cgpu_info { @@ -472,7 +472,6 @@ struct cgpu_info {
#endif
#ifdef USE_USBUTILS
struct cg_usb_info usbinfo;
int usb_cancels;
#endif
#ifdef USE_MODMINER
char fpgaid;

22
usbutils.c

@ -2218,8 +2218,7 @@ static void LIBUSB_CALL bulk_callback(struct libusb_transfer *transfer) @@ -2218,8 +2218,7 @@ static void LIBUSB_CALL bulk_callback(struct libusb_transfer *transfer)
/* Wait for callback function to tell us it has finished the USB transfer, but
* use our own timer to cancel the request if we go beyond the timeout. */
static int callback_wait(struct cgpu_info *cgpu, struct usb_transfer *ut, int *transferred,
unsigned int timeout)
static int callback_wait(struct usb_transfer *ut, int *transferred, unsigned int timeout)
{
struct libusb_transfer *transfer= ut->transfer;
struct timespec ts_now, ts_end;
@ -2227,29 +2226,21 @@ static int callback_wait(struct cgpu_info *cgpu, struct usb_transfer *ut, int *t @@ -2227,29 +2226,21 @@ static int callback_wait(struct cgpu_info *cgpu, struct usb_transfer *ut, int *t
int ret;
cgtime(&tv_now);
/* Add enough to the timeout to allow for a normal USB polling interval
* of 1ms to pass. */
ms_to_timespec(&ts_end, timeout + 2);
ms_to_timespec(&ts_end, timeout);
timeval_to_spec(&ts_now, &tv_now);
timeraddspec(&ts_end, &ts_now);
ret = pthread_cond_timedwait(&ut->cond, &ut->mutex, &ts_end);
if (ret) {
/* Assume that if we timed out on the conditional then the
* transfer has stalled for some reason. Cancel the transaction,
* treating it the same as a timeout if we receive cancelled as
* the status. */
/* We are emulating a timeout ourself here */
libusb_cancel_transfer(transfer);
applog(LOG_DEBUG, "%s%i: libusb cancelling async bulk transfer",
cgpu->drv->name, cgpu->device_id);
cgpu->usb_cancels++;
/* Now wait for the callback function to be invoked. */
pthread_cond_wait(&ut->cond, &ut->mutex);
}
ret = transfer->status;
if (ret == LIBUSB_TRANSFER_CANCELLED)
ret = LIBUSB_TRANSFER_TIMED_OUT;
/* No need to sort out mutexes here since they won't be reused */
*transferred = transfer->actual_length;
libusb_free_transfer(transfer);
@ -2292,8 +2283,9 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle, int intinfo, @@ -2292,8 +2283,9 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle, int intinfo,
init_usb_transfer(&ut);
mutex_lock(&ut.mutex);
/* We give the transfer no timeout since we manage timeouts ourself */
libusb_fill_bulk_transfer(ut.transfer, dev_handle, endpoint, buf, length,
bulk_callback, &ut, timeout);
bulk_callback, &ut, 0);
STATS_TIMEVAL(&tv_start);
cg_rlock(&cgusb_fd_lock);
@ -2301,7 +2293,7 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle, int intinfo, @@ -2301,7 +2293,7 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle, int intinfo,
cg_runlock(&cgusb_fd_lock);
errn = errno;
if (!err)
err = callback_wait(cgpu, &ut, transferred, timeout);
err = callback_wait(&ut, transferred, timeout);
STATS_TIMEVAL(&tv_finish);
USB_STATS(cgpu, &tv_start, &tv_finish, err, mode, cmd, seq, timeout);

Loading…
Cancel
Save