summaryrefslogtreecommitdiffstats
path: root/cpukit/libmisc
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-10-31 13:37:59 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-11-02 08:46:47 +0100
commitd271c3bb78f86dd9417a964b019b8e38911064fa (patch)
tree3c36b87c580464cc7f1e5aec89e1137a68759da3 /cpukit/libmisc
parentposix: Fix timer interval (diff)
downloadrtems-d271c3bb78f86dd9417a964b019b8e38911064fa.tar.bz2
rtems: Add rtems_task_iterate()
Update #2423.
Diffstat (limited to 'cpukit/libmisc')
-rw-r--r--cpukit/libmisc/capture/capture-cli.c27
-rw-r--r--cpukit/libmisc/capture/capture.c15
-rw-r--r--cpukit/libmisc/cpuuse/cpuusagereset.c8
-rw-r--r--cpukit/libmisc/cpuuse/cpuusagetop.c49
-rw-r--r--cpukit/libmisc/stackchk/check.c46
5 files changed, 57 insertions, 88 deletions
diff --git a/cpukit/libmisc/capture/capture-cli.c b/cpukit/libmisc/capture/capture-cli.c
index 05c922be44..d489d9f32a 100644
--- a/cpukit/libmisc/capture/capture-cli.c
+++ b/cpukit/libmisc/capture/capture-cli.c
@@ -42,11 +42,6 @@
#define RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS (20)
/*
- * Counter used to count the number of active tasks.
- */
-static int rtems_capture_cli_task_count = 0;
-
-/*
* The user capture timestamper.
*/
static rtems_capture_timestamp capture_timestamp;
@@ -197,8 +192,8 @@ rtems_capture_cli_disable (int argc RC_UNUSED,
fprintf (stdout, "capture engine disabled.\n");
}
-static void
-rtems_capture_cli_print_task (rtems_tcb *tcb)
+static bool
+rtems_capture_cli_print_task (rtems_tcb *tcb, void *arg)
{
rtems_task_priority ceiling = rtems_capture_watch_get_ceiling ();
rtems_task_priority floor = rtems_capture_watch_get_floor ();
@@ -242,6 +237,7 @@ rtems_capture_cli_print_task (rtems_tcb *tcb)
rtems_capture_watch_global_on () ? 'g' : '-');
}
fprintf (stdout, "\n");
+ return false;
}
/*
@@ -251,10 +247,12 @@ rtems_capture_cli_print_task (rtems_tcb *tcb)
* number of tasks.
*/
-static void
-rtems_capture_cli_count_tasks (rtems_tcb *tcb)
+static bool
+rtems_capture_cli_count_tasks (rtems_tcb *tcb, void *arg)
{
- rtems_capture_cli_task_count++;
+ uint32_t *task_count = arg;
+ ++(*task_count);
+ return false;
}
@@ -271,16 +269,17 @@ rtems_capture_cli_task_list (int argc RC_UNUSED,
bool verbose RC_UNUSED)
{
rtems_capture_time uptime;
+ uint32_t task_count;
rtems_capture_get_time (&uptime);
- rtems_capture_cli_task_count = 0;
- rtems_iterate_over_all_threads (rtems_capture_cli_count_tasks);
+ task_count = 0;
+ rtems_task_iterate (rtems_capture_cli_count_tasks, &task_count);
fprintf (stdout, "uptime: ");
rtems_capture_print_timestamp (uptime);
- fprintf (stdout, "\ntotal %i\n", rtems_capture_cli_task_count);
- rtems_iterate_over_all_threads (rtems_capture_cli_print_task);
+ fprintf (stdout, "\ntotal %" PRIu32 "\n", task_count);
+ rtems_task_iterate (rtems_capture_cli_print_task, NULL);
}
/*
diff --git a/cpukit/libmisc/capture/capture.c b/cpukit/libmisc/capture/capture.c
index 69015c8c1a..41f25aacd5 100644
--- a/cpukit/libmisc/capture/capture.c
+++ b/cpukit/libmisc/capture/capture.c
@@ -279,8 +279,8 @@ rtems_capture_find_control (rtems_name name, rtems_id id)
* This function checks if a new control structure matches
* the given task and sets the control if it does.
*/
-static void
-rtems_capture_initialize_control (rtems_tcb *tcb)
+static bool
+rtems_capture_initialize_control (rtems_tcb *tcb, void *arg)
{
if (tcb->Capture.control == NULL)
{
@@ -305,6 +305,8 @@ rtems_capture_initialize_control (rtems_tcb *tcb)
}
}
}
+
+ return false;
}
static rtems_capture_control*
@@ -342,7 +344,7 @@ rtems_capture_create_control (rtems_name name, rtems_id id)
control->next = capture_controls;
capture_controls = control;
- rtems_iterate_over_all_threads (rtems_capture_initialize_control);
+ _Thread_Iterate (rtems_capture_initialize_control, NULL);
rtems_interrupt_lock_release (&capture_lock_global, &lock_context);
}
@@ -749,10 +751,11 @@ rtems_capture_set_monitor (bool enable)
/*
* This function clears the capture trace flag in the tcb.
*/
-static void
-rtems_capture_flush_tcb (rtems_tcb *tcb)
+static bool
+rtems_capture_flush_tcb (rtems_tcb *tcb, void *arg)
{
tcb->Capture.flags &= ~RTEMS_CAPTURE_TRACED;
+ return false;
}
/*
@@ -776,7 +779,7 @@ rtems_capture_flush (bool prime)
return RTEMS_UNSATISFIED;
}
- rtems_iterate_over_all_threads (rtems_capture_flush_tcb);
+ _Thread_Iterate (rtems_capture_flush_tcb, NULL);
if (prime)
capture_flags_global &= ~(RTEMS_CAPTURE_TRIGGERED | RTEMS_CAPTURE_OVERFLOW);
diff --git a/cpukit/libmisc/cpuuse/cpuusagereset.c b/cpukit/libmisc/cpuuse/cpuusagereset.c
index abfd4db384..608c6a11e8 100644
--- a/cpukit/libmisc/cpuuse/cpuusagereset.c
+++ b/cpukit/libmisc/cpuuse/cpuusagereset.c
@@ -26,8 +26,9 @@
#include "cpuuseimpl.h"
-static void CPU_usage_Per_thread_handler(
- Thread_Control *the_thread
+static bool CPU_usage_Per_thread_handler(
+ Thread_Control *the_thread,
+ void *arg
)
{
const Scheduler_Control *scheduler;
@@ -42,6 +43,7 @@ static void CPU_usage_Per_thread_handler(
_Scheduler_Release_critical( scheduler, &scheduler_lock_context );
_Thread_State_release( the_thread, &state_lock_context );
+ return false;
}
/*
@@ -61,5 +63,5 @@ void rtems_cpu_usage_reset( void )
cpu->cpu_usage_timestamp = CPU_usage_Uptime_at_last_reset;
}
- rtems_iterate_over_all_threads(CPU_usage_Per_thread_handler);
+ rtems_task_iterate(CPU_usage_Per_thread_handler, NULL);
}
diff --git a/cpukit/libmisc/cpuuse/cpuusagetop.c b/cpukit/libmisc/cpuuse/cpuusagetop.c
index 38d5ca4b25..9afa4e292d 100644
--- a/cpukit/libmisc/cpuuse/cpuusagetop.c
+++ b/cpukit/libmisc/cpuuse/cpuusagetop.c
@@ -85,43 +85,6 @@ typedef struct
#define RTEMS_TOP_SORT_CURRENT (4)
#define RTEMS_TOP_SORT_MAX (4)
-/*
- * Private version of the iterator with an arg. This will be moved
- * to the public version in 5.0.
- */
-
-typedef void (*rtems_per_thread_routine_2)( Thread_Control *, void* );
-
-void rtems_iterate_over_all_threads_2(rtems_per_thread_routine_2 routine,
- void* arg);
-
-void rtems_iterate_over_all_threads_2(rtems_per_thread_routine_2 routine,
- void* arg)
-{
- uint32_t i;
- uint32_t api_index;
- Thread_Control *the_thread;
- Objects_Information *information;
-
- if ( !routine )
- return;
-
- for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) {
- #if !defined(RTEMS_POSIX_API) || defined(RTEMS_DEBUG)
- if ( !_Objects_Information_table[ api_index ] )
- continue;
- #endif
- information = _Objects_Information_table[ api_index ][ 1 ];
- if ( information ) {
- for ( i=1 ; i <= information->maximum ; i++ ) {
- the_thread = (Thread_Control *)information->local_table[ i ];
- if ( the_thread )
- (*routine)(the_thread, arg);
- }
- }
- }
-}
-
static inline bool equal_to_uint32_t( uint32_t * lhs, uint32_t * rhs )
{
if ( *lhs == *rhs )
@@ -190,17 +153,19 @@ print_time(rtems_cpu_usage_data* data,
/*
* Count the number of tasks.
*/
-static void
+static bool
task_counter(Thread_Control *thrad, void* arg)
{
rtems_cpu_usage_data* data = (rtems_cpu_usage_data*) arg;
++data->task_count;
+
+ return false;
}
/*
* Create the sorted table with the current and total usage.
*/
-static void
+static bool
task_usage(Thread_Control* thread, void* arg)
{
rtems_cpu_usage_data* data = (rtems_cpu_usage_data*) arg;
@@ -287,6 +252,8 @@ task_usage(Thread_Control* thread, void* arg)
data->current_usage[j] = current;
break;
}
+
+ return false;
}
/*
@@ -322,7 +289,7 @@ rtems_cpuusage_top_thread (rtems_task_argument arg)
Timestamp_Control load;
data->task_count = 0;
- rtems_iterate_over_all_threads_2(task_counter, data);
+ _Thread_Iterate(task_counter, data);
tasks_size = sizeof(Thread_Control*) * (data->task_count + 1);
usage_size = sizeof(Timestamp_Control) * (data->task_count + 1);
@@ -353,7 +320,7 @@ rtems_cpuusage_top_thread (rtems_task_argument arg)
_Timestamp_Subtract(&data->last_uptime, &data->uptime, &data->period);
data->last_uptime = data->uptime;
- rtems_iterate_over_all_threads_2(task_usage, data);
+ _Thread_Iterate(task_usage, data);
if (data->task_count > data->task_size)
{
diff --git a/cpukit/libmisc/stackchk/check.c b/cpukit/libmisc/stackchk/check.c
index ae4ae79ed8..4c48c5bde3 100644
--- a/cpukit/libmisc/stackchk/check.c
+++ b/cpukit/libmisc/stackchk/check.c
@@ -352,23 +352,20 @@ static inline void *Stack_check_find_high_water_mark(
*
* Try to print out how much stack was actually used by the task.
*/
-static const rtems_printer* printer;
-
-static void Stack_check_Dump_threads_usage(
- Thread_Control *the_thread
+static bool Stack_check_Dump_threads_usage(
+ Thread_Control *the_thread,
+ void *arg
)
{
- uint32_t size, used;
- void *low;
- void *high_water_mark;
- void *current;
- Stack_Control *stack;
- char name[5];
+ uint32_t size, used;
+ void *low;
+ void *high_water_mark;
+ void *current;
+ Stack_Control *stack;
+ char name[5];
+ const rtems_printer *printer;
- /*
- * The pointer passed in for the_thread is guaranteed to be non-NULL from
- * rtems_iterate_over_all_threads() so no need to check it here.
- */
+ printer = arg;
/*
* Obtain interrupt stack information
@@ -376,7 +373,7 @@ static void Stack_check_Dump_threads_usage(
#if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE)
if (the_thread == (Thread_Control *) -1) {
if (!Stack_check_Interrupt_stack.area)
- return;
+ return false;
stack = &Stack_check_Interrupt_stack;
the_thread = 0;
current = 0;
@@ -430,7 +427,7 @@ static void Stack_check_Dump_threads_usage(
rtems_printf( printer, "%8" PRId32 "\n", used );
}
-
+ return false;
}
/*
@@ -453,25 +450,26 @@ static void Stack_check_Dump_threads_usage(
*/
void rtems_stack_checker_report_usage_with_plugin(
- const rtems_printer* printer_
+ const rtems_printer* printer
)
{
- if ( printer != NULL || ! rtems_print_printer_valid ( printer_ ) )
- return;
-
- printer = printer_;
-
rtems_printf( printer, "Stack usage by thread\n");
rtems_printf( printer,
" ID NAME LOW HIGH CURRENT AVAILABLE USED\n"
);
/* iterate over all threads and dump the usage */
- rtems_iterate_over_all_threads( Stack_check_Dump_threads_usage );
+ rtems_task_iterate(
+ Stack_check_Dump_threads_usage,
+ RTEMS_DECONST( rtems_printer *, printer )
+ );
#if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE)
/* dump interrupt stack info if any */
- Stack_check_Dump_threads_usage((Thread_Control *) -1);
+ Stack_check_Dump_threads_usage(
+ (Thread_Control *) -1,
+ RTEMS_DECONST( rtems_printer *, printer )
+ );
#endif
printer = NULL;