[Xenomai-git] Philippe Gerum : demo/cyclictest: fixups for building over uClibc
Module: xenomai-3 Branch: arm64 Commit: f23985b033a4576773d58a9b77fd9219037f47f6 URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=f23985b033a4576773d58a9b77fd9219037f47f6 Author: Philippe Gerum Date: Mon Oct 5 14:49:44 2015 +0200 demo/cyclictest: fixups for building over uClibc Mainly for building with outdated Blackfin toolchains. --- demo/posix/cyclictest/Makefile.am |3 +- demo/posix/cyclictest/cyclictest.c | 99 ++-- demo/posix/cyclictest/rt-utils.h |5 ++ 3 files changed, 56 insertions(+), 51 deletions(-) diff --git a/demo/posix/cyclictest/Makefile.am b/demo/posix/cyclictest/Makefile.am index ff62b37..a35fdca 100644 --- a/demo/posix/cyclictest/Makefile.am +++ b/demo/posix/cyclictest/Makefile.am @@ -14,8 +14,7 @@ cyclictest_CPPFLAGS = \ -Wno-implicit-function-declaration \ -Wno-missing-prototypes \ -Wno-nonnull\ - -Wno-unused-function\ - -Wno-unused-result + -Wno-unused-function cyclictest_SOURCES = \ cyclictest.c\ diff --git a/demo/posix/cyclictest/cyclictest.c b/demo/posix/cyclictest/cyclictest.c index 92c7043..0f59e21 100644 --- a/demo/posix/cyclictest/cyclictest.c +++ b/demo/posix/cyclictest/cyclictest.c @@ -43,52 +43,12 @@ #define DEFAULT_INTERVAL 1000 #define DEFAULT_DISTANCE 500 -#ifndef SCHED_IDLE -#define SCHED_IDLE 5 -#endif -#ifndef SCHED_NORMAL -#define SCHED_NORMAL SCHED_OTHER -#endif - #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) /* Ugly, but */ #define gettid() syscall(__NR_gettid) #define sigev_notify_thread_id _sigev_un._tid -#ifdef __UCLIBC__ -#define MAKE_PROCESS_CPUCLOCK(pid, clock) \ - ((~(clockid_t) (pid) << 3) | (clockid_t) (clock)) -#define CPUCLOCK_SCHED 2 - -static int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *req, - struct timespec *rem) -{ - if (clock_id == CLOCK_THREAD_CPUTIME_ID) - return -EINVAL; - if (clock_id == CLOCK_PROCESS_CPUTIME_ID) - clock_id = MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED); - - return syscall(__NR_clock_nanosleep, clock_id, flags, req, rem); -} - -int sched_setaffinity (__pid_t __pid, size_t __cpusetsize, - __const cpu_set_t *__cpuset) -{ - return -EINVAL; -} - -#undef CPU_SET -#undef CPU_ZERO -#define CPU_SET(cpu, cpusetp) -#define CPU_ZERO(cpusetp) - -#else -extern int clock_nanosleep(clockid_t __clock_id, int __flags, - __const struct timespec *__req, - struct timespec *__rem); -#endif - #define USEC_PER_SEC 100 #define NSEC_PER_SEC 10 @@ -113,6 +73,12 @@ int enable_events; static char *policyname(int policy); +#define write_check(__fd, __buf, __len)\ + do {\ + int __ret = write(__fd, __buf, __len); \ + (void)__ret;\ + } while (0); + enum { NOTRACE, CTXTSWITCH, @@ -196,8 +162,6 @@ static pthread_mutex_t break_thread_id_lock = PTHREAD_MUTEX_INITIALIZER; static pid_t break_thread_id = 0; static uint64_t break_thread_value = 0; -static pthread_barrier_t align_barr; -static pthread_barrier_t globalt_barr; static struct timespec globalt; /* Backup of kernel variables that we modify */ @@ -437,7 +401,7 @@ static void tracemark(char *fmt, ...) va_start(ap, fmt); len = vsnprintf(tracebuf, TRACEBUFSIZ, fmt, ap); va_end(ap); - write(tracemark_fd, tracebuf, len); + write_check(tracemark_fd, tracebuf, len); } @@ -450,7 +414,7 @@ void tracing(int on) case KV_26_LT24: prctl(0, 1); break; case KV_26_33: case KV_30: - write(trace_fd, "1", 1); + write_check(trace_fd, "1", 1); break; default: break; } @@ -460,7 +424,7 @@ void tracing(int on) case KV_26_LT24: prctl(0, 0); break; case KV_26_33: case KV_30: - write(trace_fd, "0", 1); + write_check(trace_fd, "0", 1); break; default:break; } @@ -737,6 +701,43 @@ try_again: return err; } +/* Work around lack of barriers in oldish uClibc-based toolchains. */ + +static struct thread_barrier { + pthread_mutex_t lock; + pthread_cond_t wait; + unsigned int count; +} align_barr, globalt_barr; + +static inline +void barrier_init(struct thread_barrier *__restrict barrier, +unsigned int count) +{ + pthread_mutex_init(&barrier->lock, NULL); + pthread_cond_init(&barrier->wait, NULL); + bar
[Xenomai-git] Philippe Gerum : demo/cyclictest: fixups for building over uClibc
Module: xenomai-3 Branch: master Commit: f23985b033a4576773d58a9b77fd9219037f47f6 URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=f23985b033a4576773d58a9b77fd9219037f47f6 Author: Philippe Gerum Date: Mon Oct 5 14:49:44 2015 +0200 demo/cyclictest: fixups for building over uClibc Mainly for building with outdated Blackfin toolchains. --- demo/posix/cyclictest/Makefile.am |3 +- demo/posix/cyclictest/cyclictest.c | 99 ++-- demo/posix/cyclictest/rt-utils.h |5 ++ 3 files changed, 56 insertions(+), 51 deletions(-) diff --git a/demo/posix/cyclictest/Makefile.am b/demo/posix/cyclictest/Makefile.am index ff62b37..a35fdca 100644 --- a/demo/posix/cyclictest/Makefile.am +++ b/demo/posix/cyclictest/Makefile.am @@ -14,8 +14,7 @@ cyclictest_CPPFLAGS = \ -Wno-implicit-function-declaration \ -Wno-missing-prototypes \ -Wno-nonnull\ - -Wno-unused-function\ - -Wno-unused-result + -Wno-unused-function cyclictest_SOURCES = \ cyclictest.c\ diff --git a/demo/posix/cyclictest/cyclictest.c b/demo/posix/cyclictest/cyclictest.c index 92c7043..0f59e21 100644 --- a/demo/posix/cyclictest/cyclictest.c +++ b/demo/posix/cyclictest/cyclictest.c @@ -43,52 +43,12 @@ #define DEFAULT_INTERVAL 1000 #define DEFAULT_DISTANCE 500 -#ifndef SCHED_IDLE -#define SCHED_IDLE 5 -#endif -#ifndef SCHED_NORMAL -#define SCHED_NORMAL SCHED_OTHER -#endif - #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) /* Ugly, but */ #define gettid() syscall(__NR_gettid) #define sigev_notify_thread_id _sigev_un._tid -#ifdef __UCLIBC__ -#define MAKE_PROCESS_CPUCLOCK(pid, clock) \ - ((~(clockid_t) (pid) << 3) | (clockid_t) (clock)) -#define CPUCLOCK_SCHED 2 - -static int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *req, - struct timespec *rem) -{ - if (clock_id == CLOCK_THREAD_CPUTIME_ID) - return -EINVAL; - if (clock_id == CLOCK_PROCESS_CPUTIME_ID) - clock_id = MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED); - - return syscall(__NR_clock_nanosleep, clock_id, flags, req, rem); -} - -int sched_setaffinity (__pid_t __pid, size_t __cpusetsize, - __const cpu_set_t *__cpuset) -{ - return -EINVAL; -} - -#undef CPU_SET -#undef CPU_ZERO -#define CPU_SET(cpu, cpusetp) -#define CPU_ZERO(cpusetp) - -#else -extern int clock_nanosleep(clockid_t __clock_id, int __flags, - __const struct timespec *__req, - struct timespec *__rem); -#endif - #define USEC_PER_SEC 100 #define NSEC_PER_SEC 10 @@ -113,6 +73,12 @@ int enable_events; static char *policyname(int policy); +#define write_check(__fd, __buf, __len)\ + do {\ + int __ret = write(__fd, __buf, __len); \ + (void)__ret;\ + } while (0); + enum { NOTRACE, CTXTSWITCH, @@ -196,8 +162,6 @@ static pthread_mutex_t break_thread_id_lock = PTHREAD_MUTEX_INITIALIZER; static pid_t break_thread_id = 0; static uint64_t break_thread_value = 0; -static pthread_barrier_t align_barr; -static pthread_barrier_t globalt_barr; static struct timespec globalt; /* Backup of kernel variables that we modify */ @@ -437,7 +401,7 @@ static void tracemark(char *fmt, ...) va_start(ap, fmt); len = vsnprintf(tracebuf, TRACEBUFSIZ, fmt, ap); va_end(ap); - write(tracemark_fd, tracebuf, len); + write_check(tracemark_fd, tracebuf, len); } @@ -450,7 +414,7 @@ void tracing(int on) case KV_26_LT24: prctl(0, 1); break; case KV_26_33: case KV_30: - write(trace_fd, "1", 1); + write_check(trace_fd, "1", 1); break; default: break; } @@ -460,7 +424,7 @@ void tracing(int on) case KV_26_LT24: prctl(0, 0); break; case KV_26_33: case KV_30: - write(trace_fd, "0", 1); + write_check(trace_fd, "0", 1); break; default:break; } @@ -737,6 +701,43 @@ try_again: return err; } +/* Work around lack of barriers in oldish uClibc-based toolchains. */ + +static struct thread_barrier { + pthread_mutex_t lock; + pthread_cond_t wait; + unsigned int count; +} align_barr, globalt_barr; + +static inline +void barrier_init(struct thread_barrier *__restrict barrier, +unsigned int count) +{ + pthread_mutex_init(&barrier->lock, NULL); + pthread_cond_init(&barrier->wait, NULL); + ba
[Xenomai-git] Philippe Gerum : demo/cyclictest: fixups for building over uClibc
Module: xenomai-3 Branch: next Commit: f23985b033a4576773d58a9b77fd9219037f47f6 URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=f23985b033a4576773d58a9b77fd9219037f47f6 Author: Philippe Gerum Date: Mon Oct 5 14:49:44 2015 +0200 demo/cyclictest: fixups for building over uClibc Mainly for building with outdated Blackfin toolchains. --- demo/posix/cyclictest/Makefile.am |3 +- demo/posix/cyclictest/cyclictest.c | 99 ++-- demo/posix/cyclictest/rt-utils.h |5 ++ 3 files changed, 56 insertions(+), 51 deletions(-) diff --git a/demo/posix/cyclictest/Makefile.am b/demo/posix/cyclictest/Makefile.am index ff62b37..a35fdca 100644 --- a/demo/posix/cyclictest/Makefile.am +++ b/demo/posix/cyclictest/Makefile.am @@ -14,8 +14,7 @@ cyclictest_CPPFLAGS = \ -Wno-implicit-function-declaration \ -Wno-missing-prototypes \ -Wno-nonnull\ - -Wno-unused-function\ - -Wno-unused-result + -Wno-unused-function cyclictest_SOURCES = \ cyclictest.c\ diff --git a/demo/posix/cyclictest/cyclictest.c b/demo/posix/cyclictest/cyclictest.c index 92c7043..0f59e21 100644 --- a/demo/posix/cyclictest/cyclictest.c +++ b/demo/posix/cyclictest/cyclictest.c @@ -43,52 +43,12 @@ #define DEFAULT_INTERVAL 1000 #define DEFAULT_DISTANCE 500 -#ifndef SCHED_IDLE -#define SCHED_IDLE 5 -#endif -#ifndef SCHED_NORMAL -#define SCHED_NORMAL SCHED_OTHER -#endif - #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) /* Ugly, but */ #define gettid() syscall(__NR_gettid) #define sigev_notify_thread_id _sigev_un._tid -#ifdef __UCLIBC__ -#define MAKE_PROCESS_CPUCLOCK(pid, clock) \ - ((~(clockid_t) (pid) << 3) | (clockid_t) (clock)) -#define CPUCLOCK_SCHED 2 - -static int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *req, - struct timespec *rem) -{ - if (clock_id == CLOCK_THREAD_CPUTIME_ID) - return -EINVAL; - if (clock_id == CLOCK_PROCESS_CPUTIME_ID) - clock_id = MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED); - - return syscall(__NR_clock_nanosleep, clock_id, flags, req, rem); -} - -int sched_setaffinity (__pid_t __pid, size_t __cpusetsize, - __const cpu_set_t *__cpuset) -{ - return -EINVAL; -} - -#undef CPU_SET -#undef CPU_ZERO -#define CPU_SET(cpu, cpusetp) -#define CPU_ZERO(cpusetp) - -#else -extern int clock_nanosleep(clockid_t __clock_id, int __flags, - __const struct timespec *__req, - struct timespec *__rem); -#endif - #define USEC_PER_SEC 100 #define NSEC_PER_SEC 10 @@ -113,6 +73,12 @@ int enable_events; static char *policyname(int policy); +#define write_check(__fd, __buf, __len)\ + do {\ + int __ret = write(__fd, __buf, __len); \ + (void)__ret;\ + } while (0); + enum { NOTRACE, CTXTSWITCH, @@ -196,8 +162,6 @@ static pthread_mutex_t break_thread_id_lock = PTHREAD_MUTEX_INITIALIZER; static pid_t break_thread_id = 0; static uint64_t break_thread_value = 0; -static pthread_barrier_t align_barr; -static pthread_barrier_t globalt_barr; static struct timespec globalt; /* Backup of kernel variables that we modify */ @@ -437,7 +401,7 @@ static void tracemark(char *fmt, ...) va_start(ap, fmt); len = vsnprintf(tracebuf, TRACEBUFSIZ, fmt, ap); va_end(ap); - write(tracemark_fd, tracebuf, len); + write_check(tracemark_fd, tracebuf, len); } @@ -450,7 +414,7 @@ void tracing(int on) case KV_26_LT24: prctl(0, 1); break; case KV_26_33: case KV_30: - write(trace_fd, "1", 1); + write_check(trace_fd, "1", 1); break; default: break; } @@ -460,7 +424,7 @@ void tracing(int on) case KV_26_LT24: prctl(0, 0); break; case KV_26_33: case KV_30: - write(trace_fd, "0", 1); + write_check(trace_fd, "0", 1); break; default:break; } @@ -737,6 +701,43 @@ try_again: return err; } +/* Work around lack of barriers in oldish uClibc-based toolchains. */ + +static struct thread_barrier { + pthread_mutex_t lock; + pthread_cond_t wait; + unsigned int count; +} align_barr, globalt_barr; + +static inline +void barrier_init(struct thread_barrier *__restrict barrier, +unsigned int count) +{ + pthread_mutex_init(&barrier->lock, NULL); + pthread_cond_init(&barrier->wait, NULL); + barr
[Xenomai-git] Philippe Gerum : demo/cyclictest: fixups for building over uClibc
Module: xenomai-3 Branch: next Commit: 2e6c41e345389f84f9c8fae9b4d453234fc6b191 URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=2e6c41e345389f84f9c8fae9b4d453234fc6b191 Author: Philippe Gerum Date: Mon Oct 5 14:49:44 2015 +0200 demo/cyclictest: fixups for building over uClibc Mainly for building with outdated Blackfin toolchains. --- demo/posix/cyclictest/Makefile.am |3 +- demo/posix/cyclictest/cyclictest.c | 99 ++-- demo/posix/cyclictest/rt-utils.h |5 ++ 3 files changed, 56 insertions(+), 51 deletions(-) diff --git a/demo/posix/cyclictest/Makefile.am b/demo/posix/cyclictest/Makefile.am index ff62b37..a35fdca 100644 --- a/demo/posix/cyclictest/Makefile.am +++ b/demo/posix/cyclictest/Makefile.am @@ -14,8 +14,7 @@ cyclictest_CPPFLAGS = \ -Wno-implicit-function-declaration \ -Wno-missing-prototypes \ -Wno-nonnull\ - -Wno-unused-function\ - -Wno-unused-result + -Wno-unused-function cyclictest_SOURCES = \ cyclictest.c\ diff --git a/demo/posix/cyclictest/cyclictest.c b/demo/posix/cyclictest/cyclictest.c index 92c7043..7fa796e 100644 --- a/demo/posix/cyclictest/cyclictest.c +++ b/demo/posix/cyclictest/cyclictest.c @@ -43,52 +43,12 @@ #define DEFAULT_INTERVAL 1000 #define DEFAULT_DISTANCE 500 -#ifndef SCHED_IDLE -#define SCHED_IDLE 5 -#endif -#ifndef SCHED_NORMAL -#define SCHED_NORMAL SCHED_OTHER -#endif - #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) /* Ugly, but */ #define gettid() syscall(__NR_gettid) #define sigev_notify_thread_id _sigev_un._tid -#ifdef __UCLIBC__ -#define MAKE_PROCESS_CPUCLOCK(pid, clock) \ - ((~(clockid_t) (pid) << 3) | (clockid_t) (clock)) -#define CPUCLOCK_SCHED 2 - -static int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *req, - struct timespec *rem) -{ - if (clock_id == CLOCK_THREAD_CPUTIME_ID) - return -EINVAL; - if (clock_id == CLOCK_PROCESS_CPUTIME_ID) - clock_id = MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED); - - return syscall(__NR_clock_nanosleep, clock_id, flags, req, rem); -} - -int sched_setaffinity (__pid_t __pid, size_t __cpusetsize, - __const cpu_set_t *__cpuset) -{ - return -EINVAL; -} - -#undef CPU_SET -#undef CPU_ZERO -#define CPU_SET(cpu, cpusetp) -#define CPU_ZERO(cpusetp) - -#else -extern int clock_nanosleep(clockid_t __clock_id, int __flags, - __const struct timespec *__req, - struct timespec *__rem); -#endif - #define USEC_PER_SEC 100 #define NSEC_PER_SEC 10 @@ -113,6 +73,12 @@ int enable_events; static char *policyname(int policy); +#define write_check(__fd, __buf, __len)\ + do {\ + int __ret = write(__fd, __buf, __len); \ + (void)__ret;\ + } while (0); + enum { NOTRACE, CTXTSWITCH, @@ -196,8 +162,6 @@ static pthread_mutex_t break_thread_id_lock = PTHREAD_MUTEX_INITIALIZER; static pid_t break_thread_id = 0; static uint64_t break_thread_value = 0; -static pthread_barrier_t align_barr; -static pthread_barrier_t globalt_barr; static struct timespec globalt; /* Backup of kernel variables that we modify */ @@ -437,7 +401,7 @@ static void tracemark(char *fmt, ...) va_start(ap, fmt); len = vsnprintf(tracebuf, TRACEBUFSIZ, fmt, ap); va_end(ap); - write(tracemark_fd, tracebuf, len); + write_check(tracemark_fd, tracebuf, len); } @@ -450,7 +414,7 @@ void tracing(int on) case KV_26_LT24: prctl(0, 1); break; case KV_26_33: case KV_30: - write(trace_fd, "1", 1); + write_check(trace_fd, "1", 1); break; default: break; } @@ -460,7 +424,7 @@ void tracing(int on) case KV_26_LT24: prctl(0, 0); break; case KV_26_33: case KV_30: - write(trace_fd, "0", 1); + write_check(trace_fd, "0", 1); break; default:break; } @@ -737,6 +701,43 @@ try_again: return err; } +/* Work around lack of barriers in oldish uClibc-based toolchains. */ + +static struct thread_barrier { + pthread_mutex_t lock; + pthread_cond_t wait; + unsigned int count; +} align_barr, globalt_barr; + +static inline +void barrier_init(struct thread_barrier *__restrict barrier, +unsigned int count) +{ + pthread_mutex_init(&barrier->lock, NULL); + pthread_cond_init(&barrier->wait, NULL); + barr