diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fe81f75..3958da0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Barcelona Supercomputing Center (BSC) +# Copyright (c) 2021-2023 Barcelona Supercomputing Center (BSC) # SPDX-License-Identifier: GPL-3.0-or-later add_subdirectory(include) @@ -7,14 +7,14 @@ add_library(parson STATIC parson.c) target_include_directories(parson PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") set_property(TARGET parson PROPERTY POSITION_INDEPENDENT_CODE ON) -add_library(common STATIC common.c) +add_library(common STATIC common.c compat.c) target_include_directories(common PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") set_property(TARGET common PROPERTY POSITION_INDEPENDENT_CODE ON) add_library(parson-static STATIC parson.c) target_include_directories(parson-static PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") -add_library(common-static STATIC common.c) +add_library(common-static STATIC common.c compat.c) target_include_directories(common-static PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") configure_file("config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/config.h" ) diff --git a/src/include/compat.h b/src/compat.c similarity index 78% rename from src/include/compat.h rename to src/compat.c index b7f2418..2cf88a4 100644 --- a/src/include/compat.h +++ b/src/compat.c @@ -1,20 +1,19 @@ /* Copyright (c) 2021-2023 Barcelona Supercomputing Center (BSC) * SPDX-License-Identifier: MIT */ -#ifndef COMPAT_H -#define COMPAT_H +#define _GNU_SOURCE /* Only here */ -#include -pid_t gettid(void); +#include "compat.h" +#include +#include /* Define gettid for older glibc versions (below 2.30) */ #if defined(__GLIBC__) #if !__GLIBC_PREREQ(2, 30) #include -#include -static inline pid_t +static pid_t gettid(void) { return (pid_t) syscall(SYS_gettid); @@ -23,12 +22,13 @@ gettid(void) #endif /* !__GLIBC_PREREQ(2, 30) */ #endif /* defined(__GLIBC__) */ -/* usleep is deprecated */ +pid_t +get_tid(void) +{ + return gettid(); +} -#include -#include - -static inline int +int sleep_us(long usec) { struct timespec ts; @@ -48,5 +48,3 @@ sleep_us(long usec) return res; } - -#endif /* COMPAT_H */ diff --git a/src/compat.h b/src/compat.h new file mode 100644 index 0000000..f7b9c36 --- /dev/null +++ b/src/compat.h @@ -0,0 +1,12 @@ +/* Copyright (c) 2021-2023 Barcelona Supercomputing Center (BSC) + * SPDX-License-Identifier: MIT */ + +#ifndef COMPAT_H +#define COMPAT_H + +#include + +pid_t get_tid(void); +int sleep_us(long usec); + +#endif /* COMPAT_H */ diff --git a/test/emu/common/instr.h b/test/emu/common/instr.h index 58479f5..c1f24ec 100644 --- a/test/emu/common/instr.h +++ b/test/emu/common/instr.h @@ -89,7 +89,7 @@ instr_start(int rank, int nranks) ovni_version_check(); ovni_proc_init(1, rankname, getpid()); ovni_proc_set_rank(rank, nranks); - ovni_thread_init(gettid()); + ovni_thread_init(get_tid()); /* All ranks inform CPUs */ for (int i = 0; i < nranks; i++) @@ -98,7 +98,7 @@ instr_start(int rank, int nranks) int curcpu = rank; dbg("thread %d has cpu %d (ncpus=%d)", - gettid(), curcpu, nranks); + get_tid(), curcpu, nranks); instr_thread_execute(curcpu, -1, 0); } diff --git a/test/emu/nosv/mp-rank.c b/test/emu/nosv/mp-rank.c index 34831db..21abbc6 100644 --- a/test/emu/nosv/mp-rank.c +++ b/test/emu/nosv/mp-rank.c @@ -55,7 +55,7 @@ instr_start(int rank, int nranks) ovni_proc_set_rank(rank, nranks); - ovni_thread_init(gettid()); + ovni_thread_init(get_tid()); /* Only the rank 0 inform about all CPUs */ if (rank == 0) { @@ -67,7 +67,7 @@ instr_start(int rank, int nranks) int curcpu = rank; fprintf(stderr, "thread %d has cpu %d (ncpus=%d)\n", - gettid(), curcpu, nranks); + get_tid(), curcpu, nranks); instr_thread_execute(curcpu, -1, 0); } diff --git a/test/emu/ovni/clockgate.c b/test/emu/ovni/clockgate.c index e6e6a0a..035d8f8 100644 --- a/test/emu/ovni/clockgate.c +++ b/test/emu/ovni/clockgate.c @@ -37,7 +37,7 @@ start_delayed(int rank, int nranks) ovni_version_check(); ovni_proc_init(1, rankname, getpid()); ovni_proc_set_rank(rank, nranks); - ovni_thread_init(gettid()); + ovni_thread_init(get_tid()); /* All ranks inform CPUs */ for (int i = 0; i < nranks; i++) @@ -46,7 +46,7 @@ start_delayed(int rank, int nranks) int curcpu = rank; dbg("thread %d has cpu %d (ncpus=%d)", - gettid(), curcpu, nranks); + get_tid(), curcpu, nranks); delta = ((int64_t) rank) * 2LL * 3600LL * 1000LL * 1000LL * 1000LL; thread_execute_delayed(curcpu, -1, 0); diff --git a/test/emu/ovni/sort-first-and-full-ring.c b/test/emu/ovni/sort-first-and-full-ring.c index 0131563..32415cd 100644 --- a/test/emu/ovni/sort-first-and-full-ring.c +++ b/test/emu/ovni/sort-first-and-full-ring.c @@ -20,7 +20,7 @@ init(void) } ovni_proc_init(0, hostname, getpid()); - ovni_thread_init(gettid()); + ovni_thread_init(get_tid()); ovni_add_cpu(0, 0); } diff --git a/test/rt/nanos6/spawn-task-external.c b/test/rt/nanos6/spawn-task-external.c index a388727..ceb49cc 100644 --- a/test/rt/nanos6/spawn-task-external.c +++ b/test/rt/nanos6/spawn-task-external.c @@ -46,7 +46,7 @@ polling_func(void *arg) static inline void instr_thread_start(int32_t cpu, int32_t creator_tid, uint64_t tag) { - ovni_thread_init(gettid()); + ovni_thread_init(get_tid()); struct ovni_ev ev = {0};