-
Notifications
You must be signed in to change notification settings - Fork 8.3k
lib: queued_operation: add API for managing a queue of operations #24781
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
Conversation
|
All checks passed. checkpatch (informational only, not a failure)Tip: The bot edits this comment instead of posting a new one, so you can check the comment's history to see earlier messages. |
914c462 to
759458b
Compare
|
Updated to address the TBD from #22853 (comment) i.e. how to reset the queued operation manager when it depends on an on-off service that has entered an error state. |
include/sys/queued_operation.h
Outdated
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.
what about namespacing it sys_qop,
also queue_operation_manager -> sys_qop_mgr
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.
I'd take queuedop_ as the prefix. sys_queuedop_sys_qop is too opaque. I expect we'll bikeshed this in an API meeting; I'm not changing this now.
(Edited to remove sys_ prefix which is not used for on-off service, and other things in <sys/foo.h>)
include/sys/queued_operation.h
Outdated
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.
it's also quite long. SYS_QOP_APPEND or SYS_QOP_PRI_APPEND would be better, imo.
include/sys/queued_operation.h
Outdated
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.
what secondary notification means here? how to proceed when cli is null? pend on queue_operation_has_error until return false?
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.
"secondary notification" meant a non-null cli, the path by which the application gets notification of the completion of the reset attempt so it can try the queued operation agin. I'll use independent notification to match the description of cli.
pabigot
left a comment
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.
@nordic-krch comments addressed
include/sys/queued_operation.h
Outdated
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.
I'd take queuedop_ as the prefix. sys_queuedop_sys_qop is too opaque. I expect we'll bikeshed this in an API meeting; I'm not changing this now.
(Edited to remove sys_ prefix which is not used for on-off service, and other things in <sys/foo.h>)
include/sys/queued_operation.h
Outdated
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.
"secondary notification" meant a non-null cli, the path by which the application gets notification of the completion of the reset attempt so it can try the queued operation agin. I'll use independent notification to match the description of cli.
include/sys/queued_operation.h
Outdated
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.
Given the complexity of getting this correct I'm going to stick with the solution that's known to work.
include/sys/queued_operation.h
Outdated
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.
i was wondering about possibility to detect that given operation is already enqueued and return error (-EBUSY?). Maybe node field could be used for that (set to null when op is idle).
I'm having following scenario: sensor which has one queued operation instance which is used to schedule reading and i won't to detect situation when someone schedules next read (reusing same queued operation) before previous one is completed.
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.
That changes the contract used consistently for the resource management APIs: the client (in this case the sensor acting on behalf of a caller) submits a request, which is then owned by the manager until something notifies the client that the manager has released the request.
For your use case the sensor must be aware that there's an in-progress operation and refuse the attempt to schedule another.
include/sys/queued_operation.h
Outdated
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.
what about adding helper function like
int queued_operation_sync_submit(struct queued_operation_manager *mgr,
struct queued_operation *op, int priority);
which from thread context would schedule operation and pend for completion. That would safe complexity of setting up sys_notify. As i have some work based on this branch I've added there something like this which is relying on POLL being enabled (so semaphore version would need to be added as well):
int queued_operation_sync_submit(struct queued_operation_manager *qop_mgr,
struct queued_operation *qop, int priority)
{
int err;
int ret;
struct k_poll_signal signal = K_POLL_SIGNAL_INITIALIZER(signal);
struct k_poll_event event = K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL,
K_POLL_MODE_NOTIFY_ONLY,
&signal);
sys_notify_init_signal(&qop->notify, &signal);
err = queued_operation_submit(qop_mgr, qop, priority);
if (err < 0) {
return err;
}
err = k_poll(&event, 1, K_FOREVER);
if (err < 0) {
return err;
}
err = sys_notify_fetch_result(&qop->notify, &ret);
if (err < 0) {
return err;
}
return ret;
}
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.
Like the other resource management APIs this really isn't intended for direct use by application code. At a minimum there should be a service-specific API that can do type checking on the operation before it's submitted. In the reference code in the test that is service_submit(). I would expect there to be a companion service_submit_sync() to provide this feature.
I don't think lifting a generic submit_sync API into the manager is worthwhile at this time. It's possible that may change in the future, but locking it down when there are no in-tree users of this functionality is premature.
|
Marked DNM until we have a PR that provides a clear reason for adding this to the infrastructure. |
what about #23371 ? |
71c2fa8 to
1e28a78
Compare
1e28a78 to
6ba1809
Compare
6ba1809 to
5d28f36
Compare
Text failed to distinguish between success of initiating a reset and success of the reset. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Full asynchronous support for APIs such as bus transactions generally requires managing operations from unrelated clients. This API provides a data structure and functions to manage those operations generically, leaving the service to provide only the service-specific operation description and implementation. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
5d28f36 to
8bfd256
Compare
|
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
Full asynchronous support for APIs such as bus transactions generally requires managing operations from unrelated clients. This API provides a data structure and functions to manage those operations generically, leaving the service to provide only the service-specific operation description and implementation.
(This replaces #23333 which was based on an earlier version of the on-off API. See that PR for previous review history.)