Changeset af9115f3 in rtems


Ignore:
Timestamp:
Oct 6, 2017, 8:07:38 AM (18 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
da9f5f1
Parents:
65012bf
git-author:
Sebastian Huber <sebastian.huber@…> (10/06/17 08:07:38)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/09/17 12:52:58)
Message:

posix: Simplify POSIX_API_Control

Return stack area via pthread_getattr_np().

Simplify

  • pthread_attr_setaffinity_np(), and
  • pthread_attr_getaffinity_np()

and let the scheduler do the more sophisticated error checks.

Make

  • pthread_setaffinity_np(),
  • pthread_getaffinity_np(),
  • pthread_attr_setaffinity_np(), and
  • pthread_attr_getaffinity_np()

available in all configurations.

Update #2514.
Close #3145.
Close #3168.

Files:
18 edited

Legend:

Unmodified
Added
Removed
  • cpukit/posix/Makefile.am

    r65012bf raf9115f3  
    8989    src/mutexlocksupp.c src/mutexsetprioceiling.c src/mutextimedlock.c \
    9090    src/mutextrylock.c src/mutexunlock.c
     91
     92## PTHREAD_AFFINITY_C_FILES
     93libposix_a_SOURCES += src/pthreadattrsetaffinitynp.c \
     94    src/pthreadattrgetaffinitynp.c  src/pthreadgetaffinitynp.c   \
     95    src/pthreadsetaffinitynp.c
    9196
    9297if HAS_PTHREADS
     
    149154libposix_a_SOURCES += src/pthreadattrcompare.c
    150155
    151 if HAS_SMP
    152 ## PTHREAD_AFFINITY_C_FILES
    153 libposix_a_SOURCES += src/pthreadattrsetaffinitynp.c \
    154     src/pthreadattrgetaffinitynp.c  src/pthreadgetaffinitynp.c   \
    155     src/pthreadsetaffinitynp.c
    156 endif
    157 
    158156## PSIGNAL_C_FILES
    159157libposix_a_SOURCES += src/psignal.c src/alarm.c src/kill.c src/killinfo.c \
  • cpukit/posix/include/rtems/posix/pthreadimpl.h

    r65012bf raf9115f3  
    6060{
    6161  the_thread->cpu_time_budget =
    62     _Timespec_To_ticks( &api->Attributes.schedparam.sched_ss_init_budget );
     62    _Timespec_To_ticks( &api->schedparam.sched_ss_init_budget );
    6363
    6464  _Watchdog_Per_CPU_insert_relative(
    6565    &api->Sporadic.Timer,
    6666    _Per_CPU_Get(),
    67     _Timespec_To_ticks( &api->Attributes.schedparam.sched_ss_repl_period )
     67    _Timespec_To_ticks( &api->schedparam.sched_ss_repl_period )
    6868  );
    6969}
  • cpukit/posix/include/rtems/posix/threadsup.h

    r65012bf raf9115f3  
    4444  Thread_Control         *thread;
    4545
    46   /** This is the POSIX threads attribute set. */
    47   pthread_attr_t          Attributes;
     46  /** Created with explicit or inherited scheduler. */
     47  bool created_with_explicit_scheduler;
     48
     49  /** The scheduler policy. */
     50  int schedpolicy;
     51
     52  /** The scheduler parameters */
     53  struct sched_param schedparam;
    4854
    4955  /**
  • cpukit/posix/preinstall.am

    r65012bf raf9115f3  
    141141PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/timerimpl.h
    142142endif
    143 if HAS_PTHREADS
    144 endif
  • cpukit/posix/src/pthread.c

    r65012bf raf9115f3  
    7676  #endif
    7777  .detachstate             = PTHREAD_CREATE_JOINABLE,    /* detachstate */
    78   .affinitysetsize         = 0,
    79   .affinityset             = NULL,
    80   .affinitysetpreallocated = {{0x0}}
     78  .affinitysetsize         =
     79    sizeof( _POSIX_Threads_Default_attributes.affinitysetpreallocated ),
     80  .affinityset             =
     81    &_POSIX_Threads_Default_attributes.affinitysetpreallocated,
     82  .affinitysetpreallocated = {{0x1}}
    8183};
    8284
     
    167169  /* XXX check all fields are touched */
    168170  api->thread = created;
    169   _POSIX_Threads_Initialize_attributes( &api->Attributes );
    170   api->Attributes.schedparam.sched_priority = _POSIX_Priority_From_core(
     171  api->schedparam.sched_priority = _POSIX_Priority_From_core(
    171172    _Thread_Scheduler_get_home( created ),
    172173    _Thread_Get_priority( created )
     
    204205  _Thread_State_acquire( executing, &lock_context );
    205206
    206   if ( api->Attributes.schedpolicy == SCHED_SPORADIC ) {
     207  if ( api->schedpolicy == SCHED_SPORADIC ) {
    207208    _Watchdog_Per_CPU_remove_relative( &api->Sporadic.Timer );
    208209  }
  • cpukit/posix/src/pthreadattrcompare.c

    r65012bf raf9115f3  
    3333    return 1;
    3434
    35   if ( attr1->stackaddr != attr2->stackaddr )
     35  if (
     36    attr1->stackaddr != NULL &&
     37      attr2->stackaddr != NULL &&
     38      attr1->stackaddr != attr2->stackaddr )
    3639    return 1;
    3740
  • cpukit/posix/src/pthreadattrgetaffinitynp.c

    r65012bf raf9115f3  
    2525#include <errno.h>
    2626
    27 #include <rtems/posix/pthreadimpl.h>
    28 #include <rtems/posix/priorityimpl.h>
    29 #include <rtems/score/threadimpl.h>
    30 
    3127int pthread_attr_getaffinity_np(
    3228  const pthread_attr_t *attr,
     
    3531)
    3632{
    37   if ( !cpuset )
    38     return EFAULT;
    39   if ( !attr )
    40     return EFAULT;
     33  if ( attr == NULL || !attr->is_initialized ) {
     34    return EINVAL;
     35  }
    4136
    42   if ( cpusetsize != attr->affinitysetsize)
     37  if ( cpuset == NULL || cpusetsize != attr->affinitysetsize ) {
    4338    return EINVAL;
     39  }
    4440
    4541  CPU_COPY( attr->affinityset, cpuset );
  • cpukit/posix/src/pthreadattrsetaffinitynp.c

    r65012bf raf9115f3  
    2525#include <errno.h>
    2626
    27 #include <rtems/posix/pthreadimpl.h>
    28 #include <rtems/posix/priorityimpl.h>
    29 #include <rtems/score/threadimpl.h>
    30 #include <rtems/score/cpusetimpl.h>
    31 
    3227int pthread_attr_setaffinity_np(
    3328  pthread_attr_t    *attr,
     
    3631)
    3732{
    38   if ( !cpuset )
    39     return EFAULT;
    40   if ( !attr )
    41     return EFAULT;
     33  if ( attr == NULL || !attr->is_initialized ) {
     34    return EINVAL;
     35  }
    4236
    43   if (! _CPU_set_Is_valid( cpuset, cpusetsize ) )
     37  if ( cpuset == NULL || cpusetsize != attr->affinitysetsize ) {
    4438    return EINVAL;
     39  }
    4540
    4641  CPU_COPY( cpuset, attr->affinityset );
    47 
    4842  return 0;
    4943}
  • cpukit/posix/src/pthreadcreate.c

    r65012bf raf9115f3  
    243243  api = the_thread->API_Extensions[ THREAD_API_POSIX ];
    244244
    245   _POSIX_Threads_Copy_attributes( &api->Attributes, the_attr );
     245  api->created_with_explicit_scheduler =
     246    ( the_attr->inheritsched == PTHREAD_EXPLICIT_SCHED );
     247  api->schedpolicy = the_attr->schedpolicy;
     248  api->schedparam = the_attr->schedparam;
    246249  _Priority_Node_initialize( &api->Sporadic.Low_priority, core_low_prio );
    247250  _Priority_Node_set_inactive( &api->Sporadic.Low_priority );
  • cpukit/posix/src/pthreadgetaffinitynp.c

    r65012bf raf9115f3  
    2626#include <errno.h>
    2727
    28 #include <rtems/posix/pthreadimpl.h>
    29 #include <rtems/posix/priorityimpl.h>
    3028#include <rtems/score/threadimpl.h>
    3129#include <rtems/score/schedulerimpl.h>
  • cpukit/posix/src/pthreadgetattrnp.c

    r65012bf raf9115f3  
    2222#include <pthread.h>
    2323#include <errno.h>
     24#include <string.h>
    2425
    2526#include <rtems/posix/pthreadimpl.h>
     27#include <rtems/score/schedulerimpl.h>
    2628#include <rtems/score/threadimpl.h>
    2729
     
    3436  ISR_lock_Context   lock_context;
    3537  POSIX_API_Control *api;
     38  bool               ok;
    3639
    3740  if ( attr == NULL ) {
    3841    return EINVAL;
    3942  }
     43
     44  attr = memset( attr, 0, sizeof( *attr ) );
    4045
    4146  the_thread = _Thread_Get( thread, &lock_context );
     
    4853
    4954  api = the_thread->API_Extensions[ THREAD_API_POSIX ];
    50   _POSIX_Threads_Copy_attributes( attr, &api->Attributes);
     55
     56  attr->is_initialized = true;
     57  attr->stackaddr = the_thread->Start.Initial_stack.area;
     58  attr->stacksize = the_thread->Start.Initial_stack.size;
     59  attr->contentionscope = PTHREAD_SCOPE_PROCESS;
     60
     61  if ( api->created_with_explicit_scheduler ) {
     62    attr->inheritsched = PTHREAD_EXPLICIT_SCHED;
     63  } else {
     64    attr->inheritsched = PTHREAD_INHERIT_SCHED;
     65  }
     66
     67  attr->schedpolicy = api->schedpolicy;
     68  attr->schedparam = api->schedparam;
     69  attr->cputime_clock_allowed = 1;
    5170
    5271  if ( _Thread_Is_joinable( the_thread ) ) {
     
    5675  }
    5776
     77  attr->affinityset = &attr->affinitysetpreallocated;
     78  attr->affinitysetsize = sizeof( attr->affinitysetpreallocated );
     79  ok = _Scheduler_Get_affinity(
     80    the_thread,
     81    attr->affinitysetsize,
     82    attr->affinityset
     83  );
     84
    5885  _Thread_State_release( the_thread, &lock_context );
    59   return 0;
     86  return ok ? 0 : EINVAL;
    6087}
  • cpukit/posix/src/pthreadgetschedparam.c

    r65012bf raf9115f3  
    5757  _Thread_Wait_acquire_critical( the_thread, &queue_context );
    5858
    59   *policy = api->Attributes.schedpolicy;
    60   *param  = api->Attributes.schedparam;
     59  *policy = api->schedpolicy;
     60  *param  = api->schedparam;
    6161
    6262  scheduler = _Thread_Scheduler_get_home( the_thread );
  • cpukit/posix/src/pthreadsetaffinitynp.c

    r65012bf raf9115f3  
    2525#include <errno.h>
    2626
    27 #include <rtems/posix/pthreadimpl.h>
    28 #include <rtems/posix/priorityimpl.h>
    2927#include <rtems/score/threadimpl.h>
    3028#include <rtems/score/cpusetimpl.h>
     
    6159  );
    6260
    63   if ( ok ) {
    64     POSIX_API_Control *api;
    65 
    66     api = the_thread->API_Extensions[ THREAD_API_POSIX ];
    67     CPU_COPY( cpuset, api->Attributes.affinityset );
    68   }
    69 
    7061  _Thread_State_release( the_thread, &lock_context );
    7162  _Thread_Dispatch_enable( cpu_self );
  • cpukit/posix/src/pthreadsetschedparam.c

    r65012bf raf9115f3  
    9595  }
    9696
    97   api->Attributes.schedpolicy = policy;
    98   api->Attributes.schedparam  = *param;
     97  api->schedpolicy = policy;
     98  api->schedparam  = *param;
    9999
    100100  the_thread->budget_algorithm = budget_algorithm;
  • testsuites/psxtests/psxgetattrnp01/init.c

    r65012bf raf9115f3  
    4242  int                 sc;
    4343  int                 value;
     44  void               *stackaddr;
     45  size_t              stacksize;
     46  cpu_set_t           set;
    4447
    4548  puts("Thread - pthread_getattr_np - Verify value");
     
    6265  rtems_test_assert( !sc );
    6366
     67  puts("Thread - Verify get stack");
     68  stackaddr = NULL;
     69  stacksize = 0;
     70  sc = pthread_attr_getstack( &attr, &stackaddr, &stacksize );
     71  rtems_test_assert( sc == 0 );
     72  rtems_test_assert( stackaddr != NULL );
     73  rtems_test_assert( stacksize != 0 );
     74
     75  puts("Thread - Verify contention scope");
     76  sc = pthread_attr_getscope( &attr, &value );
     77  rtems_test_assert( sc == 0 );
     78  rtems_test_assert( value == PTHREAD_SCOPE_PROCESS );
     79
     80  puts("Thread - Verify explicit scheduler");
     81  sc = pthread_attr_getinheritsched( &attr, &value );
     82  rtems_test_assert( sc == 0 );
     83  rtems_test_assert( value == PTHREAD_EXPLICIT_SCHED );
     84
    6485  puts("Thread - Verify SCHED_FIFO policy");
    6586  sc = pthread_attr_getschedpolicy( &attr, &value );
     
    7495  puts("Thread - Verify detached");
    7596  sc = pthread_attr_getdetachstate( &attr, &value );
     97  rtems_test_assert( sc == 0 );
    7698  rtems_test_assert( value == PTHREAD_CREATE_DETACHED );
     99
     100  puts("Thread - Verify affinity");
     101  CPU_ZERO( &set );
     102  sc = pthread_attr_getaffinity_np( &attr, sizeof( set ), &set );
     103  rtems_test_assert( sc == 0 );
     104  rtems_test_assert( CPU_ISSET( 0, &set ) );
     105  rtems_test_assert( !CPU_ISSET( 1, &set ) );
     106
     107  puts("Thread - Destroy");
     108  sc = pthread_attr_destroy( &attr );
     109  rtems_test_assert( sc == 0 );
    77110
    78111  return NULL; /* just so the compiler thinks we returned something */
  • testsuites/psxtests/psxgetattrnp01/psxgetattrnp01.scn

    r65012bf raf9115f3  
    1 *** POSIX ATTRIBUTE TEST 1 ***
     1*** BEGIN OF TEST PSXGETATTRNP 1 ***
    22Init - pthread_getattr_np - attr NULL - EINVAL
    33Init - pthread_getattr_np - invalid id - ESRCH
     
    1717Thread - Detach
    1818Thread - pthread_getattr_np
     19Thread - Verify get stack
     20Thread - Verify contention scope
     21Thread - Verify explicit scheduler
    1922Thread - Verify SCHED_FIFO policy
    2023Thread - Verify max priority
    2124Thread - Verify detached
    22 *** END OF POSIX ATTRIBUTE TEST 1 ***
     25Thread - Verify affinity
     26Thread - Destroy
     27*** END OF TEST PSXGETATTRNP 1 ***
  • testsuites/smptests/smppsxaffinity01/init.c

    r65012bf raf9115f3  
    3939  pthread_attr_t      attr;
    4040
     41  sc = pthread_attr_init( &attr );
     42  rtems_test_assert( sc == 0 );
     43
    4144  /* Verify pthread_attr_getaffinity_np validates attr  */
    42   puts( "Init - pthread_attr_getaffinity_np - Invalid attr - EFAULT" );
    43   sc = pthread_attr_getaffinity_np( NULL, sizeof(cpu_set_t), &cpuset );
    44   rtems_test_assert( sc == EFAULT );
     45  puts( "Init - pthread_attr_getaffinity_np - Invalid attr - EINVAL" );
     46  sc = pthread_attr_getaffinity_np( NULL, sizeof( cpuset ), &cpuset );
     47  rtems_test_assert( sc == EINVAL );
    4548
    4649  /* Verify pthread_attr_getaffinity_np validates cpuset */
    47   puts( "Init - pthread_attr_getaffinity_np - Invalid attr - EFAULT" );
    48   sc = pthread_attr_getaffinity_np( &attr, sizeof(cpu_set_t), NULL );
    49   rtems_test_assert( sc == EFAULT );
     50  puts( "Init - pthread_attr_getaffinity_np - Invalid attr - EINVAL" );
     51  sc = pthread_attr_getaffinity_np( &attr, sizeof( cpuset ), NULL );
     52  rtems_test_assert( sc == EINVAL );
    5053
    5154  /* Verify pthread_attr_getaffinity_np validates cpusetsize */
    5255  puts( "Init - pthread_attr_getaffinity_np - Invalid cpusetsize - EINVAL" );
    53   sc = pthread_attr_getaffinity_np( &attr, sizeof(cpu_set_t) * 2 , &cpuset );
     56  sc = pthread_attr_getaffinity_np( &attr, sizeof( cpuset ) * 2 , &cpuset );
    5457  rtems_test_assert( sc == EINVAL );
    5558
     59  sc = pthread_attr_destroy( &attr );
     60  rtems_test_assert( sc == 0 );
     61
     62  puts( "Init - pthread_attr_getaffinity_np - Not initialized attr - EINVAL" );
     63  sc = pthread_attr_getaffinity_np( &attr, sizeof( cpuset ), &cpuset );
     64  rtems_test_assert( sc == EINVAL );
    5665}
    5766
     
    6271  pthread_attr_t      attr;
    6372
     73  sc = pthread_attr_init( &attr );
     74  rtems_test_assert( sc == 0 );
     75
    6476  /* Verify pthread_attr_setaffinity_np validates attr.  */
    65   puts( "Init - pthread_attr_setaffinity_np - Invalid attr - EFAULT" );
    66   sc = pthread_attr_setaffinity_np( NULL, sizeof(cpu_set_t), &cpuset );
    67   rtems_test_assert( sc == EFAULT );
     77  puts( "Init - pthread_attr_setaffinity_np - Invalid attr - EINVAL" );
     78  sc = pthread_attr_setaffinity_np( NULL, sizeof( cpuset ), &cpuset );
     79  rtems_test_assert( sc == EINVAL );
    6880
    6981  /* Verify pthread_attr_setaffinity_np validates cpuset    */
    70   puts( "Init - pthread_attr_setaffinity_np - Invalid attr - EFAULT" );
    71   sc = pthread_attr_setaffinity_np( &attr, sizeof(cpu_set_t), NULL );
    72   rtems_test_assert( sc == EFAULT );
     82  puts( "Init - pthread_attr_setaffinity_np - Invalid attr - EINVAL" );
     83  sc = pthread_attr_setaffinity_np( &attr, sizeof( cpuset ), NULL );
     84  rtems_test_assert( sc == EINVAL );
    7385
    7486  /* Verify pthread_attr_setaffinity_np validates cpusetsize */
    7587  puts( "Init - pthread_attr_setaffinity_np - Invalid cpusetsize - EINVAL" );
    76   sc = pthread_attr_setaffinity_np( &attr, sizeof(cpu_set_t) * 2 , &cpuset );
     88  sc = pthread_attr_setaffinity_np( &attr, sizeof( cpuset ) * 2 , &cpuset );
    7789  rtems_test_assert( sc == EINVAL );
    7890
    79   /* Verify pthread_attr_setaffinity_np validates cpuset greater than 0  */
    80   CPU_ZERO(&cpuset);
    81   puts( "Init - pthread_attr_setaffinity_np - No cpus in cpuset - EINVAL" );
    82   sc = pthread_attr_setaffinity_np( &attr, sizeof(cpu_set_t) , &cpuset );
    83   rtems_test_assert( sc == EINVAL );
     91  sc = pthread_attr_destroy( &attr );
     92  rtems_test_assert( sc == 0 );
    8493
    85   /* Verify pthread_attr_setaffinity_np validates invalid cpu in cpuset */
    86   CPU_FILL(&cpuset);
    87   puts( "Init - pthread_attr_setaffinity_np - Too many cpus in cpuset - EINVAL" );
    88   sc = pthread_attr_setaffinity_np( &attr, sizeof(cpu_set_t) , &cpuset );
     94  puts( "Init - pthread_attr_setaffinity_np - Not initialized attr - EINVAL" );
     95  sc = pthread_attr_setaffinity_np( &attr, sizeof( cpuset ), &cpuset  );
    8996  rtems_test_assert( sc == EINVAL );
    9097}
  • testsuites/smptests/smppsxaffinity01/smppsxaffinity01.scn

    r65012bf raf9115f3  
    1 *** SMP POSIX AFFINITY ATTRIBUTE TEST 1 ***
    2 Init - pthread_attr_setaffinity_np - Invalid attr - EFAULT
    3 Init - pthread_attr_setaffinity_np - Invalid attr - EFAULT
     1*** BEGIN OF TEST SMPPSXAFFINITY 1 ***
     2Init - pthread_attr_setaffinity_np - Invalid attr - EINVAL
     3Init - pthread_attr_setaffinity_np - Invalid attr - EINVAL
    44Init - pthread_attr_setaffinity_np - Invalid cpusetsize - EINVAL
    5 Init - pthread_attr_setaffinity_np - No cpus in cpuset - EINVAL
    6 Init - pthread_attr_setaffinity_np - Too many cpus in cpuset - EINVAL
    7 Init - pthread_attr_getaffinity_np - Invalid attr - EFAULT
    8 Init - pthread_attr_getaffinity_np - Invalid attr - EFAULT
     5Init - pthread_attr_setaffinity_np - Not initialized attr - EINVAL
     6Init - pthread_attr_getaffinity_np - Invalid attr - EINVAL
     7Init - pthread_attr_getaffinity_np - Invalid attr - EINVAL
    98Init - pthread_attr_getaffinity_np - Invalid cpusetsize - EINVAL
     9Init - pthread_attr_getaffinity_np - Not initialized attr - EINVAL
    1010Init - Validate pthread_attr_setaffinity_np and pthread_attr_getaffinity_np
    11 *** END OF SMP POSIX AFFINITY ATTRIBUTE TEST 1 ***
     11*** END OF TEST SMPPSXAFFINITY 1 ***
Note: See TracChangeset for help on using the changeset viewer.