Mir

Merge lp:~vanvugt/mir/wake-lock-on-input into lp:mir

Proposed by Daniel van Vugt
Status: Rejected
Rejected by: Alan Griffiths
Proposed branch: lp:~vanvugt/mir/wake-lock-on-input
Merge into: lp:mir
Diff against target: 173 lines (+133/-3)
3 files modified
3rd_party/android-input/android/CMakeLists.txt (+6/-0)
3rd_party/android-input/android/frameworks/base/services/input/EventHub.cpp (+2/-3)
3rd_party/android-input/android/hardware/libhardware_legacy/power/power.c (+125/-0)
To merge this branch: bzr merge lp:~vanvugt/mir/wake-lock-on-input
Reviewer Review Type Date Requested Status
Alberto Aguirre (community) Disapprove
PS Jenkins bot (community) continuous-integration Needs Fixing
Review via email: mp+262416@code.launchpad.net

Commit message

Re-introduce wake locks to Android input (LP: #1465514)

It appears there was no good reason for us to have ever commented this
out in Mir. Upstream Android still has it, and in theory input
responsiveness will be helped by ensuring the CPU never goes to low-power
mode in the middle of processing an input event. Which it might, as we
have to dance between server and client processes which takes system calls
and context switches.

Although I am yet to see this make a measurable difference, it doesn't
make anything worse either. And in theory in some cases it should
improve performance.

Note (i): To get wake lock functionality you need to be root (ie. a
system compositor). This is because of the restricted permissions on /sys/power/*. I don't think it matters if you fail to open them.

Note (ii): Regular Linux kernels implement the same /sys/power interface now, as first introduced in Android kernels. But most desktop kernels
don't implement the behaviour behind it by default (it's an option
apparently).

Note (iii): Yes power.c is Android code. I'm trying to avoid modifying it.

Description of the change

This is a request for comments/testing. There might be a phone where this makes a significant difference but I've only tried mako so far...

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Andreas Pokorny (andreas-pokorny) wrote :

Better look where the calls to acquire_wake_lock and release_wake_lock are done.
Why should that improve the input event transfer to the nested server and client?
It should not have any effect at all, unless of course the auto suspend is configured to be active.
So this does not affect dynamic/runtime PM or cpu frequency, this is only needed to keep the system from suspending it entirely. Which is not used in ubuntu phone.

Revision history for this message
Alberto Aguirre (albaguirre) wrote :

There is absolutely no need for MIR to acquire wakelocks ever. Wakelocks are a suspend prevention mechanism which in Ubuntu Touch is taken care of by powerd.

The user is already interacting with the screen in any case so the system will not be suspending during interaction.

review: Disapprove

Unmerged revisions

2676. By Daniel van Vugt

Merge latest trunk and fix conflict

2675. By Daniel van Vugt

Reintroduce wake locks from the Android source tree

2674. By Daniel van Vugt

sendFinishedSignal at the correct time.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '3rd_party/android-input/android/CMakeLists.txt'
2--- 3rd_party/android-input/android/CMakeLists.txt 2015-06-17 05:20:42 +0000
3+++ 3rd_party/android-input/android/CMakeLists.txt 2015-06-19 06:37:26 +0000
4@@ -15,6 +15,11 @@
5 -DANDROID_SMP=1
6 )
7
8+# Required by power.c:
9+set(CMAKE_C_FLAGS
10+ "${CMAKE_C_FLAGS} -D_POSIX_C_SOURCE=200809L -std=c99 -Wno-unused-function"
11+)
12+
13 # This is stuff for which we want non-android versions
14 set(
15 UTIL_SOURCES
16@@ -28,6 +33,7 @@
17 add_library(
18 android-input-static STATIC
19 # The stuff that we want
20+ hardware/libhardware_legacy/power/power.c
21 frameworks/base/services/input/EventHub.cpp
22 frameworks/base/services/input/InputApplication.cpp
23 frameworks/base/services/input/InputDispatcher.cpp
24
25=== modified file '3rd_party/android-input/android/frameworks/base/services/input/EventHub.cpp'
26--- 3rd_party/android-input/android/frameworks/base/services/input/EventHub.cpp 2015-06-17 05:20:42 +0000
27+++ 3rd_party/android-input/android/frameworks/base/services/input/EventHub.cpp 2015-06-19 06:37:26 +0000
28@@ -20,12 +20,11 @@
29
30 #include "EventHub.h"
31
32-#define acquire_wake_lock(lock, id) {}
33-#define release_wake_lock(id) {}
34-
35 #include "mir/input/input_report.h"
36 #include "mir/udev/wrapper.h"
37
38+#include <hardware_legacy/power.h>
39+
40 #include <cutils/properties.h>
41 #include <std/Log.h>
42 #include <std/Timers.h>
43
44=== added directory '3rd_party/android-input/android/hardware/libhardware_legacy/power'
45=== added file '3rd_party/android-input/android/hardware/libhardware_legacy/power/power.c'
46--- 3rd_party/android-input/android/hardware/libhardware_legacy/power/power.c 1970-01-01 00:00:00 +0000
47+++ 3rd_party/android-input/android/hardware/libhardware_legacy/power/power.c 2015-06-19 06:37:26 +0000
48@@ -0,0 +1,125 @@
49+/*
50+ * Copyright (C) 2008 The Android Open Source Project
51+ *
52+ * Licensed under the Apache License, Version 2.0 (the "License");
53+ * you may not use this file except in compliance with the License.
54+ * You may obtain a copy of the License at
55+ *
56+ * http://www.apache.org/licenses/LICENSE-2.0
57+ *
58+ * Unless required by applicable law or agreed to in writing, software
59+ * distributed under the License is distributed on an "AS IS" BASIS,
60+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
61+ * See the License for the specific language governing permissions and
62+ * limitations under the License.
63+ */
64+#include <hardware_legacy/power.h>
65+#include <fcntl.h>
66+#include <errno.h>
67+#include <stdlib.h>
68+#include <stdio.h>
69+#include <unistd.h>
70+#include <sys/time.h>
71+#include <time.h>
72+#include <errno.h>
73+#include <string.h>
74+#include <sys/stat.h>
75+#include <sys/types.h>
76+#include <pthread.h>
77+
78+//#define LOG_TAG "power"
79+//#include <utils/Log.h>
80+
81+enum {
82+ ACQUIRE_PARTIAL_WAKE_LOCK = 0,
83+ RELEASE_WAKE_LOCK,
84+ OUR_FD_COUNT
85+};
86+
87+const char * const OLD_PATHS[] = {
88+ "/sys/android_power/acquire_partial_wake_lock",
89+ "/sys/android_power/release_wake_lock",
90+};
91+
92+const char * const NEW_PATHS[] = {
93+ "/sys/power/wake_lock",
94+ "/sys/power/wake_unlock",
95+};
96+
97+//XXX static pthread_once_t g_initialized = THREAD_ONCE_INIT;
98+static int g_initialized = 0;
99+static int g_fds[OUR_FD_COUNT];
100+static int g_error = 1;
101+
102+static int64_t systemTime()
103+{
104+ struct timespec t;
105+ t.tv_sec = t.tv_nsec = 0;
106+ clock_gettime(CLOCK_MONOTONIC, &t);
107+ return t.tv_sec*1000000000LL + t.tv_nsec;
108+}
109+
110+static int
111+open_file_descriptors(const char * const paths[])
112+{
113+ int i;
114+ for (i=0; i<OUR_FD_COUNT; i++) {
115+ int fd = open(paths[i], O_RDWR | O_CLOEXEC);
116+ if (fd < 0) {
117+ fprintf(stderr, "fatal error opening \"%s\"\n", paths[i]);
118+ g_error = errno;
119+ return -1;
120+ }
121+ g_fds[i] = fd;
122+ }
123+
124+ g_error = 0;
125+ return 0;
126+}
127+
128+static inline void
129+initialize_fds(void)
130+{
131+ // XXX: should be this:
132+ //pthread_once(&g_initialized, open_file_descriptors);
133+ // XXX: not this:
134+ if (g_initialized == 0) {
135+ if(open_file_descriptors(NEW_PATHS) < 0)
136+ open_file_descriptors(OLD_PATHS);
137+ g_initialized = 1;
138+ }
139+}
140+
141+int
142+acquire_wake_lock(int lock, const char* id)
143+{
144+ initialize_fds();
145+
146+// ALOGI("acquire_wake_lock lock=%d id='%s'\n", lock, id);
147+
148+ if (g_error) return g_error;
149+
150+ int fd;
151+
152+ if (lock == PARTIAL_WAKE_LOCK) {
153+ fd = g_fds[ACQUIRE_PARTIAL_WAKE_LOCK];
154+ }
155+ else {
156+ return EINVAL;
157+ }
158+
159+ return write(fd, id, strlen(id));
160+}
161+
162+int
163+release_wake_lock(const char* id)
164+{
165+ initialize_fds();
166+
167+// ALOGI("release_wake_lock id='%s'\n", id);
168+
169+ if (g_error) return g_error;
170+
171+ ssize_t len = write(g_fds[RELEASE_WAKE_LOCK], id, strlen(id));
172+ return len >= 0;
173+}

Subscribers

People subscribed via source and target branches