Android-x86
Fork
Faire un don

  • R/O
  • HTTP
  • SSH
  • HTTPS

hardware-libsensors: Commit

hardware/libsensors


Commit MetaInfo

Révision9e79f829a8743e0f55463ffc01a7b88f30a424d1 (tree)
l'heure2018-04-11 16:19:34
AuteurChih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Message de Log

kbdsensor: fix system_server high load issue

After the change 1f9a8a2e, if the sensor is invalid, the polling method
will return immediately without any way to throttle the number of
executions of the main sensor thread loop. That causes CPU high load.

Indeed the HAL should not set the pointer of struct hw_device_t if the
initialization fails. Then the SensorService won't enable and poll the
sensor device.

Fixes: 1f9a8a2e (kbdsensor: update HAL version to 1_3)
Tested-by: Michael Goffioul <michael.goffioul@gmail.com>

Change Summary

Modification

--- a/kbdsensor.cpp
+++ b/kbdsensor.cpp
@@ -43,16 +43,14 @@ struct KbdSensorKeys {
4343 const int ID_ACCELERATION = (SENSORS_HANDLE_BASE + 0);
4444
4545 template <typename T> struct SensorFd : T {
46- SensorFd(const struct hw_module_t *module, struct hw_device_t **device);
46+ SensorFd(const struct hw_module_t *module);
4747 };
4848
49-template <typename T> SensorFd<T>::SensorFd(const struct hw_module_t *module, struct hw_device_t **device)
49+template <typename T> SensorFd<T>::SensorFd(const struct hw_module_t *module)
5050 {
5151 this->common.tag = HARDWARE_DEVICE_TAG;
5252 this->common.version = SENSORS_DEVICE_API_VERSION_1_3;
5353 this->common.module = const_cast<struct hw_module_t *>(module);
54- *device = &this->common;
55- ALOGD("%s: module=%p dev=%p", __FUNCTION__, module, *device);
5654 }
5755
5856 struct SensorPollContext : SensorFd<sensors_poll_device_1> {
@@ -87,7 +85,7 @@ struct SensorPollContext : SensorFd<sensors_poll_device_1> {
8785 };
8886
8987 SensorPollContext::SensorPollContext(const struct hw_module_t *module, struct hw_device_t **device)
90- : SensorFd<sensors_poll_device_1>(module, device), enabled(false), rotation(ROT_0), ktype(KeysType)
88+ : SensorFd<sensors_poll_device_1>(module), enabled(false), rotation(ROT_0), ktype(KeysType)
9189 {
9290 common.close = poll_close;
9391 activate = poll_activate;
@@ -140,8 +138,13 @@ SensorPollContext::SensorPollContext(const struct hw_module_t *module, struct hw
140138 close(fd);
141139 fd = -1;
142140 }
143- ALOGI_IF(fd >= 0, "Open %s ok, fd=%d", name, fd);
144141 closedir(dir);
142+ if (fd < 0) {
143+ ALOGW("could not find any kbdsensor device");
144+ return;
145+ }
146+ *device = &common;
147+ ALOGI("Open %s ok, fd=%d", name, fd);
145148 }
146149
147150 pfd.events = POLLIN;
@@ -166,7 +169,7 @@ SensorPollContext::SensorPollContext(const struct hw_module_t *module, struct hw
166169 orients[ROT_270].acceleration.y = 0.0;
167170 orients[ROT_270].acceleration.z = -sin_angle;
168171
169- ALOGD("%s: dev=%p fd=%d", __FUNCTION__, this, fd);
172+ ALOGD("%s: module=%p dev=%p fd=%d", __FUNCTION__, module, this, fd);
170173 }
171174
172175 SensorPollContext::~SensorPollContext()
Afficher sur ancien navigateur de dépôt.