Module: xenomai-gch Branch: for-arm64 Commit: b3485fb222e4a1623deb31701cfa473fefea0e2e URL: http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=b3485fb222e4a1623deb31701cfa473fefea0e2e
Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org> Date: Thu Oct 29 22:57:48 2015 +0100 testsuite/switchtest: fix mode switches Since the changes in pthread_setmode_np() API, switchtest threads all ran in primary mode, fix this by using the cobalt_thread_relax() service to switch to secondary mode instead of pthread_setmode_np(). --- testsuite/switchtest/switchtest.c | 50 ++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/testsuite/switchtest/switchtest.c b/testsuite/switchtest/switchtest.c index 8f54a94..5c102a2 100644 --- a/testsuite/switchtest/switchtest.c +++ b/testsuite/switchtest/switchtest.c @@ -38,6 +38,7 @@ #include <asm/xenomai/uapi/fptest.h> #include <cobalt/trace.h> #include <rtdm/testing.h> +#include <sys/cobalt.h> #if CONFIG_SMP #define smp_sched_setaffinity(pid,len,mask) sched_setaffinity(pid,len,mask) @@ -89,6 +90,7 @@ static pthread_mutex_t headers_lock; static unsigned long data_lines = 21; static unsigned freeze_on_error; static int fp_features; +static pthread_t main_tid; static inline unsigned stack_size(unsigned size) { @@ -98,7 +100,7 @@ static inline unsigned stack_size(unsigned size) static inline void clean_exit(int retval) { status = retval; - kill(getpid(), SIGTERM); + __STD(pthread_kill(main_tid, SIGTERM)); for (;;) /* Wait for cancellation. */ __STD(sem_wait(&sleeper_start)); @@ -427,6 +429,18 @@ static void *fpu_stress(void *cookie) return NULL; } +static void set_mode(const char *prefix, int fd, unsigned mode) +{ + switch (mode) { + case 1: + cobalt_thread_harden(); + return; + + case 2: + cobalt_thread_relax(); + } +} + static void *rtup(void *cookie) { struct task_params *param = (struct task_params *) cookie; @@ -450,12 +464,7 @@ static void *rtup(void *cookie) allowed when suspended in ioctl. */ pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); - if ((err = pthread_setmode_np(0, PTHREAD_CONFORMING, NULL))) { - fprintf(stderr, - "rtup: pthread_setmode_np: %s\n", - strerror(err)); - clean_exit(EXIT_FAILURE); - } + set_mode("rtup", fd, 1); do { err = ioctl(fd, RTTST_RTIOC_SWTEST_PEND, ¶m->swt); @@ -536,12 +545,7 @@ static void *rtus(void *cookie) allowed when suspended in ioctl. */ pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); - if ((err = pthread_setmode_np(PTHREAD_CONFORMING, 0, NULL))) { - fprintf(stderr, - "rtus: pthread_setmode_np: %s\n", - strerror(err)); - clean_exit(EXIT_FAILURE); - } + set_mode("rtus", fd, 2); do { err = ioctl(fd, RTTST_RTIOC_SWTEST_PEND, ¶m->swt); @@ -622,12 +626,8 @@ static void *rtuo(void *cookie) allowed when suspended in ioctl. */ pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); - if ((err = pthread_setmode_np(0, PTHREAD_CONFORMING, NULL))) { - fprintf(stderr, - "rtup: pthread_setmode_np: %s\n", - strerror(err)); - clean_exit(EXIT_FAILURE); - } + mode = 1; + set_mode("rtuo", fd, mode); do { err = ioctl(fd, RTTST_RTIOC_SWTEST_PEND, ¶m->swt); } while (err == -1 && errno == EINTR); @@ -635,7 +635,6 @@ static void *rtuo(void *cookie) if (err == -1) return NULL; - mode = PTHREAD_CONFORMING; for (;;) { unsigned expected, fp_val; @@ -680,14 +679,8 @@ static void *rtuo(void *cookie) /* Switch mode. */ if (i % 3 == 2) { - mode = PTHREAD_CONFORMING - mode; - if ((err = pthread_setmode_np - (PTHREAD_CONFORMING - mode, mode, NULL))) { - fprintf(stderr, - "rtuo: pthread_setmode_np: %s\n", - strerror(err)); - clean_exit(EXIT_FAILURE); - } + mode = 3 - mode; + set_mode("rtuo", fd, mode); } if(++i == 4000000) @@ -1133,6 +1126,7 @@ int main(int argc, const char *argv[]) int sig; status = EXIT_SUCCESS; + main_tid = pthread_self(); /* Initializations. */ if (__STD(sem_init(&sleeper_start, 0, 0))) { _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org http://xenomai.org/mailman/listinfo/xenomai-git