Changeset 185e46f in rtems


Ignore:
Timestamp:
Jan 31, 2014, 2:54:45 PM (6 years ago)
Author:
Jennifer Averett <jennifer.averett@…>
Branches:
4.11, master
Children:
baa426a
Parents:
29cacfd
git-author:
Jennifer Averett <jennifer.averett@…> (01/31/14 14:54:45)
git-committer:
Jennifer Averett <jennifer.averett@…> (03/07/14 15:10:33)
Message:

posix: Add POSIX thread affinity attribute support.

With the addition of pthread affinity information in pthread_attr_t,
the existing code for pthread_attr_t had to be adjusted.

Location:
cpukit/posix
Files:
4 edited

Legend:

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

    r29cacfd r185e46f  
    2525#include <rtems/score/objectimpl.h>
    2626#include <rtems/score/thread.h>
     27#include <rtems/score/assert.h>
    2728
    2829#ifdef __cplusplus
     
    4950 * This variable contains the default POSIX Thread attributes.
    5051 */
    51 extern const pthread_attr_t _POSIX_Threads_Default_attributes;
     52extern pthread_attr_t _POSIX_Threads_Default_attributes;
    5253
    5354/**
     
    7677 */
    7778RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Allocate( void );
     79
     80/**
     81 * @brief Copy POSIX Thread attribute structure.
     82 *
     83 * This routine copies the attr2 thread attribute structure
     84 * to the attr1 Thread Attribute structure.
     85 *
     86 * @param[in] dst_attr is a pointer to the thread attribute
     87 * structure to copy into.
     88 *
     89 * @param[out] src_attr is a pointer to the thread attribute
     90 * structure to copy from.
     91 */
     92RTEMS_INLINE_ROUTINE void _POSIX_Threads_Copy_attributes(
     93  pthread_attr_t        *dst_attr,
     94  const pthread_attr_t  *src_attr
     95);
    7896
    7997/**
     
    111129
    112130/**
     131 * @brief POSIX threads initialize user threads body.
     132 *
     133 * This routine initializes the thread attributes structure.
     134 */
     135RTEMS_INLINE_ROUTINE void _POSIX_Threads_Initialize_attributes(
     136  pthread_attr_t  *attr
     137);
     138
     139/**
    113140 * @brief Check if a POSIX thread control block is NULL.
    114141 *
     
    178205
    179206/*
     207 * rtems_pthread_attribute_compare
     208 */
     209int rtems_pthread_attribute_compare(
     210  const pthread_attr_t *attr1,
     211  const pthread_attr_t *attr2
     212);
     213 
     214/*
    180215 *  _POSIX_Threads_Allocate
    181216 */
     
    185220  return (Thread_Control *) _Objects_Allocate( &_POSIX_Threads_Information );
    186221}
     222
     223/*
     224 * _POSIX_Threads_Copy_attributes
     225 */
     226
     227RTEMS_INLINE_ROUTINE void _POSIX_Threads_Copy_attributes(
     228  pthread_attr_t        *dst_attr,
     229  const pthread_attr_t  *src_attr
     230)
     231{
     232  *dst_attr = *src_attr;
     233#if defined(__RTEMS_HAVE_SYS_CPUSET_H__)
     234  _Assert(
     235    dst_attr->affinitysetsize == sizeof(dst_attr->affinitysetpreallocated)
     236  );
     237  dst_attr->affinityset = &dst_attr->affinitysetpreallocated;
     238#endif
     239}
    187240
    188241/*
     
    211264
    212265/*
     266 * _POSIX_Threads_Initialize_attributes
     267 */
     268
     269RTEMS_INLINE_ROUTINE void _POSIX_Threads_Initialize_attributes(
     270  pthread_attr_t  *attr
     271)
     272{
     273  _POSIX_Threads_Copy_attributes(
     274    attr,
     275    &_POSIX_Threads_Default_attributes
     276  );
     277}
     278
     279/*
    213280 *  _POSIX_Threads_Is_null
    214281 */
  • cpukit/posix/src/pthread.c

    r29cacfd r185e46f  
    1818#include "config.h"
    1919#endif
     20#include <stdio.h>
    2021
    2122#include <errno.h>
    2223#include <pthread.h>
    2324#include <limits.h>
     25#include <assert.h>
    2426
    2527#include <rtems/system.h>
     
    4749 *        _POSIX_Threads_Initialize_user_threads will need to be examined.
    4850 */
    49 const pthread_attr_t _POSIX_Threads_Default_attributes = {
    50   true,                       /* is_initialized */
    51   NULL,                       /* stackaddr */
    52   0,                          /* stacksize -- will be adjusted to minimum */
    53   PTHREAD_SCOPE_PROCESS,      /* contentionscope */
    54   PTHREAD_INHERIT_SCHED,      /* inheritsched */
    55   SCHED_FIFO,                 /* schedpolicy */
     51pthread_attr_t _POSIX_Threads_Default_attributes = {
     52  .is_initialized  = true,                       /* is_initialized */
     53  .stackaddr       = NULL,                       /* stackaddr */
     54  .stacksize       = 0,                          /* stacksize -- will be adjusted to minimum */
     55  .contentionscope = PTHREAD_SCOPE_PROCESS,      /* contentionscope */
     56  .inheritsched    = PTHREAD_INHERIT_SCHED,      /* inheritsched */
     57  .schedpolicy     = SCHED_FIFO,                 /* schedpolicy */
     58  .schedparam      =
    5659  {                           /* schedparam */
    5760    2,                        /* sched_priority */
     
    6467    #endif
    6568  },
     69
    6670  #if HAVE_DECL_PTHREAD_ATTR_SETGUARDSIZE
    67     0,                        /* guardsize */
     71    .guardsize = 0,                            /* guardsize */
    6872  #endif
    6973  #if defined(_POSIX_THREAD_CPUTIME)
    70     1,                        /* cputime_clock_allowed */
    71   #endif
    72   PTHREAD_CREATE_JOINABLE,    /* detachstate */
     74    .cputime_clock_allowed = 1,                        /* cputime_clock_allowed */
     75  #endif
     76  .detachstate             = PTHREAD_CREATE_JOINABLE,    /* detachstate */
     77  #if defined(__RTEMS_HAVE_SYS_CPUSET_H__)
     78    .affinitysetsize         = 0,
     79    .affinityset             = NULL,
     80    .affinitysetpreallocated = {{0x0}}
     81  #endif
    7382};
    7483
     
    188197
    189198  /* XXX check all fields are touched */
    190   api->Attributes  = _POSIX_Threads_Default_attributes;
     199  _POSIX_Threads_Initialize_attributes( &api->Attributes );
    191200  api->detachstate = _POSIX_Threads_Default_attributes.detachstate;
    192201  api->schedpolicy = _POSIX_Threads_Default_attributes.schedpolicy;
     
    347356void _POSIX_Threads_Manager_initialization(void)
    348357{
     358  #if defined(__RTEMS_HAVE_SYS_CPUSET_H__)
     359    pthread_attr_t *attr;
     360    int i;
     361    int max_cpus = 1;
     362
     363    /* Initialize default attribute. */
     364    attr = &_POSIX_Threads_Default_attributes;
     365
     366    /* We do not support a cpu count over CPU_SETSIZE  */
     367    max_cpus = _SMP_Get_processor_count();
     368    assert( max_cpus <= CPU_SETSIZE );
     369
     370    /*  Initialize the affinity to be the set of all available CPU's   */
     371    attr->affinityset             = &attr->affinitysetpreallocated;
     372    attr->affinitysetsize         = sizeof( *attr->affinityset );
     373    CPU_ZERO_S( attr->affinitysetsize, &attr->affinitysetpreallocated );
     374
     375    for (i=0; i<max_cpus; i++) 
     376      CPU_SET_S(i, attr->affinitysetsize, attr->affinityset );
     377  #endif
     378
    349379  _Objects_Initialize_information(
    350380    &_POSIX_Threads_Information, /* object information table */
  • cpukit/posix/src/pthreadattrinit.c

    r29cacfd r185e46f  
    3535    return EINVAL;
    3636
    37   *attr = _POSIX_Threads_Default_attributes;
    38    return 0;
     37  _POSIX_Threads_Initialize_attributes( attr );
     38
     39  return 0;
    3940}
  • cpukit/posix/src/pthreadcreate.c

    r29cacfd r185e46f  
    2828#include <rtems/posix/pthreadimpl.h>
    2929#include <rtems/posix/time.h>
     30#include <rtems/score/cpusetimpl.h>
    3031#include <rtems/score/threadimpl.h>
    3132#include <rtems/score/apimutex.h>
     
    137138    return rc;
    138139
     140#if defined(RTEMS_SMP)
     141#if __RTEMS_HAVE_SYS_CPUSET_H__
     142  rc = _CPU_set_Is_valid( attr->affinityset, attr->affinitysetsize );
     143  if ( rc != 0 )
     144    return EINVAL;
     145#endif
     146#endif
     147
    139148  /*
    140149   *  Currently all POSIX threads are floating point if the hardware
     
    180189    name                  /* posix threads don't have a name */
    181190  );
    182 
    183191  if ( !status ) {
    184192    _POSIX_Threads_Free( the_thread );
     
    187195  }
    188196
     197#if defined(RTEMS_SMP)
     198#if __RTEMS_HAVE_SYS_CPUSET_H__
     199   the_thread->affinity.setsize   = attr->affinitysetsize;
     200   *the_thread->affinity.set      = *attr->affinityset;
     201#endif
     202#endif
     203
    189204  /*
    190205   *  finish initializing the per API structure
     
    192207  api = the_thread->API_Extensions[ THREAD_API_POSIX ];
    193208
    194   api->Attributes  = *the_attr;
     209  _POSIX_Threads_Copy_attributes( &api->Attributes, the_attr );
    195210  api->detachstate = the_attr->detachstate;
    196211  api->schedpolicy = schedpolicy;
Note: See TracChangeset for help on using the changeset viewer.