source: rtems/cpukit/include/rtems/recordclient.h @ 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.9 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/*
29 * This file must be compatible to general purpose POSIX system, e.g. Linux,
30 * FreeBSD.  It may be used for utility programs.
31 */
32
33#ifndef _RTEMS_RECORDCLIENT_H
34#define _RTEMS_RECORDCLIENT_H
35
36#include "recorddata.h"
37
38#include <stddef.h>
39
40#ifdef __cplusplus
41extern "C" {
42#endif /* __cplusplus */
43
44/**
45 * @addtogroup RTEMSRecord
46 *
47 * @{
48 */
49
50#define RTEMS_RECORD_CLIENT_MAXIMUM_CPU_COUNT 32
51
52typedef enum {
53  RTEMS_RECORD_CLIENT_SUCCESS,
54  RTEMS_RECORD_CLIENT_ERROR_INVALID_MAGIC,
55  RTEMS_RECORD_CLIENT_ERROR_UNKNOWN_FORMAT,
56  RTEMS_RECORD_CLIENT_ERROR_UNSUPPORTED_VERSION,
57  RTEMS_RECORD_CLIENT_ERROR_UNSUPPORTED_CPU
58} rtems_record_client_status;
59
60typedef rtems_record_client_status ( *rtems_record_client_handler )(
61  uint32_t            seconds,
62  uint32_t            nanoseconds,
63  uint32_t            cpu,
64  rtems_record_event  event,
65  uint64_t            data,
66  void               *arg
67);
68
69typedef struct {
70  struct {
71    uint64_t bt;
72    uint32_t time_at_bt;
73    uint32_t time_last;
74    uint32_t time_accumulated;
75  } uptime;
76  uint32_t tail[ 2 ];
77  uint32_t head[ 2 ];
78  size_t index;
79} rtems_record_client_per_cpu;
80
81typedef struct rtems_record_client_context {
82  uint64_t to_bt_scaler;
83  rtems_record_client_per_cpu per_cpu[ RTEMS_RECORD_CLIENT_MAXIMUM_CPU_COUNT ];
84  uint64_t data;
85  uint32_t cpu;
86  uint32_t event;
87  uint32_t count;
88  union {
89    rtems_record_item_32 format_32;
90    rtems_record_item_64 format_64;
91  } item;
92  size_t todo;
93  void *pos;
94  rtems_record_client_status ( *consume )(
95    struct rtems_record_client_context *,
96    const void *,
97    size_t
98  );
99  rtems_record_client_handler handler;
100  void *handler_arg;
101  uint32_t header[ 2 ];
102} rtems_record_client_context;
103
104/**
105 * @brief Initializes a record client.
106 *
107 * The record client consumes a record item stream produces by the record
108 * server.
109 *
110 * @param ctx The record client context to initialize.
111 * @param handler The handler is invoked for each received record item.
112 * @param arg The handler argument.
113 */
114void rtems_record_client_init(
115  rtems_record_client_context *ctx,
116  rtems_record_client_handler  handler,
117  void                        *arg
118);
119
120/**
121 * @brief Runs the record client to consume new stream data.
122 *
123 * @param ctx The record client context.
124 * @param buf The buffer with new stream data.
125 * @param n The size of the buffer.
126 */
127rtems_record_client_status rtems_record_client_run(
128  rtems_record_client_context *ctx,
129  const void                  *buf,
130  size_t                       n
131);
132
133/** @} */
134
135#ifdef __cplusplus
136}
137#endif /* __cplusplus */
138
139#endif /* _RTEMS_RECORDCLIENT_H */
Note: See TracBrowser for help on using the repository browser.