Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:42

0001 /*
0002  *  COPYRIGHT (c) 1989-2013.
0003  *  On-Line Applications Research Corporation (OAR).
0004  *  COPYRIGHT (c) 2013  Chirayu Desai (chirayudesai1@gmail.com).
0005  *
0006  *  The license and distribution terms for this file may be
0007  *  found in the file LICENSE in this distribution or at
0008  *  http://www.rtems.org/license/LICENSE.
0009  */
0010 
0011 #ifdef HAVE_CONFIG_H
0012 #include "config.h"
0013 #endif
0014 
0015 #include <timesys.h>
0016 #include <pthread.h>
0017 #include <sched.h>
0018 #include <rtems/btimer.h>
0019 #include "test_support.h"
0020 
0021 const char rtems_test_name[] = "PSXTMTHREAD 06";
0022 
0023 /* forward declarations to avoid warnings */
0024 void *POSIX_Init(void *argument);
0025 void benchmark_pthread_create(void);
0026 void benchmark_pthread_setschedparam(void);
0027 void *test_thread(void *argument);
0028 
0029 void benchmark_pthread_setschedparam(void)
0030 {
0031   int status;
0032   int policy;
0033   struct sched_param param;
0034   pthread_t thread_ID;
0035 
0036   status = pthread_create(&thread_ID, NULL, test_thread, NULL);
0037   rtems_test_assert( status == 0 );
0038 
0039   /* make test_thread equal to POSIX_Init() */
0040   pthread_getschedparam(pthread_self(), &policy, &param);
0041   pthread_setschedparam(thread_ID, policy, &param);
0042   /* At this point, we've switched to test_thread */
0043 
0044   /* Back from test_thread, switch to test_thread again */
0045   param.sched_priority = sched_get_priority_max(policy) - 1;
0046 
0047   benchmark_timer_initialize();
0048   pthread_setschedparam(thread_ID, policy, &param);
0049 }
0050 
0051 void *test_thread(
0052   void *argument
0053 )
0054 {
0055   uint32_t end_time;
0056 
0057   /* switch to POSIX_Init */
0058   sched_yield();
0059 
0060   end_time = benchmark_timer_read();
0061 
0062   put_time(
0063     "pthread_setschedparam: raise other priority preempt",
0064     end_time,
0065     1,        /* Only executed once */
0066     0,
0067     0
0068   );
0069 
0070   TEST_END();
0071   rtems_test_exit(0);
0072   //Empty thread used in pthread_create().
0073   return NULL;
0074 }
0075 
0076 void *POSIX_Init(
0077   void *argument
0078 )
0079 {
0080 
0081   TEST_BEGIN();
0082   benchmark_pthread_setschedparam();
0083 
0084   rtems_test_assert( 1 );
0085   return NULL;
0086 }
0087 
0088 /* configuration information */
0089 
0090 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0091 #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
0092 
0093 #define CONFIGURE_MAXIMUM_POSIX_THREADS     2
0094 #define CONFIGURE_POSIX_INIT_THREAD_TABLE
0095 
0096 #define CONFIGURE_INIT
0097 
0098 #include <rtems/confdefs.h>
0099 /* end of file */