diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2015-01-22 16:05:52 -0500 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2015-01-22 16:05:52 -0500 |
commit | a2cabfcd89d8ac45a60fb35847258567c3450560 (patch) | |
tree | 49919ca7302ea899df93e5d9958590bdccb0370a /gpsd.h-tail | |
parent | fbc716f9e36491c80b426bff36295c1cb0c2dc31 (diff) | |
download | gpsd-a2cabfcd89d8ac45a60fb35847258567c3450560.tar.gz |
Introduce an adaptive delay into the main loop to prevent select buzzing.
When select(2) returns too fast with only small amounts of data, the main loop
will buzz and eat power - a significant issue on, e.g. battery-powered RasPi
devices, where it was first spotted. This code watches read volume and delays
when it sees lots of small bursts.
All regressiion tests pass. But note: the adaptive-delay logic has to
suppress delays to arrange this, otherwise we get an all too familiar
class of spurious test failure.
Diffstat (limited to 'gpsd.h-tail')
-rw-r--r-- | gpsd.h-tail | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/gpsd.h-tail b/gpsd.h-tail index 3865fc29..63cfd69f 100644 --- a/gpsd.h-tail +++ b/gpsd.h-tail @@ -280,6 +280,16 @@ struct gps_context_t { #endif ssize_t (*serial_write)(struct gps_device_t *, const char *buf, const size_t len); + /* + * Used for calculation of sleep time before select(), + * needed to sidestep buggy fast looping selects. + */ +#define WINDOW_AVG_SIZE 8 /* reset avg after this number of reads */ +#define SLEEP_FACTOR 4700000U /* controls the formula to compute delay */ +#define SLEEP_THRESHOLD 4.0 /* delay if avg is less than this */ + float inbytesavg; /* average number of bytes per read */ + unsigned char inbyteswpos; + bool selectbug; /* true if the slect bug is triggered */ }; /* state for resolving interleaved Type 24 packets */ |