mirror of
https://github.com/GOSTSec/sgminer
synced 2025-08-26 05:41:55 +00:00
Make pthread conditional timeouts handle all bulk usb transfer timeouts performing libusb_cancel_transfer, disabling timeouts within libusb itself.
This commit is contained in:
parent
cda797d1be
commit
b537976036
1
api.c
1
api.c
@ -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_string(root, "USB tmo", details, true);
|
||||||
root = api_add_int(root, "USB cancellations", &cgpu->usb_cancels, false);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
miner.h
1
miner.h
@ -472,7 +472,6 @@ struct cgpu_info {
|
|||||||
#endif
|
#endif
|
||||||
#ifdef USE_USBUTILS
|
#ifdef USE_USBUTILS
|
||||||
struct cg_usb_info usbinfo;
|
struct cg_usb_info usbinfo;
|
||||||
int usb_cancels;
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_MODMINER
|
#ifdef USE_MODMINER
|
||||||
char fpgaid;
|
char fpgaid;
|
||||||
|
22
usbutils.c
22
usbutils.c
@ -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
|
/* 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. */
|
* 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,
|
static int callback_wait(struct usb_transfer *ut, int *transferred, unsigned int timeout)
|
||||||
unsigned int timeout)
|
|
||||||
{
|
{
|
||||||
struct libusb_transfer *transfer= ut->transfer;
|
struct libusb_transfer *transfer= ut->transfer;
|
||||||
struct timespec ts_now, ts_end;
|
struct timespec ts_now, ts_end;
|
||||||
@ -2227,29 +2226,21 @@ static int callback_wait(struct cgpu_info *cgpu, struct usb_transfer *ut, int *t
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
cgtime(&tv_now);
|
cgtime(&tv_now);
|
||||||
/* Add enough to the timeout to allow for a normal USB polling interval
|
ms_to_timespec(&ts_end, timeout);
|
||||||
* of 1ms to pass. */
|
|
||||||
ms_to_timespec(&ts_end, timeout + 2);
|
|
||||||
timeval_to_spec(&ts_now, &tv_now);
|
timeval_to_spec(&ts_now, &tv_now);
|
||||||
timeraddspec(&ts_end, &ts_now);
|
timeraddspec(&ts_end, &ts_now);
|
||||||
ret = pthread_cond_timedwait(&ut->cond, &ut->mutex, &ts_end);
|
ret = pthread_cond_timedwait(&ut->cond, &ut->mutex, &ts_end);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
/* Assume that if we timed out on the conditional then the
|
/* We are emulating a timeout ourself here */
|
||||||
* transfer has stalled for some reason. Cancel the transaction,
|
|
||||||
* treating it the same as a timeout if we receive cancelled as
|
|
||||||
* the status. */
|
|
||||||
libusb_cancel_transfer(transfer);
|
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. */
|
/* Now wait for the callback function to be invoked. */
|
||||||
pthread_cond_wait(&ut->cond, &ut->mutex);
|
pthread_cond_wait(&ut->cond, &ut->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = transfer->status;
|
ret = transfer->status;
|
||||||
if (ret == LIBUSB_TRANSFER_CANCELLED)
|
if (ret == LIBUSB_TRANSFER_CANCELLED)
|
||||||
ret = LIBUSB_TRANSFER_TIMED_OUT;
|
ret = LIBUSB_TRANSFER_TIMED_OUT;
|
||||||
|
|
||||||
/* No need to sort out mutexes here since they won't be reused */
|
/* No need to sort out mutexes here since they won't be reused */
|
||||||
*transferred = transfer->actual_length;
|
*transferred = transfer->actual_length;
|
||||||
libusb_free_transfer(transfer);
|
libusb_free_transfer(transfer);
|
||||||
@ -2292,8 +2283,9 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle, int intinfo,
|
|||||||
|
|
||||||
init_usb_transfer(&ut);
|
init_usb_transfer(&ut);
|
||||||
mutex_lock(&ut.mutex);
|
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,
|
libusb_fill_bulk_transfer(ut.transfer, dev_handle, endpoint, buf, length,
|
||||||
bulk_callback, &ut, timeout);
|
bulk_callback, &ut, 0);
|
||||||
|
|
||||||
STATS_TIMEVAL(&tv_start);
|
STATS_TIMEVAL(&tv_start);
|
||||||
cg_rlock(&cgusb_fd_lock);
|
cg_rlock(&cgusb_fd_lock);
|
||||||
@ -2301,7 +2293,7 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle, int intinfo,
|
|||||||
cg_runlock(&cgusb_fd_lock);
|
cg_runlock(&cgusb_fd_lock);
|
||||||
errn = errno;
|
errn = errno;
|
||||||
if (!err)
|
if (!err)
|
||||||
err = callback_wait(cgpu, &ut, transferred, timeout);
|
err = callback_wait(&ut, transferred, timeout);
|
||||||
|
|
||||||
STATS_TIMEVAL(&tv_finish);
|
STATS_TIMEVAL(&tv_finish);
|
||||||
USB_STATS(cgpu, &tv_start, &tv_finish, err, mode, cmd, seq, timeout);
|
USB_STATS(cgpu, &tv_start, &tv_finish, err, mode, cmd, seq, timeout);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user