From f99ac0ca7813a68d610e9449459d1236662f4647 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 15 Jul 2012 13:31:03 +1000 Subject: [PATCH 1/5] Allow more platforms to be probed if first does not return GPUs. --- ocl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ocl.c b/ocl.c index 464cb4e1..5dfef36d 100644 --- a/ocl.c +++ b/ocl.c @@ -118,6 +118,8 @@ int clDevicesNum(void) { status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, &numDevices); if (status != CL_SUCCESS) { applog(LOG_ERR, "Error %d: Getting Device IDs (num)", status); + if (i < numPlatforms - 1) + continue; return -1; } applog(LOG_INFO, "Platform %d devices: %d", i, numDevices); From ffd21f8db31952d0ec1f01701e1d1061027fa63a Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 15 Jul 2012 13:40:11 +1000 Subject: [PATCH 2/5] Find the gpu platform with the most devices and use that if no platform option is passed. --- ocl.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ocl.c b/ocl.c index 5dfef36d..f4c763ca 100644 --- a/ocl.c +++ b/ocl.c @@ -33,7 +33,7 @@ #include "findnonce.h" #include "ocl.h" -int opt_platform_id; +int opt_platform_id = -1; char *file_contents(const char *filename, int *length) { @@ -80,7 +80,7 @@ int clDevicesNum(void) { cl_uint numPlatforms; cl_platform_id *platforms; cl_platform_id platform = NULL; - unsigned int most_devices = 0, i; + unsigned int most_devices = 0, i, mdplatform; status = clGetPlatformIDs(0, NULL, &numPlatforms); /* If this fails, assume no GPUs. */ @@ -123,8 +123,10 @@ int clDevicesNum(void) { return -1; } applog(LOG_INFO, "Platform %d devices: %d", i, numDevices); - if (numDevices > most_devices) + if (numDevices > most_devices) { most_devices = numDevices; + mdplatform = i; + } if (numDevices) { unsigned int j; char pbuff[256]; @@ -139,6 +141,9 @@ int clDevicesNum(void) { } } + if (opt_platform_id < 0) + opt_platform_id = mdplatform;; + return most_devices; } From 07292f73a1d9ab71c01d71150d15e4a4df56dc85 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 16 Jul 2012 17:05:08 +1000 Subject: [PATCH 3/5] Initialise mdplatform. --- ocl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocl.c b/ocl.c index f4c763ca..c4480af8 100644 --- a/ocl.c +++ b/ocl.c @@ -80,7 +80,7 @@ int clDevicesNum(void) { cl_uint numPlatforms; cl_platform_id *platforms; cl_platform_id platform = NULL; - unsigned int most_devices = 0, i, mdplatform; + unsigned int most_devices = 0, i, mdplatform = 0; status = clGetPlatformIDs(0, NULL, &numPlatforms); /* If this fails, assume no GPUs. */ From 4abecc26745c8fb473b6df67ac55f85e95a85275 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 16 Jul 2012 22:03:43 +1000 Subject: [PATCH 4/5] Detach pthread from within the api thread in case it is terminated due to not being instantiated before pthread_cancel is called from main, leading to a segfault. --- cgminer.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cgminer.c b/cgminer.c index 55d3943b..c225d317 100644 --- a/cgminer.c +++ b/cgminer.c @@ -3349,6 +3349,7 @@ static void *api_thread(void *userdata) { struct thr_info *mythr = userdata; + pthread_detach(pthread_self()); pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); api(api_thr_id); @@ -5522,8 +5523,6 @@ begin_bench: thr = &thr_info[api_thr_id]; if (thr_info_create(thr, NULL, api_thread, thr)) quit(1, "API thread create failed"); - pthread_detach(thr->pth); - #ifdef HAVE_CURSES /* Create curses input thread for keyboard input. Create this last so From c55830502a0df4ae1165e583de4e96a11af33c62 Mon Sep 17 00:00:00 2001 From: Kano Date: Tue, 24 Jul 2012 02:19:23 +1000 Subject: [PATCH 5/5] BFL force all code to timeout to avoid hanging --- driver-bitforce.c | 16 +++++++++------- fpgautils.c | 10 +++++----- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/driver-bitforce.c b/driver-bitforce.c index 31892297..ff537203 100644 --- a/driver-bitforce.c +++ b/driver-bitforce.c @@ -34,13 +34,15 @@ struct device_api bitforce_api; -#define BFopen(devpath) serial_open(devpath, 0, -1, true) +// Code must deal with a timeout +#define BFopen(devpath) serial_open(devpath, 0, 1, true) static void BFgets(char *buf, size_t bufLen, int fd) { - do + do { + buf[0] = '\0'; --bufLen; - while (likely(bufLen && read(fd, buf, 1) == 1 && (buf++)[0] != '\n')); + } while (likely(bufLen && read(fd, buf, 1) == 1 && (buf++)[0] != '\n')); buf[0] = '\0'; } @@ -72,7 +74,7 @@ static bool bitforce_detect_one(const char *devpath) BFwrite(fdDev, "ZGX", 3); BFgets(pdevbuf, sizeof(pdevbuf), fdDev); if (unlikely(!pdevbuf[0])) { - applog(LOG_ERR, "BFL: Error reading (ZGX)"); + applog(LOG_ERR, "BFL: Error reading/timeout (ZGX)"); return 0; } @@ -200,7 +202,7 @@ void bitforce_init(struct cgpu_info *bitforce) if (unlikely(!pdevbuf[0])) { mutex_unlock(&bitforce->device_mutex); - applog(LOG_ERR, "BFL%i: Error reading (ZGX)", bitforce->device_id); + applog(LOG_ERR, "BFL%i: Error reading/timeout (ZGX)", bitforce->device_id); return; } @@ -240,7 +242,7 @@ static bool bitforce_get_temp(struct cgpu_info *bitforce) mutex_unlock(&bitforce->device_mutex); if (unlikely(!pdevbuf[0])) { - applog(LOG_ERR, "BFL%i: Error: Get temp returned empty string", bitforce->device_id); + applog(LOG_ERR, "BFL%i: Error: Get temp returned empty string/timed out", bitforce->device_id); bitforce->temp = 0; return false; } @@ -328,7 +330,7 @@ re_send: } if (unlikely(!pdevbuf[0])) { - applog(LOG_ERR, "BFL%i: Error: Send block data returned empty string", bitforce->device_id); + applog(LOG_ERR, "BFL%i: Error: Send block data returned empty string/timed out", bitforce->device_id); return false; } diff --git a/fpgautils.c b/fpgautils.c index 0ebee7f6..07b3fe36 100644 --- a/fpgautils.c +++ b/fpgautils.c @@ -178,7 +178,8 @@ serial_open(const char*devpath, unsigned long baud, signed short timeout, bool p SetCommConfig(hSerial, &comCfg, sizeof(comCfg)); - const DWORD ctoms = (timeout == -1) ? 30000 : (timeout * 100); + // Code must specify a valid timeout value (0 means don't timeout) + const DWORD ctoms = (timeout * 100); COMMTIMEOUTS cto = {ctoms, 0, ctoms, 0, ctoms}; SetCommTimeouts(hSerial, &cto); @@ -230,10 +231,9 @@ serial_open(const char*devpath, unsigned long baud, signed short timeout, bool p my_termios.c_oflag &= ~OPOST; my_termios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); - if (timeout >= 0) { - my_termios.c_cc[VTIME] = (cc_t)timeout; - my_termios.c_cc[VMIN] = 0; - } + // Code must specify a valid timeout value (0 means don't timeout) + my_termios.c_cc[VTIME] = (cc_t)timeout; + my_termios.c_cc[VMIN] = 0; tcsetattr(fdDev, TCSANOW, &my_termios); if (purge)