summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilippe Gerum <rpm@xenomai.org>2015-10-05 14:49:44 +0200
committerPhilippe Gerum <rpm@xenomai.org>2015-10-06 15:38:58 +0200
commitf23985b033a4576773d58a9b77fd9219037f47f6 (patch)
tree24c014e47ab88fffe4eeed6aa965b858bcf82e88
parent54161943141f38048a4fe741eeb6d62a533e8c1b (diff)
downloadxenomai-3-f23985b033a4576773d58a9b77fd9219037f47f6.tar.bz2
demo/cyclictest: fixups for building over uClibc
Mainly for building with outdated Blackfin toolchains.
-rw-r--r--demo/posix/cyclictest/Makefile.am3
-rw-r--r--demo/posix/cyclictest/cyclictest.c99
-rw-r--r--demo/posix/cyclictest/rt-utils.h5
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 = \
14 -Wno-implicit-function-declaration \ 14 -Wno-implicit-function-declaration \
15 -Wno-missing-prototypes \ 15 -Wno-missing-prototypes \
16 -Wno-nonnull \ 16 -Wno-nonnull \
17 -Wno-unused-function \ 17 -Wno-unused-function
18 -Wno-unused-result
19 18
20cyclictest_SOURCES = \ 19cyclictest_SOURCES = \
21 cyclictest.c \ 20 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 @@
43#define DEFAULT_INTERVAL 1000 43#define DEFAULT_INTERVAL 1000
44#define DEFAULT_DISTANCE 500 44#define DEFAULT_DISTANCE 500
45 45
46#ifndef SCHED_IDLE
47#define SCHED_IDLE 5
48#endif
49#ifndef SCHED_NORMAL
50#define SCHED_NORMAL SCHED_OTHER
51#endif
52
53#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 46#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
54 47
55/* Ugly, but .... */ 48/* Ugly, but .... */
56#define gettid() syscall(__NR_gettid) 49#define gettid() syscall(__NR_gettid)
57#define sigev_notify_thread_id _sigev_un._tid 50#define sigev_notify_thread_id _sigev_un._tid
58 51
59#ifdef __UCLIBC__
60#define MAKE_PROCESS_CPUCLOCK(pid, clock) \
61 ((~(clockid_t) (pid) << 3) | (clockid_t) (clock))
62#define CPUCLOCK_SCHED 2
63
64static int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *req,
65 struct timespec *rem)
66{
67 if (clock_id == CLOCK_THREAD_CPUTIME_ID)
68 return -EINVAL;
69 if (clock_id == CLOCK_PROCESS_CPUTIME_ID)
70 clock_id = MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED);
71
72 return syscall(__NR_clock_nanosleep, clock_id, flags, req, rem);
73}
74
75int sched_setaffinity (__pid_t __pid, size_t __cpusetsize,
76 __const cpu_set_t *__cpuset)
77{
78 return -EINVAL;
79}
80
81#undef CPU_SET
82#undef CPU_ZERO
83#define CPU_SET(cpu, cpusetp)
84#define CPU_ZERO(cpusetp)
85
86#else
87extern int clock_nanosleep(clockid_t __clock_id, int __flags,
88 __const struct timespec *__req,
89 struct timespec *__rem);
90#endif
91
92#define USEC_PER_SEC 1000000 52#define USEC_PER_SEC 1000000
93#define NSEC_PER_SEC 1000000000 53#define NSEC_PER_SEC 1000000000
94 54
@@ -113,6 +73,12 @@ int enable_events;
113 73
114static char *policyname(int policy); 74static char *policyname(int policy);
115 75
76#define write_check(__fd, __buf, __len) \
77 do { \
78 int __ret = write(__fd, __buf, __len); \
79 (void)__ret; \
80 } while (0);
81
116enum { 82enum {
117 NOTRACE, 83 NOTRACE,
118 CTXTSWITCH, 84 CTXTSWITCH,
@@ -196,8 +162,6 @@ static pthread_mutex_t break_thread_id_lock = PTHREAD_MUTEX_INITIALIZER;
196static pid_t break_thread_id = 0; 162static pid_t break_thread_id = 0;
197static uint64_t break_thread_value = 0; 163static uint64_t break_thread_value = 0;
198 164
199static pthread_barrier_t align_barr;
200static pthread_barrier_t globalt_barr;
201static struct timespec globalt; 165static struct timespec globalt;
202 166
203/* Backup of kernel variables that we modify */ 167/* Backup of kernel variables that we modify */
@@ -437,7 +401,7 @@ static void tracemark(char *fmt, ...)
437 va_start(ap, fmt); 401 va_start(ap, fmt);
438 len = vsnprintf(tracebuf, TRACEBUFSIZ, fmt, ap); 402 len = vsnprintf(tracebuf, TRACEBUFSIZ, fmt, ap);
439 va_end(ap); 403 va_end(ap);
440 write(tracemark_fd, tracebuf, len); 404 write_check(tracemark_fd, tracebuf, len);
441} 405}
442 406
443 407
@@ -450,7 +414,7 @@ void tracing(int on)
450 case KV_26_LT24: prctl(0, 1); break; 414 case KV_26_LT24: prctl(0, 1); break;
451 case KV_26_33: 415 case KV_26_33:
452 case KV_30: 416 case KV_30:
453 write(trace_fd, "1", 1); 417 write_check(trace_fd, "1", 1);
454 break; 418 break;
455 default: break; 419 default: break;
456 } 420 }
@@ -460,7 +424,7 @@ void tracing(int on)
460 case KV_26_LT24: prctl(0, 0); break; 424 case KV_26_LT24: prctl(0, 0); break;
461 case KV_26_33: 425 case KV_26_33:
462 case KV_30: 426 case KV_30:
463 write(trace_fd, "0", 1); 427 write_check(trace_fd, "0", 1);
464 break; 428 break;
465 default: break; 429 default: break;
466 } 430 }
@@ -737,6 +701,43 @@ try_again:
737 return err; 701 return err;
738} 702}
739 703
704/* Work around lack of barriers in oldish uClibc-based toolchains. */
705
706static struct thread_barrier {
707 pthread_mutex_t lock;
708 pthread_cond_t wait;
709 unsigned int count;
710} align_barr, globalt_barr;
711
712static inline
713void barrier_init(struct thread_barrier *__restrict barrier,
714 unsigned int count)
715{
716 pthread_mutex_init(&barrier->lock, NULL);
717 pthread_cond_init(&barrier->wait, NULL);
718 barrier->count = count;
719}
720
721static inline void barrier_destroy(struct thread_barrier *barrier)
722{
723 pthread_mutex_destroy(&barrier->lock);
724 pthread_cond_destroy(&barrier->wait);
725}
726
727static inline void barrier_wait(struct thread_barrier *barrier)
728{
729 pthread_mutex_lock(&barrier->lock);
730
731 if (barrier->count > 0) {
732 barrier->count--;
733 pthread_cond_broadcast(&barrier->wait);
734 while (barrier->count > 0)
735 pthread_cond_wait(&barrier->wait, &barrier->lock);
736 }
737
738 pthread_mutex_unlock(&barrier->lock);
739}
740
740/* 741/*
741 * timer thread 742 * timer thread
742 * 743 *
@@ -800,7 +801,7 @@ void *timerthread(void *param)
800 801
801 /* Get current time */ 802 /* Get current time */
802 if (aligned || secaligned) { 803 if (aligned || secaligned) {
803 pthread_barrier_wait(&globalt_barr); 804 barrier_wait(&globalt_barr);
804 if (par->tnum == 0) { 805 if (par->tnum == 0) {
805 clock_gettime(par->clock, &globalt); 806 clock_gettime(par->clock, &globalt);
806 if (secaligned) { 807 if (secaligned) {
@@ -813,7 +814,7 @@ void *timerthread(void *param)
813 globalt.tv_nsec = 0; 814 globalt.tv_nsec = 0;
814 } 815 }
815 } 816 }
816 pthread_barrier_wait(&align_barr); 817 barrier_wait(&align_barr);
817 now = globalt; 818 now = globalt;
818 if(offset) { 819 if(offset) {
819 if (aligned) 820 if (aligned)
@@ -1558,8 +1559,8 @@ static void process_options (int argc, char *argv[], int max_cpus)
1558 error = 1; 1559 error = 1;
1559 1560
1560 if (aligned || secaligned) { 1561 if (aligned || secaligned) {
1561 pthread_barrier_init(&globalt_barr, NULL, num_threads); 1562 barrier_init(&globalt_barr, num_threads);
1562 pthread_barrier_init(&align_barr, NULL, num_threads); 1563 barrier_init(&align_barr, num_threads);
1563 } 1564 }
1564 1565
1565 if (error) { 1566 if (error) {
diff --git a/demo/posix/cyclictest/rt-utils.h b/demo/posix/cyclictest/rt-utils.h
index ef0f6ac..a7c7640 100644
--- a/demo/posix/cyclictest/rt-utils.h
+++ b/demo/posix/cyclictest/rt-utils.h
@@ -2,6 +2,11 @@
2#define __RT_UTILS_H 2#define __RT_UTILS_H
3 3
4#include <stdint.h> 4#include <stdint.h>
5#include <linux/sched.h>
6
7#ifndef SCHED_NORMAL
8#define SCHED_NORMAL SCHED_OTHER
9#endif
5 10
6#define _STR(x) #x 11#define _STR(x) #x
7#define STR(x) _STR(x) 12#define STR(x) _STR(x)
Mirror
http://xenomai.org/mirroring-xenomai-git-repositories-with-grokmirror/