Changeset 917884c in rtems


Ignore:
Timestamp:
06/15/16 08:39:09 (7 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
5, master
Children:
661e0e63
Parents:
d6467102
git-author:
Sebastian Huber <sebastian.huber@…> (06/15/16 08:39:09)
git-committer:
Sebastian Huber <sebastian.huber@…> (06/15/16 08:43:34)
Message:

posix: Fix poradic server initial CPU budget

Update #2738.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • cpukit/posix/include/rtems/posix/pthreadimpl.h

    rd6467102 r917884c  
    5555
    5656RTEMS_INLINE_ROUTINE void _POSIX_Threads_Sporadic_timer_insert(
     57  Thread_Control    *the_thread,
    5758  POSIX_API_Control *api
    5859)
    5960{
     61  the_thread->cpu_time_budget =
     62    _Timespec_To_ticks( &api->Attributes.schedparam.sched_ss_init_budget );
     63
    6064  _Watchdog_Per_CPU_insert_relative(
    6165    &api->Sporadic_timer,
  • cpukit/posix/src/pthread.c

    rd6467102 r917884c  
    114114  _Thread_State_acquire( the_thread, &lock_context );
    115115
    116   the_thread->cpu_time_budget =
    117     _Timespec_To_ticks( &api->schedparam.sched_ss_init_budget );
    118 
    119116  _Watchdog_Per_CPU_remove_relative( &api->Sporadic_timer );
    120   _POSIX_Threads_Sporadic_timer_insert( api );
     117  _POSIX_Threads_Sporadic_timer_insert( the_thread, api );
    121118
    122119  new_priority = _POSIX_Priority_To_core( api->schedparam.sched_priority );
  • cpukit/posix/src/pthreadcreate.c

    rd6467102 r917884c  
    230230  api->schedparam  = schedparam;
    231231
     232  if ( schedpolicy == SCHED_SPORADIC ) {
     233    _ISR_lock_ISR_disable( &lock_context );
     234    _POSIX_Threads_Sporadic_timer_insert( the_thread, api );
     235    _ISR_lock_ISR_enable( &lock_context );
     236  }
     237
    232238  /*
    233239   *  POSIX threads are allocated and started in one operation.
     
    250256  #endif
    251257
    252   if ( schedpolicy == SCHED_SPORADIC ) {
    253     _ISR_lock_ISR_disable( &lock_context );
    254     _POSIX_Threads_Sporadic_timer_insert( api );
    255     _ISR_lock_ISR_enable( &lock_context );
    256   }
    257 
    258258  /*
    259259   *  Return the id and indicate we successfully created the thread
  • testsuites/psxtests/psx12/init.c

    rd6467102 r917884c  
    1212#endif
    1313
     14#include <sys/time.h>
     15#include <errno.h>
     16#include <inttypes.h>
    1417#include <sched.h>
    15 #include <errno.h>
     18#include <stdint.h>
     19#include <unistd.h>
    1620
    1721#include <pmacros.h>
     
    1923const char rtems_test_name[] = "PSX 12";
    2024
     25#define SS_REPL_PERIOD_US 200000
     26
     27#define SS_INIT_BUDGET_US 100000
     28
     29#define SS_PRIO_LOW 1
     30
     31#define SS_PRIO_HIGH 2
     32
     33#define SS_SAMPLE_PERIODS 3
     34
     35typedef struct {
     36  uint64_t start;
     37  struct {
     38    uint64_t high;
     39    uint64_t low;
     40  } samples[ SS_SAMPLE_PERIODS ];
     41} test_context;
     42
     43static test_context test_instance;
     44
     45static void wait_for_prio( int prio )
     46{
     47  int                status;
     48  int                policy;
     49  struct sched_param param;
     50
     51  do {
     52    status = pthread_getschedparam( pthread_self(), &policy, &param );
     53    rtems_test_assert( status == 0 );
     54  } while ( prio != param.sched_priority );
     55}
     56
     57static uint64_t timeval_to_us( const struct timeval *tv )
     58{
     59  uint64_t t;
     60
     61  t = tv->tv_sec;
     62  t *= 1000000;
     63  t += tv->tv_usec;
     64
     65  return t;
     66}
     67
     68static uint64_t now( void )
     69{
     70  struct timeval now;
     71
     72  gettimeofday( &now, NULL );
     73
     74  return timeval_to_us( &now );
     75}
     76
     77static uint64_t delta( test_context *ctx )
     78{
     79  return now() - ctx->start;
     80}
     81
    2182static void *sporadic_server( void *argument )
    2283{
     84  test_context *ctx;
     85  size_t        i;
     86
     87  ctx = argument;
     88
     89  for ( i = 0 ; i < SS_SAMPLE_PERIODS ; ++i ) {
     90    wait_for_prio( SS_PRIO_LOW );
     91    ctx->samples[ i ].high = delta( ctx );
     92    wait_for_prio( SS_PRIO_HIGH );
     93    ctx->samples[ i ].low = delta( ctx );
     94  }
     95
    2396  puts( "Sporadic Server: exitting" );
    2497
     
    28101static void *POSIX_Init( void *argument )
    29102{
     103  test_context       *ctx;
    30104  int                 status;
    31105  pthread_attr_t      attr;
    32106  pthread_t           thread;
    33107  struct sched_param  schedparam;
     108  size_t              i;
    34109
    35110  TEST_BEGIN();
     111
     112  ctx = &test_instance;
    36113
    37114  /* set the time of day, and print our buffer in multiple ways */
     
    87164  /* invalid sched_ss_low_priority error */
    88165
    89   schedparam.sched_ss_repl_period.tv_sec = 2;
    90   schedparam.sched_ss_repl_period.tv_nsec = 0;
    91   schedparam.sched_ss_init_budget.tv_sec = 1;
    92   schedparam.sched_ss_init_budget.tv_nsec = 0;
    93 
    94   schedparam.sched_priority = 200;
     166  schedparam.sched_ss_repl_period.tv_sec = 0;
     167  schedparam.sched_ss_repl_period.tv_nsec = SS_REPL_PERIOD_US * 1000;
     168  schedparam.sched_ss_init_budget.tv_sec = 0;
     169  schedparam.sched_ss_init_budget.tv_nsec = SS_INIT_BUDGET_US * 1000;
     170
     171  schedparam.sched_priority = SS_PRIO_HIGH;
    95172  schedparam.sched_ss_low_priority = -1;
    96173
     
    104181  /* create a thread as a sporadic server */
    105182
    106   schedparam.sched_ss_repl_period.tv_sec = 2;
    107   schedparam.sched_ss_repl_period.tv_nsec = 0;
    108   schedparam.sched_ss_init_budget.tv_sec = 1;
    109   schedparam.sched_ss_init_budget.tv_nsec = 0;
    110 
    111   schedparam.sched_priority = sched_get_priority_max( SCHED_FIFO );
    112   schedparam.sched_ss_low_priority = sched_get_priority_max( SCHED_FIFO ) - 6;
     183  schedparam.sched_ss_repl_period.tv_sec = 0;
     184  schedparam.sched_ss_repl_period.tv_nsec = SS_REPL_PERIOD_US * 1000;
     185  schedparam.sched_ss_init_budget.tv_sec = 0;
     186  schedparam.sched_ss_init_budget.tv_nsec = SS_INIT_BUDGET_US * 1000;
     187
     188  schedparam.sched_priority = SS_PRIO_HIGH;
     189  schedparam.sched_ss_low_priority = SS_PRIO_LOW;
    113190
    114191  status = pthread_attr_setschedparam( &attr, &schedparam );
     
    116193
    117194  puts( "Init: pthread_create - SUCCESSFUL" );
    118   status = pthread_create( &thread, &attr, sporadic_server, NULL );
     195
     196  /* Align with clock tick */
     197  usleep( 1 );
     198
     199  ctx->start = now();
     200
     201  status = pthread_create( &thread, &attr, sporadic_server, ctx );
    119202  rtems_test_assert( !status );
    120203
     
    122205  rtems_test_assert( !status );
    123206
    124     /* switch to Task_1 */
     207  for ( i = 0 ; i < SS_SAMPLE_PERIODS ; ++i ) {
     208    printf( "[%zu] H %6" PRIu64 "us\n", i, ctx->samples[ i ].high );
     209    printf( "[%zu] L %6" PRIu64 "us\n", i, ctx->samples[ i ].low );
     210    rtems_test_assert( ctx->samples[ i ].low / SS_REPL_PERIOD_US == i + 1 );
     211  }
    125212
    126213  TEST_END();
  • testsuites/psxtests/psx12/psx12.scn

    rd6467102 r917884c  
    99Init: pthread_create - SUCCESSFUL
    1010Sporadic Server: exitting
     11[0] H  99902us
     12[0] L 200008us
     13[1] H 289908us
     14[1] L 400009us
     15[2] H 489903us
     16[2] L 600009us
    1117*** END OF TEST PSX 12 ***
Note: See TracChangeset for help on using the changeset viewer.