[dpdk-dev] [PATCH 15/15] eal/linux: use gettid(2) for debug message in sigbus_handler

Natanael Copa ncopa at alpinelinux.org
Mon Mar 11 18:37:02 CET 2019


There is no guarantee that pthread_self() returns the thread id or that
pthread_t is an integer. Use gettid(2) to get the kernel thread id
instead.

This fixes the following warning when building with musl libc:

../lib/librte_eal/linuxapp/eal/eal_dev.c: In function 'sigbus_handler':
../lib/librte_eal/linuxapp/eal/eal_dev.c:70:3: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
   (int)pthread_self(), info->si_addr);
   ^

Signed-off-by: Natanael Copa <ncopa at alpinelinux.org>
---

This is not reallly a compile error, but the warning looked a bit scary, and
code looked wrong, so I fixed it.

 lib/librte_eal/linuxapp/eal/eal_dev.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal_dev.c b/lib/librte_eal/linuxapp/eal/eal_dev.c
index 2830c8687..9ad6650cf 100644
--- a/lib/librte_eal/linuxapp/eal/eal_dev.c
+++ b/lib/librte_eal/linuxapp/eal/eal_dev.c
@@ -7,6 +7,7 @@
 #include <fcntl.h>
 #include <signal.h>
 #include <sys/socket.h>
+#include <sys/types.h>
 #include <linux/netlink.h>
 
 #include <rte_string_fns.h>
@@ -30,6 +31,11 @@ static bool hotplug_handle;
 #define EAL_UEV_MSG_LEN 4096
 #define EAL_UEV_MSG_ELEM_LEN 128
 
+#if !defined(__GLIBC__)
+#include <sys/syscall.h>
+#define gettid() syscall(SYS_gettid)
+#endif
+
 /*
  * spinlock for device hot-unplug failure handling. If it try to access bus or
  * device, such as handle sigbus on bus or handle memory failure for device
@@ -67,7 +73,7 @@ static void sigbus_handler(int signum, siginfo_t *info,
 	int ret;
 
 	RTE_LOG(DEBUG, EAL, "Thread[%d] catch SIGBUS, fault address:%p\n",
-		(int)pthread_self(), info->si_addr);
+		(int)gettid(), info->si_addr);
 
 	rte_spinlock_lock(&failure_handle_lock);
 	ret = rte_bus_sigbus_handler(info->si_addr);
-- 
2.21.0



More information about the dev mailing list