serial: Only sleep when no characters are received.

g_usleep(XX) sleeps for *at least* XX microseconds but may sleep for
longers (on older kernels the sleep will typically be 10000us). Thus
byte receive loops containing an unconditional sleep will perform
very poorly (for example it causes the scan in agilent-dmm to timeout
prematurely).

Even on modern kernels serial_readline() has a 2ms sleep per byte which
means it will read at a maximum rate of half a character per millisecond
(~4800baud).

This is fixed by only sleeping when read() returns no data.

Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
This commit is contained in:
Daniel Thompson 2013-09-19 16:39:24 +01:00 committed by Bert Vermeulen
parent 1b142b7827
commit 5715e84fe3
1 changed files with 4 additions and 2 deletions

View File

@ -786,6 +786,7 @@ SR_PRIV int serial_readline(struct sr_serial_dev_inst *serial, char **buf,
if (g_get_monotonic_time() - start > timeout_ms) if (g_get_monotonic_time() - start > timeout_ms)
/* Timeout */ /* Timeout */
break; break;
if (len < 1)
g_usleep(2000); g_usleep(2000);
} }
if (*buflen) if (*buflen)
@ -867,6 +868,7 @@ SR_PRIV int serial_stream_detect(struct sr_serial_dev_inst *serial,
sr_dbg("Detection timed out after %dms.", time); sr_dbg("Detection timed out after %dms.", time);
break; break;
} }
if (len < 1)
g_usleep(byte_delay_us); g_usleep(byte_delay_us);
} }