Changeset 05e4e599 in rtems


Ignore:
Timestamp:
Sep 4, 2014, 6:49:04 PM (6 years ago)
Author:
Jennifer Averett <jennifer.averett@…>
Branches:
4.11, 5, master
Children:
254b7db0
Parents:
7c797a1
git-author:
Jennifer Averett <jennifer.averett@…> (09/04/14 18:49:04)
git-committer:
Jennifer Averett <jennifer.averett@…> (10/27/14 19:01:13)
Message:

capture: Removal of capture task tracking.

This patch removes functionality for stack checking from
the capture engine and requiresi the use of existing rtems
functions for this information. It modifies ctload to use
functionality similar to rtems cpuusage. It removes the
capture task and stores a new capture task record the first
time the task is seen. The per task data that was still
needed is scaled down and stored in the tcb.

Location:
cpukit/libmisc/capture
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libmisc/capture/capture-cli.c

    r7c797a1 r05e4e599  
    3636#include <rtems/capture-cli.h>
    3737#include <rtems/monitor.h>
    38 
     38#include <rtems/cpuuse.h>
     39#
    3940#define RC_UNUSED __attribute__((unused))
    4041
    4142#define RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS (20)
     43
     44/*
     45 * Counter used to count the number of active tasks.
     46 */
     47static int                   rtems_capture_cli_task_count = 0;
     48
     49/*
     50 * Array of tasks sorted by load.
     51 */
     52static rtems_tcb*            rtems_capture_cli_load_tasks[RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS + 1];
     53
     54/*
     55 * The load for each tcb at the moment rtems_capture_cli_load_tasks was generated.
     56 */
     57static unsigned long long    rtems_capture_cli_load[RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS + 1];
    4258
    4359/*
     
    234250}
    235251
     252static void
     253rtems_capture_cli_print_task (rtems_tcb *tcb)
     254{
     255  rtems_task_priority   ceiling = rtems_capture_watch_get_ceiling ();
     256  rtems_task_priority   floor = rtems_capture_watch_get_floor ();
     257  rtems_task_priority   priority;
     258  int                   length;
     259
     260  priority = rtems_capture_task_real_priority (tcb);
     261
     262  fprintf (stdout, " ");
     263  rtems_monitor_dump_id (rtems_capture_task_id (tcb));
     264  fprintf (stdout, " ");
     265  rtems_monitor_dump_name (rtems_capture_task_id (tcb));
     266  fprintf (stdout, " ");
     267  rtems_monitor_dump_priority (rtems_capture_task_start_priority (tcb));
     268  fprintf (stdout, " ");
     269  rtems_monitor_dump_priority (rtems_capture_task_real_priority (tcb));
     270  fprintf (stdout, " ");
     271  rtems_monitor_dump_priority (rtems_capture_task_curr_priority (tcb));
     272  fprintf (stdout, " ");
     273  length = rtems_monitor_dump_state (rtems_capture_task_state (tcb));
     274  fprintf (stdout, "%*c", 14 - length, ' ');
     275  fprintf (stdout, " %c%c",
     276           'a',
     277           rtems_capture_task_flags (tcb) & RTEMS_CAPTURE_TRACED ? 't' : '-');
     278
     279  if ((floor > ceiling) && (ceiling > priority))
     280    fprintf (stdout, "--");
     281  else
     282  {
     283    uint32_t flags = rtems_capture_task_control_flags (tcb);
     284    fprintf (stdout, "%c%c",
     285             rtems_capture_task_control (tcb) ?
     286             (flags & RTEMS_CAPTURE_WATCH ? 'w' : '+') : '-',
     287             rtems_capture_watch_global_on () ? 'g' : '-');
     288  }
     289  fprintf (stdout, "\n");
     290}
     291static void
     292rtems_caputure_cli_print_record_std(rtems_capture_record_t* rec, uint64_t diff)
     293{
     294  uint32_t                     event;
     295  int                          e;
     296
     297  event = rec->events >> RTEMS_CAPTURE_EVENT_START;
     298
     299  for (e = RTEMS_CAPTURE_EVENT_START; e < RTEMS_CAPTURE_EVENT_END; e++)
     300  {
     301    if (event & 1)
     302    {
     303      rtems_capture_cli_print_timestamp (rec->time);
     304      fprintf (stdout, " %9" PRId64 " ", diff);
     305      rtems_monitor_dump_id (rec->task_id);
     306      fprintf(stdout, "      %3" PRId32 " %3" PRId32 " %s\n",
     307             (rec->events >> RTEMS_CAPTURE_REAL_PRIORITY_EVENT) & 0xff,
     308             (rec->events >> RTEMS_CAPTURE_CURR_PRIORITY_EVENT) & 0xff,
     309             rtems_capture_event_text (e));
     310    }
     311    event >>= 1;
     312  }
     313}
     314
     315static void
     316rtems_caputre_cli_print_record_task(rtems_capture_record_t* rec)
     317{
     318  rtems_capture_task_record_t* task_rec = (rtems_capture_task_record_t*) rec;
     319
     320  rtems_capture_cli_print_timestamp (rec->time);
     321  fprintf (stdout, "           ");
     322  rtems_monitor_dump_id (rec->task_id);
     323   fprintf (stdout, " %c%c%c%c",
     324            (char) (task_rec->name >> 24) & 0xff,
     325            (char) (task_rec->name >> 16) & 0xff,
     326            (char) (task_rec->name >> 8) & 0xff,
     327            (char) (task_rec->name >> 0) & 0xff);
     328   fprintf (stdout, " %3" PRId32   " %3" PRId32 "\n",
     329            task_rec->start_priority,
     330            task_rec->stack_size);
     331}
     332
     333/*
     334 * rtems_capture_cli_count_tasks
     335 *
     336 *  DESCRIPTION:
     337 *
     338 * This function is called for each tcb and counts the
     339 * number of tasks.
     340 *
     341 */
     342
     343static void
     344rtems_capture_cli_count_tasks (rtems_tcb *tcb)
     345{
     346  rtems_capture_cli_task_count++;
     347}
     348
     349
    236350/*
    237351 * rtems_capture_cli_task_list
     
    249363                             bool                               verbose RC_UNUSED)
    250364{
    251   rtems_task_priority   ceiling = rtems_capture_watch_get_ceiling ();
    252   rtems_task_priority   floor = rtems_capture_watch_get_floor ();
    253   rtems_capture_task_t* task = rtems_capture_get_task_list ();
    254   int                   count = rtems_capture_task_count ();
    255365  rtems_capture_time_t  uptime;
    256366
    257367  rtems_capture_time (&uptime);
     368
     369  rtems_capture_cli_task_count = 0;
     370  rtems_iterate_over_all_threads (rtems_capture_cli_count_tasks);
    258371
    259372  fprintf (stdout, "uptime: ");
    260373  rtems_capture_cli_print_timestamp (uptime);
    261   fprintf (stdout, "\ntotal %i\n", count);
    262 
    263   while (task)
    264   {
    265     rtems_task_priority priority;
    266     int32_t             stack_used;
    267     int32_t             time_used;
    268     int                 length;
    269 
    270     stack_used = rtems_capture_task_stack_usage (task);
    271     if (stack_used)
    272       stack_used = (stack_used * 100) / rtems_capture_task_stack_size (task);
    273 
    274     if (stack_used > 100)
    275       stack_used = 100;
    276 
    277     time_used = (rtems_capture_task_time (task) * 100) / uptime;
    278 
    279     if (time_used > 100)
    280       time_used = 100;
    281 
    282     priority = rtems_capture_task_real_priority (task);
    283 
    284     fprintf (stdout, " ");
    285     rtems_monitor_dump_id (rtems_capture_task_id (task));
    286     fprintf (stdout, " ");
    287     rtems_monitor_dump_name (rtems_capture_task_id (task));
    288     fprintf (stdout, " ");
    289     rtems_monitor_dump_priority (rtems_capture_task_start_priority (task));
    290     fprintf (stdout, " ");
    291     rtems_monitor_dump_priority (rtems_capture_task_real_priority (task));
    292     fprintf (stdout, " ");
    293     rtems_monitor_dump_priority (rtems_capture_task_curr_priority (task));
    294     fprintf (stdout, " ");
    295     length = rtems_monitor_dump_state (rtems_capture_task_state (task));
    296     fprintf (stdout, "%*c", 14 - length, ' ');
    297     fprintf (stdout, " %c%c",
    298              rtems_capture_task_valid (task) ? 'a' : 'd',
    299              rtems_capture_task_flags (task) & RTEMS_CAPTURE_TRACED ? 't' : '-');
    300 
    301     if ((floor > ceiling) && (ceiling > priority))
    302       fprintf (stdout, "--");
    303     else
    304     {
    305       uint32_t flags = rtems_capture_task_control_flags (task);
    306       fprintf (stdout, "%c%c",
    307                rtems_capture_task_control (task) ?
    308                (flags & RTEMS_CAPTURE_WATCH ? 'w' : '+') : '-',
    309                rtems_capture_watch_global_on () ? 'g' : '-');
    310     }
    311     fprintf (stdout, " %3" PRId32 "%% %3" PRId32 "%% ", stack_used, time_used);
    312     rtems_capture_cli_print_timestamp (rtems_capture_task_time (task));
    313     fprintf (stdout, "\n");
    314 
    315     task = rtems_capture_next_task (task);
     374  fprintf (stdout, "\ntotal %i\n", rtems_capture_cli_task_count);
     375  rtems_iterate_over_all_threads (rtems_capture_cli_print_task);
     376}
     377
     378static void
     379rtems_capture_cli_task_sort (rtems_tcb* tcb)
     380{
     381  int                   i;
     382  int                   j;
     383
     384  if (tcb)
     385  {
     386    rtems_capture_time_t l = tcb->cpu_time_used;
     387
     388    rtems_capture_cli_task_count++;
     389
     390    for (i = 0; i < RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS; i++)
     391    {
     392      if (rtems_capture_cli_load_tasks[i])
     393      {
     394        if ((l == 0) || (l < rtems_capture_cli_load[i]))
     395          continue;
     396
     397        for (j = (RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS - 1); j >= i; j--)
     398        {
     399          rtems_capture_cli_load_tasks[j + 1] = rtems_capture_cli_load_tasks[j];
     400          rtems_capture_cli_load[j + 1]  = rtems_capture_cli_load[j];
     401        }
     402      }
     403
     404      rtems_capture_cli_load_tasks[i] = tcb;
     405      rtems_capture_cli_load[i]  = l;
     406      break;
     407    }
    316408  }
    317409}
     
    329421rtems_capture_cli_task_load_thread (rtems_task_argument arg)
    330422{
     423  rtems_tcb*          tcb;
    331424  rtems_task_priority ceiling = rtems_capture_watch_get_ceiling ();
    332425  rtems_task_priority floor = rtems_capture_watch_get_floor ();
    333426  int                 last_count = 0;
    334427  FILE*               pstdout = (FILE*) arg;
     428  int                 i;
     429  int                 j;
    335430
    336431  fileno(stdout);
     
    339434  while (true)
    340435  {
    341     rtems_capture_task_t* tasks[RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS + 1];
    342     unsigned long long    load[RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS + 1];
    343     rtems_capture_task_t* task;
    344     rtems_capture_time_t  uptime;
    345     rtems_capture_time_t  total_time;
    346     int                   count = 0;
    347     int                   i;
    348     int                   j;
    349 
    350     rtems_capture_time (&uptime);
     436    Timestamp_Control  uptime, total, ran, uptime_at_last_reset;
     437    uint32_t seconds, nanoseconds;
     438    size_t                size;
    351439
    352440    cli_load_thread_active = 1;
     
    357445     * tasks.
    358446     */
    359 
    360     memset (tasks, 0, sizeof (tasks));
    361     memset (load, 0, sizeof (load));
    362 
    363     task = rtems_capture_get_task_list ();
    364 
    365     total_time = 0;
    366 
    367     while (task)
    368     {
    369       if (rtems_capture_task_valid (task))
    370       {
    371         rtems_capture_time_t l = rtems_capture_task_delta_time (task);
    372 
    373         count++;
    374 
    375         total_time += l;
    376 
    377         for (i = 0; i < RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS; i++)
    378         {
    379           if (tasks[i])
    380           {
    381             if ((l == 0) || (l < load[i]))
    382               continue;
    383 
    384             for (j = (RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS - 1); j >= i; j--)
    385             {
    386               tasks[j + 1] = tasks[j];
    387               load[j + 1]  = load[j];
    388             }
    389           }
    390 
    391           tasks[i] = task;
    392           load[i]  = l;
    393           break;
    394         }
    395       }
    396       task = rtems_capture_next_task (task);
    397     }
     447    size = sizeof (rtems_capture_cli_load_tasks);
     448    memset (rtems_capture_cli_load_tasks, 0, size);
     449    memset (rtems_capture_cli_load, 0, sizeof (rtems_capture_cli_load));
     450
     451    _Timestamp_Set_to_zero( &total );
     452    uptime_at_last_reset = CPU_usage_Uptime_at_last_reset;
     453    _TOD_Get_uptime( &uptime );
     454    seconds = _Timestamp_Get_seconds( &uptime );
     455    nanoseconds = _Timestamp_Get_nanoseconds( &uptime ) /
     456                  TOD_NANOSECONDS_PER_MICROSECOND;
     457
     458    rtems_iterate_over_all_threads (rtems_capture_cli_task_sort);
    398459
    399460    fprintf (stdout, "\x1b[H\x1b[J Press ENTER to exit.\n\n");
    400461    fprintf (stdout, "uptime: ");
    401     rtems_capture_cli_print_timestamp (uptime);
     462    fprintf (stdout, "%7" PRIu32 ".%06" PRIu32 "\n",  seconds, nanoseconds);
    402463    fprintf (stdout,
    403464             "\n\n"
    404              "     PID NAME RPRI CPRI STATE          %%CPU     %%STK FLGS    EXEC TIME\n");
    405 
    406     if (count > last_count)
    407       j = count;
     465             "     PID NAME RPRI CPRI STATE      EXEC TIME   %%CPU\n");
     466
     467    if (rtems_capture_cli_task_count > last_count)
     468      j = rtems_capture_cli_task_count;
    408469    else
    409470      j = last_count;
     
    412473    {
    413474      rtems_task_priority priority;
    414       int                 stack_used;
    415       int                 task_load;
    416       int                 k;
    417 
    418       if (!tasks[i])
     475      Timestamp_Control   last;
     476      uint32_t            ival, fval;
     477
     478      if (!rtems_capture_cli_load_tasks[i])
    419479        break;
    420480
    421481      j--;
    422482
    423       stack_used = rtems_capture_task_stack_usage (tasks[i]);
    424       if (stack_used)
    425         stack_used = (stack_used * 100) / rtems_capture_task_stack_size (tasks[i]);
    426 
    427       if (stack_used > 100)
    428         stack_used = 100;
    429 
    430       task_load = (int) ((load[i] * 100000) / total_time);
    431 
    432       priority = rtems_capture_task_real_priority (tasks[i]);
     483      /*
     484       * If this is the currently executing thread, account for time
     485       * since the last context switch.
     486       */
     487      tcb = rtems_capture_cli_load_tasks[i];
     488      ran = rtems_capture_cli_load[i];
     489      if ( _Thread_Get_time_of_last_context_switch( tcb, &last ) ) {
     490        Timestamp_Control used;
     491        _TOD_Get_uptime( &uptime );
     492        _Timestamp_Subtract( &last, &uptime, &used );
     493        _Timestamp_Add_to( &ran, &used );
     494      } else {
     495        _TOD_Get_uptime( &uptime );
     496      }
     497      _Timestamp_Subtract( &uptime_at_last_reset, &uptime, &total );
     498      _Timestamp_Divide( &ran, &total, &ival, &fval );
     499      seconds = _Timestamp_Get_seconds( &ran );
     500      nanoseconds = _Timestamp_Get_nanoseconds( &ran ) /
     501             TOD_NANOSECONDS_PER_MICROSECOND;
     502
     503      priority = rtems_capture_task_real_priority (tcb);
    433504
    434505      fprintf (stdout, "\x1b[K");
    435       rtems_monitor_dump_id (rtems_capture_task_id (tasks[i]));
     506      rtems_monitor_dump_id (rtems_capture_task_id (tcb));
    436507      fprintf (stdout, " ");
    437       rtems_monitor_dump_name (rtems_capture_task_id (tasks[i]));
     508      rtems_monitor_dump_name (rtems_capture_task_id (tcb));
    438509      fprintf (stdout, "  ");
    439510      rtems_monitor_dump_priority (priority);
    440511      fprintf (stdout, "  ");
    441       rtems_monitor_dump_priority (rtems_capture_task_curr_priority (tasks[i]));
     512      rtems_monitor_dump_priority (rtems_capture_task_curr_priority (tcb));
    442513      fprintf (stdout, " ");
    443       k = rtems_monitor_dump_state (rtems_capture_task_state (tasks[i]));
    444       fprintf (stdout, "%*c %3i.%03i%% ", 14 - k, ' ',
    445                task_load / 1000, task_load % 1000);
    446       fprintf (stdout, "%3i%% %c%c", stack_used,
    447               rtems_capture_task_valid (tasks[i]) ? 'a' : 'd',
    448               rtems_capture_task_flags (tasks[i]) & RTEMS_CAPTURE_TRACED ? 't' : '-');
     514      rtems_monitor_dump_state (rtems_capture_task_state (tcb));
     515      fprintf (stdout,
     516            "%7" PRIu32 ".%06" PRIu32 " |%4" PRIu32 ".%03" PRIu32 ,
     517            seconds, nanoseconds, ival, fval
     518       );
     519      fprintf (stdout, "    %c%c",
     520              'a',
     521              rtems_capture_task_flags (tcb) & RTEMS_CAPTURE_TRACED ? 't' : '-');
    449522
    450523      if ((floor > ceiling) && (ceiling > priority))
     
    452525      else
    453526        fprintf (stdout, "%c%c",
    454                 rtems_capture_task_control (tasks[i]) ?
    455                 (rtems_capture_task_control_flags (tasks[i]) &
     527                rtems_capture_task_control (tcb) ?
     528                (rtems_capture_task_control_flags (tcb) &
    456529                 RTEMS_CAPTURE_WATCH ? 'w' : '+') : '-',
    457530                rtems_capture_watch_global_on () ? 'g' : '-');
    458531
    459532      fprintf (stdout, "   ");
    460       rtems_capture_cli_print_timestamp (rtems_capture_task_time (tasks[i]));
    461533      fprintf (stdout, "\n");
    462534    }
    463535
    464     if (count < RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS)
    465     {
    466       j = RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS - count;
     536    if (rtems_capture_cli_task_count < RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS)
     537    {
     538      j = RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS - rtems_capture_cli_task_count;
    467539      while (j > 0)
    468540      {
     
    472544    }
    473545
    474     last_count = count;
     546    last_count = rtems_capture_cli_task_count;
    475547
    476548    cli_load_thread_active = 0;
     
    14161488
    14171489      if (csv)
    1418         fprintf (stdout, "%08" PRIxPTR ",%03" PRIu32
     1490        fprintf (stdout, "%08" PRIu32 ",%03" PRIu32
    14191491                   ",%03" PRIu32 ",%04" PRIx32 ",%" PRId64 "\n",
    1420                  (uintptr_t) rec->task,
     1492                 rec->task_id,
    14211493                 (rec->events >> RTEMS_CAPTURE_REAL_PRIORITY_EVENT) & 0xff,
    14221494                 (rec->events >> RTEMS_CAPTURE_CURR_PRIORITY_EVENT) & 0xff,
    14231495                 (rec->events >> RTEMS_CAPTURE_EVENT_START),
    14241496                 (uint64_t) rec->time);
    1425       else
    1426       {
    1427         uint64_t diff = 0;
    1428         uint32_t event;
    1429         int      e;
    1430 
    1431         event = rec->events >> RTEMS_CAPTURE_EVENT_START;
    1432 
    1433         for (e = RTEMS_CAPTURE_EVENT_START; e < RTEMS_CAPTURE_EVENT_END; e++)
    1434         {
    1435           if (event & 1)
    1436           {
    1437             rtems_capture_cli_print_timestamp (rec->time);
    1438             if (last_t)
    1439               diff = rec->time - last_t;
    1440             last_t = rec->time;
    1441             fprintf (stdout, " %9" PRId64 " ", diff);
    1442             rtems_monitor_dump_id (rtems_capture_task_id (rec->task));
    1443             fprintf (stdout, " %c%c%c%c",
    1444                      (char) (rec->task->name >> 24) & 0xff,
    1445                      (char) (rec->task->name >> 16) & 0xff,
    1446                      (char) (rec->task->name >> 8) & 0xff,
    1447                      (char) (rec->task->name >> 0) & 0xff);
    1448             fprintf (stdout, " %3" PRId32 " %3" PRId32 " %s\n",
    1449                     (rec->events >> RTEMS_CAPTURE_REAL_PRIORITY_EVENT) & 0xff,
    1450                     (rec->events >> RTEMS_CAPTURE_CURR_PRIORITY_EVENT) & 0xff,
    1451                     rtems_capture_event_text (e));
    1452           }
    1453           event >>= 1;
     1497      else {
     1498        if ((rec->events >> RTEMS_CAPTURE_EVENT_START) == 0)
     1499          rtems_caputre_cli_print_record_task( rec );
     1500        else {
     1501          uint64_t diff = 0;
     1502          if (last_t)
     1503            diff = rec->time - last_t;
     1504          last_t = rec->time;
     1505
     1506          rtems_caputure_cli_print_record_std( rec, diff );
    14541507        }
    14551508      }
  • cpukit/libmisc/capture/capture.c

    r7c797a1 r05e4e599  
    2828#include <stdlib.h>
    2929#include <string.h>
    30 #include <rtems/rtems/tasksimpl.h>
    3130
    3231#include "captureimpl.h"
     
    6564 * RTEMS Capture Data.
    6665 */
    67 static rtems_capture_buffer_t         capture_records = {NULL, 0, 0, 0, 0, 0};
     66static rtems_capture_buffer_t   capture_records = {NULL, 0, 0, 0, 0, 0};
    6867static uint32_t                 capture_count;
    6968static uint32_t                 capture_flags;
    70 static rtems_capture_task_t*    capture_tasks;
    7169static rtems_capture_control_t* capture_controls;
    7270static int                      capture_extension_index;
     
    119117}
    120118
    121 
    122 rtems_capture_task_t* rtems_capture_find_capture_task( rtems_id ct_id )
    123 {
    124   rtems_capture_task_t* ct;
    125 
    126   for (ct = capture_tasks; ct; ct = ct->forw) {
    127     if (ct->id == ct_id)
    128       break;
    129   }
    130   return ct;
    131 }
    132 
    133119/*
    134120 * This function returns the current time. If a handler is provided
     
    208194static inline bool
    209195rtems_capture_by_in_to (uint32_t                 events,
    210                         rtems_capture_task_t*    by,
     196                        rtems_tcb*               by,
    211197                        rtems_capture_control_t* to)
    212198{
     
    236222       */
    237223      if (rtems_capture_match_name_id (to->by[i].name, to->by[i].id,
    238                                        by->name, by->id))
     224                                       rtems_capture_task_name( by ),
     225                                       by->Object.id))
    239226        return 1;
    240227    }
     
    245232
    246233  return 0;
    247 }
    248 
    249 /*
    250  * This function raises the reference count.
    251  */
    252 static inline void
    253 rtems_capture_refcount_up (rtems_capture_task_t* task)
    254 {
    255   task->refcount++;
    256 }
    257 
    258 /*
    259  * This function lowers the reference count and if the count
    260  * reaches 0 the task control block is returned to the heap.
    261  */
    262 static inline void
    263 rtems_capture_refcount_down (rtems_capture_task_t* task)
    264 {
    265   if (task->refcount)
    266     task->refcount--;
    267 }
    268 
    269 /*
    270  * This function setups a stack so its usage can be monitored.
    271  */
    272 void
    273 rtems_capture_init_stack_usage (rtems_capture_task_t* task)
    274 {
    275   if (task->tcb)
    276   {
    277     uint32_t* s;
    278     uint32_t  i;
    279 
    280     task->stack_size  = task->tcb->Start.Initial_stack.size;
    281     task->stack_clean = task->stack_size;
    282 
    283     s = task->tcb->Start.Initial_stack.area;
    284 
    285     for (i = 0; i < (task->stack_size - 128); i += 4)
    286       *(s++) = 0xdeaddead;
    287   }
    288234}
    289235
     
    303249
    304250/*
     251 * This function checks if a new control structure matches
     252 * the given task and sets the control if it does.
     253 */
     254static void
     255rtems_capture_initialize_control (rtems_tcb *tcb)
     256{
     257  rtems_name                   name;
     258  rtems_capture_control_t*     control;
     259
     260  /*
     261   * We need to scan the default control list to initialise
     262   * this control.
     263   */
     264  rtems_object_get_classic_name( tcb->Object.id, &name );
     265  control = capture_controls;
     266  if (rtems_capture_match_name_id (control->name, control->id,
     267                                   name, tcb->Object.id))
     268    tcb->Capture.control = control;
     269}
     270
     271/*
    305272 * This function creates a capture control for the capture engine.
    306273 */
     
    310277  rtems_interrupt_lock_context lock_context;
    311278  rtems_capture_control_t*     control;
    312   rtems_capture_task_t*        task;
    313279
    314280  if ((name == 0) && (id == 0))
     
    340306    control->next    = capture_controls;
    341307    capture_controls = control;
    342 
    343     /*
    344      * We need to scan the task list as set the control to the
    345      * tasks.
    346      */
    347     for (task = capture_tasks; task != NULL; task = task->forw)
    348       if (rtems_capture_match_name_id (name, id, task->name, task->id))
    349         task->control = control;
     308    rtems_iterate_over_all_threads (rtems_capture_initialize_control);
    350309
    351310    rtems_interrupt_lock_release (&capture_lock, &lock_context);
     
    355314}
    356315
    357 /*
    358  * This function create the task control.
    359  */
    360 rtems_capture_task_t*
    361 rtems_capture_create_capture_task (rtems_tcb* new_task)
    362 {
    363   rtems_interrupt_lock_context lock_context;
    364   rtems_capture_task_t*        task;
    365   rtems_capture_control_t*     control;
    366   rtems_name                   name;
    367   rtems_capture_time_t         time;
    368   bool                         ok;
    369 
    370   ok = rtems_workspace_allocate (sizeof (*task), (void **) &task);
    371 
    372   if (!ok)
    373   {
    374     capture_flags |= RTEMS_CAPTURE_NO_MEMORY;
    375     return NULL;
    376   }
    377 
    378   /*
    379    * Get the current time.
    380    */
    381   rtems_capture_get_time (&time);
    382 
    383   /*
    384    * Check the type of name the object has.
    385    */
    386 
    387   rtems_object_get_classic_name( new_task->Object.id, &name );
    388 
    389   rtems_capture_dup_name (&task->name, name);
    390 
    391   task->id               = new_task->Object.id;
    392   task->flags            = 0;
    393   task->in               = 0;
    394   task->refcount         = 0;
    395   task->out              = 0;
    396   task->tcb              = new_task;
    397   task->time             = 0;
    398   task->time_in          = time;
    399   task->control          = 0;
    400   task->last_time        = 0;
    401 
    402   task->tcb->extensions[capture_extension_index] = task;
    403 
    404   task->start_priority = _RTEMS_tasks_Priority_from_Core(
    405                            new_task->Start.initial_priority
    406                          );
    407   task->stack_size     = new_task->Start.Initial_stack.size;
    408   task->stack_clean    = task->stack_size;
    409 
    410   rtems_interrupt_lock_acquire (&capture_lock, &lock_context);
    411 
    412   task->forw    = capture_tasks;
    413   if (task->forw)
    414     task->forw->back = task;
    415   task->back    = NULL;
    416   capture_tasks = task;
    417 
    418   rtems_interrupt_lock_release (&capture_lock, &lock_context);
     316void rtems_capture_record_task( rtems_tcb* tcb )
     317{
     318  rtems_capture_control_t*    control;
     319  rtems_capture_task_record_t rec;
     320  void*                       ptr;
     321
     322  rtems_object_get_classic_name( tcb->Object.id, &rec.name );
    419323
    420324  /*
    421325   * We need to scan the default control list to initialise
    422    * this control.
    423    */
    424 
    425   for (control = capture_controls; control != NULL; control = control->next)
    426     if (rtems_capture_match_name_id (control->name, control->id,
    427                                      task->name, task->id))
    428       task->control = control;
    429 
    430   return task;
    431 }
    432 
    433 /*
    434  * This function destroy the task structure if the reference count
    435  * is 0 and the tcb has been cleared signalling the task has been
    436  * deleted.
    437  */
    438 void
    439 rtems_capture_destroy_capture_task (rtems_capture_task_t* task)
    440 {
    441   if (task)
    442   {
    443     rtems_interrupt_lock_context lock_context;
    444 
    445     rtems_interrupt_lock_acquire (&capture_lock, &lock_context);
    446 
    447     if (task->tcb || task->refcount)
    448       task = 0;
    449 
    450     if (task)
    451     {
    452       if (task->forw)
    453         task->forw->back = task->back;
    454       if (task->back)
    455         task->back->forw = task->forw;
    456       else
    457         capture_tasks = task->forw;
    458     }
    459 
    460     rtems_interrupt_lock_release (&capture_lock, &lock_context);
    461 
    462     rtems_workspace_free (task);
    463   }
     326   * this control if it is a new task.
     327   */
     328
     329  if (tcb->Capture.control == NULL) {
     330    for (control = capture_controls; control != NULL; control = control->next)
     331      if (rtems_capture_match_name_id (control->name, control->id,
     332                                       rec.name, tcb->Object.id))
     333        tcb->Capture.control = control;
     334  }
     335
     336  rec.stack_size = tcb->Start.Initial_stack.size;
     337  rec.start_priority = _RTEMS_tasks_Priority_from_Core(
     338    tcb->Start.initial_priority
     339  );
     340
     341  tcb->Capture.flags |= RTEMS_CAPTURE_RECORD_TASK;
     342
     343  /*
     344   *  Log the task information. The first time a task is
     345   *  seen a record is logged.  This record can be identified
     346   *  by a 0 in the event identifier.
     347   */
     348
     349  rtems_capture_begin_add_record (tcb, 0, sizeof(rec), &ptr);
     350  ptr = rtems_capture_append_to_record(
     351    ptr,
     352    &rec.name,
     353    sizeof( rec.name )
     354  );
     355  ptr = rtems_capture_append_to_record(
     356    ptr,
     357    &rec.start_priority,
     358    sizeof( rec.start_priority)
     359  );
     360  ptr = rtems_capture_append_to_record(
     361    ptr,
     362    &rec.stack_size,
     363    sizeof( rec.stack_size)
     364  );
     365  rtems_capture_end_add_record ( ptr );
    464366}
    465367
     
    468370 * log.
    469371 */
    470 bool rtems_capture_filter( rtems_capture_task_t* task,
     372bool rtems_capture_filter( rtems_tcb*            tcb,
    471373                           uint32_t              events)
    472374{
    473   if (task &&
     375  if (tcb &&
    474376      ((capture_flags &
    475377        (RTEMS_CAPTURE_TRIGGERED | RTEMS_CAPTURE_ONLY_MONITOR)) ==
     
    478380    rtems_capture_control_t* control;
    479381
    480     control = task->control;
     382    control = tcb->Capture.control;
    481383
    482384    /*
     
    486388     */
    487389    if ((events & RTEMS_CAPTURE_RECORD_EVENTS) ||
    488         ((task->tcb->real_priority >= capture_ceiling) &&
    489          (task->tcb->real_priority <= capture_floor) &&
     390        ((tcb->real_priority >= capture_ceiling) &&
     391         (tcb->real_priority <= capture_floor) &&
    490392         ((capture_flags & RTEMS_CAPTURE_GLOBAL_WATCH) ||
    491393          (control && (control->flags & RTEMS_CAPTURE_WATCH)))))
     
    502404 */
    503405void *
    504 rtems_capture_record_open (rtems_capture_task_t*         task,
     406rtems_capture_record_open (rtems_tcb*                    tcb,
    505407                           uint32_t                      events,
    506408                           size_t                        size,
     
    517419  {
    518420    capture_count++;
    519     capture_in->size   = size;
    520     capture_in->task   = task;
    521     capture_in->events = (events |
    522                           (task->tcb->real_priority) |
    523                           (task->tcb->current_priority << 8));
     421    capture_in->size    = size;
     422    capture_in->task_id = tcb->Object.id;
     423    capture_in->events  = (events |
     424                          (tcb->real_priority) |
     425                          (tcb->current_priority << 8));
    524426
    525427    if ((events & RTEMS_CAPTURE_RECORD_EVENTS) == 0)
    526       task->flags |= RTEMS_CAPTURE_TRACED;
     428      tcb->Capture.flags |= RTEMS_CAPTURE_TRACED;
    527429
    528430    rtems_capture_get_time (&capture_in->time);
    529431
    530     rtems_capture_refcount_up (task);
    531432    ptr = ptr + sizeof(*capture_in);
    532433  }
     
    547448 */
    548449bool
    549 rtems_capture_trigger (rtems_capture_task_t* ft,
    550                        rtems_capture_task_t* tt,
    551                        uint32_t              events)
    552 {
     450rtems_capture_trigger (rtems_tcb* ft,
     451                       rtems_tcb* tt,
     452                       uint32_t   events)
     453{
     454
    553455  /*
    554456   * If we have not triggered then see if this is a trigger condition.
     
    564466    if (ft)
    565467    {
    566       fc = ft->control;
     468      fc = ft->Capture.control;
    567469      if (fc)
    568470        from_events = fc->from_triggers & events;
     
    571473    if (tt)
    572474    {
    573       tc = tt->control;
     475      tc = tt->Capture.control;
    574476      if (tc)
    575477      {
     
    634536  capture_count   = 0;
    635537  capture_flags   = 0;
    636   capture_tasks   = NULL;
    637538  capture_ceiling = 0;
    638539  capture_floor   = 255;
     
    660561{
    661562  rtems_interrupt_lock_context lock_context;
    662   rtems_capture_task_t*        task;
    663563  rtems_capture_control_t*     control;
    664564  rtems_status_code            sc;
     
    685585  if (sc != RTEMS_SUCCESSFUL)
    686586    return sc;
    687 
    688   task = capture_tasks;
    689 
    690   while (task)
    691   {
    692     rtems_capture_task_t* delete = task;
    693     task = task->forw;
    694     rtems_workspace_free (delete);
    695   }
    696 
    697   capture_tasks = NULL;
    698587
    699588  control = capture_controls;
     
    714603
    715604  return RTEMS_SUCCESSFUL;
    716 }
    717 
    718 /*
    719  * This function allows control of tracing at a global level.
    720  */
    721 static void
    722 rtems_capture_task_setup (Thread_Control *tcb)
    723 {
    724   rtems_capture_create_capture_task (tcb);
    725605}
    726606
     
    743623    capture_flags &= ~RTEMS_CAPTURE_ON;
    744624
    745   rtems_iterate_over_all_threads (rtems_capture_task_setup);
    746 
    747625  rtems_interrupt_lock_release (&capture_lock, &lock_context);
    748626
     
    779657
    780658/*
     659 * This function clears the capture trace flag in the tcb.
     660 */
     661static void
     662rtems_capture_flush_tcb (rtems_tcb *tcb)
     663{
     664  tcb->Capture.flags &= ~RTEMS_CAPTURE_TRACED;
     665}
     666
     667
     668/*
    781669 * This function flushes the capture buffer. The prime parameter allows the
    782670 * capture engine to also be primed again.
     
    786674{
    787675  rtems_interrupt_lock_context lock_context;
    788   rtems_capture_task_t*        task;
    789676
    790677  rtems_interrupt_lock_acquire (&capture_lock, &lock_context);
    791678
    792   for (task = capture_tasks; task != NULL; task = task->forw)
    793   {
    794     task->flags &= ~RTEMS_CAPTURE_TRACED;
    795     task->refcount = 0;
    796   }
     679  rtems_iterate_over_all_threads (rtems_capture_flush_tcb);
    797680
    798681  if (prime)
     
    806689  rtems_interrupt_lock_release (&capture_lock, &lock_context);
    807690
    808   task = capture_tasks;
    809 
    810   while (task)
    811   {
    812     rtems_capture_task_t* check = task;
    813     task = task->forw;
    814     rtems_capture_destroy_capture_task (check);
    815   }
    816 
    817691  return RTEMS_SUCCESSFUL;
    818692}
     
    857731  rtems_capture_control_t*     control;
    858732  rtems_capture_control_t**    prev_control;
    859   rtems_capture_task_t*        task;
    860733  bool                         found = false;
    861734
     
    870743    {
    871744      rtems_interrupt_lock_acquire (&capture_lock, &lock_context);
    872 
    873       for (task = capture_tasks; task != NULL; task = task->forw)
    874         if (task->control == control)
    875           task->control = 0;
    876745
    877746      *prev_control = control->next;
     
    13741243    rec = (rtems_capture_record_t*) ptr;
    13751244    ptr_size += rec->size;
    1376     rtems_capture_refcount_down (rec->task);
    1377     rtems_capture_destroy_capture_task (rec->task);
    13781245    ptr += rec->size;
    13791246  }
     
    14171284
    14181285/*
    1419  * This function returns the head of the list of tasks that the
    1420  * capture engine has detected.
    1421  */
    1422 rtems_capture_task_t*
    1423 rtems_capture_get_task_list (void)
    1424 {
    1425   return capture_tasks;
    1426 }
    1427 
    1428 /*
    1429  * This function updates the stack usage. The task control block
    1430  * is updated.
    1431  */
    1432 uint32_t
    1433 rtems_capture_task_stack_usage (rtems_capture_task_t* task)
    1434 {
    1435   if (task->tcb)
    1436   {
    1437     uint32_t* st;
    1438     uint32_t* s;
    1439 
    1440     /*
    1441      * @todo: Assumes all stacks move the same way.
    1442      */
    1443     st = task->tcb->Start.Initial_stack.area + task->stack_size;
    1444     s  = task->tcb->Start.Initial_stack.area;
    1445 
    1446     while (s < st)
    1447     {
    1448       if (*s != 0xdeaddead)
    1449         break;
    1450       s++;
    1451     }
    1452 
    1453     task->stack_clean =
    1454       s - (uint32_t*) task->tcb->Start.Initial_stack.area;
    1455   }
    1456 
    1457   return task->stack_clean;
    1458 }
    1459 
    1460 /*
    14611286 * This function returns the head of the list of control in the
    14621287 * capture engine.
  • cpukit/libmisc/capture/capture.h

    r7c797a1 r05e4e599  
    4747
    4848#include <rtems.h>
     49#include <rtems/rtems/tasksimpl.h>
    4950
    5051/**
     
    138139
    139140/**
    140  * @brief Catpure task control
    141  *
    142  * RTEMS capture control provdes the information about a task, along
    143  * with its trigger state. The control is referenced by each
    144  * capture record. This is information neeed by the decoder. The
    145  * capture record cannot assume the task will exist when the record is
    146  * dumped via the target interface so task info needed for tracing is
    147  * copied and held here. Once the references in the trace buffer
    148  * have been removed and the task is deleted this structure is
    149  * released back to the heap.
    150  *
    151  * The inline helper functions provide more details about the info
    152  * contained in this structure.
    153  *
    154  * Note, the tracer code exploits the fact an rtems_name is a
    155  * 32bit value.
    156  */
    157 typedef struct rtems_capture_task_s
    158 {
    159   rtems_name                   name;
    160   rtems_id                     id;
    161   uint32_t                     flags;
    162   uint32_t                     refcount;
    163   rtems_tcb*                   tcb;
    164   uint32_t                     in;
    165   uint32_t                     out;
    166   rtems_task_priority          start_priority;
    167   uint32_t                     stack_size;
    168   uint32_t                     stack_clean;
    169   rtems_capture_time_t         time;
    170   rtems_capture_time_t         time_in;
    171   rtems_capture_time_t         last_time;
    172   rtems_capture_control_t*     control;
    173   struct rtems_capture_task_s* forw;
    174   struct rtems_capture_task_s* back;
    175 } rtems_capture_task_t;
    176 
    177 /**
    178141 * Task flags.
    179142 */
    180 #define RTEMS_CAPTURE_TRACED  (1U << 0)
     143#define RTEMS_CAPTURE_TRACED      (1U << 0)
     144#define RTEMS_CAPTURE_RECORD_TASK (1U << 1)
    181145
    182146/*
     
    189153typedef struct rtems_capture_record_s
    190154{
    191   rtems_capture_task_t* task;
    192155  uint32_t              events;
    193156  rtems_capture_time_t  time;
    194157  size_t                size;
     158  rtems_id              task_id;
    195159} rtems_capture_record_t;
     160
     161/*
     162 * @brief Capture task record.
     163 *
     164 * This is a record that is written into
     165 * the buffer. The events includes the priority of the task
     166 * at the time of the context switch.
     167 */
     168typedef struct rtems_capture_task_record_s
     169{
     170  rtems_capture_record_t rec;
     171  rtems_name             name;
     172  rtems_task_priority    start_priority;
     173  uint32_t               stack_size;
     174} rtems_capture_task_record_t;
    196175
    197176/**
     
    620599
    621600/**
    622  * @brief Capture get task list.
    623  *
    624  * This function returns the head of the list of tasks that the
    625  * capture engine has detected.
    626  *
    627  * @retval  This function returns the head of the list of tasks that
    628  *          the capture engine has detected.
    629  */
    630 rtems_capture_task_t*
    631 rtems_capture_get_task_list (void);
    632 
    633 /**
    634  * @brief Capture get next task in list.
    635  *
    636  * This function returns the pointer to the next task in the list. The
    637  * pointer NULL terminates the list.
    638  *
    639  * @param[in] task The capture task to get the next entry from.
    640  *
    641  * @retval This function returns the pointer to the next task in the list. The
    642  * pointer NULL terminates the list.
    643  */
    644 static inline rtems_capture_task_t*
    645 rtems_capture_next_task (rtems_capture_task_t* task)
    646 {
    647   return task->forw;
    648 }
    649 
    650 /**
    651  * @brief Capture is valid task control block
    652  *
    653  * This function returns true if the task control block points to
    654  * a valid task.
     601 * @brief Capture record task.
     602 *
     603 * This function records a new capture task record.
     604 *
     605 * @param[in] tcb is the task control block for the task
     606 */
     607void rtems_capture_record_task( rtems_tcb* tcb );
     608
     609/**
     610 * @brief Capture task recorded
     611 *
     612 * This function returns true if this task information has been
     613 * recorded.
     614 *
     615 * @param[in] tcb is the task control block for the task
     616 */
     617static inline bool rtems_capture_task_recorded( rtems_tcb* tcb ) {
     618  return ( (tcb->Capture.flags & RTEMS_CAPTURE_RECORD_TASK) != 0 );
     619}
     620
     621/**
     622 * @brief Capture get task id.
     623 *
     624 * This function returns the task id.
    655625 *
    656626 * @param[in] task The capture task.
    657627 *
    658  * @retval This function returns true if the task control block points to
    659  * a valid task. Otherwise, it returns false.
    660  */
    661 static inline bool
    662 rtems_capture_task_valid (rtems_capture_task_t* task)
    663 {
    664   return task->tcb != NULL;
    665 }
    666 
    667 /**
    668  * @brief Capture get task id.
    669  *
    670  * This function returns the task id.
     628 * @retval This function returns the task id.
     629 */
     630static inline rtems_id
     631rtems_capture_task_id (rtems_tcb* tcb)
     632{
     633  return tcb->Object.id;
     634}
     635
     636/**
     637 * @brief Capture get task state.
     638 *
     639 * This function returns the task state.
    671640 *
    672641 * @param[in] task The capture task.
    673642 *
    674  * @retval This function returns the task id.
    675  */
    676 static inline rtems_id
    677 rtems_capture_task_id (rtems_capture_task_t* task)
    678 {
    679   return task->id;
    680 }
    681 
    682 /**
    683  * @brief Capture get task state.
    684  *
    685  * This function returns the task state.
     643 * @retval This function returns the task state.
     644 */
     645static inline States_Control
     646rtems_capture_task_state (rtems_tcb* tcb)
     647{
     648  if (tcb)
     649    return tcb->current_state;
     650  return 0;
     651}
     652
     653/**
     654 * @brief Capture get task name.
     655 *
     656 * This function returns the task name.
    686657 *
    687658 * @param[in] task The capture task.
    688659 *
    689  * @retval This function returns the task state.
    690  */
    691 static inline States_Control
    692 rtems_capture_task_state (rtems_capture_task_t* task)
    693 {
    694   if (rtems_capture_task_valid (task))
    695     return task->tcb->current_state;
    696   return 0;
    697 }
    698 
    699 /**
    700  * @brief Capture get task name.
    701  *
    702  * This function returns the task name.
     660 * @retval This function returns the task name.
     661 */
     662static inline rtems_name
     663rtems_capture_task_name (rtems_tcb* tcb)
     664{
     665  rtems_name  name;
     666  rtems_object_get_classic_name( tcb->Object.id, &name );
     667  return name;
     668}
     669
     670/**
     671 * @brief Capture get task flags.
     672 *
     673 * This function returns the task flags.
    703674 *
    704675 * @param[in] task The capture task.
    705676 *
    706  * @retval This function returns the task name.
    707  */
    708 static inline rtems_name
    709 rtems_capture_task_name (rtems_capture_task_t* task)
    710 {
    711   return task->name;
    712 }
    713 
    714 /**
    715  * @brief Capture get task flags.
    716  *
    717  * This function returns the task flags.
     677 * @retval This function returns the task flags.
     678 */
     679static inline uint32_t
     680rtems_capture_task_flags (rtems_tcb* tcb)
     681{
     682  return tcb->Capture.flags;
     683}
     684
     685/**
     686 * @brief Capture get task control
     687 *
     688 * This function returns the task control if present.
    718689 *
    719690 * @param[in] task The capture task.
    720691 *
    721  * @retval This function returns the task flags.
     692 * @retval This function returns the task control if present.
     693 */
     694static inline rtems_capture_control_t*
     695rtems_capture_task_control (rtems_tcb* tcb)
     696{
     697  return tcb->Capture.control;
     698}
     699
     700/**
     701 * @brief Capture get task control flags.
     702 *
     703 * This function returns the task control flags if a control is present.
     704 *
     705 * @param[in] task The capture task.
     706 *
     707 * @retval This function returns the task control flags if a control is present.
    722708 */
    723709static inline uint32_t
    724 rtems_capture_task_flags (rtems_capture_task_t* task)
    725 {
    726   return task->flags;
    727 }
    728 
    729 /**
    730  * @brief Capture get task control
    731  *
    732  * This function returns the task control if present.
    733  *
    734  * @param[in] task The capture task.
    735  *
    736  * @retval This function returns the task control if present.
    737  */
    738 static inline rtems_capture_control_t*
    739 rtems_capture_task_control (rtems_capture_task_t* task)
    740 {
    741   return task->control;
    742 }
    743 
    744 /**
    745  * @brief Capture get task control flags.
    746  *
    747  * This function returns the task control flags if a control is present.
    748  *
    749  * @param[in] task The capture task.
    750  *
    751  * @retval This function returns the task control flags if a control is present.
    752  */
    753 static inline uint32_t
    754 rtems_capture_task_control_flags (rtems_capture_task_t* task)
    755 {
    756   if (!task->control)
     710rtems_capture_task_control_flags (rtems_tcb* tcb)
     711{
     712  rtems_capture_control_t*  control = tcb->Capture.control;
     713  if (!control)
    757714    return 0;
    758   return task->control->flags;
    759 }
    760 
    761 /**
    762  * @brief Capture get number of times task switched in.
    763  *
    764  * This function returns the number of times the task has
    765  * been switched into context.
    766  *
    767  * @param[in] task The capture task.
    768  *
    769  * @retval This function returns the number of times the task has
    770  * been switched into context.
    771  */
    772 static inline uint32_t
    773 rtems_capture_task_switched_in (rtems_capture_task_t* task)
    774 {
    775   return task->in;
    776 }
    777 
    778 /**
    779  * @brief Capture get number of times task switched out.
    780  *
    781  * This function returns the number of times the task has
    782  * been switched out of context.
    783  *
    784  * @param[in] task The capture task.
    785  *
    786  * @retval This function returns the number of times the task has
    787  * been switched out of context.
    788  */
    789 static inline uint32_t
    790 rtems_capture_task_switched_out (rtems_capture_task_t* task)
    791 {
    792   return task->out;
     715  return control->flags;
    793716}
    794717
     
    805728 */
    806729static inline rtems_task_priority
    807 rtems_capture_task_start_priority (rtems_capture_task_t* task)
    808 {
    809   return task->start_priority;
     730rtems_capture_task_start_priority (rtems_tcb* tcb)
     731{
     732  return _RTEMS_tasks_Priority_from_Core(
     733    tcb->Start.initial_priority
     734  );
    810735}
    811736
     
    820745 */
    821746static inline rtems_task_priority
    822 rtems_capture_task_real_priority (rtems_capture_task_t* task)
    823 {
    824   if (rtems_capture_task_valid (task))
    825     return task->tcb->real_priority;
    826   return 0;
     747rtems_capture_task_real_priority (rtems_tcb* tcb)
     748{
     749  return tcb->real_priority;
    827750}
    828751
     
    837760 */
    838761static inline rtems_task_priority
    839 rtems_capture_task_curr_priority (rtems_capture_task_t* task)
    840 {
    841   if (rtems_capture_task_valid (task))
    842     return task->tcb->current_priority;
    843   return 0;
    844 }
    845 
    846 /**
    847  * @brief Capture update stack usage.
    848  *
    849  * This function updates the stack usage. The task control block
    850  * is updated.
    851  *
    852  * @param[in] task The capture task.
    853  *
    854  * @retval This function updates the stack usage. The task control block
    855  * is updated.
    856  */
    857 uint32_t
    858 rtems_capture_task_stack_usage (rtems_capture_task_t* task);
    859 
    860 /**
    861  * @brief Capture get stack size.
    862  *
    863  * This function returns the task's stack size.
    864  *
    865  * @param[in] task The capture task.
    866  *
    867  * @retval This function returns the task's stack size.
    868  */
    869 static inline uint32_t
    870 rtems_capture_task_stack_size (rtems_capture_task_t* task)
    871 {
    872   return task->stack_size;
    873 }
    874 
    875 /**
    876  * @brief Capture get stack used.
    877  *
    878  * This function returns the amount of stack used.
    879  *
    880  * @param[in] task The capture task.
    881  *
    882  * @retval This function returns the amount of stack used.
    883  */
    884 static inline uint32_t
    885 rtems_capture_task_stack_used (rtems_capture_task_t* task)
    886 {
    887   return task->stack_size - task->stack_clean;
    888 }
    889 
    890 /**
    891  * @brief Capture get task execution time.
    892  *
    893  * This function returns the current execution time.
    894  *
    895  * @param[in] task The capture task.
    896  *
    897  * @retval This function returns the current execution time.
    898  */
    899 static inline uint64_t
    900 rtems_capture_task_time (rtems_capture_task_t* task)
    901 {
    902   return task->time;
    903 }
    904 
    905 /**
    906  * @brief Capture get delta in execution time.
    907  *
    908  * This function returns the execution time as a different between the
    909  * last time the detla time was and now.
    910  *
    911  * @param[in] task The capture task.
    912  *
    913  * @retval This function returns the execution time as a different between the
    914  * last time the detla time was and now.
    915  */
    916 static inline uint64_t
    917 rtems_capture_task_delta_time (rtems_capture_task_t* task)
    918 {
    919   uint64_t t = task->time - task->last_time;
    920   task->last_time = task->time;
    921   return t;
    922 }
    923 
    924 /**
    925  * @brief Capture get task count.
    926  *
    927  * This function returns the number of tasks the capture
    928  * engine knows about.
    929  *
    930  * @retval This function returns the number of tasks the capture
    931  * engine knows about.
    932  */
    933 static inline uint32_t
    934 rtems_capture_task_count (void)
    935 {
    936   rtems_capture_task_t* task = rtems_capture_get_task_list ();
    937   uint32_t              count = 0;
    938 
    939   while (task)
    940   {
    941     count++;
    942     task = rtems_capture_next_task (task);
    943   }
    944 
    945   return count;
     762rtems_capture_task_curr_priority (rtems_tcb* tcb)
     763{
     764  return tcb->current_priority;
    946765}
    947766
     
    1071890 *
    1072891 * @param[in] control The capture control.
    1073  * @param[in] slot The XXX.
     892 * @param[in] slot The slot.
    1074893 *
    1075894 * @retval This function returns the control valid BY flags.
     
    1087906 *
    1088907 * @param[in] control The capture control.
    1089  * @param[in] by The XXX.
     908 * @param[in] by The by index.
    1090909 *
    1091910 * @retval This function returns the control @a by task name.
  • cpukit/libmisc/capture/capture_user_extension.c

    r7c797a1 r05e4e599  
    8585};
    8686
    87 
    8887static inline void rtems_capture_record (
    89   rtems_capture_task_t* task,
    90   uint32_t              events
     88  rtems_tcb*    tcb,
     89  uint32_t      events
    9190)
    9291{
    9392  rtems_capture_record_t*  rec;
    94 
    95   if (rtems_capture_filter( task, events) )
     93  void*                    ptr;
     94  size_t                   size = sizeof(*rec);
     95
     96  if (rtems_capture_filter( tcb, events) )
    9697    return;
    97  
    98   rtems_capture_begin_add_record (task, events, sizeof(*rec), &rec);
    99 
    100   rtems_capture_end_add_record ( rec );
     98
     99  rtems_capture_begin_add_record (tcb, events, size, &ptr);
     100  rtems_capture_end_add_record ( ptr );
    101101}
    102102
     
    134134 */
    135135static bool
    136 rtems_capture_create_task (rtems_tcb* current_task,
    137                            rtems_tcb* new_task)
    138 {
    139   rtems_capture_task_t* ct;
    140   rtems_capture_task_t* nt;
    141   int                   index = rtems_capture_get_extension_index();
    142 
    143   ct = current_task->extensions[index];
    144 
    145   /*
    146    * The task pointers may not be known as the task may have
    147    * been created before the capture engine was open. Add them.
    148    */
    149 
    150   if (ct == NULL)
    151     ct = rtems_capture_create_capture_task (current_task);
     136rtems_capture_create_task (rtems_tcb* ct,
     137                           rtems_tcb* nt)
     138{
     139  /*
     140   * The task pointers may not be known as the task may have
     141   * been created before the capture engine was open. Add them.
     142   */
     143
     144  if (!rtems_capture_task_recorded (ct))
     145    rtems_capture_record_task (ct);
    152146
    153147  /*
    154148   * Create the new task's capture control block.
    155149   */
    156   nt = rtems_capture_create_capture_task (new_task);
     150  rtems_capture_record_task (nt);
    157151
    158152  if (rtems_capture_trigger (ct, nt, RTEMS_CAPTURE_CREATE))
     
    169163 */
    170164static void
    171 rtems_capture_start_task (rtems_tcb* current_task,
    172                           rtems_tcb* started_task)
    173 {
    174   /*
    175    * Get the capture task control block so we can trace this
    176    * event.
    177    */
    178   rtems_capture_task_t* ct;
    179   rtems_capture_task_t* st;
    180   int                   index = rtems_capture_get_extension_index();
    181 
    182   ct = current_task->extensions[index];
    183   st = started_task->extensions[index];
    184 
    185   /*
    186    * The task pointers may not be known as the task may have
    187    * been created before the capture engine was open. Add them.
    188    */
    189 
    190   if (ct == NULL)
    191     ct = rtems_capture_create_capture_task (current_task);
     165rtems_capture_start_task (rtems_tcb* ct,
     166                          rtems_tcb* st)
     167{
     168  /*
     169   * The task pointers may not be known as the task may have
     170   * been created before the capture engine was open. Add them.
     171   */
     172
     173  if (!rtems_capture_task_recorded (ct))
     174    rtems_capture_record_task (ct);
    192175
    193176  if (st == NULL)
    194     st = rtems_capture_create_capture_task (started_task);
     177    rtems_capture_record_task (st);
    195178
    196179  if (rtems_capture_trigger (ct, st, RTEMS_CAPTURE_START))
     
    199182    rtems_capture_record (st, RTEMS_CAPTURE_STARTED_EVENT);
    200183  }
    201 
    202   rtems_capture_init_stack_usage (st);
    203184}
    204185
     
    207188 */
    208189static void
    209 rtems_capture_restart_task (rtems_tcb* current_task,
    210                             rtems_tcb* restarted_task)
    211 {
    212   /*
    213    * Get the capture task control block so we can trace this
    214    * event.
    215    */
    216   rtems_capture_task_t* ct;
    217   rtems_capture_task_t* rt;
    218   int                   index = rtems_capture_get_extension_index();
    219 
    220   ct = current_task->extensions[index];
    221   rt = restarted_task->extensions[index];
    222 
    223   /*
    224    * The task pointers may not be known as the task may have
    225    * been created before the capture engine was open. Add them.
    226    */
    227 
    228   if (ct == NULL)
    229     ct = rtems_capture_create_capture_task (current_task);
    230 
    231   if (rt == NULL)
    232     rt = rtems_capture_create_capture_task (restarted_task);
     190rtems_capture_restart_task (rtems_tcb* ct,
     191                            rtems_tcb* rt)
     192{
     193  /*
     194   * The task pointers may not be known as the task may have
     195   * been created before the capture engine was open. Add them.
     196   */
     197
     198  if (!rtems_capture_task_recorded (ct))
     199    rtems_capture_record_task (ct);
     200
     201  if (!rtems_capture_task_recorded (rt))
     202    rtems_capture_record_task (rt);
    233203
    234204  if (rtems_capture_trigger (ct, rt, RTEMS_CAPTURE_RESTART))
     
    237207    rtems_capture_record (rt, RTEMS_CAPTURE_RESTARTED_EVENT);
    238208  }
    239 
    240   rtems_capture_task_stack_usage (rt);
    241   rtems_capture_init_stack_usage (rt);
    242209}
    243210
     
    246213 */
    247214static void
    248 rtems_capture_delete_task (rtems_tcb* current_task,
    249                            rtems_tcb* deleted_task)
    250 {
    251   /*
    252    * Get the capture task control block so we can trace this
    253    * event.
    254    */
    255   rtems_capture_task_t* ct;
    256   rtems_capture_task_t* dt;
    257   int                   index = rtems_capture_get_extension_index();
    258 
    259   /*
    260    * The task pointers may not be known as the task may have
    261    * been created before the capture engine was open. Add them.
    262    */
    263 
    264   ct = current_task->extensions[index];
    265   dt = deleted_task->extensions[index];
    266 
    267   if (ct == NULL)
    268     ct = rtems_capture_create_capture_task (current_task);
    269 
    270   if (dt == NULL)
    271     dt = rtems_capture_create_capture_task (deleted_task);
     215rtems_capture_delete_task (rtems_tcb* ct,
     216                           rtems_tcb* dt)
     217{
     218  if (!rtems_capture_task_recorded (ct))
     219    rtems_capture_record_task (ct);
     220
     221  if (!rtems_capture_task_recorded (dt))
     222    rtems_capture_record_task (dt);
    272223
    273224  if (rtems_capture_trigger (ct, dt, RTEMS_CAPTURE_DELETE))
     
    276227    rtems_capture_record (dt, RTEMS_CAPTURE_DELETED_EVENT);
    277228  }
    278 
    279   rtems_capture_task_stack_usage (dt);
    280 
    281   /*
    282    * This task's tcb will be invalid. This signals the
    283    * task has been deleted.
    284    */
    285   dt->tcb = 0;
    286 
    287   rtems_capture_destroy_capture_task (dt);
    288229}
    289230
     
    292233 */
    293234static void
    294 rtems_capture_begin_task (rtems_tcb* begin_task)
    295 {
    296   /*
    297    * Get the capture task control block so we can trace this
    298    * event.
    299    */
    300   rtems_capture_task_t* bt;
    301   int                   index = rtems_capture_get_extension_index();
    302 
    303   bt = begin_task->extensions[index];
    304 
    305   /*
    306    * The task pointers may not be known as the task may have
    307    * been created before the capture engine was open. Add them.
    308    */
    309 
    310   if (bt == NULL)
    311     bt = rtems_capture_create_capture_task (begin_task);
     235rtems_capture_begin_task (rtems_tcb* bt)
     236{
     237  /*
     238   * The task pointers may not be known as the task may have
     239   * been created before the capture engine was open. Add them.
     240   */
     241
     242  if (!rtems_capture_task_recorded (bt))
     243    rtems_capture_record_task (bt);
    312244
    313245  if (rtems_capture_trigger (NULL, bt, RTEMS_CAPTURE_BEGIN))
     
    320252 */
    321253static void
    322 rtems_capture_exitted_task (rtems_tcb* exitted_task)
    323 {
    324   /*
    325    * Get the capture task control block so we can trace this
    326    * event.
    327    */
    328   rtems_capture_task_t* et;
    329   int                   index = rtems_capture_get_extension_index();
    330 
    331   et = exitted_task->extensions[index];
    332 
    333   /*
    334    * The task pointers may not be known as the task may have
    335    * been created before the capture engine was open. Add them.
    336    */
    337 
    338   if (et == NULL)
    339     et = rtems_capture_create_capture_task (exitted_task);
     254rtems_capture_exitted_task (rtems_tcb* et)
     255{
     256  /*
     257   * The task pointers may not be known as the task may have
     258   * been created before the capture engine was open. Add them.
     259   */
     260
     261  if (!rtems_capture_task_recorded (et))
     262    rtems_capture_record_task (et);
    340263
    341264  if (rtems_capture_trigger (NULL, et, RTEMS_CAPTURE_EXITTED))
    342265    rtems_capture_record (et, RTEMS_CAPTURE_EXITTED_EVENT);
    343 
    344   rtems_capture_task_stack_usage (et);
    345266}
    346267
     
    349270 */
    350271static void
    351 rtems_capture_terminated_task (rtems_tcb* terminated_task)
    352 {
    353   /*
    354    * Get the capture task control block so we can trace this
    355    * event.
    356    */
    357   rtems_capture_task_t* tt;
    358   int                   index = rtems_capture_get_extension_index();
    359 
    360   tt = terminated_task->extensions[index];
    361 
    362   /*
    363    * The task pointers may not be known as the task may have
    364    * been created before the capture engine was open. Add them.
    365    */
    366 
    367   if (tt == NULL)
    368     tt = rtems_capture_create_capture_task (terminated_task);
     272rtems_capture_terminated_task (rtems_tcb* tt)
     273{
     274  /*
     275   * The task pointers may not be known as the task may have
     276   * been created before the capture engine was open. Add them.
     277   */
     278
     279  if (!rtems_capture_task_recorded (tt))
     280    rtems_capture_record_task (tt);
    369281
    370282  if (rtems_capture_trigger (NULL, tt, RTEMS_CAPTURE_TERMINATED))
    371283    rtems_capture_record (tt, RTEMS_CAPTURE_TERMINATED_EVENT);
    372 
    373   rtems_capture_task_stack_usage (tt);
    374284}
    375285
     
    378288 */
    379289static void
    380 rtems_capture_switch_task (rtems_tcb* current_task,
    381                            rtems_tcb* heir_task)
     290rtems_capture_switch_task (rtems_tcb* ct,
     291                           rtems_tcb* ht)
    382292{
    383293  uint32_t flags = rtems_capture_get_flags();
    384   int      index = rtems_capture_get_extension_index();
    385294
    386295  /*
     
    392301    rtems_capture_time_t time;
    393302
    394     /*
    395      * Get the cpature task control block so we can update the
    396      * reference and perform any watch or trigger functions.
    397      * The task pointers may not be known as the task may have
    398      * been created before the capture engine was open. Add them.
    399      */
    400     rtems_capture_task_t* ct;
    401     rtems_capture_task_t* ht;
    402 
    403 
    404     if (_States_Is_dormant (current_task->current_state))
    405     {
    406       rtems_id ct_id = current_task->Object.id;
    407       ct = rtems_capture_find_capture_task( ct_id );
    408     }
    409     else
    410     {
    411       ct = current_task->extensions[index];
    412 
    413       if (ct == NULL)
    414         ct = rtems_capture_create_capture_task (current_task);
    415     }
    416 
    417     ht = heir_task->extensions[index];
    418 
    419     if (ht == NULL)
    420       ht = rtems_capture_create_capture_task (heir_task);
     303    if (!rtems_capture_task_recorded (ct))
     304      rtems_capture_record_task (ct);
     305
     306    if (!rtems_capture_task_recorded (ht))
     307      rtems_capture_record_task (ht);
    421308
    422309    /*
     
    426313    rtems_capture_get_time (&time);
    427314
    428     /*
    429      * We could end up with null pointers for both the current task
    430      * and the heir task.
    431      */
    432 
    433     if (ht)
    434     {
    435       ht->in++;
    436       ht->time_in = time;
    437     }
    438 
    439     if (ct)
    440     {
    441       ct->out++;
    442       if (ct->time_in)
    443         ct->time += time - ct->time_in;
    444     }
    445 
    446315    if (rtems_capture_trigger (ct, ht, RTEMS_CAPTURE_SWITCH))
    447316    {
  • cpukit/libmisc/capture/captureimpl.h

    r7c797a1 r05e4e599  
    117117
    118118/**
    119  * @brief Capture find capture task.
    120  *
    121  * This function finds the capture task control block
    122  *
    123  * @param[in] ct_id specifies the task_id
    124  *
    125  * @retval This method returns the capture task control block associated
    126  * with the given task id.
    127  */
    128 rtems_capture_task_t* rtems_capture_find_capture_task( rtems_id ct_id );
    129 
    130 /**
    131  * @brief Capture create capture task control block.
    132  *
    133  * This function create the capture task control block
    134  *
    135  * @param[in] new_task specifies the rtems thread control block
    136  *
    137  * @retval This method returns a capture task control block.
    138  */
    139 rtems_capture_task_t* rtems_capture_create_capture_task (rtems_tcb* new_task);
    140 
    141 /**
    142119 * @brief Capture trigger.
    143120 *
     
    152129 * if the event is a cause of a trigger.
    153130 */
    154 bool rtems_capture_trigger (rtems_capture_task_t* ft,
    155                        rtems_capture_task_t* tt,
    156                        uint32_t              events);
     131bool rtems_capture_trigger (rtems_tcb* ft,
     132                            rtems_tcb* tt,
     133                            uint32_t   events);
    157134
    158135/**
     
    189166 * should be logged.
    190167 */
    191 bool rtems_capture_filter( rtems_capture_task_t* task,
     168bool rtems_capture_filter( rtems_tcb*            task,
    192169                           uint32_t              events);
    193170/**
     
    239216
    240217/**
    241  * @brief Capture initialize stack usage
    242  *
    243  * This function setups a stack so its usage can be monitored.
    244  *
    245  * @param[in] task specifies the capture task block
    246  */
    247 void rtems_capture_init_stack_usage (rtems_capture_task_t* task);
    248 
    249 /**
    250  * @brief Capture destroy task.
    251  *
    252  * This function destroy the task structure if the reference count
    253  * is 0 and the tcb has been cleared signalling the task has been
    254  * deleted.
    255  *
    256  * @param[in] task specifies the capture task block
    257  */
    258 void rtems_capture_destroy_capture_task (rtems_capture_task_t* task);
    259 
    260 /**
    261218 * @brief .
    262219 *
     
    288245 * the capture record to store data.
    289246 */
    290 void* rtems_capture_record_open (rtems_capture_task_t*         task,
     247void* rtems_capture_record_open (rtems_tcb*                    task,
    291248                                 uint32_t                      events,
    292249                                 size_t                        size,
Note: See TracChangeset for help on using the changeset viewer.