[PATCH evemu 4/5] Use a sleep error margin of 150µs when replaying events
Peter Hutterer
peter.hutterer at who-t.net
Thu Aug 6 17:58:25 PDT 2015
The previous code would only sleep when the time delta between two events was
500µs, but then it sleeps for the whole time delta, stretching out the event
recording beyond its length.
Reduce the sleep delta by an (mostly arbitrary, locally observed) 150µs error
margin to give the kernel time to actually replay the events and still stay
within the delta. And while we're at it, sleep any time we get above that
error margin times 2 (so we don't usleep for 1µs).
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
src/evemu.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/evemu.c b/src/evemu.c
index 0899b60..ad45dd3 100644
--- a/src/evemu.c
+++ b/src/evemu.c
@@ -839,6 +839,7 @@ int evemu_read_event_realtime(FILE *fp, struct input_event *ev,
struct timeval *evtime)
{
unsigned long usec;
+ const unsigned long ERROR_MARGIN = 150; /* µs */
int ret;
ret = evemu_read_event(fp, ev);
@@ -849,10 +850,10 @@ int evemu_read_event_realtime(FILE *fp, struct input_event *ev,
if (evtime->tv_sec == 0 && evtime->tv_usec == 0)
*evtime = ev->time;
usec = time_to_long(&ev->time) - time_to_long(evtime);
- if (usec > 500) {
+ if (usec > ERROR_MARGIN * 2) {
if (usec > s2us(10))
error(INFO, "Sleeping for %lds.\n", us2s(usec));
- usleep(usec);
+ usleep(usec - ERROR_MARGIN);
*evtime = ev->time;
}
}
--
2.4.3
More information about the Input-tools
mailing list