New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor LwM2M engine to support tickless operation #60887
Refactor LwM2M engine to support tickless operation #60887
Conversation
b41b1db
to
50ecf3c
Compare
Unfortunately this creates dependency to heap as the Socketpair uses heap to allocate storage. Is this acceptable? I could refactor the socketpair to support statically allocated storage as well, if that would be preferred. |
50ecf3c
to
1f049cc
Compare
I have a proposal that would allocate socketpairs statically on devices that don't define heap by default: #60914 |
Power measurements of the changes in this PRMeasurements are done in nRF Connect SDK with these changes cherry-picked into the working tree. Target chip is nRF9160 and tool is Nordic Semiconductor Power Profiler Kit. Client is configured to use LwM2M QUEUE mode and LTE modem is configured to use eDRX and PSM power saving modes. Effect of these changes are clearly visible in the PSM power saving mode, where only thing that is constantly ticking in 500 ms interval is our LwM2M client. Floor current stays aroung 4 uA. When client is re-build using tickless mode, those spikes in 500 ms interval disappear and the floor current drops below 2 uA. Current main (without this PR)This PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a significant improvement, however I'm wondering - perhaps we should retain the old behaviour (timeout-based poll()) as a Kconfig option? For the sake of platforms, that use socket offloading and are not able to use socketpair (i.e. offload entire poll() call).
I think this makes sense. |
1f049cc
to
9d224d5
Compare
Updated the first commit, so there is now Kconfig option Btw. Whoever is reviewing, all 3 commits can be reviewed independently. I tried to separate the logical changes so that you can see what changes I did for engine, and what changes are done into RD state machine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks. We should probably wait for conclusion on #60914 so we can get rid of heap dependency?
9d224d5
to
06f5bdf
Compare
Allow socket-loop to wake up immediately, if there are changes, instead of waiting for zsock_poll() to timeout. This change makes engine more reactive and removes hard coded timeout from zsock_poll(). Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
Engine now allows registering service callbacks that are called only once on a given timestamp. This allows tickless services to be developed. Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
Call RD client service only when there is state transitioning. Remove periodic 500 ms timer. Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
06f5bdf
to
fc6b7fa
Compare
Now that #60914 is merged in, this PR does not add any dependency to heap. I rebased on top of main branch and added |
This is a combination of 3 changes that allows LwM2M engine to sleep longer without ticking 500 ms timer.
Create socketpair that can wake up zsock_poll()]
Allow socket-loop to wake up immediately, if there are changes,
instead of waiting for zsock_poll() to timeout.
This change makes engine more reactive and removes
hard coded timeout from zsock_poll().
New API (internal):
Add support for non-periodic services
Engine now allows registering service callbacks that are
called only once on a given timestamp.
This allows tickless services to be developed.
New API proposed:
Refactor RD client to be tickless
Call RD client service only when there is state transitioning by using
lwm2m_engine_call_at()
Remove periodic 500 ms timer.
When all these changes are combined, client will react to changes immediately as there is no 500ms timeout in
zsock_poll()
. Also it sleeps properly, when inQUEUE_RX_OFF
. I measure the change on nRF9160. Current usage on sleep was reduced from 4 uA to 2 uA. So 50% power saving in sleep mode, where we are going to spend most of the time.