From c6505f3f8df8a5f00197f0eee5cc502e4e59c6a4 Mon Sep 17 00:00:00 2001 From: Ledion Daja Date: Wed, 20 Apr 2022 09:55:21 +0200 Subject: Change mutex and semaphore handling weak functions prototype Changed mutex lock/unlock and semaphore take/give functions to return an int value instead of void. Change-Id: I619327b9e14a3c37697617cbe0cba358102bd6a0 --- include/ethosu_driver.h | 13 +++++++++---- src/ethosu_driver.c | 21 +++++++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/include/ethosu_driver.h b/include/ethosu_driver.h index bf6a578..053b529 100644 --- a/include/ethosu_driver.h +++ b/include/ethosu_driver.h @@ -120,11 +120,16 @@ void ethosu_invalidate_dcache(uint32_t *p, size_t bytes); * ethosu_driver.c. */ void *ethosu_mutex_create(void); -void ethosu_mutex_lock(void *mutex); -void ethosu_mutex_unlock(void *mutex); void *ethosu_semaphore_create(void); -void ethosu_semaphore_take(void *sem); -void ethosu_semaphore_give(void *sem); +/* + * Returns: + * -1 on error + * 0 on success + */ +int ethosu_mutex_lock(void *mutex); +int ethosu_mutex_unlock(void *mutex); +int ethosu_semaphore_take(void *sem); +int ethosu_semaphore_give(void *sem); /* * Callbacks for begin/end of inference. user_data pointer is passed to the diff --git a/src/ethosu_driver.c b/src/ethosu_driver.c index 9175991..316ed4d 100644 --- a/src/ethosu_driver.c +++ b/src/ethosu_driver.c @@ -163,14 +163,16 @@ void __attribute__((weak)) ethosu_mutex_destroy(void *mutex) UNUSED(mutex); } -void __attribute__((weak)) ethosu_mutex_lock(void *mutex) +int __attribute__((weak)) ethosu_mutex_lock(void *mutex) { UNUSED(mutex); + return 0; } -void __attribute__((weak)) ethosu_mutex_unlock(void *mutex) +int __attribute__((weak)) ethosu_mutex_unlock(void *mutex) { UNUSED(mutex); + return 0; } // Baremetal implementation of creating a semaphore @@ -187,7 +189,7 @@ void __attribute__((weak)) ethosu_semaphore_destroy(void *sem) } // Baremetal simulation of waiting/sleeping for and then taking a semaphore using intrisics -void __attribute__((weak)) ethosu_semaphore_take(void *sem) +int __attribute__((weak)) ethosu_semaphore_take(void *sem) { struct ethosu_semaphore_t *s = sem; while (s->count == 0) @@ -195,14 +197,16 @@ void __attribute__((weak)) ethosu_semaphore_take(void *sem) __WFE(); } s->count = 0; + return 0; } // Baremetal simulation of giving a semaphore and waking up processes using intrinsics -void __attribute__((weak)) ethosu_semaphore_give(void *sem) +int __attribute__((weak)) ethosu_semaphore_give(void *sem) { struct ethosu_semaphore_t *s = sem; s->count = 1; __SEV(); + return 0; } /****************************************************************************** @@ -369,6 +373,7 @@ void __attribute__((weak)) ethosu_irq_handler(struct ethosu_driver *drv) { drv->status_error = true; } + /* TODO: feedback needed aout how to handle error (-1) return value */ ethosu_semaphore_give(drv->semaphore); } @@ -475,6 +480,7 @@ int ethosu_wait(struct ethosu_driver *drv, bool block) case ETHOSU_JOB_DONE: // Wait for interrupt in blocking mode. In non-blocking mode // the interrupt has already triggered + /* TODO: feedback needed aout how to handle error (-1) return value */ ethosu_semaphore_take(drv->semaphore); // Inference done callback @@ -689,8 +695,10 @@ struct ethosu_driver *ethosu_reserve_driver(void) do { + /* TODO: feedback needed aout how to handle error (-1) return value */ ethosu_mutex_lock(ethosu_mutex); drv = ethosu_find_and_reserve_driver(); + /* TODO: feedback needed aout how to handle error (-1) return value */ ethosu_mutex_unlock(ethosu_mutex); if (drv != NULL) @@ -699,6 +707,7 @@ struct ethosu_driver *ethosu_reserve_driver(void) } LOG_INFO("Waiting for NPU driver handle to become available..."); + /* TODO: feedback needed aout how to handle error (-1) return value */ ethosu_semaphore_take(ethosu_semaphore); } while (1); @@ -708,6 +717,7 @@ struct ethosu_driver *ethosu_reserve_driver(void) void ethosu_release_driver(struct ethosu_driver *drv) { + /* TODO: feedback needed aout how to handle error (-1) return value */ ethosu_mutex_lock(ethosu_mutex); if (drv != NULL && drv->reserved) { @@ -720,6 +730,7 @@ void ethosu_release_driver(struct ethosu_driver *drv) ethosu_dev_soft_reset(drv->dev); ethosu_reset_job(drv); drv->status_error = false; + /* TODO: feedback needed aout how to handle error (-1) return value */ ethosu_semaphore_give(drv->semaphore); (void)set_clock_and_power_request( drv, ETHOSU_INFERENCE_REQUEST, ETHOSU_CLOCK_Q_ENABLE, ETHOSU_POWER_Q_ENABLE); @@ -728,8 +739,10 @@ void ethosu_release_driver(struct ethosu_driver *drv) drv->reserved = false; LOG_DEBUG("NPU driver handle %p released", drv); + /* TODO: feedback needed aout how to handle error (-1) return value */ ethosu_semaphore_give(ethosu_semaphore); } + /* TODO: feedback needed aout how to handle error (-1) return value */ ethosu_mutex_unlock(ethosu_mutex); } -- cgit v1.2.1