diff options
author | Mikael Olsson <mikael.olsson@arm.com> | 2024-01-16 11:19:09 +0100 |
---|---|---|
committer | Mikael Olsson <mikael.olsson@arm.com> | 2024-01-16 16:20:39 +0100 |
commit | 6d5e2d28d1cf60e1f7a1fe5fb591f3cd9b854b5a (patch) | |
tree | 4154098a48e8a0e739e67ec8a780870a1ecf99ff | |
parent | 3918eeabcda9aaf74b457e0bee98b77059625436 (diff) | |
download | ethos-u-linux-driver-stack-6d5e2d28d1cf60e1f7a1fe5fb591f3cd9b854b5a.tar.gz |
Fix inference cancellation behavior
There is currently a possible race when canceling an inference, where
the inference may be the one currently running and a response will be
sent later or the inference response is already in the mailbox queue. To
handle these cases, the kernel will no longer process the inference
response for an inference that has been marked as aborted or is in the
process of being aborted.
Change-Id: Ifcd86591b09075f994ed2e903cb11ba7c0ee0418
Signed-off-by: Mikael Olsson <mikael.olsson@arm.com>
-rw-r--r-- | kernel/ethosu_cancel_inference.c | 7 | ||||
-rw-r--r-- | kernel/ethosu_inference.c | 13 |
2 files changed, 17 insertions, 3 deletions
diff --git a/kernel/ethosu_cancel_inference.c b/kernel/ethosu_cancel_inference.c index d89f719..47687b8 100644 --- a/kernel/ethosu_cancel_inference.c +++ b/kernel/ethosu_cancel_inference.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: Copyright 2022-2023 Arm Limited and/or its affiliates <open-source-office@arm.com> + * SPDX-FileCopyrightText: Copyright 2022-2024 Arm Limited and/or its affiliates <open-source-office@arm.com> * SPDX-License-Identifier: GPL-2.0-only * * This program is free software and is provided to you under the terms of the @@ -88,7 +88,7 @@ int ethosu_cancel_inference_request(struct device *dev, /* increase ref count on the inference we are refering to */ ethosu_inference_get(inf); /* mark inference ABORTING to avoid resending the inference message */ - inf->status = ETHOSU_CORE_STATUS_ABORTING; + inf->status = ETHOSU_UAPI_STATUS_ABORTING; cancellation->dev = dev; cancellation->inf = inf; @@ -136,6 +136,9 @@ int ethosu_cancel_inference_request(struct device *dev, goto deregister; } + if (inf->status != ETHOSU_UAPI_STATUS_ABORTED) + inf->status = ETHOSU_UAPI_STATUS_ABORTED; + deregister: ethosu_mailbox_deregister(mailbox, &cancellation->msg); diff --git a/kernel/ethosu_inference.c b/kernel/ethosu_inference.c index 5fbad58..3238d7e 100644 --- a/kernel/ethosu_inference.c +++ b/kernel/ethosu_inference.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: Copyright 2020,2022-2023 Arm Limited and/or its affiliates <open-source-office@arm.com> + * SPDX-FileCopyrightText: Copyright 2020,2022-2024 Arm Limited and/or its affiliates <open-source-office@arm.com> * SPDX-License-Identifier: GPL-2.0-only * * This program is free software and is provided to you under the terms of the @@ -437,6 +437,16 @@ void ethosu_inference_rsp(struct ethosu_mailbox *mailbox, inf = container_of(msg, typeof(*inf), msg); + /* + * Don't handle the response if the inference is aborted or + * in the process of being aborted + */ + if (inf->status == ETHOSU_UAPI_STATUS_ABORTED || + inf->status == ETHOSU_UAPI_STATUS_ABORTING) { + inf->status = ETHOSU_UAPI_STATUS_ABORTED; + goto done; + } + if (rsp->status == ETHOSU_CORE_STATUS_OK && inf->ofm_count <= ETHOSU_CORE_BUFFER_MAX) inf->status = ETHOSU_UAPI_STATUS_OK; @@ -469,6 +479,7 @@ void ethosu_inference_rsp(struct ethosu_mailbox *mailbox, inf->pmu_cycle_counter_count); } +done: inf->done = true; wake_up_interruptible(&inf->waitq); ethosu_inference_put(inf); |