Browse Source

Bugfix: Deal with serial_open timeout maximum (25.5s)

fpgautils: Linux only supports uint8_t decisecond values for timeouts, so use uint8_t for timeout value; this gets smart compilers to throw warnings when overflowed in some cases
bitforce: Reduce serial timeout to 25 seconds (was 30) and increase job long timeout to 25 seconds (was 15) to handle throttling gracefully
modminer: 300 seconds is not possible nor needed: drop to 25
Luke Dashjr 13 years ago
parent
commit
d4f755d3d1
4 changed files with 11 additions and 6 deletions
  1. 2 2
      driver-bitforce.c
  2. 1 1
      driver-modminer.c
  3. 6 2
      fpgautils.c
  4. 2 1
      fpgautils.h

+ 2 - 2
driver-bitforce.c

@@ -24,7 +24,7 @@
 #define BITFORCE_SLEEP_MS 500
 #define BITFORCE_TIMEOUT_S 7
 #define BITFORCE_TIMEOUT_MS (BITFORCE_TIMEOUT_S * 1000)
-#define BITFORCE_LONG_TIMEOUT_S 15
+#define BITFORCE_LONG_TIMEOUT_S 25
 #define BITFORCE_LONG_TIMEOUT_MS (BITFORCE_LONG_TIMEOUT_S * 1000)
 #define BITFORCE_CHECK_INTERVAL_MS 10
 #define WORK_CHECK_INTERVAL_MS 50
@@ -35,7 +35,7 @@
 struct device_api bitforce_api;
 
 // Code must deal with a timeout
-#define BFopen(devpath)  serial_open(devpath, 0, 300, true)
+#define BFopen(devpath)  serial_open(devpath, 0, 250, true)
 
 static void BFgets(char *buf, size_t bufLen, int fd)
 {

+ 1 - 1
driver-modminer.c

@@ -216,7 +216,7 @@ fd_set fds;
 static bool
 modminer_device_prepare(struct cgpu_info *modminer)
 {
-	int fd = serial_open(modminer->device_path, 0, /*FIXME=-1*/3000, true);
+	int fd = serial_open(modminer->device_path, 0, 250, true);
 	if (unlikely(-1 == fd))
 		bailout(LOG_ERR, "%s %u: Failed to open %s", modminer->api->name, modminer->device_id, modminer->device_path);
 

+ 6 - 2
fpgautils.c

@@ -10,6 +10,7 @@
 
 #include "config.h"
 
+#include <stdint.h>
 #include <sys/types.h>
 #include <dirent.h>
 #include <string.h>
@@ -143,8 +144,11 @@ _serial_detect(const char*dname, detectone_func_t detectone, autoscan_func_t aut
 	return found;
 }
 
+/* NOTE: Linux only supports uint8_t (decisecond) timeouts; limiting it in
+ *       this interface buys us warnings when bad constants are passed in.
+ */
 int
-serial_open(const char*devpath, unsigned long baud, signed short timeout, bool purge)
+serial_open(const char*devpath, unsigned long baud, uint8_t timeout, bool purge)
 {
 #ifdef WIN32
 	HANDLE hSerial = CreateFile(devpath, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
@@ -179,7 +183,7 @@ serial_open(const char*devpath, unsigned long baud, signed short timeout, bool p
 	SetCommConfig(hSerial, &comCfg, sizeof(comCfg));
 
 	// Code must specify a valid timeout value (0 means don't timeout)
-	const DWORD ctoms = (timeout * 100);
+	const DWORD ctoms = ((DWORD)timeout * 100);
 	COMMTIMEOUTS cto = {ctoms, 0, ctoms, 0, ctoms};
 	SetCommTimeouts(hSerial, &cto);
 

+ 2 - 1
fpgautils.h

@@ -11,6 +11,7 @@
 #define FPGAUTILS_H
 
 #include <stdbool.h>
+#include <stdint.h>
 #include <stdio.h>
 
 typedef bool(*detectone_func_t)(const char*);
@@ -26,7 +27,7 @@ extern char _serial_detect(const char*dname, detectone_func_t, autoscan_func_t,
 extern char serial_autodetect_devserial(detectone_func_t, const char*prodname);
 extern char serial_autodetect_udev     (detectone_func_t, const char*prodname);
 
-extern int serial_open(const char*devpath, unsigned long baud, signed short timeout, bool purge);
+extern int serial_open(const char*devpath, unsigned long baud, uint8_t timeout, bool purge);
 extern ssize_t _serial_read(int fd, char *buf, size_t buflen, char*eol);
 #define serial_read(fd, buf, count)  \
 	_serial_read(fd, (char*)(buf), count, NULL)