Skip to contentSkip to conversation

CodeSamples: Enable building on QNX

PATCH In review Elad Lahav 2 participants 3 messages Aug 14, 2022 – Aug 15, 2022

lore
Share & tools
lore

Elad Lahav

author
#0 lore raw

PATCH 1/1 CodeSamples: Enable building on QNX

---
 CodeSamples/Makefile                    |  3 ++-
 CodeSamples/api-pthreads/api-pthreads.h | 19 +++++++++++++++++++
 CodeSamples/arch-arm64/arch-arm64.h     |  4 ++++
 CodeSamples/depends.mk                  |  4 +++-
 4 files changed, 28 insertions(+), 2 deletions(-)
CodeSamples/Makefile +2 -1
index 3a96f5cf..b0231b1c 100644
@@ -41,7 +41,8 @@ endif
 	echo "" >> api.h
 	if test -f /usr/include/urcu-call-rcu.h -o \
 		-f /usr/local/include/urcu-call-rcu.h -o \
-		-f /usr/include/$(subdir_ub)/urcu-call-rcu.h ; \
+		-f /usr/include/$(subdir_ub)/urcu-call-rcu.h -o \
+		-f $(QNX_TARGET)/usr/include/urcu-call-rcu.h ; \
 	then \
 		echo "#define _LGPL_SOURCE" >> api.h; \
 		echo "#include <urcu/rculist.h>" >> api.h; \
CodeSamples/api-pthreads/api-pthreads.h +19 -0
index 44e55c0d..5af73947 100644
@@ -43,6 +43,11 @@
 #include <sys/param.h>
 /* #include "atomic.h" */
 
+#if defined (__QNX__)
+#include <stdint.h>
+#include <sys/neutrino.h>
+#endif
+
 /*
  * Compiler magic.
  */
@@ -310,6 +315,7 @@ static __inline__ void waitall(void)
 
 static __inline__ void run_on(int cpu)
 {
+#if defined (__linux__)
 	cpu_set_t mask;
 	int ret;
 
@@ -320,6 +326,19 @@ static __inline__ void run_on(int cpu)
 		perror("sched_setaffinity");
 		abort();
 	}
+#elif defined (__QNX__)
+    uintptr_t runmask;
+    int ret;
+
+    runmask = (1UL << cpu);
+    ret = ThreadCtl(_NTO_TCTL_RUNMASK, (void *)runmask);
+	if (ret) {
+		perror("sched_setaffinity");
+		abort();
+	}
+#else
+#error Implement for OS
+#endif
 }
 
 /*
CodeSamples/arch-arm64/arch-arm64.h +4 -0
index 0e724740..c1b2d474 100644
@@ -54,6 +54,10 @@ static __inline__ unsigned long long get_timestamp(void)
 	unsigned long long thetime;
 	struct timespec tv;
 
+#ifndef CLOCK_MONOTONIC_RAW
+#define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
+#endif
+
 	if (clock_gettime(CLOCK_MONOTONIC_RAW, &tv) != 0)
 		return 0;
 	thetime = ((unsigned long long)tv.tv_sec) * 1000000000ULL +
CodeSamples/depends.mk +3 -1
index a6db993f..e192c2c2 100644
@@ -1,5 +1,5 @@
 ifeq ($(strip $(arch)),)
-arch := $(shell uname -m)
+arch := $(shell uname -p)
 endif
 
 ifeq ($(arch),i686)
@@ -17,6 +17,8 @@ subdir_ub := powerpc64le-linux-gnu
 else ifeq ($(arch),aarch64)
 target := arm64
 subdir_ub := aarch64-linux-gnu
+else ifeq ($(arch),aarch64le)
+target := arm64
 else ifneq (,$(findstring arm,$(arch)))
 target := arm
 subdir_ub := arm-linux-gnueabihf
Signature · 1 line
2.25.1
author
#1 lore raw

CodeSamples/api-pthreads/api-pthreads.h static __inline__ void run_on(int cpu) · line 338

Quoted 10 lines · Elad Lahav
CodeSamples/api-pthreads/api-pthreads.h +10 -0
+#elif defined (__QNX__)
+    uintptr_t runmask;
+    int ret;
+
+    runmask = (1UL << cpu);
+    ret = ThreadCtl(_NTO_TCTL_RUNMASK, (void *)runmask);
+	if (ret) {
+		perror("sched_setaffinity");
+		abort();
+	}

Argh, I've just noticed the mix of tabs and spaces here. What's the protocol for updating a patch?

--Elad

#2 lore raw
Quoted 14 lines · Elad Lahav

CodeSamples/api-pthreads/api-pthreads.h static __inline__ void run_on(int cpu) · line 338

Quoted 10 lines · Elad Lahav
CodeSamples/api-pthreads/api-pthreads.h +10 -0
+#elif defined (__QNX__)
+    uintptr_t runmask;
+    int ret;
+
+    runmask = (1UL << cpu);
+    ret = ThreadCtl(_NTO_TCTL_RUNMASK, (void *)runmask);
+	if (ret) {
+		perror("sched_setaffinity");
+		abort();
+	}

Argh, I've just noticed the mix of tabs and spaces here. What's the protocol for updating a patch?

Since I have not pulled it in yet, just resend it with "v2" after the "PATCH" in the subject line.

But given that we are adding another OS type, it would be good to have a more organized way of dealing with this. Those #ifdefs are OK at first, but get ugly quickly.

Would you be willing to propose something that co-locates the OS-specific code? For example, one file for the QNX code and a parallel file for Linux/POSIX code? Maybe a .h file, or maybe a separate .c file. That way, the same functions names are invoked and the code specific to a given OS is easily located.

Thoughts?

Thanx, Paul