source: rtems/cpukit/libtrace/record/record-userext.c @ dca6184

5
Last change on this file since dca6184 was dca6184, checked in by Sebastian Huber <sebastian.huber@…>, on 04/28/18 at 09:36:11

Add low level event recording support

Add low level event recording infrastructure for system and user
defined events. The infrastructure is able to record high frequency
events such as

  • SMP lock acquire/release,
  • interrupt entry/exit,
  • thread switches,
  • UMA zone allocate/free, and
  • Ethernet packet input/output, etc.

It allows post-mortem analysis in fatal error handlers, e.g. the last
events are in the record buffer, the newest event overwrites the oldest
event. It is possible to detect record buffer overflows for consumers
that expect a continuous stream of events, e.g. to display the system
state in real-time.

The implementation supports high-end SMP machines (more than 1GHz
processor frequency, more than four processors).

Add a new API instead. The implementation uses per-processor data
structures and no atomic read-modify-write operations. It is uses
per-processor ring buffers to record the events.

The CPU counter is used to get the time of events. It is combined with
periodic uptime events to synchronize it with CLOCK_REALTIME.

The existing capture engine tries to solve this problem also, but its
performance is not good enough for high-end production systems. The
main issues are the variable-size buffers and the use of SMP locks for
synchronization. To fix this, the API would change significantly.

Update #3665.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (C) 2018, 2019 embedded brains GmbH
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#if HAVE_CONFIG_H
29#include "config.h"
30#endif
31
32#include <rtems/record.h>
33#include <rtems/score/thread.h>
34
35bool _Record_Thread_create(
36  struct _Thread_Control *executing,
37  struct _Thread_Control *created
38)
39{
40  rtems_record_produce(
41    RTEMS_RECORD_THREAD_CREATE,
42    created->Object.id
43  );
44
45  return true;
46}
47
48void _Record_Thread_start(
49  struct _Thread_Control *executing,
50  struct _Thread_Control *started
51)
52{
53  rtems_record_produce(
54    RTEMS_RECORD_THREAD_START,
55    started->Object.id
56  );
57}
58
59void _Record_Thread_restart(
60  struct _Thread_Control *executing,
61  struct _Thread_Control *restarted
62)
63{
64  rtems_record_produce(
65    RTEMS_RECORD_THREAD_RESTART,
66    restarted->Object.id
67  );
68}
69
70void _Record_Thread_delete(
71  struct _Thread_Control *executing,
72  struct _Thread_Control *deleted
73)
74{
75  rtems_record_produce(
76    RTEMS_RECORD_THREAD_DELETE,
77    deleted->Object.id
78  );
79}
80
81void _Record_Thread_switch(
82  struct _Thread_Control *executing,
83  struct _Thread_Control *heir
84)
85{
86  rtems_record_item items[ 3 ];
87
88  items[ 0 ].event = RTEMS_RECORD_THREAD_SWITCH_OUT;
89  items[ 0 ].data = executing->Object.id;
90  items[ 1 ].event = RTEMS_RECORD_THREAD_STACK_CURRENT;
91  items[ 1 ].data =
92#if defined(__GNUC__)
93    (uintptr_t) __builtin_frame_address( 0 )
94      - (uintptr_t) executing->Start.Initial_stack.area;
95#else
96    0;
97#endif
98  items[ 2 ].event = RTEMS_RECORD_THREAD_SWITCH_IN;
99  items[ 2 ].data = heir->Object.id;
100  rtems_record_produce_n( items, RTEMS_ARRAY_SIZE( items ) );
101}
102
103void _Record_Thread_begin( struct _Thread_Control *executing )
104{
105  rtems_record_produce(
106    RTEMS_RECORD_THREAD_BEGIN,
107    executing->Object.id
108  );
109}
110
111void _Record_Thread_exitted( struct _Thread_Control *executing )
112{
113  rtems_record_produce(
114    RTEMS_RECORD_THREAD_EXITTED,
115    executing->Object.id
116  );
117}
118
119void _Record_Thread_terminate( struct _Thread_Control *executing )
120{
121  rtems_record_produce(
122    RTEMS_RECORD_THREAD_TERMINATE,
123    executing->Object.id
124  );
125}
Note: See TracBrowser for help on using the repository browser.