This is mostly speculative right now, but I think there might be some impact on power consumption with sensors support in SDM845. I noticed when recording a video of my op6 that the proximity sensor is always activated with the IR LED blinking. I guess this is the case for other sensors too. We should restrict some sensors like proximity to only be used on-demand (or if supported some lower frequency polling handled by the SLPI).
Cc: @dylanvanassche
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
libssc provides already a way to disable each sensor, this function is called when the iio-sensor-proxy client stops claiming the sensor. Basically, we have to check if DE e.g. Phosh, Plasma, etc. or any other iio-sensor-proxy client stops claiming the sensor. If that's the case, the sensor should be disabled.
Configuring the frequency etc. is not supported yet by libssc because iio-sensor-proxy does not support anything like that. However, we should maybe verify if the sensor is configured by default with the lowest sample frequency. During development, I noticed that they are configured by default with the lowest frequency, but verifying it and configuring it during enablement of the sensor would not hurt.
libssc provides already a way to disable each sensor, this function is called when the iio-sensor-proxy client stops claiming the sensor. Basically, we have to check if DE e.g. Phosh, Plasma, etc. or any other iio-sensor-proxy client stops claiming the sensor. If that's the case, the sensor should be disabled.
I am new to iio-sensor-proxy code and C, let alone Glib, so some of the driver stuff is a bit over my head. However, while running iio-sensor-proxy in debug mode with my new input proximity driver, I noticed that it always reports the proximity states, whereas the accelerometer and ambient light sensor only report data when the sensor is claimed (by, e.g. monitor-sensor).
I am yet to test it, but i think it is because i followed the ssc driver, and did not implement the <driver>_set_polling method. So currently, it seems your ssc drivers (as well as mine) permanently and unconditionally open the sensor after the <driver>_open is called, https://gitlab.com/dylanvanassche/iio-sensor-proxy/-/blob/ssc/src/drv-ssc-proximity.c#L70. This fits in with the observation by @calebccff that their proximity sensor is always activated.
No idea if implementing <driver>_set_polling will really solve the problem mentioned here, but should hopefully make some difference. E.g. proximity sensors are generally only claimed by the dialer, and I would guess they only claim it when there's an ongoing call.
Yes, adding <driver>_set_polling, even though it doesn't actually poll, makes the proximity sensor send events only when claimed. The rest of the time, there are no events emitted. I'll update my MR with this.
Nice catch! I looked at the source code and I can confirm your observations :)
Definitely agreed that set_polling should be renamed, probably a left-over from when only polling based sensors are supported. Made an issue, let's discuss things there: https://gitlab.freedesktop.org/hadess/iio-sensor-proxy/-/issues/385
Sorry / not-sorry to be the person, but.. any progress?
Currently I'm suffering by side effect of constant polling and that's the rotation of screen is too fast, so when I accidentally move the phone in a rotated manner, it immediately without delay rotates. I think the reasonable delay in polling would save this trouble and also the battery.
Second option would be adding delay before UI rotation, but it seems to be unnecessary and don't resolve the battery issue.
I don't understand everything well, but I think what I'd like is to have a greater threshold before which the rotation can be triggered, currently it's 45° but it's too little, you can e.g. lay in bed with your phone in portrait mode because of that. I'd expect the phone to activate the rotation after passing 60° or maybe even 75°, plus a very short delay (250ms?) to confirm the rotation. That way to rotate you would just have to put the phone in the desired rotation, wait just a tiny bit, and then be able to move freely once it's triggered the rotation.
That's all unrelated to the polling issue but well, both likely should be fixed.
There's already a threshold set to 35, maybe we need to experiment a bit here?
plus a very short delay (250ms?)
That should be already the case if we add this set_polling to the driver. Name of the function seems to be a bit wrong though, there's an issue about that in iio-sensor-proxy. I'm not sure yet what the new name should be (or what the exact function is of this method in the driver).
Maybe make it configurable somehow? It is reasonable to expect sensitivities to vary across devices
That should be already the case if we add this set_polling to the driver. Name of the function seems to be a bit wrong though, there's an issue about that in iio-sensor-proxy. I'm not sure yet what the new name should be (or what the exact function is of this method in the driver).
regarding method names and functions, here's my (very limited) understanding:
method
purpose
possible new method name
discover
searches for supported sensors
NO CHANGE
open
create a handle for a sensor (and possibly any needed setup to get things into a ready state)
register
close
remove handle for a sensor
unregister/deregister
set_polling
read live data from sensor when called with true as 2nd argument (acquiring a "Claim" does this), and stop reading when that argument is false (done when "Claim" is released)
A thought I've had thinking on this issue again: do we need to keep a handle open with the DSP all the time? Could libssc simply open a connection each time the value is polled?
if there's minimal latency here then this ought to help?
Unless the way things work atm means GNOME/phosh are always polling which is definitely not great...
Unless the way things work atm means GNOME/phosh are always polling which is definitely not great...
Phosh polls the sensors if you activate functions related to them. E.g. Accelerometer is always polled if you enable UI auto-rotation, and not polled if that's disabled. On my L5, ALS is always polled - no idea if there's a setting to disable adaptive brightness ...
No idea about GNOME as I've not run it, but I should expect similar behavior.
tldr; i think the UIs are doing correct thing
Could libssc simply open a connection each time the value is polled?
opening such connection is what .set_polling would need to do. for the ssc driver in iio-sensor-proxy, that logic is currently in .open, hence the constant polling
Regular IIO sensors: read them every X times with polling
Buffered IIO sensors: read the buffer from the kernel every X times with polling
libssc sensors: incoming stream of sensors, similar to buffer
NOW: read the stream on every value change, speed depends on how fast the DSP sends data
FUTURE: store the stream data of the last X values, read the stored data every X times with polling. So emitting new sensor data by iio-sensor-proxy must happen in set_polling's timer function, not when the data comes in. If set_polling == TRUE or the queue is empty, we should block until a new value is received. This would help GNOME Mobile as well, see https://gitlab.freedesktop.org/hadess/iio-sensor-proxy/-/issues/378 as when claiming the sensor, sometimes the data is not recent when storing it in a buffer.
This future approach will make sure the polling times are guaranteed: we define how fast the data is processed by iio-sensor-proxy instead of the DSP deciding how fast the data propagates.
Given how long this has been a know issue and assuming it will still take a while until somebody has time/motivation to address it properly, I wonder if we should disable the proximity sensor implementation for the time being (assuming that's enough to close this issue).
Does disabling the proximity sensor affect screen wakeup though?
PlaMo has double tap to wake, that can't be turned off. If disabling the sensor makes the phone wakeup more often in pockets then it might make battery life worse.
I'm not actually sure that the proximity sensor it used by PlaMo for wakeup detection though, I think I have seen the phone wakeup in my pocket with the proximity sensor sensor working
We cannot turn off the sensors currently I think. Not sure what would be needed to turn them off. Besides proximity, there are many other sensors active. It depends if the DE is claiming the sensor continuously or not.
It depends if the DE is claiming the sensor continuously or not.
I haven't verified this myself yet, however I was told DE devs that this should already be the case (i.e. only claiming the sensors when needed) and that it's most likely a driver/iio-sensor-proxy issue (also mentioned above). AFAIK the SSC driver is the only one known to show this behavior - the excessive CPU usage - atm, somewhat supporting that claim :/
Does disabling the proximity sensor affect screen wakeup though?
Yeah, according to Jonas Dreßler Gnome-Mobile uses the proximity only when the screen is or gets turned on.
Besides proximity, there are many other sensors active.
Hm, that would make things more difficult indeed. I'll try to verify which exact sensors keep iio-sensor-proxy busy, in case it's not all of them.
dynamic screen brightness based on ambient light, then ALS is claimed
UI autorotation, then accelerometer is claimed
DEs should be smart enough to release the sensors when the screen is turned off though (and I'm being told they do). The main issue I see here is that iio-sensor-proxy is even active when it really shouldn't (only with SSC though).
It might be that we are missing something in the SSC driver of iio-sensor-proxy, but I have no idea what to be honest. We would need to collect logs I suppose with the different scenarios (screen off, sleep, regular use)
It might be that we are missing something in the SSC driver of iio-sensor-proxy, but I have no idea what to be honest
@DylanVanAssche I'm a little sad to read this, after having spent time studying the code and explaining it here, here and on Matrix, as well as providing a summary (with a nice table) on what seems to be the function of each of the methods.
One more attempt however - disclaimer: I do not have an SSC-device, and thus have no way to test. However, the main problem that I see is that the iio-sensor-proxy drivers are still missing the _set_polling method. Do not focus on the obviously-wrong method name, but on what it actually does.
Quick recap: when iio-sensor-proxy loads a sensor driver, it first executes the _discover method, then the _open method. After that, it waits (does not read anything from the sensor) until a Claim on a sensor is obtained, after which it runs _set_polling, which causes sensor data to flow into iio-sensor-proxy.
In their current state, the SSC drivers in iio-sensor-proxy, are already reading from sensors (SSC) while waiting in the _open method, and that's one of the reasons why sensors appear to be hyperactive. IOW, the actions of Claiming or releasing Claim are basically a No-Op for these drivers - iio-sensor-proxy simply does nothing, since there's no _set_polling to run.
So, as far as I understand this, the following needs to be done, at least as a start. I'll use the proximity driver as an example:
make any other needed adjustments so the code makes sense, e.g. keeping a flag in DrvData that tracks if sensor is currently activated for reading. This is useful in _set_polling to avoid wasting time trying to activate a sensor when it's already open, i.e. when a 2nd client tries to claim a sensor that is already claimed, this should No-Op in _set_polling. It also ensures that the sensor is not shutdown until there are no clients anymore. This flag generally has _id suffix in existing iio-sensor-proxy drivers. For quick and dirty testing, it can probably be skipped
build and see if there is any difference
It is possible that some modifications are also needed in the underlying libssc itself, but doing the above is an important first step for the iio-sensor-proxy side of the problem
Yeah, I'm very sorry about this, I'm so occupied lately with my daily job and life, I haven't touched anything in months. The set_polling is being added upstream. I just have no idea about the 'fix'. I agree we need this method of course! I even missed the relation between your work above (which is SUPER nice) and this comment
Let me put it differently: I will not be able to fix it myself due to the lack of time, or even have time to locate what we need exactly.
It appears that by now you understand the code better than I do currently... Maybe I shouldn't be writing code that is 'popular'
@DylanVanAssche Out of curiosity, why SSC? What does the first S stand for? I guess the last SC means Sensor Core
@rmader want to give the suggestion above a go? Shouldn't need you to write any extensive code (if any), but will at least show us if we're going in the correct direction (I absolutely think we are!)