Changeset d271c3bb in rtems


Ignore:
Timestamp:
Oct 31, 2016, 12:37:59 PM (3 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
4cf58905
Parents:
bb9f09f
git-author:
Sebastian Huber <sebastian.huber@…> (10/31/16 12:37:59)
git-committer:
Sebastian Huber <sebastian.huber@…> (11/02/16 07:46:47)
Message:

rtems: Add rtems_task_iterate()

Update #2423.

Files:
2 added
14 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libcsupport/src/sync.c

    rbb9f09f rd271c3bb  
    4848
    4949/* iterate over all FILE *'s for this thread */
    50 static void sync_per_thread(Thread_Control *t)
     50static bool sync_per_thread(Thread_Control *t, void *arg)
    5151{
    5252   struct _reent *current_reent;
     
    6565     executing->libc_reent = current_reent;
    6666   }
     67
     68   return false;
    6769}
    6870
     
    9698   *  Now walk all the per-thread reentrancy structures.
    9799   */
    98   rtems_iterate_over_all_threads(sync_per_thread);
     100  rtems_task_iterate(sync_per_thread, NULL);
    99101}
  • cpukit/libmisc/capture/capture-cli.c

    rbb9f09f rd271c3bb  
    4343
    4444/*
    45  * Counter used to count the number of active tasks.
    46  */
    47 static int rtems_capture_cli_task_count = 0;
    48 
    49 /*
    5045 * The user capture timestamper.
    5146 */
     
    198193}
    199194
    200 static void
    201 rtems_capture_cli_print_task (rtems_tcb *tcb)
     195static bool
     196rtems_capture_cli_print_task (rtems_tcb *tcb, void *arg)
    202197{
    203198  rtems_task_priority   ceiling = rtems_capture_watch_get_ceiling ();
     
    243238  }
    244239  fprintf (stdout, "\n");
     240  return false;
    245241}
    246242
     
    252248 */
    253249
    254 static void
    255 rtems_capture_cli_count_tasks (rtems_tcb *tcb)
    256 {
    257   rtems_capture_cli_task_count++;
     250static bool
     251rtems_capture_cli_count_tasks (rtems_tcb *tcb, void *arg)
     252{
     253  uint32_t *task_count = arg;
     254  ++(*task_count);
     255  return false;
    258256}
    259257
     
    272270{
    273271  rtems_capture_time uptime;
     272  uint32_t           task_count;
    274273
    275274  rtems_capture_get_time (&uptime);
    276275
    277   rtems_capture_cli_task_count = 0;
    278   rtems_iterate_over_all_threads (rtems_capture_cli_count_tasks);
     276  task_count = 0;
     277  rtems_task_iterate (rtems_capture_cli_count_tasks, &task_count);
    279278
    280279  fprintf (stdout, "uptime: ");
    281280  rtems_capture_print_timestamp (uptime);
    282   fprintf (stdout, "\ntotal %i\n", rtems_capture_cli_task_count);
    283   rtems_iterate_over_all_threads (rtems_capture_cli_print_task);
     281  fprintf (stdout, "\ntotal %" PRIu32 "\n", task_count);
     282  rtems_task_iterate (rtems_capture_cli_print_task, NULL);
    284283}
    285284
  • cpukit/libmisc/capture/capture.c

    rbb9f09f rd271c3bb  
    280280 * the given task and sets the control if it does.
    281281 */
    282 static void
    283 rtems_capture_initialize_control (rtems_tcb *tcb)
     282static bool
     283rtems_capture_initialize_control (rtems_tcb *tcb, void *arg)
    284284{
    285285  if (tcb->Capture.control == NULL)
     
    306306    }
    307307  }
     308
     309  return false;
    308310}
    309311
     
    343345    capture_controls = control;
    344346
    345     rtems_iterate_over_all_threads (rtems_capture_initialize_control);
     347    _Thread_Iterate (rtems_capture_initialize_control, NULL);
    346348
    347349    rtems_interrupt_lock_release (&capture_lock_global, &lock_context);
     
    750752 * This function clears the capture trace flag in the tcb.
    751753 */
    752 static void
    753 rtems_capture_flush_tcb (rtems_tcb *tcb)
     754static bool
     755rtems_capture_flush_tcb (rtems_tcb *tcb, void *arg)
    754756{
    755757  tcb->Capture.flags &= ~RTEMS_CAPTURE_TRACED;
     758  return false;
    756759}
    757760
     
    777780    }
    778781
    779     rtems_iterate_over_all_threads (rtems_capture_flush_tcb);
     782    _Thread_Iterate (rtems_capture_flush_tcb, NULL);
    780783
    781784    if (prime)
  • cpukit/libmisc/cpuuse/cpuusagereset.c

    rbb9f09f rd271c3bb  
    2727#include "cpuuseimpl.h"
    2828
    29 static void CPU_usage_Per_thread_handler(
    30   Thread_Control *the_thread
     29static bool CPU_usage_Per_thread_handler(
     30  Thread_Control *the_thread,
     31  void           *arg
    3132)
    3233{
     
    4344  _Scheduler_Release_critical( scheduler, &scheduler_lock_context );
    4445  _Thread_State_release( the_thread, &state_lock_context );
     46  return false;
    4547}
    4648
     
    6264  }
    6365
    64   rtems_iterate_over_all_threads(CPU_usage_Per_thread_handler);
     66  rtems_task_iterate(CPU_usage_Per_thread_handler, NULL);
    6567}
  • cpukit/libmisc/cpuuse/cpuusagetop.c

    rbb9f09f rd271c3bb  
    8686#define RTEMS_TOP_SORT_MAX           (4)
    8787
    88 /*
    89  * Private version of the iterator with an arg. This will be moved
    90  * to the public version in 5.0.
    91  */
    92 
    93 typedef void (*rtems_per_thread_routine_2)( Thread_Control *, void* );
    94 
    95 void rtems_iterate_over_all_threads_2(rtems_per_thread_routine_2 routine,
    96                                       void*                      arg);
    97 
    98 void rtems_iterate_over_all_threads_2(rtems_per_thread_routine_2 routine,
    99                                       void*                      arg)
    100 {
    101   uint32_t             i;
    102   uint32_t             api_index;
    103   Thread_Control      *the_thread;
    104   Objects_Information *information;
    105 
    106   if ( !routine )
    107     return;
    108 
    109   for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) {
    110     #if !defined(RTEMS_POSIX_API) || defined(RTEMS_DEBUG)
    111       if ( !_Objects_Information_table[ api_index ] )
    112         continue;
    113     #endif
    114     information = _Objects_Information_table[ api_index ][ 1 ];
    115     if ( information ) {
    116       for ( i=1 ; i <= information->maximum ; i++ ) {
    117         the_thread = (Thread_Control *)information->local_table[ i ];
    118         if ( the_thread )
    119           (*routine)(the_thread, arg);
    120       }
    121     }
    122   }
    123 }
    124 
    12588static inline bool equal_to_uint32_t( uint32_t * lhs, uint32_t * rhs )
    12689{
     
    191154 * Count the number of tasks.
    192155 */
    193 static void
     156static bool
    194157task_counter(Thread_Control *thrad, void* arg)
    195158{
    196159  rtems_cpu_usage_data* data = (rtems_cpu_usage_data*) arg;
    197160  ++data->task_count;
     161
     162  return false;
    198163}
    199164
     
    201166 * Create the sorted table with the current and total usage.
    202167 */
    203 static void
     168static bool
    204169task_usage(Thread_Control* thread, void* arg)
    205170{
     
    288253    break;
    289254  }
     255
     256  return false;
    290257}
    291258
     
    323290
    324291    data->task_count = 0;
    325     rtems_iterate_over_all_threads_2(task_counter, data);
     292    _Thread_Iterate(task_counter, data);
    326293
    327294    tasks_size = sizeof(Thread_Control*) * (data->task_count + 1);
     
    354321    data->last_uptime = data->uptime;
    355322
    356     rtems_iterate_over_all_threads_2(task_usage, data);
     323    _Thread_Iterate(task_usage, data);
    357324
    358325    if (data->task_count > data->task_size)
  • cpukit/libmisc/stackchk/check.c

    rbb9f09f rd271c3bb  
    353353 *  Try to print out how much stack was actually used by the task.
    354354 */
    355 static const rtems_printer* printer;
    356 
    357 static void Stack_check_Dump_threads_usage(
    358   Thread_Control *the_thread
    359 )
    360 {
    361   uint32_t        size, used;
    362   void           *low;
    363   void           *high_water_mark;
    364   void           *current;
    365   Stack_Control  *stack;
    366   char            name[5];
    367 
    368   /*
    369    *  The pointer passed in for the_thread is guaranteed to be non-NULL from
    370    *  rtems_iterate_over_all_threads() so no need to check it here.
    371    */
     355static bool Stack_check_Dump_threads_usage(
     356  Thread_Control *the_thread,
     357  void           *arg
     358)
     359{
     360  uint32_t             size, used;
     361  void                *low;
     362  void                *high_water_mark;
     363  void                *current;
     364  Stack_Control       *stack;
     365  char                 name[5];
     366  const rtems_printer *printer;
     367
     368  printer = arg;
    372369
    373370  /*
     
    377374    if (the_thread == (Thread_Control *) -1) {
    378375      if (!Stack_check_Interrupt_stack.area)
    379         return;
     376        return false;
    380377      stack = &Stack_check_Interrupt_stack;
    381378      the_thread = 0;
     
    431428  }
    432429
    433 
     430  return false;
    434431}
    435432
     
    454451
    455452void rtems_stack_checker_report_usage_with_plugin(
    456   const rtems_printer* printer_
    457 )
    458 {
    459   if ( printer != NULL || ! rtems_print_printer_valid ( printer_ ) )
    460     return;
    461 
    462   printer = printer_;
    463 
     453  const rtems_printer* printer
     454)
     455{
    464456  rtems_printf( printer, "Stack usage by thread\n");
    465457  rtems_printf( printer,
     
    468460
    469461  /* iterate over all threads and dump the usage */
    470   rtems_iterate_over_all_threads( Stack_check_Dump_threads_usage );
     462  rtems_task_iterate(
     463    Stack_check_Dump_threads_usage,
     464    RTEMS_DECONST( rtems_printer *, printer )
     465  );
    471466
    472467  #if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE)
    473468    /* dump interrupt stack info if any */
    474     Stack_check_Dump_threads_usage((Thread_Control *) -1);
     469    Stack_check_Dump_threads_usage(
     470      (Thread_Control *) -1,
     471      RTEMS_DECONST( rtems_printer *, printer )
     472    );
    475473  #endif
    476474
  • cpukit/rtems/Makefile.am

    rbb9f09f rd271c3bb  
    9494librtems_a_SOURCES += src/taskinitusers.c
    9595librtems_a_SOURCES += src/taskissuspended.c
     96librtems_a_SOURCES += src/taskiterate.c
    9697librtems_a_SOURCES += src/taskmode.c
    9798librtems_a_SOURCES += src/taskrestart.c
  • cpukit/rtems/include/rtems/rtems/tasks.h

    rbb9f09f rd271c3bb  
    514514
    515515/**
     516 * @brief Task visitor.
     517 *
     518 * @param[in] tcb The task control block.
     519 * @param[in] arg The visitor argument.
     520 *
     521 * @retval true Stop the iteration.
     522 * @retval false Otherwise.
     523 *
     524 * @see rtems_task_iterate().
     525 */
     526typedef bool ( *rtems_task_visitor )( rtems_tcb *tcb, void *arg );
     527
     528/**
     529 * @brief Iterates over all tasks in the system.
     530 *
     531 * This operation covers all tasks of all APIs.
     532 *
     533 * Must be called from task context.  This operation obtains and releases the
     534 * objects allocator lock.  The task visitor is called while owning the objects
     535 * allocator lock.  It is possible to perform blocking operations in the task
     536 * visitor, however, take care that no deadlocks via the object allocator lock
     537 * can occur.
     538 *
     539 * @param[in] visitor The task visitor.
     540 * @param[in] arg The visitor argument.
     541 */
     542void rtems_task_iterate(
     543  rtems_task_visitor  visitor,
     544  void               *arg
     545);
     546
     547/**
    516548 * @brief Identifies a scheduler by its name.
    517549 *
  • cpukit/score/Makefile.am

    rbb9f09f rd271c3bb  
    311311libscore_a_SOURCES += src/threadgetcputimeused.c
    312312libscore_a_SOURCES += src/threadglobalconstruction.c
     313libscore_a_SOURCES += src/threaditerate.c
    313314libscore_a_SOURCES += src/threadtimeout.c
    314315libscore_a_SOURCES += src/threadwaitgetid.c
  • cpukit/score/include/rtems/score/thread.h

    rbb9f09f rd271c3bb  
    835835#endif
    836836
    837 /**  This defines the type for a method which operates on a single thread.
    838  */
    839837typedef void (*rtems_per_thread_routine)( Thread_Control * );
    840838
    841 /**
    842  *  @brief Iterates over all threads.
    843  *  This routine iterates over all threads regardless of API and
    844  *  invokes the specified routine.
    845  */
     839/* Use rtems_task_iterate() instead */
    846840void rtems_iterate_over_all_threads(
    847841  rtems_per_thread_routine routine
    848 );
     842) RTEMS_DEPRECATED;
    849843
    850844/**
  • cpukit/score/include/rtems/score/threadimpl.h

    rbb9f09f rd271c3bb  
    8383  RTEMS_CONTAINER_OF( node, Thread_Control, Resource_node )
    8484#endif
     85
     86typedef bool ( *Thread_Visitor )( Thread_Control *the_thread, void *arg );
     87
     88void _Thread_Iterate(
     89  Thread_Visitor  visitor,
     90  void           *arg
     91);
    8592
    8693void _Thread_Initialize_information(
  • cpukit/score/src/iterateoverthreads.c

    rbb9f09f rd271c3bb  
    1919#endif
    2020
    21 #include <rtems/score/thread.h>
    22 #include <rtems/score/objectimpl.h>
     21#include <rtems/score/threadimpl.h>
    2322
    24 void rtems_iterate_over_all_threads(rtems_per_thread_routine routine)
     23typedef struct {
     24  rtems_per_thread_routine routine;
     25} routine_arg;
     26
     27static bool routine_adaptor( rtems_tcb *tcb, void *arg )
    2528{
    26   uint32_t             i;
    27   uint32_t             api_index;
    28   Thread_Control      *the_thread;
    29   Objects_Information *information;
     29  routine_arg *ra;
    3030
    31   if ( !routine )
    32     return;
     31  ra = arg;
     32  ( *ra->routine )( tcb );
     33  return false;
     34}
    3335
    34   for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) {
    35     #if !defined(RTEMS_POSIX_API) || defined(RTEMS_DEBUG)
    36       if ( !_Objects_Information_table[ api_index ] )
    37         continue;
    38     #endif
     36void rtems_iterate_over_all_threads( rtems_per_thread_routine routine )
     37{
     38  routine_arg arg = {
     39    .routine = routine
     40  };
    3941
    40     information = _Objects_Information_table[ api_index ][ 1 ];
    41     if ( !information )
    42       continue;
    43 
    44     for ( i=1 ; i <= information->maximum ; i++ ) {
    45       the_thread = (Thread_Control *)information->local_table[ i ];
    46 
    47       if ( !the_thread )
    48         continue;
    49 
    50       (*routine)(the_thread);
    51     }
     42  if ( routine != NULL ) {
     43    _Thread_Iterate( routine_adaptor, &arg );
    5244  }
    53 
    5445}
  • testsuites/sptests/sp41/init.c

    rbb9f09f rd271c3bb  
    1212#endif
    1313
     14#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
     15
    1416#include <tmacros.h>
    1517
     
    1820const char rtems_test_name[] = "SP 41";
    1921
    20 /* forward declarations to avoid warnings */
    21 rtems_task Init(rtems_task_argument argument);
    22 void iterator(Thread_Control *thread);
     22static bool visitor( Thread_Control *thread, void *arg )
     23{
     24  int *counter = arg;
     25  ++( *counter );
     26  return false;
     27}
    2328
    24 void iterator(
    25   Thread_Control *thread
    26 )
     29static void iterator( Thread_Control *thread )
    2730{
    2831}
    2932
    30 rtems_task Init(
     33static rtems_task Init(
    3134  rtems_task_argument ignored
    3235)
    3336{
    3437  void *tmp;
     38  int   counter;
    3539
    3640  TEST_BEGIN();
     
    4044  _Objects_Information_table[ OBJECTS_CLASSIC_API ][ 1 ] = NULL;
    4145
    42   puts( "Init - rtems_iterate_over_all_threads" );
    43   rtems_iterate_over_all_threads(iterator);
     46  puts( "Init - rtems_task_iterate - NULL table" );
     47  counter = 0;
     48  rtems_task_iterate( visitor, &counter );
    4449  _Objects_Information_table[ OBJECTS_CLASSIC_API ][ 1 ] = tmp;
     50  rtems_test_assert( counter == 1 );
     51
     52  puts( "Init - rtems_task_iterate - normal" );
     53  counter = 0;
     54  rtems_task_iterate( visitor, &counter );
     55  rtems_test_assert( counter == 2 );
     56
     57  puts( "Init - rtems_iterate_over_all_threads - NULL" );
     58  rtems_iterate_over_all_threads( NULL );
     59
     60  puts( "Init - rtems_iterate_over_all_threads - iterator" );
     61  rtems_iterate_over_all_threads( iterator );
    4562
    4663  TEST_END();
  • testsuites/sptests/sp41/sp41.scn

    rbb9f09f rd271c3bb  
    1 *** TEST 41 ***
     1*** BEGIN OF TEST SP 41 ***
    22Init - overwrite internal value to trip case
    3 Init - rtems_iterate_over_all_threads
    4 *** END OF TEST 41 ***
     3Init - rtems_task_iterate - NULL table
     4Init - rtems_task_iterate - normal
     5Init - rtems_iterate_over_all_threads - NULL
     6Init - rtems_iterate_over_all_threads - iterator
     7*** END OF TEST SP 41 ***
Note: See TracChangeset for help on using the changeset viewer.