[db08c38] | 1 | /* |
---|
[50162e0] | 2 | * COPYRIGHT (c) 1989-2013. |
---|
[db08c38] | 3 | * On-Line Applications Research Corporation (OAR). |
---|
| 4 | * COPYRIGHT (c) 2013. |
---|
| 5 | * |
---|
| 6 | * The license and distribution terms for this file may be |
---|
| 7 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 8 | * http://www.rtems.org/license/LICENSE. |
---|
[db08c38] | 9 | */ |
---|
| 10 | |
---|
| 11 | #ifdef HAVE_CONFIG_H |
---|
| 12 | #include "config.h" |
---|
| 13 | #endif |
---|
| 14 | |
---|
| 15 | #include <timesys.h> |
---|
| 16 | #include <pthread.h> |
---|
| 17 | #include <sched.h> |
---|
[8fbe2e6] | 18 | #include <rtems/btimer.h> |
---|
[db08c38] | 19 | #include "test_support.h" |
---|
| 20 | |
---|
[fd46711] | 21 | const char rtems_test_name[] = "PSXTMTHREAD 05"; |
---|
| 22 | |
---|
[db08c38] | 23 | /* forward declarations to avoid warnings */ |
---|
| 24 | void *POSIX_Init(void *argument); |
---|
| 25 | void benchmark_pthread_create(void); |
---|
| 26 | void benchmark_pthread_setschedparam(void); |
---|
| 27 | void *test_thread(void *argument); |
---|
| 28 | |
---|
| 29 | void benchmark_pthread_setschedparam(void) |
---|
| 30 | { |
---|
| 31 | int status; |
---|
| 32 | int policy; |
---|
| 33 | struct sched_param param; |
---|
| 34 | pthread_t thread_ID; |
---|
| 35 | |
---|
| 36 | status = pthread_create(&thread_ID, NULL, test_thread, NULL); |
---|
| 37 | rtems_test_assert( status == 0 ); |
---|
| 38 | |
---|
| 39 | /* make test_thread equal to POSIX_Init() */ |
---|
| 40 | pthread_getschedparam(pthread_self(), &policy, ¶m); |
---|
[e9a1c99] | 41 | |
---|
[db08c38] | 42 | pthread_setschedparam(thread_ID, policy, ¶m); |
---|
| 43 | /* At this point, we've switched to test_thread */ |
---|
| 44 | |
---|
| 45 | /* Back from test_thread, switch to test_thread again */ |
---|
[e9a1c99] | 46 | param.sched_priority = sched_get_priority_min(policy); |
---|
[db08c38] | 47 | |
---|
| 48 | benchmark_timer_initialize(); |
---|
[e9a1c99] | 49 | //lower own priority to minimun, scheduler forces an involuntary context switch |
---|
| 50 | pthread_setschedparam(pthread_self(), policy, ¶m); |
---|
[db08c38] | 51 | } |
---|
| 52 | |
---|
| 53 | void *test_thread( |
---|
| 54 | void *argument |
---|
| 55 | ) |
---|
| 56 | { |
---|
[de549c3] | 57 | uint32_t end_time; |
---|
| 58 | |
---|
[db08c38] | 59 | sched_yield(); |
---|
| 60 | |
---|
| 61 | end_time = benchmark_timer_read(); |
---|
| 62 | put_time( |
---|
[50162e0] | 63 | "pthread_setschedparam: lower own priority preempt", |
---|
[db08c38] | 64 | end_time, |
---|
| 65 | 1, /* Only executed once */ |
---|
| 66 | 0, |
---|
| 67 | 0 |
---|
| 68 | ); |
---|
| 69 | |
---|
[fd46711] | 70 | TEST_END(); |
---|
[db08c38] | 71 | rtems_test_exit(0); |
---|
| 72 | //Empty thread used in pthread_create(). |
---|
| 73 | return NULL; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | void *POSIX_Init( |
---|
| 77 | void *argument |
---|
| 78 | ) |
---|
| 79 | { |
---|
| 80 | |
---|
[fd46711] | 81 | TEST_BEGIN(); |
---|
[db08c38] | 82 | benchmark_pthread_setschedparam(); |
---|
| 83 | |
---|
| 84 | rtems_test_assert( 1 ); |
---|
| 85 | return NULL; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | /* configuration information */ |
---|
| 89 | |
---|
| 90 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
| 91 | #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER |
---|
| 92 | |
---|
| 93 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 2 |
---|
| 94 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
| 95 | |
---|
| 96 | #define CONFIGURE_INIT |
---|
| 97 | |
---|
| 98 | #include <rtems/confdefs.h> |
---|
| 99 | /* end of file */ |
---|