Changeset 133962b in rtems


Ignore:
Timestamp:
07/22/14 14:40:54 (9 years ago)
Author:
Jennifer Averett <jennifer.averett@…>
Branches:
4.11, 5, master
Children:
2a86615
Parents:
b2356837
git-author:
Jennifer Averett <jennifer.averett@…> (07/22/14 14:40:54)
git-committer:
Jennifer Averett <jennifer.averett@…> (09/05/14 11:50:29)
Message:

capture: Split user extension methods out.

Location:
cpukit/libmisc
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libmisc/Makefile.am

    rb2356837 r133962b  
    1919noinst_LIBRARIES += libcapture.a
    2020libcapture_a_SOURCES = capture/capture.c capture/capture-cli.c \
    21     capture/capture.h capture/capture-cli.h
     21    capture/capture_user_extension.c \
     22    capture/capture.h capture/captureimpl.h capture/capture-cli.h
    2223
    2324## cpuuse
  • cpukit/libmisc/capture/capture.c

    rb2356837 r133962b  
    3030#include <rtems/rtems/tasksimpl.h>
    3131
    32 #include "capture.h"
     32#include "captureimpl.h"
    3333
    3434#include <rtems/score/statesimpl.h>
     
    5858#endif
    5959
    60 static bool
    61 rtems_capture_create_task (rtems_tcb* current_task,
    62                            rtems_tcb* new_task);
    63 
    64 static void
    65 rtems_capture_start_task (rtems_tcb* current_task,
    66                           rtems_tcb* started_task);
    67 
    68 static void
    69 rtems_capture_restart_task (rtems_tcb* current_task,
    70                             rtems_tcb* restarted_task);
    71 
    72 static void
    73 rtems_capture_delete_task (rtems_tcb* current_task,
    74                            rtems_tcb* deleted_task);
    75 
    76 static void
    77 rtems_capture_switch_task (rtems_tcb* current_task,
    78                            rtems_tcb* heir_task);
    79 
    80 static void
    81 rtems_capture_begin_task (rtems_tcb* begin_task);
    82 
    83 static void
    84 rtems_capture_exitted_task (rtems_tcb* exitted_task);
    85 
    86 static void
    87 rtems_capture_terminated_task (rtems_tcb* terminated_task);
    88 
    89 /*
    90  * Global capture flags.
    91  */
    92 #define RTEMS_CAPTURE_ON             (1U << 0)
    93 #define RTEMS_CAPTURE_NO_MEMORY      (1U << 1)
    94 #define RTEMS_CAPTURE_OVERFLOW       (1U << 2)
    95 #define RTEMS_CAPTURE_TRIGGERED      (1U << 3)
    96 #define RTEMS_CAPTURE_READER_ACTIVE  (1U << 4)
    97 #define RTEMS_CAPTURE_READER_WAITING (1U << 5)
    98 #define RTEMS_CAPTURE_GLOBAL_WATCH   (1U << 6)
    99 #define RTEMS_CAPTURE_ONLY_MONITOR   (1U << 7)
    10060
    10161/*
     
    11171static rtems_capture_control_t* capture_controls;
    11272static int                      capture_extension_index;
    113 static rtems_id                 capture_id;
    11473static rtems_capture_timestamp  capture_timestamp;
    11574static rtems_task_priority      capture_ceiling;
     
    11877static rtems_interrupt_lock     capture_lock =
    11978  RTEMS_INTERRUPT_LOCK_INITIALIZER("capture");
    120 
    121 static const rtems_extensions_table capture_extensions = {
    122   .thread_create    = rtems_capture_create_task,
    123   .thread_start     = rtems_capture_start_task,
    124   .thread_restart   = rtems_capture_restart_task,
    125   .thread_delete    = rtems_capture_delete_task,
    126   .thread_switch    = rtems_capture_switch_task,
    127   .thread_begin     = rtems_capture_begin_task,
    128   .thread_exitted   = rtems_capture_exitted_task,
    129   .fatal            = NULL,
    130   .thread_terminate = rtems_capture_terminated_task
    131 };
    13279
    13380/*
     
    15299};
    153100
     101void rtems_capture_set_extension_index(int index)
     102{
     103  capture_extension_index = index;
     104}
     105
     106int  rtems_capture_get_extension_index(void)
     107{
     108  return capture_extension_index;
     109}
     110
     111uint32_t rtems_capture_get_flags(void)
     112{
     113  return capture_flags;
     114}
     115
     116void rtems_capture_set_flags(uint32_t mask)
     117{
     118  capture_flags |= mask;
     119}
     120
     121
     122rtems_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
    154133/*
    155134 * This function returns the current time. If a handler is provided
    156135 * by the user get the time from that.
    157136 */
    158 static inline void
     137void
    159138rtems_capture_get_time (rtems_capture_time_t* time)
    160139{
     
    291270 * This function setups a stack so its usage can be monitored.
    292271 */
    293 static inline void
     272void
    294273rtems_capture_init_stack_usage (rtems_capture_task_t* task)
    295274{
     
    379358 * This function create the task control.
    380359 */
    381 static inline rtems_capture_task_t*
     360rtems_capture_task_t*
    382361rtems_capture_create_capture_task (rtems_tcb* new_task)
    383362{
     
    457436 * deleted.
    458437 */
    459 static inline void
     438void
    460439rtems_capture_destroy_capture_task (rtems_capture_task_t* task)
    461440{
     
    488467 * This function records a capture record into the capture buffer.
    489468 */
    490 static inline void
     469void
    491470rtems_capture_record (rtems_capture_task_t* task,
    492471                      uint32_t              events)
     
    551530 * cause of a trigger.
    552531 */
    553 static bool
     532bool
    554533rtems_capture_trigger (rtems_capture_task_t* ft,
    555534                       rtems_capture_task_t* tt,
     
    617596
    618597/*
    619  * This function is called when a task is created.
    620  */
    621 static bool
    622 rtems_capture_create_task (rtems_tcb* current_task,
    623                            rtems_tcb* new_task)
    624 {
    625   rtems_capture_task_t* ct;
    626   rtems_capture_task_t* nt;
    627 
    628   ct = current_task->extensions[capture_extension_index];
    629 
    630   /*
    631    * The task pointers may not be known as the task may have
    632    * been created before the capture engine was open. Add them.
    633    */
    634 
    635   if (ct == NULL)
    636     ct = rtems_capture_create_capture_task (current_task);
    637 
    638   /*
    639    * Create the new task's capture control block.
    640    */
    641   nt = rtems_capture_create_capture_task (new_task);
    642 
    643   if (rtems_capture_trigger (ct, nt, RTEMS_CAPTURE_CREATE))
    644   {
    645     rtems_capture_record (ct, RTEMS_CAPTURE_CREATED_BY_EVENT);
    646     rtems_capture_record (nt, RTEMS_CAPTURE_CREATED_EVENT);
    647   }
    648 
    649   return 1 == 1;
    650 }
    651 
    652 /*
    653  * This function is called when a task is started.
    654  */
    655 static void
    656 rtems_capture_start_task (rtems_tcb* current_task,
    657                           rtems_tcb* started_task)
    658 {
    659   /*
    660    * Get the capture task control block so we can trace this
    661    * event.
    662    */
    663   rtems_capture_task_t* ct;
    664   rtems_capture_task_t* st;
    665 
    666   ct = current_task->extensions[capture_extension_index];
    667   st = started_task->extensions[capture_extension_index];
    668 
    669   /*
    670    * The task pointers may not be known as the task may have
    671    * been created before the capture engine was open. Add them.
    672    */
    673 
    674   if (ct == NULL)
    675     ct = rtems_capture_create_capture_task (current_task);
    676 
    677   if (st == NULL)
    678     st = rtems_capture_create_capture_task (started_task);
    679 
    680   if (rtems_capture_trigger (ct, st, RTEMS_CAPTURE_START))
    681   {
    682     rtems_capture_record (ct, RTEMS_CAPTURE_STARTED_BY_EVENT);
    683     rtems_capture_record (st, RTEMS_CAPTURE_STARTED_EVENT);
    684   }
    685 
    686   rtems_capture_init_stack_usage (st);
    687 }
    688 
    689 /*
    690  * This function is called when a task is restarted.
    691  */
    692 static void
    693 rtems_capture_restart_task (rtems_tcb* current_task,
    694                             rtems_tcb* restarted_task)
    695 {
    696   /*
    697    * Get the capture task control block so we can trace this
    698    * event.
    699    */
    700   rtems_capture_task_t* ct;
    701   rtems_capture_task_t* rt;
    702 
    703   ct = current_task->extensions[capture_extension_index];
    704   rt = restarted_task->extensions[capture_extension_index];
    705 
    706   /*
    707    * The task pointers may not be known as the task may have
    708    * been created before the capture engine was open. Add them.
    709    */
    710 
    711   if (ct == NULL)
    712     ct = rtems_capture_create_capture_task (current_task);
    713 
    714   if (rt == NULL)
    715     rt = rtems_capture_create_capture_task (restarted_task);
    716 
    717   if (rtems_capture_trigger (ct, rt, RTEMS_CAPTURE_RESTART))
    718   {
    719     rtems_capture_record (ct, RTEMS_CAPTURE_RESTARTED_BY_EVENT);
    720     rtems_capture_record (rt, RTEMS_CAPTURE_RESTARTED_EVENT);
    721   }
    722 
    723   rtems_capture_task_stack_usage (rt);
    724   rtems_capture_init_stack_usage (rt);
    725 }
    726 
    727 /*
    728  * This function is called when a task is deleted.
    729  */
    730 static void
    731 rtems_capture_delete_task (rtems_tcb* current_task,
    732                            rtems_tcb* deleted_task)
    733 {
    734   /*
    735    * Get the capture task control block so we can trace this
    736    * event.
    737    */
    738   rtems_capture_task_t* ct;
    739   rtems_capture_task_t* dt;
    740 
    741   /*
    742    * The task pointers may not be known as the task may have
    743    * been created before the capture engine was open. Add them.
    744    */
    745 
    746   ct = current_task->extensions[capture_extension_index];
    747   dt = deleted_task->extensions[capture_extension_index];
    748 
    749   if (ct == NULL)
    750     ct = rtems_capture_create_capture_task (current_task);
    751 
    752   if (dt == NULL)
    753     dt = rtems_capture_create_capture_task (deleted_task);
    754 
    755   if (rtems_capture_trigger (ct, dt, RTEMS_CAPTURE_DELETE))
    756   {
    757     rtems_capture_record (ct, RTEMS_CAPTURE_DELETED_BY_EVENT);
    758     rtems_capture_record (dt, RTEMS_CAPTURE_DELETED_EVENT);
    759   }
    760 
    761   rtems_capture_task_stack_usage (dt);
    762 
    763   /*
    764    * This task's tcb will be invalid. This signals the
    765    * task has been deleted.
    766    */
    767   dt->tcb = 0;
    768 
    769   rtems_capture_destroy_capture_task (dt);
    770 }
    771 
    772 /*
    773  * This function is called when a task is begun.
    774  */
    775 static void
    776 rtems_capture_begin_task (rtems_tcb* begin_task)
    777 {
    778   /*
    779    * Get the capture task control block so we can trace this
    780    * event.
    781    */
    782   rtems_capture_task_t* bt;
    783 
    784   bt = begin_task->extensions[capture_extension_index];
    785 
    786   /*
    787    * The task pointers may not be known as the task may have
    788    * been created before the capture engine was open. Add them.
    789    */
    790 
    791   if (bt == NULL)
    792     bt = rtems_capture_create_capture_task (begin_task);
    793 
    794   if (rtems_capture_trigger (NULL, bt, RTEMS_CAPTURE_BEGIN))
    795     rtems_capture_record (bt, RTEMS_CAPTURE_BEGIN_EVENT);
    796 }
    797 
    798 /*
    799  * This function is called when a task is exitted. That is
    800  * returned rather than was deleted.
    801  */
    802 static void
    803 rtems_capture_exitted_task (rtems_tcb* exitted_task)
    804 {
    805   /*
    806    * Get the capture task control block so we can trace this
    807    * event.
    808    */
    809   rtems_capture_task_t* et;
    810 
    811   et = exitted_task->extensions[capture_extension_index];
    812 
    813   /*
    814    * The task pointers may not be known as the task may have
    815    * been created before the capture engine was open. Add them.
    816    */
    817 
    818   if (et == NULL)
    819     et = rtems_capture_create_capture_task (exitted_task);
    820 
    821   if (rtems_capture_trigger (NULL, et, RTEMS_CAPTURE_EXITTED))
    822     rtems_capture_record (et, RTEMS_CAPTURE_EXITTED_EVENT);
    823 
    824   rtems_capture_task_stack_usage (et);
    825 }
    826 
    827 /*
    828  * This function is called when a termination request is identified.
    829  */
    830 static void
    831 rtems_capture_terminated_task (rtems_tcb* terminated_task)
    832 {
    833   /*
    834    * Get the capture task control block so we can trace this
    835    * event.
    836    */
    837   rtems_capture_task_t* tt;
    838 
    839   tt = terminated_task->extensions[capture_extension_index];
    840 
    841   /*
    842    * The task pointers may not be known as the task may have
    843    * been created before the capture engine was open. Add them.
    844    */
    845 
    846   if (tt == NULL)
    847     tt = rtems_capture_create_capture_task (terminated_task);
    848 
    849   if (rtems_capture_trigger (NULL, tt, RTEMS_CAPTURE_TERMINATED))
    850     rtems_capture_record (tt, RTEMS_CAPTURE_TERMINATED_EVENT);
    851 
    852   rtems_capture_task_stack_usage (tt);
    853 }
    854 
    855 /*
    856  * This function is called when a context is switched.
    857  */
    858 static void
    859 rtems_capture_switch_task (rtems_tcb* current_task,
    860                            rtems_tcb* heir_task)
    861 {
    862   /*
    863    * Only perform context switch trace processing if tracing is
    864    * enabled.
    865    */
    866   if (capture_flags & RTEMS_CAPTURE_ON)
    867   {
    868     rtems_capture_time_t time;
    869 
    870     /*
    871      * Get the cpature task control block so we can update the
    872      * reference and perform any watch or trigger functions.
    873      * The task pointers may not be known as the task may have
    874      * been created before the capture engine was open. Add them.
    875      */
    876     rtems_capture_task_t* ct;
    877     rtems_capture_task_t* ht;
    878 
    879 
    880     if (_States_Is_dormant (current_task->current_state))
    881     {
    882       rtems_id ct_id = current_task->Object.id;
    883 
    884       for (ct = capture_tasks; ct; ct = ct->forw)
    885         if (ct->id == ct_id)
    886           break;
    887     }
    888     else
    889     {
    890       ct = current_task->extensions[capture_extension_index];
    891 
    892       if (ct == NULL)
    893         ct = rtems_capture_create_capture_task (current_task);
    894     }
    895 
    896     ht = heir_task->extensions[capture_extension_index];
    897 
    898     if (ht == NULL)
    899       ht = rtems_capture_create_capture_task (heir_task);
    900 
    901     /*
    902      * Update the execution time. Assume the time will not overflow
    903      * for now. This may need to change.
    904      */
    905     rtems_capture_get_time (&time);
    906 
    907     /*
    908      * We could end up with null pointers for both the current task
    909      * and the heir task.
    910      */
    911 
    912     if (ht)
    913     {
    914       ht->in++;
    915       ht->time_in = time;
    916     }
    917 
    918     if (ct)
    919     {
    920       ct->out++;
    921       if (ct->time_in)
    922         ct->time += time - ct->time_in;
    923     }
    924 
    925     if (rtems_capture_trigger (ct, ht, RTEMS_CAPTURE_SWITCH))
    926     {
    927       rtems_capture_record (ct, RTEMS_CAPTURE_SWITCHED_OUT_EVENT);
    928       rtems_capture_record (ht, RTEMS_CAPTURE_SWITCHED_IN_EVENT);
    929     }
    930   }
    931 }
    932 
    933 /*
    934598 * This function initialises the realtime capture engine allocating the trace
    935599 * buffer. It is assumed we have a working heap at stage of initialisation.
     
    938602rtems_capture_open (uint32_t   size, rtems_capture_timestamp timestamp __attribute__((unused)))
    939603{
    940   rtems_name             name;
    941604  rtems_status_code      sc;
    942605
     
    962625  capture_floor   = 255;
    963626
    964   /*
    965    * Register the user extension handlers for the CAPture Engine.
    966    */
    967   name = rtems_build_name ('C', 'A', 'P', 'E');
    968   sc   = rtems_extension_create (name, &capture_extensions, &capture_id);
     627  sc = rtems_capture_user_extension_open();
    969628
    970629  if (sc != RTEMS_SUCCESSFUL)
    971630  {
    972     capture_id = 0;
    973631    free (capture_records);
    974632    capture_records = NULL;
    975   }
    976   else
    977   {
    978     capture_extension_index = rtems_object_id_get_index (capture_id);
    979633  }
    980634
     
    1017671   */
    1018672
    1019   sc = rtems_extension_delete (capture_id);
     673  sc = rtems_capture_user_extension_close();
    1020674
    1021675  if (sc != RTEMS_SUCCESSFUL)
Note: See TracChangeset for help on using the changeset viewer.