On Fri, Mar 17, 2023 at 03:34:15PM -0700, Tyler Retzlaff wrote:
> Update driver to use rte thread API where available instead of pthread
> as a prerequisite to removing pthread stubs on Windows.
> 
> Signed-off-by: Tyler Retzlaff <roret...@linux.microsoft.com>
> ---
>  drivers/dma/skeleton/skeleton_dmadev.c | 15 ++++++++-------
>  drivers/dma/skeleton/skeleton_dmadev.h |  4 ++--
>  2 files changed, 10 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/dma/skeleton/skeleton_dmadev.c 
> b/drivers/dma/skeleton/skeleton_dmadev.c
> index daf35ec..2ec10db 100644
> --- a/drivers/dma/skeleton/skeleton_dmadev.c
> +++ b/drivers/dma/skeleton/skeleton_dmadev.c
> @@ -5,6 +5,8 @@
>  #include <inttypes.h>
>  #include <stdlib.h>
>  
> +#include <pthread.h>
> +

Curious as to why this is needed here. Does rte_thread.h not include all
needed threading dependencies?
[Self-answer] I assume this is for pthread_cancel below, right?


>  #include <bus_vdev_driver.h>
>  #include <rte_cycles.h>
>  #include <rte_eal.h>
> @@ -53,7 +55,7 @@
>       return 0;
>  }
>  
> -static void *
> +static uint32_t
>  cpucopy_thread(void *param)
>  {
>  #define SLEEP_THRESHOLD              10000
> @@ -81,7 +83,7 @@
>               (void)rte_ring_enqueue(hw->desc_completed, (void *)desc);
>       }
>  
> -     return NULL;
> +     return 0;
>  }
>  
>  static void
> @@ -126,7 +128,7 @@
>       rte_mb();
>  
>       snprintf(name, sizeof(name), "dma_skel_%d", dev->data->dev_id);
> -     ret = rte_ctrl_thread_create(&hw->thread, name, NULL,
> +     ret = rte_thread_create_control(&hw->thread, name, NULL,
>                                    cpucopy_thread, dev);
>       if (ret) {
>               SKELDMA_LOG(ERR, "Start cpucopy thread fail!");
> @@ -135,8 +137,7 @@
>  
>       if (hw->lcore_id != -1) {
>               cpuset = rte_lcore_cpuset(hw->lcore_id);
> -             ret = pthread_setaffinity_np(hw->thread, sizeof(cpuset),
> -                                          &cpuset);
> +             ret = rte_thread_get_affinity_by_id(hw->thread, &cpuset);
>               if (ret)
>                       SKELDMA_LOG(WARNING,
>                               "Set thread affinity lcore = %d fail!",
> @@ -154,8 +155,8 @@
>       hw->exit_flag = true;
>       rte_delay_ms(1);
>  
> -     (void)pthread_cancel(hw->thread);
> -     pthread_join(hw->thread, NULL);
> +     (void)pthread_cancel((pthread_t)hw->thread.opaque_id);
> +     rte_thread_join(hw->thread, NULL);
>  

Is there no rte_* equivalent to pthread_cancel? Will that cause issues
later?

>       return 0;
>  }
> diff --git a/drivers/dma/skeleton/skeleton_dmadev.h 
> b/drivers/dma/skeleton/skeleton_dmadev.h
> index 6f89400..8670a68 100644
> --- a/drivers/dma/skeleton/skeleton_dmadev.h
> +++ b/drivers/dma/skeleton/skeleton_dmadev.h
> @@ -5,9 +5,9 @@
>  #ifndef SKELETON_DMADEV_H
>  #define SKELETON_DMADEV_H
>  
> -#include <pthread.h>
>  
>  #include <rte_ring.h>
> +#include <rte_thread.h>
>  
>  #define SKELDMA_ARG_LCORE    "lcore"
>  
> @@ -21,7 +21,7 @@ struct skeldma_desc {
>  struct skeldma_hw {
>       int lcore_id; /* cpucopy task affinity core */
>       int socket_id;
> -     pthread_t thread; /* cpucopy task thread */
> +     rte_thread_t thread; /* cpucopy task thread */
>       volatile int exit_flag; /* cpucopy task exit flag */
>  
>       struct skeldma_desc *desc_mem;
> -- 
> 1.8.3.1
> 

Reply via email to