2019-06-26 17:17:18 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022 Intel Corporation.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2023-02-17 19:16:05 +01:00
|
|
|
#include "rtio_executor_common.h"
|
2019-06-26 17:17:18 +02:00
|
|
|
#include <zephyr/rtio/rtio_executor_simple.h>
|
|
|
|
#include <zephyr/rtio/rtio.h>
|
|
|
|
#include <zephyr/kernel.h>
|
|
|
|
|
|
|
|
#include <zephyr/logging/log.h>
|
|
|
|
LOG_MODULE_REGISTER(rtio_executor_simple, CONFIG_RTIO_LOG_LEVEL);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Submit submissions to simple executor
|
|
|
|
*
|
|
|
|
* The simple executor provides no concurrency instead
|
|
|
|
* execution each submission chain one after the next.
|
|
|
|
*
|
|
|
|
* @param r RTIO context
|
|
|
|
*
|
|
|
|
* @retval 0 Always succeeds
|
|
|
|
*/
|
|
|
|
int rtio_simple_submit(struct rtio *r)
|
|
|
|
{
|
2022-10-28 04:44:00 +02:00
|
|
|
struct rtio_simple_executor *exc = (struct rtio_simple_executor *)r->executor;
|
|
|
|
|
|
|
|
/* Task is already running */
|
|
|
|
if (exc->task.sqe != NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-06-26 17:17:18 +02:00
|
|
|
struct rtio_sqe *sqe = rtio_spsc_consume(r->sq);
|
|
|
|
|
2023-02-25 00:43:59 +01:00
|
|
|
if (sqe == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Some validation on the sqe to ensure no programming errors were
|
|
|
|
* made so assumptions in ok and err are valid.
|
|
|
|
*/
|
|
|
|
#ifdef CONFIG_ASSERT
|
|
|
|
__ASSERT(sqe != NULL, "Expected a valid sqe on submit call");
|
|
|
|
|
|
|
|
bool transaction = sqe->flags & RTIO_SQE_TRANSACTION;
|
|
|
|
bool chained = sqe->flags & RTIO_SQE_CHAINED;
|
|
|
|
|
|
|
|
if (transaction || chained) {
|
|
|
|
struct rtio_sqe *next = rtio_spsc_next(r->sq, sqe);
|
|
|
|
|
|
|
|
__ASSERT(next != NULL,
|
|
|
|
"sqe %p flagged as transaction (%d) or chained (%d) without subsequent sqe in queue",
|
|
|
|
sqe, transaction, chained);
|
|
|
|
}
|
|
|
|
__ASSERT(!(chained && transaction),
|
|
|
|
"sqe %p flagged as both being transaction and chained, only one is allowed",
|
|
|
|
sqe);
|
|
|
|
#endif
|
|
|
|
|
2022-10-28 04:44:00 +02:00
|
|
|
exc->task.sqe = sqe;
|
|
|
|
exc->task.r = r;
|
|
|
|
|
2023-02-17 19:16:05 +01:00
|
|
|
rtio_executor_submit(&exc->task);
|
2019-06-26 17:17:18 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Callback from an iodev describing success
|
|
|
|
*/
|
2022-10-28 04:44:00 +02:00
|
|
|
void rtio_simple_ok(struct rtio_iodev_sqe *iodev_sqe, int result)
|
2019-06-26 17:17:18 +02:00
|
|
|
{
|
2022-10-28 04:44:00 +02:00
|
|
|
struct rtio *r = iodev_sqe->r;
|
|
|
|
const struct rtio_sqe *sqe = iodev_sqe->sqe;
|
|
|
|
|
|
|
|
#ifdef CONFIG_ASSERT
|
|
|
|
struct rtio_simple_executor *exc =
|
|
|
|
(struct rtio_simple_executor *)r->executor;
|
|
|
|
|
|
|
|
__ASSERT_NO_MSG(iodev_sqe == &exc->task);
|
|
|
|
#endif
|
|
|
|
|
2023-02-25 00:43:59 +01:00
|
|
|
bool transaction = sqe->flags & RTIO_SQE_TRANSACTION;
|
|
|
|
|
|
|
|
while (transaction) {
|
|
|
|
rtio_spsc_release(r->sq);
|
|
|
|
sqe = rtio_spsc_consume(r->sq);
|
|
|
|
__ASSERT_NO_MSG(sqe != NULL);
|
|
|
|
transaction = sqe->flags & RTIO_SQE_TRANSACTION;
|
|
|
|
}
|
|
|
|
|
2022-10-03 19:44:46 +02:00
|
|
|
void *userdata = sqe->userdata;
|
|
|
|
|
2019-06-26 17:17:18 +02:00
|
|
|
rtio_spsc_release(r->sq);
|
2022-10-28 04:44:00 +02:00
|
|
|
iodev_sqe->sqe = NULL;
|
2023-02-25 00:43:59 +01:00
|
|
|
|
2022-10-03 19:44:46 +02:00
|
|
|
rtio_cqe_submit(r, result, userdata);
|
2019-06-26 17:17:18 +02:00
|
|
|
rtio_simple_submit(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Callback from an iodev describing error
|
2023-02-25 00:43:59 +01:00
|
|
|
*
|
|
|
|
* Some assumptions are made and should have been validated on rtio_submit
|
|
|
|
* - a sqe marked as chained or transaction has a next sqe
|
|
|
|
* - a sqe is marked either chained or transaction but not both
|
2019-06-26 17:17:18 +02:00
|
|
|
*/
|
2022-10-28 04:44:00 +02:00
|
|
|
void rtio_simple_err(struct rtio_iodev_sqe *iodev_sqe, int result)
|
2019-06-26 17:17:18 +02:00
|
|
|
{
|
2023-02-25 00:43:59 +01:00
|
|
|
const struct rtio_sqe *sqe = iodev_sqe->sqe;
|
2022-10-28 04:44:00 +02:00
|
|
|
struct rtio *r = iodev_sqe->r;
|
2022-10-03 19:44:46 +02:00
|
|
|
void *userdata = sqe->userdata;
|
|
|
|
bool chained = sqe->flags & RTIO_SQE_CHAINED;
|
2023-02-25 00:43:59 +01:00
|
|
|
bool transaction = sqe->flags & RTIO_SQE_TRANSACTION;
|
2019-06-26 17:17:18 +02:00
|
|
|
|
2022-10-28 04:44:00 +02:00
|
|
|
#ifdef CONFIG_ASSERT
|
|
|
|
struct rtio_simple_executor *exc =
|
|
|
|
(struct rtio_simple_executor *)r->executor;
|
|
|
|
|
|
|
|
__ASSERT_NO_MSG(iodev_sqe == &exc->task);
|
|
|
|
#endif
|
|
|
|
|
2019-06-26 17:17:18 +02:00
|
|
|
rtio_spsc_release(r->sq);
|
2022-10-28 04:44:00 +02:00
|
|
|
iodev_sqe->sqe = NULL;
|
2023-02-25 00:43:59 +01:00
|
|
|
if (!transaction) {
|
|
|
|
rtio_cqe_submit(r, result, userdata);
|
|
|
|
}
|
|
|
|
while (chained | transaction) {
|
|
|
|
sqe = rtio_spsc_consume(r->sq);
|
|
|
|
chained = sqe->flags & RTIO_SQE_CHAINED;
|
|
|
|
transaction = sqe->flags & RTIO_SQE_TRANSACTION;
|
|
|
|
userdata = sqe->userdata;
|
|
|
|
rtio_spsc_release(r->sq);
|
|
|
|
|
|
|
|
if (!transaction) {
|
|
|
|
rtio_cqe_submit(r, result, userdata);
|
|
|
|
} else {
|
2022-10-03 19:44:46 +02:00
|
|
|
rtio_cqe_submit(r, -ECANCELED, userdata);
|
2019-06-26 17:17:18 +02:00
|
|
|
}
|
2023-02-25 00:43:59 +01:00
|
|
|
}
|
2019-06-26 17:17:18 +02:00
|
|
|
|
2023-02-25 00:43:59 +01:00
|
|
|
iodev_sqe->sqe = rtio_spsc_consume(r->sq);
|
|
|
|
if (iodev_sqe->sqe != NULL) {
|
2023-02-17 19:16:05 +01:00
|
|
|
rtio_executor_submit(iodev_sqe);
|
2019-06-26 17:17:18 +02:00
|
|
|
}
|
|
|
|
}
|