hadess / iio-sensor-proxy

IIO accelerometer sensor to input device proxy
197 stars 64 forks source link

iio-poll-accel: Use thread to poll accelerometer's data #246

Closed starnight closed 5 years ago

starnight commented 5 years ago

We have some Acer Veriton Z4660G and Z4860G AIO desktops which equip with an accelerometer SMO8840.

We found it takes more than 2 seconds to poll accelerometer's one axis data.

date; \ cat /sys/devices/pci0000:00/0000:00:15.0/i2c_designware.0/i2c-7/i2c-SMO8840:00/iio:device0/in_accel_x_raw; \ date

Thu Nov 15 12:28:33 CST 2018 1 Thu Nov 15 12:28:36 CST 2018

Reading 3 axes takes almost 7 seconds. The IO blocks the single thread main event loop.

This patch uses another thread for reading the accelerator's values. The read values will be saved in the middle variables. poll_orientation function only reads the middle values and will not block main event loop long time. #245

Signed-off-by: Jian-Hong Pan jian-hong@endlessm.com

jwrdegoede commented 5 years ago

Hi,

Have you tested the latest iio-sensor-proxy master code (without the patches from this pull-req) ?

I've seen similar issues and this should be made much better by the recent 5828b05b0c63271ce0e3892b4a832bc0a3a6e65d commit.

That commit actually makes the accelerometer report data more often which will also make the UI respond sooner when rotating the device.

Note reading the data from a separate thread might still be a good idea regardless, but I do wonder if commit 5828b05b0c63271ce0e3892b4a832bc0a3a6e65d helps. And maybe it helps enough that we do not need the thread?

Regards,

Hans

hadess commented 5 years ago

This needs a complete rewrite. You might also want to investigate the driver's behaviour before spending more time on this, including Hans' patch.

starnight commented 5 years ago

Thanks for Hans' comment.

After applying the commit 5828b05, it helps system suspend and resume in a better way. The original sampling rate is set as 1 Hz in st_sensors kernel module, and it does msleep with 2000ms in the st_sensors_read_info_raw function. :( The sampling rate is changed to 10 Hz by commit 5828b05. So, st_sensors_read_info_raw function does msleep with 200ms for each call.

Overall, it is not perfect, but looks fine from outside now.

hadess commented 5 years ago

So, st_sensors_read_info_raw function does msleep with 200ms for each call.

Sounds like some changes to the driver are in order...