Closed nefarius closed 3 years ago
Sorry for delayed response.
See resolution below...
Ok, I see what the issue is:
You need to use:
dmfSchedulerCfg.ExecuteWhen = ScheduledTaskExecuteWhenPrepareHardware; or dmfSchedulerCfg.ExecuteWhen = ScheduledTaskExecuteWhenD0Entry;
When you do so you do not use:
DMF_ScheduledTask_ExecuteNowDeferred() or DMF_ScheduledTask_ExecuteNow() Instead the scheduled task will be automatically started when PrepareHardware or D0Entry happen.
In this case, the scheduled task callback will be called automatically and repeatedly as you expected.
You used:
dmfSchedulerCfg.ExecuteWhen = ScheduledTaskExecuteWhenOther;
In this case you also used: DMF_ScheduledTask_ExecuteNowDeferred() or DMF_ScheduledTask_ExecuteNow()
But when you do so using the Method, the automatic retry does not happen (by design).
This is not intuitive and can be considered to be a bug. At the minimum, the documentation and comments in the code will be updated to reflect this behavior. But, if possible, we will see if we can update the code so that "Other" mode allows periodic call of Scheduled Task so that it works as one would expect.
Thank you for your feedback.
Please contact dmf-feedback@microsoft.com for faster responses.
Thank you very much for the insights, I will test with ScheduledTask_ExecuteWhen_D0Entry
then, should be alright.
Appreciate the addition to documentation!
One more question though; am I then by design allowed to still call DMF_ScheduledTask_ExecuteNowDeferred()
"in between" when I need to not await the specified timeout value? I'd like to utilize it that way to send a packet to my device ASAP when necessary and sticking to just using the scheduler callback would allow me to not care about synchronization as the only sending code would remain in that callback.
Cheers!
Yes, you instantiate using ScheduledTask_ExecuteWhen_D0Entry
. Then, you can use DMF_ScheduledTask_ExecuteNow()
to cause the same callback to be immediately called. In this case, however, you may need to acquire and release a lock in the callback to make sure that the deferred callback using timer does not race with your immediate execution. In fact, there is a comment in the code that explains that. If I recall, we specifically added DMF_ScheduledTask_ExecuteNow()
for the exact purpose you describe.
Having said all that, I will update the documentation to explain all this (and possibly add a Method to do what you originally intended). I will keep this issue open until the documentation is updated. Let me know if you have any other questions. Thank you for the feedback.
Yes, you instantiate using
ScheduledTask_ExecuteWhen_D0Entry
. Then, you can useDMF_ScheduledTask_ExecuteNow()
to cause the same callback to be immediately called. In this case, however, you may need to acquire and release a lock in the callback to make sure that the deferred callback using timer does not race with your immediate execution. In fact, there is a comment in the code that explains that. If I recall, we specifically addedDMF_ScheduledTask_ExecuteNow()
for the exact purpose you describe.
It works now exactly as I need it with these adjustments, thanks! Also introduced a lock just to be safe.
The pending PR has a fix for this issue: https://github.com/microsoft/DMF/pull/178
Resolved by Release v1.1.98. Please use new DMF_ScheduledTask_ExecuteNowDeferredEx() Method. It honors the return value correctly.
Greetings!
First of all; this might be on me for misconfiguring or misusing this module so let me quickly summarize what I try to achieve. I have a device which requires a buffer sent to periodically while it's powered on, for example like every 10ms and/or sooner on demand.
Therefore I chose the
ScheduledTask
module which offers a deferred and "retry on success" pattern. This is unfortunately not working for me (the callback as seen below is only fired once after invoked), here's my setup:Here's my callback:
I invoke it like so (which works, but only once until called again):
Before I do a deep-dive into dissecting the module; any obvious error here in my thinking of what the module can do for me or the configuration I posted? Thanks!