RTEMS 5.2
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
recordclient.h
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 <stdbool.h>
39#include <stddef.h>
40
41#ifdef __cplusplus
42extern "C" {
43#endif /* __cplusplus */
44
51#define RTEMS_RECORD_CLIENT_MAXIMUM_CPU_COUNT 32
52
53typedef enum {
54 RTEMS_RECORD_CLIENT_SUCCESS,
55 RTEMS_RECORD_CLIENT_ERROR_INVALID_MAGIC,
56 RTEMS_RECORD_CLIENT_ERROR_UNKNOWN_FORMAT,
57 RTEMS_RECORD_CLIENT_ERROR_UNSUPPORTED_VERSION,
58 RTEMS_RECORD_CLIENT_ERROR_UNSUPPORTED_CPU,
59 RTEMS_RECORD_CLIENT_ERROR_UNSUPPORTED_CPU_MAX,
60 RTEMS_RECORD_CLIENT_ERROR_DOUBLE_CPU_MAX,
61 RTEMS_RECORD_CLIENT_ERROR_DOUBLE_PER_CPU_COUNT,
62 RTEMS_RECORD_CLIENT_ERROR_NO_CPU_MAX,
63 RTEMS_RECORD_CLIENT_ERROR_NO_MEMORY,
64 RTEMS_RECORD_CLIENT_ERROR_PER_CPU_ITEMS_OVERFLOW
65} rtems_record_client_status;
66
67typedef rtems_record_client_status ( *rtems_record_client_handler )(
68 uint64_t bt,
69 uint32_t cpu,
71 uint64_t data,
72 void *arg
73);
74
75typedef struct {
79 struct {
80 uint64_t bt;
81 uint32_t time_at_bt;
82 uint32_t time_last;
83 uint32_t time_accumulated;
84 } uptime;
85
91 uint32_t tail[ 2 ];
92
98 uint32_t head[ 2 ];
99
107
111 uint32_t overflow;
112
118
131 rtems_record_item_64 *items;
132
138
140 uint64_t to_bt_scaler;
141 rtems_record_client_per_cpu per_cpu[ RTEMS_RECORD_CLIENT_MAXIMUM_CPU_COUNT ];
142 uint32_t cpu;
143 uint32_t cpu_count;
144 uint32_t count;
145 union {
146 rtems_record_item_32 format_32;
147 rtems_record_item_64 format_64;
148 } item;
149 size_t todo;
150 void *pos;
151 rtems_record_client_status ( *consume )(
153 const void *,
154 size_t
155 );
156 rtems_record_client_handler handler;
157 void *handler_arg;
158 size_t data_size;
159 uint32_t header[ 2 ];
160 rtems_record_client_status status;
162
175 rtems_record_client_handler handler,
176 void *arg
177);
178
186rtems_record_client_status rtems_record_client_run(
188 const void *buf,
189 size_t n
190);
191
202);
203
204static inline void rtems_record_client_set_handler(
206 rtems_record_client_handler handler
207)
208{
209 ctx->handler = handler;
210}
211
212static inline uint64_t rtems_record_client_bintime_to_nanoseconds(
213 uint64_t bt
214)
215{
216 uint64_t ns_per_sec;
217 uint64_t nanoseconds;
218
219 ns_per_sec = 1000000000ULL;
220 nanoseconds = ns_per_sec * ( (uint32_t) ( bt >> 32 ) );
221 nanoseconds += ( ns_per_sec * (uint32_t) bt ) >> 32;
222
223 return nanoseconds;
224}
225
226static inline void rtems_record_client_bintime_to_seconds_and_nanoseconds(
227 uint64_t bt,
228 uint32_t *seconds,
229 uint32_t *nanoseconds
230)
231{
232 uint64_t ns_per_sec;
233
234 ns_per_sec = 1000000000ULL;
235 *seconds = (uint32_t) ( bt >> 32 );
236 *nanoseconds = (uint32_t) ( ( ns_per_sec * (uint32_t) bt ) >> 32 );
237}
238
241#ifdef __cplusplus
242}
243#endif /* __cplusplus */
244
245#endif /* _RTEMS_RECORDCLIENT_H */
void rtems_record_client_destroy(rtems_record_client_context *ctx)
Drains all internal buffers and frees the allocated resources.
Definition: record-client.c:712
rtems_record_event
The record events.
Definition: recorddata.h:90
rtems_record_client_status rtems_record_client_run(rtems_record_client_context *ctx, const void *buf, size_t n)
Runs the record client to consume new stream data.
Definition: record-client.c:703
void rtems_record_client_init(rtems_record_client_context *ctx, rtems_record_client_handler handler, void *arg)
Initializes a record client.
Definition: record-client.c:688
Definition: recordclient.h:139
Definition: recordclient.h:75
size_t tail_head_index
The index of the tail and head members.
Definition: recordclient.h:106
bool hold_back
If true, then hold back items for overflow or initial ramp up processing.
Definition: recordclient.h:117
uint32_t overflow
Count of lost items due to ring buffer overflows.
Definition: recordclient.h:111
size_t item_index
The index for the next hold back item.
Definition: recordclient.h:136
The 32-bit format record item.
Definition: recorddata.h:1183