Message ID | 1418827759-1179-1-git-send-email-taras.kondratiuk@linaro.org |
---|---|
State | New |
Headers | show |
On 12/17/2014 06:36 PM, Savolainen, Petri (NSN - FI/Espoo) wrote: > > >> -----Original Message----- >> From: ext Taras Kondratiuk [mailto:taras.kondratiuk@linaro.org] >> Sent: Wednesday, December 17, 2014 4:49 PM >> To: lng-odp@lists.linaro.org; Savolainen, Petri (NSN - FI/Espoo) >> Cc: Taras Kondratiuk >> Subject: [RFC PATCH] api: init: add a way to determine a last ODP thread >> termination >> >> Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org> >> --- >> platform/linux-generic/include/api/odp_init.h | 5 ++--- >> platform/linux-generic/include/odp_internal.h | 1 + >> platform/linux-generic/odp_init.c | 4 +++- >> platform/linux-generic/odp_linux.c | 10 ++++++++-- >> platform/linux-generic/odp_thread.c | 14 ++++++++++++-- >> 5 files changed, 26 insertions(+), 8 deletions(-) >> >> diff --git a/platform/linux-generic/include/api/odp_init.h >> b/platform/linux-generic/include/api/odp_init.h >> index 49f5e41..8ded080 100644 >> --- a/platform/linux-generic/include/api/odp_init.h >> +++ b/platform/linux-generic/include/api/odp_init.h >> @@ -124,10 +124,9 @@ int odp_init_local(void); >> * >> * @warning The unwinding of HW resources to allow them to be re used >> without reseting >> * the device is a complex task that the application is expected to >> coordinate. >> - * All threads must call this function before calling >> - * any other ODP API functions. >> * >> - * @retval 0 if successful >> + * @retval 1 if successful and more ODP thread exists >> + * @retval 0 if successful and it was the last ODP thread > > Document somewhere that the last thread must call odp_term_global(). Ok. Will add. > >> * @retval -1 on failure >> */ >> int odp_term_local(void); >> diff --git a/platform/linux-generic/include/odp_internal.h >> b/platform/linux-generic/include/odp_internal.h >> index ee2ab1a..549d406 100644 >> --- a/platform/linux-generic/include/odp_internal.h >> +++ b/platform/linux-generic/include/odp_internal.h >> @@ -23,6 +23,7 @@ int odp_system_info_init(void); >> >> int odp_thread_init_global(void); >> int odp_thread_init_local(void); >> +int odp_thread_term_local(void); >> >> int odp_shm_init_global(void); >> int odp_shm_init_local(void); >> diff --git a/platform/linux-generic/odp_init.c b/platform/linux- >> generic/odp_init.c >> index c661231..6c2fc8c 100644 >> --- a/platform/linux-generic/odp_init.c >> +++ b/platform/linux-generic/odp_init.c >> @@ -90,6 +90,8 @@ int odp_init_local(void) >> >> int odp_term_local(void) >> { >> - ODP_UNIMPLEMENTED(); >> + if (odp_thread_term_local() == 0) > > Should this be odp_thread_term_local() > 0 ? == more threads exist. Yeah... I've swapped 0 and 1 in the specification at the last moment.
diff --git a/platform/linux-generic/include/api/odp_init.h b/platform/linux-generic/include/api/odp_init.h index 49f5e41..8ded080 100644 --- a/platform/linux-generic/include/api/odp_init.h +++ b/platform/linux-generic/include/api/odp_init.h @@ -124,10 +124,9 @@ int odp_init_local(void); * * @warning The unwinding of HW resources to allow them to be re used without reseting * the device is a complex task that the application is expected to coordinate. - * All threads must call this function before calling - * any other ODP API functions. * - * @retval 0 if successful + * @retval 1 if successful and more ODP thread exists + * @retval 0 if successful and it was the last ODP thread * @retval -1 on failure */ int odp_term_local(void); diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h index ee2ab1a..549d406 100644 --- a/platform/linux-generic/include/odp_internal.h +++ b/platform/linux-generic/include/odp_internal.h @@ -23,6 +23,7 @@ int odp_system_info_init(void); int odp_thread_init_global(void); int odp_thread_init_local(void); +int odp_thread_term_local(void); int odp_shm_init_global(void); int odp_shm_init_local(void); diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c index c661231..6c2fc8c 100644 --- a/platform/linux-generic/odp_init.c +++ b/platform/linux-generic/odp_init.c @@ -90,6 +90,8 @@ int odp_init_local(void) int odp_term_local(void) { - ODP_UNIMPLEMENTED(); + if (odp_thread_term_local() == 0) + return 1; + return 0; } diff --git a/platform/linux-generic/odp_linux.c b/platform/linux-generic/odp_linux.c index 95761a9..229d24e 100644 --- a/platform/linux-generic/odp_linux.c +++ b/platform/linux-generic/odp_linux.c @@ -43,9 +43,15 @@ static void *odp_run_start_routine(void *arg) return NULL; } - void *ret = start_args->start_routine(start_args->arg); + void *ret_ptr = start_args->start_routine(start_args->arg); _odp_flush_caches(); - return ret; + int ret = odp_term_local(); + if (ret < 0) + ODP_ERR("Local term failed\n"); + else if (ret == 0 && odp_term_global()) + ODP_ERR("Global term failed\n"); + + return ret_ptr; } diff --git a/platform/linux-generic/odp_thread.c b/platform/linux-generic/odp_thread.c index faa12a2..01c8147 100644 --- a/platform/linux-generic/odp_thread.c +++ b/platform/linux-generic/odp_thread.c @@ -32,6 +32,7 @@ typedef struct { typedef struct { thread_state_t thr[ODP_CONFIG_MAX_THREADS]; odp_atomic_u32_t num; + odp_atomic_u32_t next_id; } thread_globals_t; @@ -58,6 +59,8 @@ int odp_thread_init_global(void) return -1; memset(thread_globals, 0, sizeof(thread_globals_t)); + odp_atomic_init_u32(&thread_globals->next_id, 0); + odp_atomic_init_u32(&thread_globals->num, 0); return 0; } @@ -67,12 +70,13 @@ static int thread_id(void) uint32_t id; int cpu; - id = odp_atomic_fetch_inc_u32(&thread_globals->num); + id = odp_atomic_fetch_inc_u32(&thread_globals->next_id); if (id >= ODP_CONFIG_MAX_THREADS) { ODP_ERR("Too many threads\n"); return -1; } + odp_atomic_inc_u32(&thread_globals->num); cpu = sched_getcpu(); @@ -87,7 +91,6 @@ static int thread_id(void) return id; } - int odp_thread_init_local(void) { int id; @@ -101,6 +104,13 @@ int odp_thread_init_local(void) return 0; } +int odp_thread_term_local(void) +{ + uint32_t num; + num = odp_atomic_fetch_dec_u32(&thread_globals->num); + ODP_ASSERT(num > 0, "Number of threads should be > 0"); + return num - 1; /* return a number of threads left */ +} int odp_thread_id(void) {
Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org> --- platform/linux-generic/include/api/odp_init.h | 5 ++--- platform/linux-generic/include/odp_internal.h | 1 + platform/linux-generic/odp_init.c | 4 +++- platform/linux-generic/odp_linux.c | 10 ++++++++-- platform/linux-generic/odp_thread.c | 14 ++++++++++++-- 5 files changed, 26 insertions(+), 8 deletions(-)