* [PATCH v3] CodeSamples: Support for building on different operating systems
@ 2022-08-16 0:22 Elad Lahav
2022-08-16 19:07 ` Paul E. McKenney
0 siblings, 1 reply; 2+ messages in thread
From: Elad Lahav @ 2022-08-16 0:22 UTC (permalink / raw)
To: perfbook; +Cc: Elad Lahav
Signed-off-by: Elad Lahav <e2lahav@gmail.com>
---
CodeSamples/Makefile | 4 ++-
CodeSamples/api-pthreads/api-linux.h | 36 ++++++++++++++++++++++++
CodeSamples/api-pthreads/api-pthreads.h | 13 ---------
CodeSamples/api-pthreads/api-qnx.h | 37 +++++++++++++++++++++++++
CodeSamples/arch-arm64/arch-arm64.h | 4 +++
CodeSamples/depends.mk | 29 ++++++++++++++++++-
6 files changed, 108 insertions(+), 15 deletions(-)
create mode 100644 CodeSamples/api-pthreads/api-linux.h
create mode 100644 CodeSamples/api-pthreads/api-qnx.h
diff --git a/CodeSamples/Makefile b/CodeSamples/Makefile
index 3a96f5cf..38143638 100644
--- a/CodeSamples/Makefile
+++ b/CodeSamples/Makefile
@@ -38,10 +38,12 @@ endif
sed '/end{snippet}/d' >> api.h
echo "" >> api.h
cat api-pthreads/api-gcc.h >> api.h
+ cat api-pthreads/api-$(os_compat).h >> api.h
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; \
diff --git a/CodeSamples/api-pthreads/api-linux.h b/CodeSamples/api-pthreads/api-linux.h
new file mode 100644
index 00000000..03522a54
--- /dev/null
+++ b/CodeSamples/api-pthreads/api-linux.h
@@ -0,0 +1,36 @@
+/*
+ * api-linux.h: Linux-specific functions
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version. However, please note that much
+ * of the code in this file derives from the Linux kernel, and that such
+ * code may not be available except under GPLv2.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, you can access it online at
+ * http://www.gnu.org/licenses/gpl-2.0.html.
+ *
+ * Copyright (c) 2006-2019 Paul E. McKenney, IBM.
+ * Copyright (c) 2019 Paul E. McKenney, Facebook.
+ */
+
+static __inline__ void run_on(int cpu)
+{
+ cpu_set_t mask;
+ int ret;
+
+ CPU_ZERO(&mask);
+ CPU_SET(cpu, &mask);
+ ret = sched_setaffinity(0, sizeof(mask), &mask);
+ if (ret) {
+ perror("sched_setaffinity");
+ abort();
+ }
+}
diff --git a/CodeSamples/api-pthreads/api-pthreads.h b/CodeSamples/api-pthreads/api-pthreads.h
index 44e55c0d..3e21fdb9 100644
--- a/CodeSamples/api-pthreads/api-pthreads.h
+++ b/CodeSamples/api-pthreads/api-pthreads.h
@@ -308,19 +308,6 @@ static __inline__ void waitall(void)
}
// \end{snippet}
-static __inline__ void run_on(int cpu)
-{
- cpu_set_t mask;
- int ret;
-
- CPU_ZERO(&mask);
- CPU_SET(cpu, &mask);
- ret = sched_setaffinity(0, sizeof(mask), &mask);
- if (ret) {
- perror("sched_setaffinity");
- abort();
- }
-}
/*
* Timekeeping, using monotonic globally coherent clock.
diff --git a/CodeSamples/api-pthreads/api-qnx.h b/CodeSamples/api-pthreads/api-qnx.h
new file mode 100644
index 00000000..ed2fb543
--- /dev/null
+++ b/CodeSamples/api-pthreads/api-qnx.h
@@ -0,0 +1,37 @@
+/*
+ * api-qnx.h: QNX-specific functions
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version. However, please note that much
+ * of the code in this file derives from the Linux kernel, and that such
+ * code may not be available except under GPLv2.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, you can access it online at
+ * http://www.gnu.org/licenses/gpl-2.0.html.
+ *
+ * Copyright (c) 2022 Elad Lahav
+ */
+
+#include <stdint.h>
+#include <sys/neutrino.h>
+
+static inline void run_on(int cpu)
+{
+ uintptr_t runmask;
+ int ret;
+
+ runmask = (1UL << cpu);
+ ret = ThreadCtl(_NTO_TCTL_RUNMASK, (void *)runmask);
+ if (ret) {
+ perror("sched_setaffinity");
+ abort();
+ }
+}
diff --git a/CodeSamples/arch-arm64/arch-arm64.h b/CodeSamples/arch-arm64/arch-arm64.h
index 0e724740..f45d8bdc 100644
--- a/CodeSamples/arch-arm64/arch-arm64.h
+++ b/CodeSamples/arch-arm64/arch-arm64.h
@@ -46,6 +46,10 @@
#include <stdlib.h>
#include <time.h>
+#ifndef CLOCK_MONOTONIC_RAW
+#define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
+#endif
+
/*
* Generate 64-bit timestamp.
*/
diff --git a/CodeSamples/depends.mk b/CodeSamples/depends.mk
index a6db993f..30810339 100644
--- a/CodeSamples/depends.mk
+++ b/CodeSamples/depends.mk
@@ -1,7 +1,13 @@
ifeq ($(strip $(arch)),)
-arch := $(shell uname -m)
+arch := $(shell uname -p)
endif
+ifeq ($(strip $(os)),)
+os := $(shell uname)
+endif
+
+ifeq ($(os),Linux)
+# Linux
ifeq ($(arch),i686)
target := x86
subdir_ub := i386-linux-gnu
@@ -23,6 +29,27 @@ subdir_ub := arm-linux-gnueabihf
else
target :=
subdir_ub :=
+endif
+os_compat := linux
+
+else ifeq ($(os),QNX)
+# QNX
+ifeq ($(arch),x86_64)
+target := x86
+else ifeq ($(arch),aarch64le)
+target := arm64
+else
+target :=
+endif
+subdir_ub :=
+os_compat := qnx
+
+else
+# Other OS
+target :=
+subdir_ub :=
+os_compat :=
+
endif
api_depend_common := $(top)/linux/common.h \
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3] CodeSamples: Support for building on different operating systems
2022-08-16 0:22 [PATCH v3] CodeSamples: Support for building on different operating systems Elad Lahav
@ 2022-08-16 19:07 ` Paul E. McKenney
0 siblings, 0 replies; 2+ messages in thread
From: Paul E. McKenney @ 2022-08-16 19:07 UTC (permalink / raw)
To: Elad Lahav; +Cc: perfbook
On Mon, Aug 15, 2022 at 08:22:25PM -0400, Elad Lahav wrote:
> Signed-off-by: Elad Lahav <e2lahav@gmail.com>
Queued and pushed, thank you!
Thanx, Paul
> ---
> CodeSamples/Makefile | 4 ++-
> CodeSamples/api-pthreads/api-linux.h | 36 ++++++++++++++++++++++++
> CodeSamples/api-pthreads/api-pthreads.h | 13 ---------
> CodeSamples/api-pthreads/api-qnx.h | 37 +++++++++++++++++++++++++
> CodeSamples/arch-arm64/arch-arm64.h | 4 +++
> CodeSamples/depends.mk | 29 ++++++++++++++++++-
> 6 files changed, 108 insertions(+), 15 deletions(-)
> create mode 100644 CodeSamples/api-pthreads/api-linux.h
> create mode 100644 CodeSamples/api-pthreads/api-qnx.h
>
> diff --git a/CodeSamples/Makefile b/CodeSamples/Makefile
> index 3a96f5cf..38143638 100644
> --- a/CodeSamples/Makefile
> +++ b/CodeSamples/Makefile
> @@ -38,10 +38,12 @@ endif
> sed '/end{snippet}/d' >> api.h
> echo "" >> api.h
> cat api-pthreads/api-gcc.h >> api.h
> + cat api-pthreads/api-$(os_compat).h >> api.h
> 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; \
> diff --git a/CodeSamples/api-pthreads/api-linux.h b/CodeSamples/api-pthreads/api-linux.h
> new file mode 100644
> index 00000000..03522a54
> --- /dev/null
> +++ b/CodeSamples/api-pthreads/api-linux.h
> @@ -0,0 +1,36 @@
> +/*
> + * api-linux.h: Linux-specific functions
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version. However, please note that much
> + * of the code in this file derives from the Linux kernel, and that such
> + * code may not be available except under GPLv2.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, you can access it online at
> + * http://www.gnu.org/licenses/gpl-2.0.html.
> + *
> + * Copyright (c) 2006-2019 Paul E. McKenney, IBM.
> + * Copyright (c) 2019 Paul E. McKenney, Facebook.
> + */
> +
> +static __inline__ void run_on(int cpu)
> +{
> + cpu_set_t mask;
> + int ret;
> +
> + CPU_ZERO(&mask);
> + CPU_SET(cpu, &mask);
> + ret = sched_setaffinity(0, sizeof(mask), &mask);
> + if (ret) {
> + perror("sched_setaffinity");
> + abort();
> + }
> +}
> diff --git a/CodeSamples/api-pthreads/api-pthreads.h b/CodeSamples/api-pthreads/api-pthreads.h
> index 44e55c0d..3e21fdb9 100644
> --- a/CodeSamples/api-pthreads/api-pthreads.h
> +++ b/CodeSamples/api-pthreads/api-pthreads.h
> @@ -308,19 +308,6 @@ static __inline__ void waitall(void)
> }
> // \end{snippet}
>
> -static __inline__ void run_on(int cpu)
> -{
> - cpu_set_t mask;
> - int ret;
> -
> - CPU_ZERO(&mask);
> - CPU_SET(cpu, &mask);
> - ret = sched_setaffinity(0, sizeof(mask), &mask);
> - if (ret) {
> - perror("sched_setaffinity");
> - abort();
> - }
> -}
>
> /*
> * Timekeeping, using monotonic globally coherent clock.
> diff --git a/CodeSamples/api-pthreads/api-qnx.h b/CodeSamples/api-pthreads/api-qnx.h
> new file mode 100644
> index 00000000..ed2fb543
> --- /dev/null
> +++ b/CodeSamples/api-pthreads/api-qnx.h
> @@ -0,0 +1,37 @@
> +/*
> + * api-qnx.h: QNX-specific functions
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version. However, please note that much
> + * of the code in this file derives from the Linux kernel, and that such
> + * code may not be available except under GPLv2.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, you can access it online at
> + * http://www.gnu.org/licenses/gpl-2.0.html.
> + *
> + * Copyright (c) 2022 Elad Lahav
> + */
> +
> +#include <stdint.h>
> +#include <sys/neutrino.h>
> +
> +static inline void run_on(int cpu)
> +{
> + uintptr_t runmask;
> + int ret;
> +
> + runmask = (1UL << cpu);
> + ret = ThreadCtl(_NTO_TCTL_RUNMASK, (void *)runmask);
> + if (ret) {
> + perror("sched_setaffinity");
> + abort();
> + }
> +}
> diff --git a/CodeSamples/arch-arm64/arch-arm64.h b/CodeSamples/arch-arm64/arch-arm64.h
> index 0e724740..f45d8bdc 100644
> --- a/CodeSamples/arch-arm64/arch-arm64.h
> +++ b/CodeSamples/arch-arm64/arch-arm64.h
> @@ -46,6 +46,10 @@
> #include <stdlib.h>
> #include <time.h>
>
> +#ifndef CLOCK_MONOTONIC_RAW
> +#define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
> +#endif
> +
> /*
> * Generate 64-bit timestamp.
> */
> diff --git a/CodeSamples/depends.mk b/CodeSamples/depends.mk
> index a6db993f..30810339 100644
> --- a/CodeSamples/depends.mk
> +++ b/CodeSamples/depends.mk
> @@ -1,7 +1,13 @@
> ifeq ($(strip $(arch)),)
> -arch := $(shell uname -m)
> +arch := $(shell uname -p)
> endif
>
> +ifeq ($(strip $(os)),)
> +os := $(shell uname)
> +endif
> +
> +ifeq ($(os),Linux)
> +# Linux
> ifeq ($(arch),i686)
> target := x86
> subdir_ub := i386-linux-gnu
> @@ -23,6 +29,27 @@ subdir_ub := arm-linux-gnueabihf
> else
> target :=
> subdir_ub :=
> +endif
> +os_compat := linux
> +
> +else ifeq ($(os),QNX)
> +# QNX
> +ifeq ($(arch),x86_64)
> +target := x86
> +else ifeq ($(arch),aarch64le)
> +target := arm64
> +else
> +target :=
> +endif
> +subdir_ub :=
> +os_compat := qnx
> +
> +else
> +# Other OS
> +target :=
> +subdir_ub :=
> +os_compat :=
> +
> endif
>
> api_depend_common := $(top)/linux/common.h \
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-08-16 19:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-16 0:22 [PATCH v3] CodeSamples: Support for building on different operating systems Elad Lahav
2022-08-16 19:07 ` Paul E. McKenney
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.