Skip to content

Commit 3b0ea8d

Browse files
Jeff BrownAndroid (Google) Code Review
authored andcommitted
Merge "Use new EVIOCSCLOCKID ioctl if supported."
2 parents 081cc9a + eca3cf5 commit 3b0ea8d

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

services/input/EventHub.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,18 +1103,35 @@ status_t EventHub::openDeviceLocked(const char *devicePath) {
11031103

11041104
// Enable wake-lock behavior on kernels that support it.
11051105
// TODO: Only need this for devices that can really wake the system.
1106-
bool usingSuspendBlock = ioctl(fd, EVIOCSSUSPENDBLOCK, 1) == 0;
1106+
bool usingSuspendBlockIoctl = !ioctl(fd, EVIOCSSUSPENDBLOCK, 1);
1107+
1108+
// Tell the kernel that we want to use the monotonic clock for reporting timestamps
1109+
// associated with input events. This is important because the input system
1110+
// uses the timestamps extensively and assumes they were recorded using the monotonic
1111+
// clock.
1112+
//
1113+
// In older kernel, before Linux 3.4, there was no way to tell the kernel which
1114+
// clock to use to input event timestamps. The standard kernel behavior was to
1115+
// record a real time timestamp, which isn't what we want. Android kernels therefore
1116+
// contained a patch to the evdev_event() function in drivers/input/evdev.c to
1117+
// replace the call to do_gettimeofday() with ktime_get_ts() to cause the monotonic
1118+
// clock to be used instead of the real time clock.
1119+
//
1120+
// As of Linux 3.4, there is a new EVIOCSCLOCKID ioctl to set the desired clock.
1121+
// Therefore, we no longer require the Android-specific kernel patch described above
1122+
// as long as we make sure to set select the monotonic clock. We do that here.
1123+
bool usingClockIoctl = !ioctl(fd, EVIOCSCLOCKID, CLOCK_MONOTONIC);
11071124

11081125
ALOGI("New device: id=%d, fd=%d, path='%s', name='%s', classes=0x%x, "
11091126
"configuration='%s', keyLayout='%s', keyCharacterMap='%s', builtinKeyboard=%s, "
1110-
"usingSuspendBlock=%s",
1127+
"usingSuspendBlockIoctl=%s, usingClockIoctl=%s",
11111128
deviceId, fd, devicePath, device->identifier.name.string(),
11121129
device->classes,
11131130
device->configurationFile.string(),
11141131
device->keyMap.keyLayoutFile.string(),
11151132
device->keyMap.keyCharacterMapFile.string(),
11161133
toString(mBuiltInKeyboardId == deviceId),
1117-
toString(usingSuspendBlock));
1134+
toString(usingSuspendBlockIoctl), toString(usingClockIoctl));
11181135

11191136
mDevices.add(deviceId, device);
11201137

0 commit comments

Comments
 (0)