diff mbox series

[v5,15/17] vdpa/mlx5: replace pthread functions unavailable in musl

Message ID 20210225182250.1149592-16-thomas@monjalon.net (mailing list archive)
State Superseded
Headers show
Series Alpine/musl build support | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Thomas Monjalon Feb. 25, 2021, 6:22 p.m. UTC
1/ The function pthread_yield() does not exist in musl libc,
and can be replaced with sched_yield() after including sched.h.

2/ The function pthread_attr_setaffinity_np() does not exist in musl libc,
and can be replaced with pthread_setaffinity_np() after pthread_create().

Fixes: b7fa0bf4d5c6 ("vdpa/mlx5: fix polling threads scheduling")
Fixes: 5cf3fd3af4df ("vdpa/mlx5: add CPU core parameter to bind polling thread")
Cc: stable@dpdk.org

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 drivers/vdpa/mlx5/mlx5_vdpa_event.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

Comments

Matan Azrad March 1, 2021, 7:30 a.m. UTC | #1
From: Thomas Monjalon
> 1/ The function pthread_yield() does not exist in musl libc, and can be replaced
> with sched_yield() after including sched.h.
> 
> 2/ The function pthread_attr_setaffinity_np() does not exist in musl libc, and
> can be replaced with pthread_setaffinity_np() after pthread_create().
> 
> Fixes: b7fa0bf4d5c6 ("vdpa/mlx5: fix polling threads scheduling")
> Fixes: 5cf3fd3af4df ("vdpa/mlx5: add CPU core parameter to bind polling
> thread")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Matan Azrad <matan@nvidia.com>
diff mbox series

Patch

diff --git a/drivers/vdpa/mlx5/mlx5_vdpa_event.c b/drivers/vdpa/mlx5/mlx5_vdpa_event.c
index 86adc864f5..49632dfaa7 100644
--- a/drivers/vdpa/mlx5/mlx5_vdpa_event.c
+++ b/drivers/vdpa/mlx5/mlx5_vdpa_event.c
@@ -3,6 +3,7 @@ 
  */
 #include <unistd.h>
 #include <stdint.h>
+#include <sched.h>
 #include <fcntl.h>
 #include <sys/eventfd.h>
 
@@ -234,7 +235,7 @@  mlx5_vdpa_timer_sleep(struct mlx5_vdpa_priv *priv, uint32_t max)
 		usleep(priv->timer_delay_us);
 	else
 		/* Give-up CPU to improve polling threads scheduling. */
-		pthread_yield();
+		sched_yield();
 }
 
 static void *
@@ -515,17 +516,6 @@  mlx5_vdpa_cqe_event_setup(struct mlx5_vdpa_priv *priv)
 		pthread_cond_init(&priv->timer_cond, NULL);
 		priv->timer_on = 0;
 		pthread_attr_init(&attr);
-		CPU_ZERO(&cpuset);
-		if (priv->event_core != -1)
-			CPU_SET(priv->event_core, &cpuset);
-		else
-			cpuset = rte_lcore_cpuset(rte_get_main_lcore());
-		ret = pthread_attr_setaffinity_np(&attr, sizeof(cpuset),
-						  &cpuset);
-		if (ret) {
-			DRV_LOG(ERR, "Failed to set thread affinity.");
-			return -1;
-		}
 		ret = pthread_attr_setschedpolicy(&attr, SCHED_RR);
 		if (ret) {
 			DRV_LOG(ERR, "Failed to set thread sched policy = RR.");
@@ -542,6 +532,17 @@  mlx5_vdpa_cqe_event_setup(struct mlx5_vdpa_priv *priv)
 			DRV_LOG(ERR, "Failed to create timer thread.");
 			return -1;
 		}
+		CPU_ZERO(&cpuset);
+		if (priv->event_core != -1)
+			CPU_SET(priv->event_core, &cpuset);
+		else
+			cpuset = rte_lcore_cpuset(rte_get_main_lcore());
+		ret = pthread_setaffinity_np(priv->timer_tid,
+					     sizeof(cpuset), &cpuset);
+		if (ret) {
+			DRV_LOG(ERR, "Failed to set thread affinity.");
+			goto error;
+		}
 		snprintf(name, sizeof(name), "vDPA-mlx5-%d", priv->vid);
 		ret = pthread_setname_np(priv->timer_tid, name);
 		if (ret) {