summaryrefslogtreecommitdiffstats
path: root/cpukit/libtrace
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2018-04-28 11:36:11 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2019-01-29 13:51:33 +0100
commitdca618404ee61c1be8a883ddb679889dbfea284b (patch)
tree49a61cb40d4fcce31c1c84b7f83737a4852630a0 /cpukit/libtrace
parentm68k: Avoid _Addresses_Add_offset() (diff)
downloadrtems-dca618404ee61c1be8a883ddb679889dbfea284b.tar.bz2
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.
Diffstat (limited to 'cpukit/libtrace')
-rw-r--r--cpukit/libtrace/record/record-client.c448
-rw-r--r--cpukit/libtrace/record/record-server.c290
-rw-r--r--cpukit/libtrace/record/record-sysinit.c128
-rw-r--r--cpukit/libtrace/record/record-text.c197
-rw-r--r--cpukit/libtrace/record/record-userext.c125
-rw-r--r--cpukit/libtrace/record/record.c132
6 files changed, 1320 insertions, 0 deletions
diff --git a/cpukit/libtrace/record/record-client.c b/cpukit/libtrace/record/record-client.c
new file mode 100644
index 0000000000..585aa3895d
--- /dev/null
+++ b/cpukit/libtrace/record/record-client.c
@@ -0,0 +1,448 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (C) 2018, 2019 embedded brains GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * This file must be compatible to general purpose POSIX system, e.g. Linux,
+ * FreeBSD. It may be used for utility programs.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/recordclient.h>
+
+#include <string.h>
+
+static void set_to_bt_scaler(
+ rtems_record_client_context *ctx,
+ uint32_t frequency
+)
+{
+ uint64_t bin_per_s;
+
+ bin_per_s = UINT64_C( 1 ) << 32;
+ ctx->to_bt_scaler = ( ( bin_per_s << 31 ) + frequency - 1 ) / frequency;
+}
+
+static rtems_record_client_status call_handler(
+ const rtems_record_client_context *ctx,
+ uint64_t bt,
+ rtems_record_event event,
+ uint64_t data
+)
+{
+ uint32_t seconds;
+ uint32_t nanosec;
+
+ seconds = (uint32_t) ( bt >> 32 );
+ nanosec = (uint32_t) ( ( UINT64_C( 1000000000 ) * (uint32_t) bt ) >> 32 );
+
+ return ( *ctx->handler )(
+ seconds,
+ nanosec,
+ ctx->cpu,
+ event,
+ data,
+ ctx->handler_arg
+ );
+}
+
+static void check_overflow(
+ const rtems_record_client_context *ctx,
+ const rtems_record_client_per_cpu *per_cpu,
+ uint32_t new_head
+)
+{
+ uint32_t last_tail;
+ uint32_t last_head;
+ uint32_t capacity;
+ uint32_t new_content;
+ uint64_t bt;
+
+ last_tail = per_cpu->tail[ per_cpu->index ];
+ last_head = per_cpu->head[ per_cpu->index ];
+
+ if ( last_tail == last_head ) {
+ return;
+ }
+
+ capacity = ( last_tail - last_head - 1 ) & ( ctx->count - 1 );
+ new_content = new_head - last_head;
+
+ if ( new_content <= capacity ) {
+ return;
+ }
+
+ bt = ( per_cpu->uptime.time_accumulated * ctx->to_bt_scaler ) >> 31;
+ bt += per_cpu->uptime.bt;
+
+ call_handler(
+ ctx,
+ bt,
+ RTEMS_RECORD_OVERFLOW,
+ new_content - capacity
+ );
+}
+
+static rtems_record_client_status visit( rtems_record_client_context *ctx )
+{
+ rtems_record_client_per_cpu *per_cpu;
+ uint32_t time;
+ rtems_record_event event;
+ uint64_t data;
+ uint64_t bt;
+
+ per_cpu = &ctx->per_cpu[ ctx->cpu ];
+ time = RTEMS_RECORD_GET_TIME( ctx->event );
+ event = RTEMS_RECORD_GET_EVENT( ctx->event );
+ data = ctx->data;
+
+ switch ( event ) {
+ case RTEMS_RECORD_PROCESSOR:
+ if ( data >= RTEMS_RECORD_CLIENT_MAXIMUM_CPU_COUNT ) {
+ return RTEMS_RECORD_CLIENT_ERROR_UNSUPPORTED_CPU;
+ }
+
+ ctx->cpu = (uint32_t) data;
+ per_cpu = &ctx->per_cpu[ ctx->cpu ];
+ break;
+ case RTEMS_RECORD_UPTIME_LOW:
+ per_cpu->uptime.bt = (uint32_t) data;
+ per_cpu->uptime.time_at_bt = time;
+ per_cpu->uptime.time_last = time;
+ per_cpu->uptime.time_accumulated = 0;
+ time = 0;
+ break;
+ case RTEMS_RECORD_UPTIME_HIGH:
+ per_cpu->uptime.bt += (int64_t) data << 32;
+ time = 0;
+ break;
+ case RTEMS_RECORD_TAIL:
+ per_cpu->tail[ per_cpu->index ] = (uint32_t) data;
+ break;
+ case RTEMS_RECORD_HEAD:
+ per_cpu->head[ per_cpu->index ]= (uint32_t) data;
+ per_cpu->index ^= 1;
+ check_overflow( ctx, per_cpu, (uint32_t) data );
+ break;
+ case RTEMS_RECORD_COUNT:
+ ctx->count = (uint32_t) data;
+ break;
+ case RTEMS_RECORD_FREQUENCY:
+ set_to_bt_scaler( ctx, (uint32_t) data );
+ break;
+ case RTEMS_RECORD_VERSION:
+ if ( data != RTEMS_RECORD_THE_VERSION ) {
+ return RTEMS_RECORD_CLIENT_ERROR_UNSUPPORTED_VERSION;
+ }
+
+ break;
+ default:
+ break;
+ }
+
+ if ( time != 0 ) {
+ uint32_t delta;
+
+ delta = ( time - per_cpu->uptime.time_last )
+ & ( ( UINT32_C( 1 ) << RTEMS_RECORD_TIME_BITS ) - 1 );
+ per_cpu->uptime.time_last = time;
+ per_cpu->uptime.time_accumulated += delta;
+ bt = ( per_cpu->uptime.time_accumulated * ctx->to_bt_scaler ) >> 31;
+ bt += per_cpu->uptime.bt;
+ } else {
+ bt = 0;
+ }
+
+ return call_handler( ctx, bt, event, data );
+}
+
+static rtems_record_client_status consume_32(
+ rtems_record_client_context *ctx,
+ const void *buf,
+ size_t n
+)
+{
+ while ( n > 0 ) {
+ size_t m;
+ char *pos;
+
+ m = ctx->todo < n ? ctx->todo : n;
+ pos = ctx->pos;
+ pos = memcpy( pos, buf, m );
+ n -= m;
+ buf = (char *) buf + m;
+
+ if ( m == ctx->todo ) {
+ rtems_record_client_status status;
+
+ ctx->todo = sizeof( ctx->item.format_32 );
+ ctx->pos = &ctx->item.format_32;
+ ctx->event = ctx->item.format_32.event;
+ ctx->data = ctx->item.format_32.data;
+
+ status = visit( ctx );
+
+ if ( status != RTEMS_RECORD_CLIENT_SUCCESS ) {
+ return status;
+ }
+ } else {
+ ctx->todo -= m;
+ ctx->pos = pos + m;
+ }
+ }
+
+ return RTEMS_RECORD_CLIENT_SUCCESS;
+}
+
+static rtems_record_client_status consume_64(
+ rtems_record_client_context *ctx,
+ const void *buf,
+ size_t n
+)
+{
+ while ( n > 0 ) {
+ size_t m;
+ char *pos;
+
+ m = ctx->todo < n ? ctx->todo : n;
+ pos = ctx->pos;
+ pos = memcpy( pos, buf, m );
+ n -= m;
+ buf = (char *) buf + m;
+
+ if ( m == ctx->todo ) {
+ rtems_record_client_status status;
+
+ ctx->todo = sizeof( ctx->item.format_64 );
+ ctx->pos = &ctx->item.format_64;
+ ctx->event = ctx->item.format_64.event;
+ ctx->data = ctx->item.format_64.data;
+
+ status = visit( ctx );
+
+ if ( status != RTEMS_RECORD_CLIENT_SUCCESS ) {
+ return status;
+ }
+ } else {
+ ctx->todo -= m;
+ ctx->pos = pos + m;
+ }
+ }
+
+ return RTEMS_RECORD_CLIENT_SUCCESS;
+}
+
+static rtems_record_client_status consume_swap_32(
+ rtems_record_client_context *ctx,
+ const void *buf,
+ size_t n
+)
+{
+ while ( n > 0 ) {
+ size_t m;
+ char *pos;
+
+ m = ctx->todo < n ? ctx->todo : n;
+ pos = ctx->pos;
+ pos = memcpy( pos, buf, m );
+ n -= m;
+ buf = (char *) buf + m;
+
+ if ( m == ctx->todo ) {
+ rtems_record_client_status status;
+
+ ctx->todo = sizeof( ctx->item.format_32 );
+ ctx->pos = &ctx->item.format_32;
+ ctx->event = __builtin_bswap32( ctx->item.format_32.event );
+ ctx->data = __builtin_bswap32( ctx->item.format_32.data );
+
+ status = visit( ctx );
+
+ if ( status != RTEMS_RECORD_CLIENT_SUCCESS ) {
+ return status;
+ }
+ } else {
+ ctx->todo -= m;
+ ctx->pos = pos + m;
+ }
+ }
+
+ return RTEMS_RECORD_CLIENT_SUCCESS;
+}
+
+static rtems_record_client_status consume_swap_64(
+ rtems_record_client_context *ctx,
+ const void *buf,
+ size_t n
+)
+{
+ while ( n > 0 ) {
+ size_t m;
+ char *pos;
+
+ m = ctx->todo < n ? ctx->todo : n;
+ pos = ctx->pos;
+ pos = memcpy( pos, buf, m );
+ n -= m;
+ buf = (char *) buf + m;
+
+ if ( m == ctx->todo ) {
+ rtems_record_client_status status;
+
+ ctx->todo = sizeof( ctx->item.format_64 );
+ ctx->pos = &ctx->item.format_64;
+ ctx->event = __builtin_bswap32( ctx->item.format_64.event );
+ ctx->data = __builtin_bswap64( ctx->item.format_64.data );
+
+ status = visit( ctx );
+
+ if ( status != RTEMS_RECORD_CLIENT_SUCCESS ) {
+ return status;
+ }
+ } else {
+ ctx->todo -= m;
+ ctx->pos = pos + m;
+ }
+ }
+
+ return RTEMS_RECORD_CLIENT_SUCCESS;
+}
+
+static rtems_record_client_status consume_init(
+ rtems_record_client_context *ctx,
+ const void *buf,
+ size_t n
+)
+{
+ while ( n > 0 ) {
+ size_t m;
+ char *pos;
+
+ m = ctx->todo < n ? ctx->todo : n;
+ pos = ctx->pos;
+ pos = memcpy( pos, buf, m );
+ n -= m;
+ buf = (char *) buf + m;
+
+ if ( m == ctx->todo ) {
+ uint32_t magic;
+
+ magic = ctx->header[ 1 ];
+
+ switch ( ctx->header[ 0 ] ) {
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+ case RTEMS_RECORD_FORMAT_LE_32:
+ ctx->todo = sizeof( ctx->item.format_32 );
+ ctx->pos = &ctx->item.format_32;
+ ctx->consume = consume_32;
+ break;
+ case RTEMS_RECORD_FORMAT_LE_64:
+ ctx->todo = sizeof( ctx->item.format_64 );
+ ctx->pos = &ctx->item.format_64;
+ ctx->consume = consume_64;
+ break;
+ case RTEMS_RECORD_FORMAT_BE_32:
+ ctx->todo = sizeof( ctx->item.format_32 );
+ ctx->pos = &ctx->item.format_32;
+ ctx->consume = consume_swap_32;
+ magic = __builtin_bswap32( magic );
+ break;
+ case RTEMS_RECORD_FORMAT_BE_64:
+ ctx->todo = sizeof( ctx->item.format_64 );
+ ctx->pos = &ctx->item.format_64;
+ ctx->consume = consume_swap_64;
+ magic = __builtin_bswap32( magic );
+ break;
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+ case RTEMS_RECORD_FORMAT_LE_32:
+ ctx->todo = sizeof( ctx->item.format_32 );
+ ctx->pos = &ctx->item.format_32;
+ ctx->consume = consume_swap_32;
+ magic = __builtin_bswap32( magic );
+ break;
+ case RTEMS_RECORD_FORMAT_LE_64:
+ ctx->todo = sizeof( ctx->item.format_64 );
+ ctx->pos = &ctx->item.format_64;
+ ctx->consume = consume_swap_64;
+ magic = __builtin_bswap32( magic );
+ break;
+ case RTEMS_RECORD_FORMAT_BE_32:
+ ctx->todo = sizeof( ctx->item.format_32 );
+ ctx->pos = &ctx->item.format_32;
+ ctx->consume = consume_32;
+ break;
+ case RTEMS_RECORD_FORMAT_BE_64:
+ ctx->todo = sizeof( ctx->item.format_64 );
+ ctx->pos = &ctx->item.format_64;
+ ctx->consume = consume_64;
+ break;
+#else
+#error "unexpected __BYTE_ORDER__"
+#endif
+ default:
+ return RTEMS_RECORD_CLIENT_ERROR_UNKNOWN_FORMAT;
+ }
+
+ if ( magic != RTEMS_RECORD_MAGIC ) {
+ return RTEMS_RECORD_CLIENT_ERROR_INVALID_MAGIC;
+ }
+
+ return rtems_record_client_run( ctx, buf, n );
+ } else {
+ ctx->todo -= m;
+ ctx->pos = pos + m;
+ }
+ }
+
+ return RTEMS_RECORD_CLIENT_SUCCESS;
+}
+
+void rtems_record_client_init(
+ rtems_record_client_context *ctx,
+ rtems_record_client_handler handler,
+ void *arg
+)
+{
+ ctx = memset( ctx, 0, sizeof( *ctx ) );
+ ctx->to_bt_scaler = UINT64_C( 1 ) << 31;
+ ctx->handler = handler;
+ ctx->handler_arg = arg;
+ ctx->todo = sizeof( ctx->header );
+ ctx->pos = &ctx->header;
+ ctx->consume = consume_init;
+}
+
+rtems_record_client_status rtems_record_client_run(
+ rtems_record_client_context *ctx,
+ const void *buf,
+ size_t n
+)
+{
+ return ( *ctx->consume )( ctx, buf, n );
+}
diff --git a/cpukit/libtrace/record/record-server.c b/cpukit/libtrace/record/record-server.c
new file mode 100644
index 0000000000..3f34b5d075
--- /dev/null
+++ b/cpukit/libtrace/record/record-server.c
@@ -0,0 +1,290 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (C) 2018, 2019 embedded brains GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/record.h>
+#include <rtems.h>
+
+#include <sys/endian.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+
+#include <string.h>
+#include <unistd.h>
+
+#include <netinet/in.h>
+
+#ifdef RTEMS_SMP
+#define CHUNKS (3 * CPU_MAXIMUM_PROCESSORS)
+#else
+#define CHUNKS 4
+#endif
+
+typedef struct {
+ int available;
+ struct iovec *current;
+ struct iovec iov[CHUNKS];
+} writev_visitor_context;
+
+static void writev_visitor(
+ const rtems_record_item *items,
+ size_t count,
+ void *arg
+)
+{
+ writev_visitor_context *ctx;
+
+ ctx = arg;
+
+ if ( ctx->available > 0 ) {
+ ctx->current->iov_base = RTEMS_DECONST( rtems_record_item *, items );
+ ctx->current->iov_len = count * sizeof( *items );
+ --ctx->available;
+ ++ctx->current;
+ }
+}
+
+ssize_t rtems_record_writev( int fd, bool *written )
+{
+ writev_visitor_context ctx;
+ int n;
+
+ ctx.available = CHUNKS;
+ ctx.current = &ctx.iov[ 0 ];
+ rtems_record_drain( writev_visitor, &ctx );
+ n = CHUNKS - ctx.available;
+
+ if ( n > 0 ) {
+ *written = true;
+ return writev( fd, &ctx.iov[ 0 ], n );
+ } else {
+ *written = false;
+ return 0;
+ }
+}
+
+#define WAKEUP_EVENT RTEMS_EVENT_0
+
+static void wakeup( rtems_id task )
+{
+ (void) rtems_event_send( task, WAKEUP_EVENT );
+}
+
+static void wait( rtems_option options )
+{
+ rtems_event_set events;
+
+ (void) rtems_event_receive(
+ WAKEUP_EVENT,
+ RTEMS_EVENT_ANY | options,
+ RTEMS_NO_TIMEOUT,
+ &events
+ );
+}
+
+static void wakeup_timer( rtems_id timer, void *arg )
+{
+ rtems_id *server;
+
+ server = arg;
+ wakeup( *server );
+ (void) rtems_timer_reset( timer );
+}
+
+void _Record_Stream_header_initialize( Record_Stream_header *header )
+{
+#if BYTE_ORDER == LITTLE_ENDIAN
+#if __INTPTR_WIDTH__ == 32
+ header->format = RTEMS_RECORD_FORMAT_LE_32,
+#elif __INTPTR_WIDTH__ == 64
+ header->format = RTEMS_RECORD_FORMAT_LE_64,
+#else
+#error "unexpected __INTPTR_WIDTH__"
+#endif
+#elif BYTE_ORDER == BIG_ENDIAN
+#if __INTPTR_WIDTH__ == 32
+ header->format = RTEMS_RECORD_FORMAT_BE_32,
+#elif __INTPTR_WIDTH__ == 64
+ header->format = RTEMS_RECORD_FORMAT_BE_64,
+#else
+#error "unexpected __INTPTR_WIDTH__"
+#endif
+#else
+#error "unexpected BYTE_ORDER"
+#endif
+
+ header->magic = RTEMS_RECORD_MAGIC;
+
+ header->Version.event = RTEMS_RECORD_TIME_EVENT( 0, RTEMS_RECORD_VERSION );
+ header->Version.data = RTEMS_RECORD_THE_VERSION;
+
+ header->Processor_maximum.event =
+ RTEMS_RECORD_TIME_EVENT( 0, RTEMS_RECORD_PROCESSOR_MAXIMUM );
+ header->Processor_maximum.data = rtems_get_processor_count() - 1;
+
+ header->Count.event = RTEMS_RECORD_TIME_EVENT( 0, RTEMS_RECORD_COUNT );
+ header->Count.data = _Record_Item_count;
+
+ header->Frequency.event =
+ RTEMS_RECORD_TIME_EVENT( 0, RTEMS_RECORD_FREQUENCY );
+ header->Frequency.data = rtems_counter_frequency();
+}
+
+static void send_header( int fd )
+{
+ Record_Stream_header header;
+
+ _Record_Stream_header_initialize( &header );
+ (void) write( fd, &header, sizeof( header ) );
+}
+
+void rtems_record_server( uint16_t port, rtems_interval period )
+{
+ rtems_status_code sc;
+ rtems_id self;
+ rtems_id timer;
+ struct sockaddr_in addr;
+ int sd;
+ int rv;
+
+ sd = -1;
+ self = rtems_task_self();
+
+ sc = rtems_timer_create( rtems_build_name( 'R', 'C', 'R', 'D' ), &timer );
+ if ( sc != RTEMS_SUCCESSFUL ) {
+ return;
+ }
+
+ sd = socket( PF_INET, SOCK_STREAM, 0 );
+ if (sd < 0) {
+ goto error;
+ }
+
+ memset( &addr, 0, sizeof( addr ) );
+ addr.sin_family = AF_INET;
+ addr.sin_port = htons( port );
+ addr.sin_addr.s_addr = htonl( INADDR_ANY );
+
+ rv = bind( sd, (const struct sockaddr *) &addr, sizeof( addr ) );
+ if (rv != 0) {
+ goto error;
+ }
+
+ rv = listen( sd, 0 );
+ if (rv != 0) {
+ goto error;
+ }
+
+ while ( true ) {
+ int cd;
+ bool written;
+ ssize_t n;
+
+ cd = accept( sd, NULL, NULL );
+
+ if ( cd < 0 ) {
+ break;
+ }
+
+ wait( RTEMS_NO_WAIT );
+ (void) rtems_timer_fire_after( timer, period, wakeup_timer, &self );
+ send_header( cd );
+
+ while ( true ) {
+ n = rtems_record_writev( cd, &written );
+
+ if ( written && n <= 0 ) {
+ break;
+ }
+
+ wait( RTEMS_WAIT );
+ }
+
+ (void) rtems_timer_cancel( timer );
+ (void) close( cd );
+ }
+
+error:
+
+ (void) close( sd );
+ (void) rtems_timer_delete( timer );
+}
+
+typedef struct {
+ rtems_id task;
+ uint16_t port;
+ rtems_interval period;
+} server_arg;
+
+static void server( rtems_task_argument arg )
+{
+ server_arg *sarg;
+ uint16_t port;
+ rtems_interval period;
+
+ sarg = (server_arg *) arg;
+ port = sarg->port;
+ period = sarg->period;
+ wakeup(sarg->task);
+ rtems_record_server( port, period );
+ rtems_task_exit();
+}
+
+rtems_status_code rtems_record_start_server(
+ rtems_task_priority priority,
+ uint16_t port,
+ rtems_interval period
+)
+{
+ rtems_status_code sc;
+ rtems_id id;
+ server_arg sarg;
+
+ sarg.port = port;
+ sarg.period = period;
+ sarg.task = rtems_task_self();
+
+ sc = rtems_task_create(
+ rtems_build_name( 'R', 'C', 'R', 'D' ),
+ priority,
+ RTEMS_MINIMUM_STACK_SIZE,
+ RTEMS_DEFAULT_MODES,
+ RTEMS_DEFAULT_ATTRIBUTES,
+ &id
+ );
+ if ( sc != RTEMS_SUCCESSFUL ) {
+ return sc;
+ }
+
+ (void) rtems_task_start( id, server, (rtems_task_argument) &sarg );
+ wait( RTEMS_WAIT );
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/libtrace/record/record-sysinit.c b/cpukit/libtrace/record/record-sysinit.c
new file mode 100644
index 0000000000..59bd97346f
--- /dev/null
+++ b/cpukit/libtrace/record/record-sysinit.c
@@ -0,0 +1,128 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (C) 2018, 2019 embedded brains GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/record.h>
+#include <rtems/config.h>
+#include <rtems/sysinit.h>
+#include <rtems/score/timecounter.h>
+#include <rtems/score/watchdogimpl.h>
+
+static Watchdog_Interval _Record_Tick_interval;
+
+void _Record_Initialize( void )
+{
+ uint32_t cpu_max;
+ uint32_t cpu_index;
+ uintptr_t offset;
+
+ cpu_max = rtems_configuration_get_maximum_processors();
+ offset = PER_CPU_DATA_OFFSET( _Record_Per_CPU );
+
+ for ( cpu_index = 0; cpu_index < cpu_max; ++cpu_index ) {
+ Per_CPU_Control *cpu;
+ Record_Control *control;
+
+ cpu = _Per_CPU_Get_by_index( cpu_index );
+ control = PER_CPU_DATA_GET_BY_OFFSET( cpu, Record_Control, offset );
+ control->mask = _Record_Item_count - 1U;
+ cpu->record = control;
+ }
+}
+
+static void _Record_Watchdog( Watchdog_Control *watchdog )
+{
+ ISR_Level level;
+ sbintime_t now;
+
+ _ISR_Local_disable( level );
+ _Watchdog_Per_CPU_insert_ticks(
+ watchdog,
+ _Watchdog_Get_CPU( watchdog ),
+ _Record_Tick_interval
+ );
+ _ISR_Local_enable( level );
+
+ now = _Timecounter_Sbinuptime();
+ rtems_record_produce_2(
+ RTEMS_RECORD_UPTIME_LOW,
+ (uint32_t) ( now >> 0 ),
+ RTEMS_RECORD_UPTIME_HIGH,
+ (uint32_t) ( now >> 32 )
+ );
+}
+
+static void _Record_Initialize_watchdogs( void )
+{
+ Watchdog_Interval interval;
+ uint32_t cpu_max;
+ uint32_t cpu_index;
+ sbintime_t now;
+
+ interval = rtems_counter_frequency() / _Watchdog_Ticks_per_second;
+ interval = ( UINT32_C( 1 ) << 22 ) / interval;
+
+ if ( interval == 0 ) {
+ interval = 1;
+ }
+
+ _Record_Tick_interval = interval;
+
+ cpu_max = rtems_configuration_get_maximum_processors();
+
+ for ( cpu_index = 0; cpu_index < cpu_max; ++cpu_index ) {
+ Per_CPU_Control *cpu;
+ Record_Control *control;
+
+ cpu = _Per_CPU_Get_by_index( cpu_index );
+ control = cpu->record;
+ _Watchdog_Preinitialize( &control->Watchdog, cpu );
+ _Watchdog_Initialize( &control->Watchdog, _Record_Watchdog );
+ _Watchdog_Per_CPU_insert_ticks(
+ &control->Watchdog,
+ cpu,
+ _Record_Tick_interval
+ );
+ }
+
+ now = _Timecounter_Sbinuptime();
+ rtems_record_produce_2(
+ RTEMS_RECORD_UPTIME_LOW,
+ (uint32_t) ( now >> 0 ),
+ RTEMS_RECORD_UPTIME_HIGH,
+ (uint32_t) ( now >> 32 )
+ );
+}
+
+RTEMS_SYSINIT_ITEM(
+ _Record_Initialize_watchdogs,
+ RTEMS_SYSINIT_DEVICE_DRIVERS,
+ RTEMS_SYSINIT_ORDER_LAST
+);
diff --git a/cpukit/libtrace/record/record-text.c b/cpukit/libtrace/record/record-text.c
new file mode 100644
index 0000000000..f8173ce047
--- /dev/null
+++ b/cpukit/libtrace/record/record-text.c
@@ -0,0 +1,197 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (C) 2018, 2019 embedded brains GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * This file must be compatible to general purpose POSIX system, e.g. Linux,
+ * FreeBSD. It may be used for utility programs.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/recorddata.h>
+
+#include <stddef.h>
+
+static const char * const event_text[] = {
+ [ RTEMS_RECORD_EMPTY ] = "EMPTY",
+ [ RTEMS_RECORD_VERSION ] = "VERSION",
+ [ RTEMS_RECORD_ACCEPT ] = "ACCEPT",
+ [ RTEMS_RECORD_BIND ] = "BIND",
+ [ RTEMS_RECORD_BUFFER ] = "BUFFER",
+ [ RTEMS_RECORD_CHOWN ] = "CHOWN",
+ [ RTEMS_RECORD_CLOSE ] = "CLOSE",
+ [ RTEMS_RECORD_CONNECT ] = "CONNECT",
+ [ RTEMS_RECORD_COUNT ] = "COUNT",
+ [ RTEMS_RECORD_ETHER_INPUT ] = "ETHER_INPUT",
+ [ RTEMS_RECORD_ETHER_OUTPUT ] = "ETHER_OUTPUT",
+ [ RTEMS_RECORD_FCHMOD ] = "FCHMOD",
+ [ RTEMS_RECORD_FCNTL ] = "FCNTL",
+ [ RTEMS_RECORD_FDATASYNC ] = "FDATASYNC",
+ [ RTEMS_RECORD_FREQUENCY ] = "FREQUENCY",
+ [ RTEMS_RECORD_FSTAT ] = "FSTAT",
+ [ RTEMS_RECORD_FSYNC ] = "FSYNC",
+ [ RTEMS_RECORD_FTRUNCATE ] = "FTRUNCATE",
+ [ RTEMS_RECORD_GIT_HASH ] = "GIT_HASH",
+ [ RTEMS_RECORD_HEAD ] = "HEAD",
+ [ RTEMS_RECORD_HEAP_ALLOC ] = "HEAP_ALLOC",
+ [ RTEMS_RECORD_HEAP_FREE ] = "HEAP_FREE",
+ [ RTEMS_RECORD_HEAP_SIZE ] = "HEAP_SIZE",
+ [ RTEMS_RECORD_HEAP_USAGE ] = "HEAP_USAGE",
+ [ RTEMS_RECORD_INTERUPT_BEGIN ] = "INTERUPT_BEGIN",
+ [ RTEMS_RECORD_INTERUPT_END ] = "INTERUPT_END",
+ [ RTEMS_RECORD_INTERUPT_INSTALL ] = "INTERUPT_INSTALL",
+ [ RTEMS_RECORD_INTERUPT_REMOVE ] = "INTERUPT_REMOVE",
+ [ RTEMS_RECORD_IOCTL ] = "IOCTL",
+ [ RTEMS_RECORD_IP6_INPUT ] = "IP6_INPUT",
+ [ RTEMS_RECORD_IP6_OUTPUT ] = "IP6_OUTPUT",
+ [ RTEMS_RECORD_IP_INPUT ] = "IP_INPUT",
+ [ RTEMS_RECORD_IP_OUTPUT ] = "IP_OUTPUT",
+ [ RTEMS_RECORD_KEVENT ] = "KEVENT",
+ [ RTEMS_RECORD_KQUEUE ] = "KQUEUE",
+ [ RTEMS_RECORD_LENGTH ] = "LENGTH",
+ [ RTEMS_RECORD_LINK ] = "LINK",
+ [ RTEMS_RECORD_LSEEK ] = "LSEEK",
+ [ RTEMS_RECORD_MKNOD ] = "MKNOD",
+ [ RTEMS_RECORD_MMAP ] = "MMAP",
+ [ RTEMS_RECORD_MOUNT ] = "MOUNT",
+ [ RTEMS_RECORD_OPEN ] = "OPEN",
+ [ RTEMS_RECORD_OVERFLOW ] = "OVERFLOW",
+ [ RTEMS_RECORD_PAGE_ALLOC ] = "PAGE_ALLOC",
+ [ RTEMS_RECORD_PAGE_FREE ] = "PAGE_FREE",
+ [ RTEMS_RECORD_POLL ] = "POLL",
+ [ RTEMS_RECORD_PROCESSOR ] = "PROCESSOR",
+ [ RTEMS_RECORD_PROCESSOR_MAXIMUM ] = "PROCESSOR_MAXIMUM",
+ [ RTEMS_RECORD_READ ] = "READ",
+ [ RTEMS_RECORD_READLINK ] = "READLINK",
+ [ RTEMS_RECORD_READV ] = "READV",
+ [ RTEMS_RECORD_RECV ] = "RECV",
+ [ RTEMS_RECORD_RECVFROM ] = "RECVFROM",
+ [ RTEMS_RECORD_RECVMSG ] = "RECVMSG",
+ [ RTEMS_RECORD_RENAME ] = "RENAME",
+ [ RTEMS_RECORD_RTEMS_BARRIER_CREATE ] = "RTEMS_BARRIER_CREATE",
+ [ RTEMS_RECORD_RTEMS_BARRIER_DELETE ] = "RTEMS_BARRIER_DELETE",
+ [ RTEMS_RECORD_RTEMS_BARRIER_RELEASE ] = "RTEMS_BARRIER_RELEASE",
+ [ RTEMS_RECORD_RTEMS_BARRIER_WAIT ] = "RTEMS_BARRIER_WAIT",
+ [ RTEMS_RECORD_RTEMS_EVENT_RECEIVE ] = "RTEMS_EVENT_RECEIVE",
+ [ RTEMS_RECORD_RTEMS_EVENT_SEND ] = "RTEMS_EVENT_SEND",
+ [ RTEMS_RECORD_RTEMS_EVENT_SYSTEM_RECEIVE ] = "RTEMS_EVENT_SYSTEM_RECEIVE",
+ [ RTEMS_RECORD_RTEMS_EVENT_SYSTEM_SEND ] = "RTEMS_EVENT_SYSTEM_SEND",
+ [ RTEMS_RECORD_RTEMS_MESSAGE_QUEUE_BROADCAST ] = "RTEMS_MESSAGE_QUEUE_BROADCAST",
+ [ RTEMS_RECORD_RTEMS_MESSAGE_QUEUE_CREATE ] = "RTEMS_MESSAGE_QUEUE_CREATE",
+ [ RTEMS_RECORD_RTEMS_MESSAGE_QUEUE_DELETE ] = "RTEMS_MESSAGE_QUEUE_DELETE",
+ [ RTEMS_RECORD_RTEMS_MESSAGE_QUEUE_FLUSH ] = "RTEMS_MESSAGE_QUEUE_FLUSH",
+ [ RTEMS_RECORD_RTEMS_MESSAGE_QUEUE_RECEIVE ] = "RTEMS_MESSAGE_QUEUE_RECEIVE",
+ [ RTEMS_RECORD_RTEMS_MESSAGE_QUEUE_SEND ] = "RTEMS_MESSAGE_QUEUE_SEND",
+ [ RTEMS_RECORD_RTEMS_MESSAGE_QUEUE_URGENT ] = "RTEMS_MESSAGE_QUEUE_URGENT",
+ [ RTEMS_RECORD_RTEMS_PARTITION_CREATE ] = "RTEMS_PARTITION_CREATE",
+ [ RTEMS_RECORD_RTEMS_PARTITION_DELETE ] = "RTEMS_PARTITION_DELETE",
+ [ RTEMS_RECORD_RTEMS_PARTITION_GET_BUFFER ] = "RTEMS_PARTITION_GET_BUFFER",
+ [ RTEMS_RECORD_RTEMS_PARTITION_RETURN_BUFFER ] = "RTEMS_PARTITION_RETURN_BUFFER",
+ [ RTEMS_RECORD_RTEMS_RATE_MONOTONIC_CANCEL ] = "RTEMS_RATE_MONOTONIC_CANCEL",
+ [ RTEMS_RECORD_RTEMS_RATE_MONOTONIC_CREATE ] = "RTEMS_RATE_MONOTONIC_CREATE",
+ [ RTEMS_RECORD_RTEMS_RATE_MONOTONIC_DELETE ] = "RTEMS_RATE_MONOTONIC_DELETE",
+ [ RTEMS_RECORD_RTEMS_RATE_MONOTONIC_PERIOD ] = "RTEMS_RATE_MONOTONIC_PERIOD",
+ [ RTEMS_RECORD_RTEMS_SEMAPHORE_CREATE ] = "RTEMS_SEMAPHORE_CREATE",
+ [ RTEMS_RECORD_RTEMS_SEMAPHORE_DELETE ] = "RTEMS_SEMAPHORE_DELETE",
+ [ RTEMS_RECORD_RTEMS_SEMAPHORE_FLUSH ] = "RTEMS_SEMAPHORE_FLUSH",
+ [ RTEMS_RECORD_RTEMS_SEMAPHORE_OBTAIN ] = "RTEMS_SEMAPHORE_OBTAIN",
+ [ RTEMS_RECORD_RTEMS_SEMAPHORE_RELEASE ] = "RTEMS_SEMAPHORE_RELEASE",
+ [ RTEMS_RECORD_RTEMS_TIMER_CANCEL ] = "RTEMS_TIMER_CANCEL",
+ [ RTEMS_RECORD_RTEMS_TIMER_CREATE ] = "RTEMS_TIMER_CREATE",
+ [ RTEMS_RECORD_RTEMS_TIMER_DELETE ] = "RTEMS_TIMER_DELETE",
+ [ RTEMS_RECORD_RTEMS_TIMER_FIRE_AFTER ] = "RTEMS_TIMER_FIRE_AFTER",
+ [ RTEMS_RECORD_RTEMS_TIMER_FIRE_WHEN ] = "RTEMS_TIMER_FIRE_WHEN",
+ [ RTEMS_RECORD_RTEMS_TIMER_RESET ] = "RTEMS_TIMER_RESET",
+ [ RTEMS_RECORD_RTEMS_TIMER_SERVER_FIRE_AFTER ] = "RTEMS_TIMER_SERVER_FIRE_AFTER",
+ [ RTEMS_RECORD_RTEMS_TIMER_SERVER_FIRE_WHEN ] = "RTEMS_TIMER_SERVER_FIRE_WHEN",
+ [ RTEMS_RECORD_SELECT ] = "SELECT",
+ [ RTEMS_RECORD_SEND ] = "SEND",
+ [ RTEMS_RECORD_SENDMSG ] = "SENDMSG",
+ [ RTEMS_RECORD_SENDTO ] = "SENDTO",
+ [ RTEMS_RECORD_SOCKET ] = "SOCKET",
+ [ RTEMS_RECORD_STATVFS ] = "STATVFS",
+ [ RTEMS_RECORD_SYMLINK ] = "SYMLINK",
+ [ RTEMS_RECORD_TAIL ] = "TAIL",
+ [ RTEMS_RECORD_TCP_INPUT ] = "TCP_INPUT",
+ [ RTEMS_RECORD_TCP_OUTPUT ] = "TCP_OUTPUT",
+ [ RTEMS_RECORD_THREAD_BEGIN ] = "THREAD_BEGIN",
+ [ RTEMS_RECORD_THREAD_CREATE ] = "THREAD_CREATE",
+ [ RTEMS_RECORD_THREAD_DELETE ] = "THREAD_DELETE",
+ [ RTEMS_RECORD_THREAD_EXIT ] = "THREAD_EXIT",
+ [ RTEMS_RECORD_THREAD_EXITTED ] = "THREAD_EXITTED",
+ [ RTEMS_RECORD_THREAD_ID ] = "THREAD_ID",
+ [ RTEMS_RECORD_THREAD_PRIO_CURRENT_HIGH ] = "THREAD_PRIO_CURRENT_HIGH",
+ [ RTEMS_RECORD_THREAD_PRIO_CURRENT_LOW ] = "THREAD_PRIO_CURRENT_LOW",
+ [ RTEMS_RECORD_THREAD_PRIO_REAL_HIGH ] = "THREAD_PRIO_REAL_HIGH",
+ [ RTEMS_RECORD_THREAD_PRIO_REAL_LOW ] = "THREAD_PRIO_REAL_LOW",
+ [ RTEMS_RECORD_THREAD_QUEUE_ENQUEUE ] = "THREAD_QUEUE_ENQUEUE",
+ [ RTEMS_RECORD_THREAD_QUEUE_ENQUEUE_STICKY ] = "THREAD_QUEUE_ENQUEUE_STICKY",
+ [ RTEMS_RECORD_THREAD_QUEUE_EXTRACT ] = "THREAD_QUEUE_EXTRACT",
+ [ RTEMS_RECORD_THREAD_QUEUE_SURRENDER ] = "THREAD_QUEUE_SURRENDER",
+ [ RTEMS_RECORD_THREAD_QUEUE_SURRENDER_STICKY ] = "THREAD_QUEUE_SURRENDER_STICKY",
+ [ RTEMS_RECORD_THREAD_RESTART ] = "THREAD_RESTART",
+ [ RTEMS_RECORD_THREAD_STACK_CURRENT ] = "THREAD_STACK_CURRENT",
+ [ RTEMS_RECORD_THREAD_STACK_SIZE ] = "THREAD_STACK_SIZE",
+ [ RTEMS_RECORD_THREAD_STACK_USAGE ] = "THREAD_STACK_USAGE",
+ [ RTEMS_RECORD_THREAD_START ] = "THREAD_START",
+ [ RTEMS_RECORD_THREAD_STATE_CLEAR ] = "THREAD_STATE_CLEAR",
+ [ RTEMS_RECORD_THREAD_STATE_SET ] = "THREAD_STATE_SET",
+ [ RTEMS_RECORD_THREAD_SWITCH_IN ] = "THREAD_SWITCH_IN",
+ [ RTEMS_RECORD_THREAD_SWITCH_OUT ] = "THREAD_SWITCH_OUT",
+ [ RTEMS_RECORD_THREAD_TERMINATE ] = "THREAD_TERMINATE",
+ [ RTEMS_RECORD_UDP_INPUT ] = "UDP_INPUT",
+ [ RTEMS_RECORD_UDP_OUTPUT ] = "UDP_OUTPUT",
+ [ RTEMS_RECORD_UMA_ALLOC_PTR ] = "UMA_ALLOC_PTR",
+ [ RTEMS_RECORD_UMA_ALLOC_ZONE ] = "UMA_ALLOC_ZONE",
+ [ RTEMS_RECORD_UMA_FREE_PTR ] = "UMA_FREE_PTR",
+ [ RTEMS_RECORD_UMA_FREE_ZONE ] = "UMA_FREE_ZONE",
+ [ RTEMS_RECORD_UNLINK ] = "UNLINK",
+ [ RTEMS_RECORD_UNMOUNT ] = "UNMOUNT",
+ [ RTEMS_RECORD_UPTIME_HIGH ] = "UPTIME_HIGH",
+ [ RTEMS_RECORD_UPTIME_LOW ] = "UPTIME_LOW",
+ [ RTEMS_RECORD_WORKSPACE_ALLOC ] = "WORKSPACE_ALLOC",
+ [ RTEMS_RECORD_WORKSPACE_FREE ] = "WORKSPACE_FREE",
+ [ RTEMS_RECORD_WORKSPACE_SIZE ] = "WORKSPACE_SIZE",
+ [ RTEMS_RECORD_WORKSPACE_USAGE ] = "WORKSPACE_USAGE",
+ [ RTEMS_RECORD_WRITE ] = "WRITE",
+ [ RTEMS_RECORD_WRITEV ] = "WRITEV"
+};
+
+const char *rtems_record_event_text( rtems_record_event event )
+{
+ size_t n;
+
+ n = event;
+
+ if ( n < sizeof( event_text ) / sizeof( event_text[ 0 ] ) ) {
+ return event_text[ n ];
+ }
+
+ return NULL;
+}
diff --git a/cpukit/libtrace/record/record-userext.c b/cpukit/libtrace/record/record-userext.c
new file mode 100644
index 0000000000..a57a3f751e
--- /dev/null
+++ b/cpukit/libtrace/record/record-userext.c
@@ -0,0 +1,125 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (C) 2018, 2019 embedded brains GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/record.h>
+#include <rtems/score/thread.h>
+
+bool _Record_Thread_create(
+ struct _Thread_Control *executing,
+ struct _Thread_Control *created
+)
+{
+ rtems_record_produce(
+ RTEMS_RECORD_THREAD_CREATE,
+ created->Object.id
+ );
+
+ return true;
+}
+
+void _Record_Thread_start(
+ struct _Thread_Control *executing,
+ struct _Thread_Control *started
+)
+{
+ rtems_record_produce(
+ RTEMS_RECORD_THREAD_START,
+ started->Object.id
+ );
+}
+
+void _Record_Thread_restart(
+ struct _Thread_Control *executing,
+ struct _Thread_Control *restarted
+)
+{
+ rtems_record_produce(
+ RTEMS_RECORD_THREAD_RESTART,
+ restarted->Object.id
+ );
+}
+
+void _Record_Thread_delete(
+ struct _Thread_Control *executing,
+ struct _Thread_Control *deleted
+)
+{
+ rtems_record_produce(
+ RTEMS_RECORD_THREAD_DELETE,
+ deleted->Object.id
+ );
+}
+
+void _Record_Thread_switch(
+ struct _Thread_Control *executing,
+ struct _Thread_Control *heir
+)
+{
+ rtems_record_item items[ 3 ];
+
+ items[ 0 ].event = RTEMS_RECORD_THREAD_SWITCH_OUT;
+ items[ 0 ].data = executing->Object.id;
+ items[ 1 ].event = RTEMS_RECORD_THREAD_STACK_CURRENT;
+ items[ 1 ].data =
+#if defined(__GNUC__)
+ (uintptr_t) __builtin_frame_address( 0 )
+ - (uintptr_t) executing->Start.Initial_stack.area;
+#else
+ 0;
+#endif
+ items[ 2 ].event = RTEMS_RECORD_THREAD_SWITCH_IN;
+ items[ 2 ].data = heir->Object.id;
+ rtems_record_produce_n( items, RTEMS_ARRAY_SIZE( items ) );
+}
+
+void _Record_Thread_begin( struct _Thread_Control *executing )
+{
+ rtems_record_produce(
+ RTEMS_RECORD_THREAD_BEGIN,
+ executing->Object.id
+ );
+}
+
+void _Record_Thread_exitted( struct _Thread_Control *executing )
+{
+ rtems_record_produce(
+ RTEMS_RECORD_THREAD_EXITTED,
+ executing->Object.id
+ );
+}
+
+void _Record_Thread_terminate( struct _Thread_Control *executing )
+{
+ rtems_record_produce(
+ RTEMS_RECORD_THREAD_TERMINATE,
+ executing->Object.id
+ );
+}
diff --git a/cpukit/libtrace/record/record.c b/cpukit/libtrace/record/record.c
new file mode 100644
index 0000000000..33b770badd
--- /dev/null
+++ b/cpukit/libtrace/record/record.c
@@ -0,0 +1,132 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (C) 2018, 2019 embedded brains GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/record.h>
+#include <rtems/config.h>
+#include <rtems/score/assert.h>
+
+#include <string.h>
+
+void rtems_record_produce( rtems_record_event event, rtems_record_data data )
+{
+ rtems_record_context context;
+
+ rtems_record_prepare( &context );
+ rtems_record_add( &context, event, data );
+ rtems_record_commit( &context );
+}
+
+void rtems_record_produce_2(
+ rtems_record_event event_0,
+ rtems_record_data data_0,
+ rtems_record_event event_1,
+ rtems_record_data data_1
+)
+{
+ rtems_record_context context;
+
+ rtems_record_prepare( &context );
+ rtems_record_add( &context, event_0, data_0 );
+ rtems_record_add( &context, event_1, data_1 );
+ rtems_record_commit( &context );
+}
+
+void rtems_record_produce_n(
+ const rtems_record_item *items,
+ size_t n
+)
+{
+ rtems_record_context context;
+
+ _Assert( n > 0 );
+
+ rtems_record_prepare( &context );
+
+ do {
+ rtems_record_add( &context, items->event, items->data );
+ ++items;
+ --n;
+ } while ( n > 0 );
+
+ rtems_record_commit( &context );
+}
+
+void rtems_record_drain( rtems_record_drain_visitor visitor, void *arg )
+{
+ uint32_t cpu_max;
+ uint32_t cpu_index;
+
+ cpu_max = rtems_configuration_get_maximum_processors();
+
+ for ( cpu_index = 0; cpu_index < cpu_max; ++cpu_index ) {
+ Per_CPU_Control *cpu;
+ Record_Control *control;
+ unsigned int tail;
+ unsigned int head;
+
+ cpu = _Per_CPU_Get_by_index( cpu_index );
+ control = cpu->record;
+
+ tail = _Record_Tail( control );
+ head = _Atomic_Load_uint( &control->head, ATOMIC_ORDER_ACQUIRE );
+
+ if ( tail == head ) {
+ continue;
+ }
+
+ control->tail = head;
+
+ control->Header[ 0 ].event = RTEMS_RECORD_PROCESSOR;
+ control->Header[ 0 ].data = cpu_index;
+ control->Header[ 1 ].event = RTEMS_RECORD_TAIL;
+ control->Header[ 1 ].data = tail;
+ control->Header[ 2 ].event = RTEMS_RECORD_HEAD;
+ control->Header[ 2 ].data = head;
+ ( *visitor )( control->Header, RTEMS_ARRAY_SIZE( control->Header ), arg );
+
+ if ( _Record_Is_overflow( control, tail, head ) ) {
+ tail = head + 1;
+ }
+
+ tail = _Record_Index( control, tail );
+ head = _Record_Index( control, head );
+
+ if ( tail < head ) {
+ ( *visitor )( &control->Items[ tail ], head - tail, arg );
+ } else {
+ ( *visitor )( &control->Items[ tail ], control->mask + 1 - tail, arg );
+
+ if ( head > 0 ) {
+ ( *visitor )( &control->Items[ 0 ], head, arg );
+ }
+ }
+ }
+}