Changeset 0712d17 in rtems


Ignore:
Timestamp:
Apr 8, 2014, 9:14:27 AM (5 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
133d54c5
Parents:
69aa3349
git-author:
Sebastian Huber <sebastian.huber@…> (04/08/14 09:14:27)
git-committer:
Sebastian Huber <sebastian.huber@…> (04/15/14 06:37:12)
Message:

score: Task get/set affinity

Make rtems_task_get_affinity() and rtems_task_set_affinity() available
on non-SMP configurations. Allow larger CPU sets.

Files:
6 added
9 edited

Legend:

Unmodified
Added
Removed
  • cpukit/rtems/Makefile.am

    r69aa3349 r0712d17  
    9393librtems_a_SOURCES += src/taskcreate.c
    9494librtems_a_SOURCES += src/taskdelete.c
     95librtems_a_SOURCES += src/taskgetaffinity.c
    9596librtems_a_SOURCES += src/taskgetnote.c
    9697librtems_a_SOURCES += src/taskident.c
     
    101102librtems_a_SOURCES += src/taskresume.c
    102103librtems_a_SOURCES += src/taskself.c
     104librtems_a_SOURCES += src/tasksetaffinity.c
    103105librtems_a_SOURCES += src/tasksetnote.c
    104106librtems_a_SOURCES += src/tasksetpriority.c
     
    275277endif
    276278
    277 ## SMP Files
    278 if HAS_SMP
    279 librtems_a_SOURCES += src/tasksetaffinity.c
    280 librtems_a_SOURCES += src/taskgetaffinity.c
    281 endif
    282 
    283 
    284279include $(srcdir)/preinstall.am
    285280include $(top_srcdir)/automake/local.am
  • cpukit/rtems/include/rtems/rtems/tasks.h

    r69aa3349 r0712d17  
    495495#endif
    496496
    497 #if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
    498 /**
    499  *  @brief RTEMS Get Task Affinity
    500  *
    501  *  This directive returns the cpuset for the
    502  *  given task.  The cpuset size must be the
    503  *  same size as the task affinity set size.
    504  *
    505  * @param[in] id is the thread to extract
    506  * @param[in] cpusetsize is the size of the cpuset
    507  * @param[out] cpuset is the tasks affinity cpuset
    508  *
    509  * @retval RTEMS_SUCCESSFUL if successful or error code if unsuccessful
    510  * @retval RTEMS_INVALID_ADDRESS if cpuset is NULL
    511  * @retval RTEMS_INVALID_NUMBER if cpusetsize is incorrect
    512  * @retval RTEMS_INVALID_ID if id not valid
     497#if defined(__RTEMS_HAVE_SYS_CPUSET_H__)
     498/**
     499 * @brief Gets the processor affinity set of a task.
     500 *
     501 * @param[in] id Identifier of the task.  Use @ref RTEMS_SELF to select the
     502 * executing task.
     503 * @param[in] cpusetsize Size of the specified affinity set buffer in
     504 * bytes.  This value must be positive.
     505 * @param[out] cpuset The current processor affinity set of the task.  A set
     506 * bit in the affinity set means that the task can execute on this processor
     507 * and a cleared bit means the opposite.
     508 *
     509 * @retval RTEMS_SUCCESSFUL Successful operation.
     510 * @retval RTEMS_INVALID_ADDRESS The @a cpuset parameter is @c NULL.
     511 * @retval RTEMS_INVALID_ID Invalid task identifier.
     512 * @retval RTEMS_INVALID_NUMBER The affinity set buffer is too small for the
     513 * current processor affinity set of the task.
    513514 */
    514515rtems_status_code rtems_task_get_affinity(
     
    519520
    520521/**
    521  *  @brief RTEMS Set Task Affinity
    522  *
    523  *  This directive sets the given tasks
    524  *  affinity cpuset.
    525  *
    526  * @param[in] id is the thread to extract
    527  * @param[in] cpusetsize is the size of the cpuset
    528  * @param[in] cpuset is affinity set to assign to the task
    529  *
    530  * @retval RTEMS_SUCCESSFUL if successful or error code if unsuccessful
    531  * @retval RTEMS_INVALID_ADDRESS if cpuset is NULL
    532  * @retval RTEMS_INVALID_NUMBER if cpuset or cpusetsize is incorrect
    533  * @retval RTEMS_INVALID_ID if id not valid
     522 * @brief Sets the processor affinity set of a task.
     523 *
     524 * @param[in] id Identifier of the task.  Use @ref RTEMS_SELF to select the
     525 * executing task.
     526 * @param[in] cpusetsize Size of the specified affinity set buffer in
     527 * bytes.  This value must be positive.
     528 * @param[in] cpuset The new processor affinity set for the task.  A set bit in
     529 * the affinity set means that the task can execute on this processor and a
     530 * cleared bit means the opposite.
     531 *
     532 * @retval RTEMS_SUCCESSFUL Successful operation.
     533 * @retval RTEMS_INVALID_ADDRESS The @a cpuset parameter is @c NULL.
     534 * @retval RTEMS_INVALID_ID Invalid task identifier.
     535 * @retval RTEMS_INVALID_NUMBER Invalid processor affinity set.
    534536 */
    535537rtems_status_code rtems_task_set_affinity(
  • cpukit/score/Makefile.am

    r69aa3349 r0712d17  
    196196libscore_a_SOURCES += src/log2table.c
    197197libscore_a_SOURCES += src/scheduler.c
     198libscore_a_SOURCES += src/schedulergetaffinity.c
     199libscore_a_SOURCES += src/schedulersetaffinity.c
    198200libscore_a_SOURCES += src/schedulerdefaultallocatefree.c
    199201libscore_a_SOURCES += src/schedulerdefaultreleasejob.c
  • cpukit/score/include/rtems/score/cpusetimpl.h

    r69aa3349 r0712d17  
    2121
    2222#include <rtems/score/cpuset.h>
     23#include <rtems/score/smp.h>
     24
     25#include <limits.h>
    2326
    2427#ifdef __cplusplus
     
    5962const CPU_set_Control *_CPU_set_Default(void);
    6063
     64RTEMS_INLINE_ROUTINE size_t _CPU_set_Maximum_CPU_count(
     65  size_t cpusetsize
     66)
     67{
     68  return cpusetsize * CHAR_BIT;
     69}
     70
     71RTEMS_INLINE_ROUTINE bool _CPU_set_Is_large_enough(
     72  size_t cpusetsize
     73)
     74{
     75  return _CPU_set_Maximum_CPU_count( cpusetsize )
     76    >= _SMP_Get_processor_count();
     77}
     78
    6179#endif
    6280
  • cpukit/score/include/rtems/score/schedulerimpl.h

    r69aa3349 r0712d17  
    2121
    2222#include <rtems/score/scheduler.h>
     23#include <rtems/score/cpusetimpl.h>
    2324#include <rtems/score/threadimpl.h>
    2425
     
    258259}
    259260
    260 #if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
    261   /**
    262    * @brief Obtain the processor affinity for a thread.
    263    *
    264    * @param[in,out] thread The thread.
    265    * @parma[out] cpuset The processor affinity for this thread
    266    */
    267   RTEMS_INLINE_ROUTINE int _Scheduler_Get_affinity(
    268     const Scheduler_Control *scheduler,
    269     Thread_Control          *the_thread,
    270     size_t                   cpusetsize,
    271     cpu_set_t               *cpuset
    272   )
    273   {
    274     return ( *scheduler->Operations.get_affinity )(
    275       scheduler,
    276       the_thread,
    277       cpusetsize,
    278       cpuset
    279     );
    280   }
    281 
    282   /**
    283    * @brief Set the processor affinity for a thread.
    284    *
    285    * @param[in,out] thread The thread.
    286    * @parma[in] cpuset The processor affinity for this thread
    287    */
    288   RTEMS_INLINE_ROUTINE int _Scheduler_Set_affinity(
    289     const Scheduler_Control *scheduler,
    290     Thread_Control          *the_thread,
    291     size_t                   cpusetsize,
    292     const cpu_set_t         *cpuset
    293   )
    294   {
    295     return ( *scheduler->Operations.set_affinity )(
    296       scheduler,
    297       the_thread,
    298       cpusetsize,
    299       cpuset
    300     );
    301   }
    302 #endif
     261#if defined(__RTEMS_HAVE_SYS_CPUSET_H__)
     262
     263RTEMS_INLINE_ROUTINE void _Scheduler_Get_processor_set(
     264  const Scheduler_Control *scheduler,
     265  size_t                   cpusetsize,
     266  cpu_set_t               *cpuset
     267)
     268{
     269  uint32_t cpu_count = _SMP_Get_processor_count();
     270  uint32_t cpu_index;
     271
     272  (void) scheduler;
     273
     274  CPU_ZERO_S( cpusetsize, cpuset );
     275
     276  for ( cpu_index = 0 ; cpu_index < cpu_count ; ++cpu_index ) {
     277    CPU_SET_S( (int) cpu_index, cpusetsize, cpuset );
     278  }
     279}
     280
     281RTEMS_INLINE_ROUTINE bool _Scheduler_default_Get_affinity_body(
     282  const Scheduler_Control *scheduler,
     283  Thread_Control          *the_thread,
     284  size_t                   cpusetsize,
     285  cpu_set_t               *cpuset
     286)
     287{
     288  (void) the_thread;
     289
     290  _Scheduler_Get_processor_set( scheduler, cpusetsize, cpuset );
     291
     292  return true;
     293}
     294
     295bool _Scheduler_Get_affinity(
     296  const Scheduler_Control *scheduler,
     297  Thread_Control          *the_thread,
     298  size_t                   cpusetsize,
     299  cpu_set_t               *cpuset
     300);
     301
     302RTEMS_INLINE_ROUTINE bool _Scheduler_default_Set_affinity_body(
     303  const Scheduler_Control *scheduler,
     304  Thread_Control          *the_thread,
     305  size_t                   cpusetsize,
     306  const cpu_set_t         *cpuset
     307)
     308{
     309  size_t   cpu_max   = _CPU_set_Maximum_CPU_count( cpusetsize );
     310  uint32_t cpu_count = _SMP_Get_processor_count();
     311  uint32_t cpu_index;
     312  bool     ok = true;
     313
     314  (void) scheduler;
     315  (void) the_thread;
     316
     317  for ( cpu_index = 0 ; cpu_index < cpu_count ; ++cpu_index ) {
     318    ok = ok && CPU_ISSET_S( (int) cpu_index, cpusetsize, cpuset );
     319  }
     320
     321  for ( ; cpu_index < cpu_max ; ++cpu_index ) {
     322    ok = ok && !CPU_ISSET_S( (int) cpu_index, cpusetsize, cpuset );
     323  }
     324
     325  return ok;
     326}
     327
     328bool _Scheduler_Set_affinity(
     329  const Scheduler_Control *scheduler,
     330  Thread_Control          *the_thread,
     331  size_t                   cpusetsize,
     332  const cpu_set_t         *cpuset
     333);
     334
     335#endif /* defined(__RTEMS_HAVE_SYS_CPUSET_H__) */
    303336
    304337RTEMS_INLINE_ROUTINE void _Scheduler_Update_heir(
  • cpukit/score/src/schedulerdefaultgetaffinity.c

    r69aa3349 r0712d17  
    2121
    2222#include <rtems/score/schedulerimpl.h>
    23 #include <rtems/score/cpusetimpl.h>
    2423
    2524bool _Scheduler_default_Get_affinity(
     
    3029)
    3130{
    32   const CPU_set_Control *ctl;
    33 
    34   (void) scheduler;
    35   (void) thread;
    36 
    37   ctl = _CPU_set_Default();
    38   if ( cpusetsize != ctl->setsize ) {
    39     return false;
    40   }
    41 
    42   CPU_COPY( cpuset, ctl->set );
    43 
    44   return true;
     31  return _Scheduler_default_Get_affinity_body(
     32    scheduler,
     33    thread,
     34    cpusetsize,
     35    cpuset
     36  );
    4537}
  • cpukit/score/src/schedulerdefaultsetaffinity.c

    r69aa3349 r0712d17  
    2121
    2222#include <rtems/score/schedulerimpl.h>
    23 #include <rtems/score/cpusetimpl.h>
    2423
    2524bool _Scheduler_default_Set_affinity(
     
    3029)
    3130{
    32   (void) scheduler;
    33   (void) thread;
    34 
    35   return _CPU_set_Is_valid( cpuset, cpusetsize );
     31  return _Scheduler_default_Set_affinity_body(
     32    scheduler,
     33    thread,
     34    cpusetsize,
     35    cpuset
     36  );
    3637}
  • testsuites/sptests/Makefile.am

    r69aa3349 r0712d17  
    3838SUBDIRS += sp29
    3939endif
    40  SUBDIRS += spprofiling01
     40SUBDIRS += spscheduler01
     41SUBDIRS += spprofiling01
    4142SUBDIRS += spfatal28
    4243SUBDIRS += spthreadlife01
  • testsuites/sptests/configure.ac

    r69aa3349 r0712d17  
    4141# Explicitly list all Makefiles here
    4242AC_CONFIG_FILES([Makefile
     43spscheduler01/Makefile
    4344spfatal28/Makefile
    4445spthreadlife01/Makefile
Note: See TracChangeset for help on using the changeset viewer.