> -----Original Message-----
> From: lng-odp [mailto:[email protected]] On Behalf Of
> Ruslan Babayev
> Sent: Wednesday, June 29, 2016 6:32 AM
> To: [email protected]
> Subject: [lng-odp] [PATCH 4/7] linux-generic: set thread affinity POSIX
> style
> 
> pthread_attr_setaffinity_np is a GLIBC extension.
> The same can be achieved in a portable way by calling
> pthread_setaffinity_np after thread is created.
> 
> This fixes build with musl libc.
> 
> Signed-off-by: Ruslan Babayev <[email protected]>
> ---
>  helper/linux.c                            | 13 +++++++------
>  platform/linux-generic/odp_traffic_mngr.c |  4 ++--
>  2 files changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/helper/linux.c b/helper/linux.c
> index a1dbe52..dab7b5d 100644
> --- a/helper/linux.c
> +++ b/helper/linux.c
> @@ -17,6 +17,7 @@
>  #include <stdlib.h>
>  #include <string.h>
>  #include <stdio.h>
> +#include <pthread.h>
> 
>  #include <odp_api.h>
>  #include <odp/helper/linux.h>
> @@ -80,9 +81,6 @@ int odph_linux_pthread_create(odph_linux_pthread_t
> *pthread_tbl,
> 
>               pthread_tbl[i].cpu = cpu;
> 
> -             pthread_attr_setaffinity_np(&pthread_tbl[i].attr,
> -                                         sizeof(cpu_set_t), &cpu_set);
> -
>               pthread_tbl[i].thr_params.start    = thr_params->start;
>               pthread_tbl[i].thr_params.arg      = thr_params->arg;
>               pthread_tbl[i].thr_params.thr_type = thr_params->thr_type;
> @@ -97,6 +95,9 @@ int odph_linux_pthread_create(odph_linux_pthread_t
> *pthread_tbl,
>                       break;
>               }
> 
> +             pthread_setaffinity_np(pthread_tbl[i].thread,
> +                                    sizeof(cpu_set_t), &cpu_set);
> +


This fix seems erroneous. If affinity is changed after thread creation, it must 
be done before the new thread calls odp_local_init(). Now there's a race 
between local_init and affinity change.

Local init should run on the target CPU, so that e.g. any CPU local register 
initializations are done on the right CPU.

-Petri

_______________________________________________
lng-odp mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to