source: rtems/testsuites/libtests/record02/init.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.6 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#ifdef HAVE_CONFIG_H
29#include "config.h"
30#endif
31
32#include <rtems/record.h>
33#include <rtems/recordclient.h>
34#include <rtems.h>
35
36#include <string.h>
37
38#include "tmacros.h"
39
40const char rtems_test_name[] = "RECORD 2";
41
42typedef struct {
43  rtems_record_client_context client;
44} test_context;
45
46static test_context test_instance;
47
48static rtems_record_client_status client_handler(
49  uint32_t            seconds,
50  uint32_t            nanoseconds,
51  uint32_t            cpu,
52  rtems_record_event  event,
53  uint64_t            data,
54  void               *arg
55)
56{
57  const char *event_text;
58
59  (void) arg;
60
61  if ( seconds != 0 && nanoseconds != 0 ) {
62    printf( "%" PRIu32 ".%09" PRIu32 ":", seconds, nanoseconds );
63  } else {
64    printf( "*:" );
65  }
66
67  event_text = rtems_record_event_text( event );
68
69  if ( event_text != NULL ) {
70    printf( "%" PRIu32 ":%s:%" PRIx64 "\n", cpu, event_text, data );
71  } else {
72    printf( "%" PRIu32 ":%i:%" PRIx64 "\n", cpu, event, data );
73  }
74
75  return RTEMS_RECORD_CLIENT_SUCCESS;
76}
77
78static void drain_visitor(
79  const rtems_record_item *items,
80  size_t                   count,
81  void                    *arg
82)
83{
84  test_context *ctx;
85  rtems_record_client_status cs;
86
87  ctx = arg;
88  cs = rtems_record_client_run(&ctx->client, items, count * sizeof(*items));
89  rtems_test_assert(cs == RTEMS_RECORD_CLIENT_SUCCESS);
90}
91
92static void Init(rtems_task_argument arg)
93{
94  test_context *ctx;
95  Record_Stream_header header;
96  rtems_record_client_status cs;
97  int i;
98
99  TEST_BEGIN();
100  ctx = &test_instance;
101
102  for (i = 0; i < 10; ++i) {
103    rtems_task_wake_after(1);
104  }
105
106  rtems_record_client_init(&ctx->client, client_handler, NULL);
107  _Record_Stream_header_initialize(&header);
108  cs = rtems_record_client_run(&ctx->client, &header, sizeof(header));
109  rtems_test_assert(cs == RTEMS_RECORD_CLIENT_SUCCESS);
110  rtems_record_drain(drain_visitor, ctx);
111
112  TEST_END();
113  rtems_test_exit(0);
114}
115
116#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
117
118#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
119
120#define CONFIGURE_MAXIMUM_TASKS 1
121
122#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
123
124#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
125
126#define CONFIGURE_RECORD_PER_PROCESSOR_ITEMS 128
127
128#define CONFIGURE_RECORD_EXTENSIONS_ENABLED
129
130#define CONFIGURE_INIT
131
132#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.