Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 67774c74 authored by Michael Wright's avatar Michael Wright
Browse files

Move EventHub over to using EPOLLWAKEUP when available

Bug: 10901016
Change-Id: If63c0de5cf120cdf1534d63fc2382d2925b35c6a
parent 6f7be89b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -484,6 +484,7 @@ public class ZygoteInit {
    private static boolean startSystemServer()
            throws MethodAndArgsCaller, RuntimeException {
        long capabilities = posixCapabilitiesAsBits(
            OsConstants.CAP_BLOCK_SUSPEND,
            OsConstants.CAP_KILL,
            OsConstants.CAP_NET_ADMIN,
            OsConstants.CAP_NET_BIND_SERVICE,
+25 −6
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@
#include <sys/ioctl.h>
#include <sys/limits.h>
#include <sys/sha1.h>
#include <sys/utsname.h>

/* this macro is used to tell if "bit" is set in "array"
 * it selects a byte from the array, and does a boolean AND
@@ -93,6 +94,14 @@ static String8 sha1(const String8& in) {
    return out;
}

static void getLinuxRelease(int* major, int* minor) {
    struct utsname info;
    if (uname(&info) || sscanf(info.release, "%d.%d", major, minor) <= 0) {
        *major = 0, *minor = 0;
        ALOGE("Could not get linux version: %s", strerror(errno));
    }
}

static void setDescriptor(InputDeviceIdentifier& identifier) {
    // Compute a device descriptor that uniquely identifies the device.
    // The descriptor is assumed to be a stable identifier.  Its value should not
@@ -236,6 +245,11 @@ EventHub::EventHub(void) :
    result = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, mWakeReadPipeFd, &eventItem);
    LOG_ALWAYS_FATAL_IF(result != 0, "Could not add wake read pipe to epoll instance.  errno=%d",
            errno);

    int major, minor;
    getLinuxRelease(&major, &minor);
    // EPOLLWAKEUP was introduced in kernel 3.5
    mUsingEpollWakeup = major > 3 || (major == 3 && minor >= 5);
}

EventHub::~EventHub(void) {
@@ -1244,7 +1258,7 @@ status_t EventHub::openDeviceLocked(const char *devicePath) {
    // Register with epoll.
    struct epoll_event eventItem;
    memset(&eventItem, 0, sizeof(eventItem));
    eventItem.events = EPOLLIN;
    eventItem.events = mUsingEpollWakeup ? EPOLLIN : EPOLLIN | EPOLLWAKEUP;
    eventItem.data.u32 = deviceId;
    if (epoll_ctl(mEpollFd, EPOLL_CTL_ADD, fd, &eventItem)) {
        ALOGE("Could not add device fd to epoll instance.  errno=%d", errno);
@@ -1252,9 +1266,14 @@ status_t EventHub::openDeviceLocked(const char *devicePath) {
        return -1;
    }

    // Enable wake-lock behavior on kernels that support it.
    // TODO: Only need this for devices that can really wake the system.
    bool usingSuspendBlockIoctl = !ioctl(fd, EVIOCSSUSPENDBLOCK, 1);
    String8 wakeMechanism("EPOLLWAKEUP");
    if (!mUsingEpollWakeup) {
        if (ioctl(fd, EVIOCSSUSPENDBLOCK, 1)) {
            wakeMechanism = "<none>";
        } else {
            wakeMechanism = "EVIOCSSUSPENDBLOCK";
        }
    }

    // Tell the kernel that we want to use the monotonic clock for reporting timestamps
    // associated with input events.  This is important because the input system
@@ -1276,14 +1295,14 @@ status_t EventHub::openDeviceLocked(const char *devicePath) {

    ALOGI("New device: id=%d, fd=%d, path='%s', name='%s', classes=0x%x, "
            "configuration='%s', keyLayout='%s', keyCharacterMap='%s', builtinKeyboard=%s, "
            "usingSuspendBlockIoctl=%s, usingClockIoctl=%s",
            "wakeMechanism=%s, usingClockIoctl=%s",
         deviceId, fd, devicePath, device->identifier.name.string(),
         device->classes,
         device->configurationFile.string(),
         device->keyMap.keyLayoutFile.string(),
         device->keyMap.keyCharacterMapFile.string(),
         toString(mBuiltInKeyboardId == deviceId),
         toString(usingSuspendBlockIoctl), toString(usingClockIoctl));
         wakeMechanism.string(), toString(usingClockIoctl));

    addDeviceLocked(device);
    return 0;
+2 −0
Original line number Diff line number Diff line
@@ -440,6 +440,8 @@ private:
    size_t mPendingEventCount;
    size_t mPendingEventIndex;
    bool mPendingINotify;

    bool mUsingEpollWakeup;
};

}; // namespace android
+1 −1
Original line number Diff line number Diff line
@@ -574,8 +574,8 @@ public:
private:
    InputReaderContext* mContext;
    int32_t mId;
    int32_t mControllerNumber;
    int32_t mGeneration;
    int32_t mControllerNumber;
    InputDeviceIdentifier mIdentifier;
    String8 mAlias;
    uint32_t mClasses;