Skip to content

RFC: Queued operations manager #22494

@nordic-krch

Description

@nordic-krch

General idea

A generic module for managing access to single resource capable of performing certain asynchronous operation. A management is needed because there are multiple contexts (clients) trying to perform this operation with own data. A client is interested in scheduling asynchronous operation and then get notification when operation is performed. Scheduling may support prioritization.

Use cases

SPI

There are potentially multiple devices on single spi bus (e.g. display, memory, sensor) each attempts to randomly access the bus. Current SPI is synchronous so access management is achieved on API level: user will block (sleep) when device is busy. That is ok, but it limits API access only to the context which can sleep (thread). Thread only access has following consequences:

  • transfers cannot be scheduled from interrupts (e.g. k_timer timeout handler) see RFC: asynchronous i2c and spi API #21538
  • mutiple transfers from same context requires many context switches (evaulation shown 10-20% CPU load increase)

I2C

Similarly to SPI: multiple devices on single bus.

Others

ADC?

Client

On-off service has already defined an asynchronous client. Currently it is part of the on-off API but it can be extracted and used for all asynchronous access modules like queued operation manager.
Client defines 3 types of access:

  • spin wait
  • signal
  • callback with user_data

Operations

Scheduling

Operation can be scheduled by a client, something like
int qop_mngr_schedule(struct qop_mngr *mngr, struct qop_op *op, struct async_client *cli)
Operation may return error is scheduling fails. If operation returns success it does not mean that operation will be successfully completed. Result of the operation is passed to the client when operation is completed.

Canceling

Operation can be cancelled if it is still in the queue and not yet started. Something like:
int qop_mngr_cancel(struct qop_mngr *mngr, struct qop_op *op, struct async_client *cli)
See include/sys/onoff.h for cancel behavior details.

Others

  • onoff service supports case where operations (start, stop, reset) sleeps. Queued operation manager can also support that.

Last but not least - naming

working name queued operations manager (with qop_mngr as abbreviation)

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCRequest For Comments: want input from the community

    Type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions