<div dir="auto">How does this <a href="http://relate.to">relate.to</a> the existing infrastructure for the capture engine? It seems duplicative.</div><br><div class="gmail_quote"><div dir="ltr">On Wed, Dec 19, 2018, 7:21 AM Sebastian Huber <<a href="mailto:sebastian.huber@embedded-brains.de">sebastian.huber@embedded-brains.de</a> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Add low level event recording infrastructure for system and user<br>
defined events. The infrastructure is able to record high frequency<br>
events such as<br>
<br>
* SMP lock acquire/release,<br>
* interrupt entry/exit,<br>
* thread switches,<br>
* UMA zone allocate/free, and<br>
* Ethernet packet input/output, etc.<br>
<br>
It allows post-mortem analysis in fatal error handlers, e.g. the last<br>
events are in the record buffer, the newest event overwrites the oldest<br>
event. It is possible to detect record buffer overflows for consumers<br>
that expect a continuous stream of events, e.g. to display the system<br>
state in real-time.<br>
<br>
The implementation supports high-end SMP machines (more than 1GHz<br>
processor frequency, more than four processors).<br>
<br>
Add a new API instead. The implementation uses per-processor data<br>
structures and no atomic read-modify-write operations. It is uses<br>
per-processor ring buffers to record the events.<br>
<br>
The CPU counter is used to get the time of events. It is combined with<br>
periodic uptime events to synchronize it with CLOCK_REALTIME.<br>
<br>
The existing capture engine tries to solve this problem also, but its<br>
performance is not good enough for high-end production systems. The<br>
main issues are the variable-size buffers and the use of SMP locks for<br>
synchronization. To fix this, the API would change significantly.<br>
<br>
Update #3665.<br>
---<br>
cpukit/Makefile.am | 6 +<br>
cpukit/<a href="http://headers.am" rel="noreferrer noreferrer" target="_blank">headers.am</a> | 3 +<br>
cpukit/include/rtems/confdefs.h | 31 ++<br>
cpukit/include/rtems/record.h | 333 ++++++++++++++<br>
cpukit/include/rtems/recordclient.h | 137 ++++++<br>
cpukit/include/rtems/recorddata.h | 293 ++++++++++++<br>
cpukit/include/rtems/score/percpu.h | 4 +<br>
cpukit/include/rtems/sysinit.h | 1 +<br>
cpukit/libmisc/record/record-client.c | 429 ++++++++++++++++++<br>
cpukit/libmisc/record/record-server.c | 286 ++++++++++++<br>
cpukit/libmisc/record/record-static.c | 131 ++++++<br>
cpukit/libmisc/record/record-text.c | 173 ++++++++<br>
cpukit/libmisc/record/record-userext.c | 125 ++++++<br>
cpukit/libmisc/record/record.c | 132 ++++++<br>
testsuites/libtests/Makefile.am | 18 +<br>
testsuites/libtests/<a href="http://configure.ac" rel="noreferrer noreferrer" target="_blank">configure.ac</a> | 2 +<br>
testsuites/libtests/record01/init.c | 709 ++++++++++++++++++++++++++++++<br>
testsuites/libtests/record01/record01.doc | 15 +<br>
testsuites/libtests/record01/record01.scn | 7 +<br>
testsuites/libtests/record02/init.c | 132 ++++++<br>
testsuites/libtests/record02/record02.doc | 12 +<br>
testsuites/libtests/record02/record02.scn | 81 ++++<br>
22 files changed, 3060 insertions(+)<br>
create mode 100644 cpukit/include/rtems/record.h<br>
create mode 100644 cpukit/include/rtems/recordclient.h<br>
create mode 100644 cpukit/include/rtems/recorddata.h<br>
create mode 100644 cpukit/libmisc/record/record-client.c<br>
create mode 100644 cpukit/libmisc/record/record-server.c<br>
create mode 100644 cpukit/libmisc/record/record-static.c<br>
create mode 100644 cpukit/libmisc/record/record-text.c<br>
create mode 100644 cpukit/libmisc/record/record-userext.c<br>
create mode 100644 cpukit/libmisc/record/record.c<br>
create mode 100644 testsuites/libtests/record01/init.c<br>
create mode 100644 testsuites/libtests/record01/record01.doc<br>
create mode 100644 testsuites/libtests/record01/record01.scn<br>
create mode 100644 testsuites/libtests/record02/init.c<br>
create mode 100644 testsuites/libtests/record02/record02.doc<br>
create mode 100644 testsuites/libtests/record02/record02.scn<br>
<br>
diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am<br>
index 23f4f40521..6695abd79d 100644<br>
--- a/cpukit/Makefile.am<br>
+++ b/cpukit/Makefile.am<br>
@@ -307,6 +307,12 @@ librtemscpu_a_SOURCES += libmisc/monitor/mon-symbols.c<br>
librtemscpu_a_SOURCES += libmisc/monitor/mon-task.c<br>
librtemscpu_a_SOURCES += libmisc/mouse/mouse_parser.c<br>
librtemscpu_a_SOURCES += libmisc/mouse/serial_mouse.c<br>
+librtemscpu_a_SOURCES += libmisc/record/record.c<br>
+librtemscpu_a_SOURCES += libmisc/record/record-client.c<br>
+librtemscpu_a_SOURCES += libmisc/record/record-server.c<br>
+librtemscpu_a_SOURCES += libmisc/record/record-static.c<br>
+librtemscpu_a_SOURCES += libmisc/record/record-text.c<br>
+librtemscpu_a_SOURCES += libmisc/record/record-userext.c<br>
librtemscpu_a_SOURCES += libmisc/redirector/stdio-redirect.c<br>
librtemscpu_a_SOURCES += libmisc/rtems-fdt/rtems-fdt.c<br>
librtemscpu_a_SOURCES += libmisc/rtems-fdt/rtems-fdt-shell.c<br>
diff --git a/cpukit/<a href="http://headers.am" rel="noreferrer noreferrer" target="_blank">headers.am</a> b/cpukit/<a href="http://headers.am" rel="noreferrer noreferrer" target="_blank">headers.am</a><br>
index 3ab97a95ca..fba976e5b1 100644<br>
--- a/cpukit/<a href="http://headers.am" rel="noreferrer noreferrer" target="_blank">headers.am</a><br>
+++ b/cpukit/<a href="http://headers.am" rel="noreferrer noreferrer" target="_blank">headers.am</a><br>
@@ -136,6 +136,9 @@ include_rtems_HEADERS += include/rtems/qreslib.h<br>
include_rtems_HEADERS += include/rtems/ramdisk.h<br>
include_rtems_HEADERS += include/rtems/rbheap.h<br>
include_rtems_HEADERS += include/rtems/rbtree.h<br>
+include_rtems_HEADERS += include/rtems/record.h<br>
+include_rtems_HEADERS += include/rtems/recordclient.h<br>
+include_rtems_HEADERS += include/rtems/recorddata.h<br>
include_rtems_HEADERS += include/rtems/ringbuf.h<br>
include_rtems_HEADERS += include/rtems/rtc.h<br>
include_rtems_HEADERS += include/rtems/rtems-debugger-remote-tcp.h<br>
diff --git a/cpukit/include/rtems/confdefs.h b/cpukit/include/rtems/confdefs.h<br>
index 45e70313fb..89b47050d6 100644<br>
--- a/cpukit/include/rtems/confdefs.h<br>
+++ b/cpukit/include/rtems/confdefs.h<br>
@@ -2123,6 +2123,10 @@ extern rtems_initialization_tasks_table Initialization_tasks[];<br>
defined(CONFIGURE_STACK_CHECKER_ENABLED) || \<br>
(defined(RTEMS_NEWLIB) && !defined(CONFIGURE_DISABLE_NEWLIB_REENTRANCY))<br>
static const rtems_extensions_table Configuration_Initial_Extensions[] = {<br>
+ #if CONFIGURE_RECORD_PER_PROCESSOR_ITEMS > 0 && \<br>
+ defined(CONFIGURE_RECORD_EXTENSIONS_ENABLED)<br>
+ RECORD_EXTENSION,<br>
+ #endif<br>
#if !defined(CONFIGURE_DISABLE_NEWLIB_REENTRANCY)<br>
RTEMS_NEWLIB_EXTENSION,<br>
#endif<br>
@@ -2965,6 +2969,33 @@ struct _reent *__getreent(void)<br>
_CONFIGURE_MAXIMUM_PROCESSORS,<br>
#endif<br>
};<br>
+<br>
+ #if CONFIGURE_RECORD_PER_PROCESSOR_ITEMS > 0<br>
+ #include <rtems/record.h><br>
+<br>
+ #if (CONFIGURE_RECORD_PER_PROCESSOR_ITEMS & (CONFIGURE_RECORD_PER_PROCESSOR_ITEMS - 1)) != 0<br>
+ #error "CONFIGURE_RECORD_PER_PROCESSOR_ITEMS must be a power of two"<br>
+ #endif<br>
+<br>
+ #if CONFIGURE_RECORD_PER_PROCESSOR_ITEMS < 16<br>
+ #error "CONFIGURE_RECORD_PER_PROCESSOR_ITEMS must be at least 16"<br>
+ #endif<br>
+<br>
+ const unsigned int _Record_Item_count = CONFIGURE_RECORD_PER_PROCESSOR_ITEMS;<br>
+<br>
+ struct Record_Configured_control {<br>
+ Record_Control Control;<br>
+ rtems_record_item Items[ CONFIGURE_RECORD_PER_PROCESSOR_ITEMS ];<br>
+ };<br>
+<br>
+ PER_CPU_DATA_ITEM( Record_Configured_control, _Record_Per_CPU );<br>
+<br>
+ RTEMS_SYSINIT_ITEM(<br>
+ _Record_Initialize,<br>
+ RTEMS_SYSINIT_RECORD,<br>
+ RTEMS_SYSINIT_ORDER_MIDDLE<br>
+ );<br>
+ #endif<br>
#endif<br>
<br>
#if defined(RTEMS_SMP)<br>
diff --git a/cpukit/include/rtems/record.h b/cpukit/include/rtems/record.h<br>
new file mode 100644<br>
index 0000000000..b8f7560fbe<br>
--- /dev/null<br>
+++ b/cpukit/include/rtems/record.h<br>
@@ -0,0 +1,333 @@<br>
+/*<br>
+ * SPDX-License-Identifier: BSD-2-Clause<br>
+ *<br>
+ * Copyright (C) 2018 embedded brains GmbH<br>
+ *<br>
+ * Redistribution and use in source and binary forms, with or without<br>
+ * modification, are permitted provided that the following conditions<br>
+ * are met:<br>
+ * 1. Redistributions of source code must retain the above copyright<br>
+ * notice, this list of conditions and the following disclaimer.<br>
+ * 2. Redistributions in binary form must reproduce the above copyright<br>
+ * notice, this list of conditions and the following disclaimer in the<br>
+ * documentation and/or other materials provided with the distribution.<br>
+ *<br>
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"<br>
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE<br>
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br>
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br>
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br>
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br>
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br>
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br>
+ * POSSIBILITY OF SUCH DAMAGE.<br>
+ */<br>
+<br>
+#ifndef _RTEMS_RECORD_H<br>
+#define _RTEMS_RECORD_H<br>
+<br>
+#include "recorddata.h"<br>
+<br>
+#include <rtems/score/atomic.h><br>
+#include <rtems/score/cpu.h><br>
+#include <rtems/score/percpudata.h><br>
+#include <rtems/score/watchdog.h><br>
+#include <rtems/rtems/intr.h><br>
+#include <rtems/rtems/tasks.h><br>
+#include <rtems/counter.h><br>
+<br>
+#ifdef __cplusplus<br>
+extern "C" {<br>
+#endif /* __cplusplus */<br>
+<br>
+struct Record_Control {<br>
+ Atomic_Uint head;<br>
+ unsigned int tail;<br>
+ unsigned int mask;<br>
+ Watchdog_Control Watchdog;<br>
+ rtems_record_item Header[ 3 ];<br>
+ rtems_record_item Items[ RTEMS_ZERO_LENGTH_ARRAY ];<br>
+};<br>
+<br>
+typedef struct Record_Control Record_Control;<br>
+<br>
+typedef RTEMS_ALIGNED( CPU_CACHE_LINE_BYTES )<br>
+ struct Record_Configured_control Record_Configured_control;<br>
+<br>
+typedef struct {<br>
+ Record_Control *control;<br>
+ unsigned int head;<br>
+ uint32_t now;<br>
+ rtems_interrupt_level level;<br>
+} rtems_record_context;<br>
+<br>
+PER_CPU_DATA_ITEM_DECLARE( Record_Configured_control, _Record_Per_CPU );<br>
+<br>
+extern const unsigned int _Record_Item_count;<br>
+<br>
+void _Record_Initialize( void );<br>
+<br>
+bool _Record_Thread_create(<br>
+ struct _Thread_Control *executing,<br>
+ struct _Thread_Control *created<br>
+);<br>
+<br>
+void _Record_Thread_start(<br>
+ struct _Thread_Control *executing,<br>
+ struct _Thread_Control *started<br>
+);<br>
+<br>
+void _Record_Thread_restart(<br>
+ struct _Thread_Control *executing,<br>
+ struct _Thread_Control *restarted<br>
+);<br>
+<br>
+void _Record_Thread_delete(<br>
+ struct _Thread_Control *executing,<br>
+ struct _Thread_Control *deleted<br>
+);<br>
+<br>
+void _Record_Thread_switch(<br>
+ struct _Thread_Control *executing,<br>
+ struct _Thread_Control *heir<br>
+);<br>
+<br>
+void _Record_Thread_begin( struct _Thread_Control *executing );<br>
+<br>
+void _Record_Thread_exitted( struct _Thread_Control *executing );<br>
+<br>
+void _Record_Thread_terminate(<br>
+ struct _Thread_Control *executing<br>
+);<br>
+<br>
+#define RECORD_EXTENSION \<br>
+ { \<br>
+ _Record_Thread_create, \<br>
+ _Record_Thread_start, \<br>
+ _Record_Thread_restart, \<br>
+ _Record_Thread_delete, \<br>
+ _Record_Thread_switch, \<br>
+ _Record_Thread_begin, \<br>
+ _Record_Thread_exitted, \<br>
+ NULL, \<br>
+ _Record_Thread_terminate \<br>
+ }<br>
+<br>
+RTEMS_INLINE_ROUTINE unsigned int _Record_Index(<br>
+ const Record_Control *control,<br>
+ unsigned int index<br>
+)<br>
+{<br>
+ return index & control->mask;<br>
+}<br>
+<br>
+RTEMS_INLINE_ROUTINE unsigned int _Record_Head( const Record_Control *control )<br>
+{<br>
+ return _Atomic_Load_uint( &control->head, ATOMIC_ORDER_RELAXED );<br>
+}<br>
+<br>
+RTEMS_INLINE_ROUTINE unsigned int _Record_Tail( const Record_Control *control )<br>
+{<br>
+ return control->tail;<br>
+}<br>
+<br>
+RTEMS_INLINE_ROUTINE bool _Record_Is_overflow(<br>
+ const Record_Control *control,<br>
+ unsigned int tail,<br>
+ unsigned int head<br>
+)<br>
+{<br>
+ return head - tail >= control->mask + 1U;<br>
+}<br>
+<br>
+RTEMS_INLINE_ROUTINE unsigned int _Record_Capacity(<br>
+ const Record_Control *control,<br>
+ unsigned int tail,<br>
+ unsigned int head<br>
+)<br>
+{<br>
+ return ( tail - head - 1U ) & control->mask;<br>
+}<br>
+<br>
+RTEMS_INLINE_ROUTINE rtems_counter_ticks _Record_Now( void )<br>
+{<br>
+ return rtems_counter_read();<br>
+}<br>
+<br>
+typedef struct RTEMS_PACKED {<br>
+ uint32_t format;<br>
+ uint32_t magic;<br>
+ rtems_record_item Version;<br>
+ rtems_record_item Count;<br>
+ rtems_record_item Frequency;<br>
+} Record_Stream_header;<br>
+<br>
+void _Record_Stream_header_initialize( Record_Stream_header *header );<br>
+<br>
+/**<br>
+ * @addtogroup RTEMSRecord<br>
+ *<br>
+ * @{<br>
+ */<br>
+<br>
+/**<br>
+ * @brief Prepares to add and commit record items.<br>
+ *<br>
+ * This function disables interrupts.<br>
+ *<br>
+ * @param context The record context which must be used for the following<br>
+ * rtems_record_add() and rtems_record_commit() calls. The record context<br>
+ * may have an arbitrary content at function entry.<br>
+ *<br>
+ * @see rtems_record_produce().<br>
+ */<br>
+RTEMS_INLINE_ROUTINE void rtems_record_prepare( rtems_record_context *context )<br>
+{<br>
+ rtems_interrupt_level level;<br>
+ const Per_CPU_Control *cpu_self;<br>
+ Record_Control *control;<br>
+ unsigned int head;<br>
+<br>
+ rtems_interrupt_local_disable( level );<br>
+ context->now = RTEMS_RECORD_TIME_EVENT( _Record_Now(), 0 );<br>
+ context->level = level;<br>
+ cpu_self = _Per_CPU_Get();<br>
+ control = cpu_self->record;<br>
+ context->control = control;<br>
+ head = _Record_Head( control );<br>
+ context->head = head;<br>
+}<br>
+<br>
+/**<br>
+ * @brief Adds a record item.<br>
+ *<br>
+ * @param context The record context initialized via rtems_record_prepare().<br>
+ * @param event The record event without a time stamp for the item.<br>
+ * @param data The record data for the item.<br>
+ */<br>
+RTEMS_INLINE_ROUTINE void rtems_record_add(<br>
+ rtems_record_context *context,<br>
+ rtems_record_event event,<br>
+ rtems_record_data data<br>
+)<br>
+{<br>
+ Record_Control *control;<br>
+ rtems_record_item *item;<br>
+ unsigned int head;<br>
+<br>
+ control = context->control;<br>
+ head = context->head;<br>
+ item = &control->Items[ _Record_Index( control, head ) ];<br>
+ context->head = head + 1;<br>
+<br>
+ item->event = context->now | event;<br>
+ item->data = data;<br>
+}<br>
+<br>
+/**<br>
+ * @brief Commits a set of record items.<br>
+ *<br>
+ * @param context The record context initialized via rtems_record_prepare().<br>
+ */<br>
+RTEMS_INLINE_ROUTINE void rtems_record_commit( rtems_record_context *context )<br>
+{<br>
+ _Atomic_Store_uint(<br>
+ &context->control->head,<br>
+ context->head,<br>
+ ATOMIC_ORDER_RELEASE<br>
+ );<br>
+ rtems_interrupt_local_enable( context->level );<br>
+}<br>
+<br>
+/**<br>
+ * @brief Produces a record item.<br>
+ *<br>
+ * @param event The record event without a time stamp for the item.<br>
+ * @param data The record data for the item.<br>
+ */<br>
+void rtems_record_produce( rtems_record_event event, rtems_record_data data );<br>
+<br>
+/**<br>
+ * @brief Produces two record items.<br>
+ *<br>
+ * @param event_0 The record event without a time stamp for the first item.<br>
+ * @param data_0 The record data for the first item.<br>
+ * @param event_1 The record event without a time stamp for the second item.<br>
+ * @param data_1 The record data for the second item.<br>
+ */<br>
+void rtems_record_produce_2(<br>
+ rtems_record_event event_0,<br>
+ rtems_record_data data_0,<br>
+ rtems_record_event event_1,<br>
+ rtems_record_data data_1<br>
+);<br>
+<br>
+/**<br>
+ * @brief Produces n record items.<br>
+ *<br>
+ * @param item The record items without a time stamps.<br>
+ * @param n The count of record items.<br>
+ */<br>
+void rtems_record_produce_n(<br>
+ const rtems_record_item *items,<br>
+ size_t n<br>
+);<br>
+<br>
+typedef void ( *rtems_record_drain_visitor )(<br>
+ const rtems_record_item *items,<br>
+ size_t count,<br>
+ void *arg<br>
+);<br>
+<br>
+/**<br>
+ * @brief Drains the record items on all processors.<br>
+ *<br>
+ * Calls the visitor function for each drained item set.<br>
+ *<br>
+ * @param visitor The visitor function.<br>
+ * @param arg The argument for the visitor function.<br>
+ */<br>
+void rtems_record_drain( rtems_record_drain_visitor visitor, void *arg );<br>
+<br>
+/**<br>
+ * @brief Drains the record items on all processors an writes them to the file<br>
+ * descriptor.<br>
+ *<br>
+ * @param fd The file descriptor.<br>
+ * @param written Set to true if items were written to the file descriptor,<br>
+ * otherwise set to false.<br>
+ *<br>
+ * @retval The bytes written to the file descriptor.<br>
+ */<br>
+ssize_t rtems_record_writev( int fd, bool *written );<br>
+<br>
+/**<br>
+ * @brief Runs a record TCP server loop.<br>
+ *<br>
+ * @param port The TCP port to listen in host byte order.<br>
+ * @param period The drain period in clock ticks.<br>
+ */<br>
+void rtems_record_server( uint16_t port, rtems_interval period );<br>
+<br>
+/**<br>
+ * @brief Starts a record TCP server task.<br>
+ *<br>
+ * @param priority The task priority.<br>
+ * @param port The TCP port to listen in host byte order.<br>
+ * @param period The drain period in clock ticks.<br>
+ */<br>
+rtems_status_code rtems_record_start_server(<br>
+ rtems_task_priority priority,<br>
+ uint16_t port,<br>
+ rtems_interval period<br>
+);<br>
+<br>
+/** @} */<br>
+<br>
+#ifdef __cplusplus<br>
+}<br>
+#endif /* __cplusplus */<br>
+<br>
+#endif /* _RTEMS_RECORD_H */<br>
diff --git a/cpukit/include/rtems/recordclient.h b/cpukit/include/rtems/recordclient.h<br>
new file mode 100644<br>
index 0000000000..21c16665a2<br>
--- /dev/null<br>
+++ b/cpukit/include/rtems/recordclient.h<br>
@@ -0,0 +1,137 @@<br>
+/*<br>
+ * SPDX-License-Identifier: BSD-2-Clause<br>
+ *<br>
+ * Copyright (C) 2018 embedded brains GmbH<br>
+ *<br>
+ * Redistribution and use in source and binary forms, with or without<br>
+ * modification, are permitted provided that the following conditions<br>
+ * are met:<br>
+ * 1. Redistributions of source code must retain the above copyright<br>
+ * notice, this list of conditions and the following disclaimer.<br>
+ * 2. Redistributions in binary form must reproduce the above copyright<br>
+ * notice, this list of conditions and the following disclaimer in the<br>
+ * documentation and/or other materials provided with the distribution.<br>
+ *<br>
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"<br>
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE<br>
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br>
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br>
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br>
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br>
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br>
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br>
+ * POSSIBILITY OF SUCH DAMAGE.<br>
+ */<br>
+<br>
+/*<br>
+ * This file must be compatible to general purpose POSIX system, e.g. Linux,<br>
+ * FreeBSD. It may be used for utility programs.<br>
+ */<br>
+<br>
+#ifndef _RTEMS_RECORDCLIENT_H<br>
+#define _RTEMS_RECORDCLIENT_H<br>
+<br>
+#include "recorddata.h"<br>
+<br>
+#include <stddef.h><br>
+<br>
+#ifdef __cplusplus<br>
+extern "C" {<br>
+#endif /* __cplusplus */<br>
+<br>
+/**<br>
+ * @addtogroup RTEMSRecord<br>
+ *<br>
+ * @{<br>
+ */<br>
+<br>
+#define RTEMS_RECORD_CLIENT_MAXIMUM_CPU_COUNT 32<br>
+<br>
+typedef enum {<br>
+ RTEMS_RECORD_CLIENT_SUCCESS,<br>
+ RTEMS_RECORD_CLIENT_ERROR_INVALID_MAGIC,<br>
+ RTEMS_RECORD_CLIENT_ERROR_UNKNOWN_FORMAT,<br>
+ RTEMS_RECORD_CLIENT_ERROR_UNSUPPORTED_VERSION,<br>
+ RTEMS_RECORD_CLIENT_ERROR_UNSUPPORTED_CPU<br>
+} rtems_record_client_status;<br>
+<br>
+typedef rtems_record_client_status ( *rtems_record_client_handler )(<br>
+ uint32_t seconds,<br>
+ uint32_t nanoseconds,<br>
+ uint32_t cpu,<br>
+ rtems_record_event event,<br>
+ uint64_t data,<br>
+ void *arg<br>
+);<br>
+<br>
+typedef struct {<br>
+ struct {<br>
+ uint64_t bt;<br>
+ uint32_t time;<br>
+ } uptime;<br>
+ uint32_t tail[ 2 ];<br>
+ uint32_t head[ 2 ];<br>
+ size_t index;<br>
+} rtems_record_client_per_cpu;<br>
+<br>
+typedef struct rtems_record_client_context {<br>
+ uint64_t to_bt_scaler;<br>
+ rtems_record_client_per_cpu per_cpu[ RTEMS_RECORD_CLIENT_MAXIMUM_CPU_COUNT ];<br>
+ uint64_t data;<br>
+ uint32_t cpu;<br>
+ uint32_t event;<br>
+ uint32_t count;<br>
+ union {<br>
+ rtems_record_item_32 format_32;<br>
+ rtems_record_item_64 format_64;<br>
+ } item;<br>
+ size_t todo;<br>
+ void *pos;<br>
+ rtems_record_client_status ( *consume )(<br>
+ struct rtems_record_client_context *,<br>
+ const void *,<br>
+ size_t<br>
+ );<br>
+ rtems_record_client_handler handler;<br>
+ void *handler_arg;<br>
+ uint32_t header[ 2 ];<br>
+} rtems_record_client_context;<br>
+<br>
+/**<br>
+ * @brief Initializes a record client.<br>
+ *<br>
+ * The record client consumes a record item stream produces by the record<br>
+ * server.<br>
+ *<br>
+ * @param ctx The record client context to initialize.<br>
+ * @param handler The handler is invoked for each received record item.<br>
+ * @param arg The handler argument.<br>
+ */<br>
+void rtems_record_client_init(<br>
+ rtems_record_client_context *ctx,<br>
+ rtems_record_client_handler handler,<br>
+ void *arg<br>
+);<br>
+<br>
+/**<br>
+ * @brief Runs the record client to consume new stream data.<br>
+ *<br>
+ * @param ctx The record client context.<br>
+ * @param buf The buffer with new stream data.<br>
+ * @param n The size of the buffer.<br>
+ */<br>
+rtems_record_client_status rtems_record_client_run(<br>
+ rtems_record_client_context *ctx,<br>
+ const void *buf,<br>
+ size_t n<br>
+);<br>
+<br>
+/** @} */<br>
+<br>
+#ifdef __cplusplus<br>
+}<br>
+#endif /* __cplusplus */<br>
+<br>
+#endif /* _RTEMS_RECORDCLIENT_H */<br>
diff --git a/cpukit/include/rtems/recorddata.h b/cpukit/include/rtems/recorddata.h<br>
new file mode 100644<br>
index 0000000000..e029ece53f<br>
--- /dev/null<br>
+++ b/cpukit/include/rtems/recorddata.h<br>
@@ -0,0 +1,293 @@<br>
+/*<br>
+ * SPDX-License-Identifier: BSD-2-Clause<br>
+ *<br>
+ * Copyright (C) 2018 embedded brains GmbH<br>
+ *<br>
+ * Redistribution and use in source and binary forms, with or without<br>
+ * modification, are permitted provided that the following conditions<br>
+ * are met:<br>
+ * 1. Redistributions of source code must retain the above copyright<br>
+ * notice, this list of conditions and the following disclaimer.<br>
+ * 2. Redistributions in binary form must reproduce the above copyright<br>
+ * notice, this list of conditions and the following disclaimer in the<br>
+ * documentation and/or other materials provided with the distribution.<br>
+ *<br>
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"<br>
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE<br>
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br>
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br>
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br>
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br>
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br>
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br>
+ * POSSIBILITY OF SUCH DAMAGE.<br>
+ */<br>
+<br>
+/*<br>
+ * This file must be compatible to general purpose POSIX system, e.g. Linux,<br>
+ * FreeBSD. It may be used for utility programs.<br>
+ */<br>
+<br>
+#ifndef _RTEMS_RECORDDATA_H<br>
+#define _RTEMS_RECORDDATA_H<br>
+<br>
+#include <stdint.h><br>
+<br>
+#ifdef __cplusplus<br>
+extern "C" {<br>
+#endif /* __cplusplus */<br>
+<br>
+/**<br>
+ * @defgroup RTEMSRecord Event Recording<br>
+ *<br>
+ * @brief Low-level event recording support.<br>
+ *<br>
+ * @{<br>
+ */<br>
+<br>
+/**<br>
+ * @brief The record version.<br>
+ *<br>
+ * The record version reflects the record event definitions. It is reported by<br>
+ * the RTEMS_RECORD_VERSION event.<br>
+ */<br>
+#define RTEMS_RECORD_THE_VERSION 1<br>
+<br>
+/**<br>
+ * @brief The items are in 32-bit little-endian format.<br>
+ */<br>
+#define RTEMS_RECORD_FORMAT_LE_32 0x11111111<br>
+<br>
+/**<br>
+ * @brief The items are in 64-bit little-endian format.<br>
+ */<br>
+#define RTEMS_RECORD_FORMAT_LE_64 0x22222222<br>
+<br>
+/**<br>
+ * @brief The items are in 32-bit big-endian format.<br>
+ */<br>
+#define RTEMS_RECORD_FORMAT_BE_32 0x33333333<br>
+<br>
+/**<br>
+ * @brief The items are in 64-bit big-endian format.<br>
+ */<br>
+#define RTEMS_RECORD_FORMAT_BE_64 0x44444444<br>
+<br>
+/**<br>
+ * @brief Magic number to identify a record item stream.<br>
+ *<br>
+ * This is a random number.<br>
+ */<br>
+#define RTEMS_RECORD_MAGIC 0x82e14ec1<br>
+<br>
+/**<br>
+ * @brief The record events.<br>
+ */<br>
+typedef enum {<br>
+ /* There are 512 events reserved for the system */<br>
+ RTEMS_RECORD_EMPTY,<br>
+ RTEMS_RECORD_VERSION,<br>
+<br>
+ /*<br>
+ * Keep the following system events in lexicographical order, increment<br>
+ * RTEMS_RECORD_THE_VERSION after each change.<br>
+ */<br>
+ RTEMS_RECORD_ACCEPT,<br>
+ RTEMS_RECORD_BIND,<br>
+ RTEMS_RECORD_CHOWN,<br>
+ RTEMS_RECORD_CLOSE,<br>
+ RTEMS_RECORD_CONNECT,<br>
+ RTEMS_RECORD_COUNT,<br>
+ RTEMS_RECORD_FCHMOD,<br>
+ RTEMS_RECORD_FCNTL,<br>
+ RTEMS_RECORD_FDATASYNC,<br>
+ RTEMS_RECORD_FREQUENCY,<br>
+ RTEMS_RECORD_FSTAT,<br>
+ RTEMS_RECORD_FSYNC,<br>
+ RTEMS_RECORD_FTRUNCATE,<br>
+ RTEMS_RECORD_HEAD,<br>
+ RTEMS_RECORD_HEAP_ALLOC,<br>
+ RTEMS_RECORD_HEAP_FREE,<br>
+ RTEMS_RECORD_HEAP_SIZE,<br>
+ RTEMS_RECORD_HEAP_USAGE,<br>
+ RTEMS_RECORD_INTERUPT_BEGIN,<br>
+ RTEMS_RECORD_INTERUPT_END,<br>
+ RTEMS_RECORD_INTERUPT_INSTALL,<br>
+ RTEMS_RECORD_INTERUPT_REMOVE,<br>
+ RTEMS_RECORD_IOCTL,<br>
+ RTEMS_RECORD_KEVENT,<br>
+ RTEMS_RECORD_KQUEUE,<br>
+ RTEMS_RECORD_LINK,<br>
+ RTEMS_RECORD_LSEEK,<br>
+ RTEMS_RECORD_MKNOD,<br>
+ RTEMS_RECORD_MMAP,<br>
+ RTEMS_RECORD_MOUNT,<br>
+ RTEMS_RECORD_OPEN,<br>
+ RTEMS_RECORD_OVERFLOW,<br>
+ RTEMS_RECORD_POLL,<br>
+ RTEMS_RECORD_PROCESSOR,<br>
+ RTEMS_RECORD_READ,<br>
+ RTEMS_RECORD_READLINK,<br>
+ RTEMS_RECORD_READV,<br>
+ RTEMS_RECORD_RECV,<br>
+ RTEMS_RECORD_RECVFROM,<br>
+ RTEMS_RECORD_RECVMSG,<br>
+ RTEMS_RECORD_RENAME,<br>
+ RTEMS_RECORD_RTEMS_BARRIER_CREATE,<br>
+ RTEMS_RECORD_RTEMS_BARRIER_DELETE,<br>
+ RTEMS_RECORD_RTEMS_BARRIER_RELEASE,<br>
+ RTEMS_RECORD_RTEMS_BARRIER_WAIT,<br>
+ RTEMS_RECORD_RTEMS_EVENT_RECEIVE,<br>
+ RTEMS_RECORD_RTEMS_EVENT_SEND,<br>
+ RTEMS_RECORD_RTEMS_EVENT_SYSTEM_RECEIVE,<br>
+ RTEMS_RECORD_RTEMS_EVENT_SYSTEM_SEND,<br>
+ RTEMS_RECORD_RTEMS_MESSAGE_QUEUE_BROADCAST,<br>
+ RTEMS_RECORD_RTEMS_MESSAGE_QUEUE_CREATE,<br>
+ RTEMS_RECORD_RTEMS_MESSAGE_QUEUE_DELETE,<br>
+ RTEMS_RECORD_RTEMS_MESSAGE_QUEUE_FLUSH,<br>
+ RTEMS_RECORD_RTEMS_MESSAGE_QUEUE_RECEIVE,<br>
+ RTEMS_RECORD_RTEMS_MESSAGE_QUEUE_SEND,<br>
+ RTEMS_RECORD_RTEMS_MESSAGE_QUEUE_URGENT,<br>
+ RTEMS_RECORD_RTEMS_PARTITION_CREATE,<br>
+ RTEMS_RECORD_RTEMS_PARTITION_DELETE,<br>
+ RTEMS_RECORD_RTEMS_PARTITION_GET_BUFFER,<br>
+ RTEMS_RECORD_RTEMS_PARTITION_RETURN_BUFFER,<br>
+ RTEMS_RECORD_RTEMS_RATE_MONOTONIC_CANCEL,<br>
+ RTEMS_RECORD_RTEMS_RATE_MONOTONIC_CREATE,<br>
+ RTEMS_RECORD_RTEMS_RATE_MONOTONIC_DELETE,<br>
+ RTEMS_RECORD_RTEMS_RATE_MONOTONIC_PERIOD,<br>
+ RTEMS_RECORD_RTEMS_SEMAPHORE_CREATE,<br>
+ RTEMS_RECORD_RTEMS_SEMAPHORE_DELETE,<br>
+ RTEMS_RECORD_RTEMS_SEMAPHORE_FLUSH,<br>
+ RTEMS_RECORD_RTEMS_SEMAPHORE_OBTAIN,<br>
+ RTEMS_RECORD_RTEMS_SEMAPHORE_RELEASE,<br>
+ RTEMS_RECORD_RTEMS_TIMER_CANCEL,<br>
+ RTEMS_RECORD_RTEMS_TIMER_CREATE,<br>
+ RTEMS_RECORD_RTEMS_TIMER_DELETE,<br>
+ RTEMS_RECORD_RTEMS_TIMER_FIRE_AFTER,<br>
+ RTEMS_RECORD_RTEMS_TIMER_FIRE_WHEN,<br>
+ RTEMS_RECORD_RTEMS_TIMER_RESET,<br>
+ RTEMS_RECORD_RTEMS_TIMER_SERVER_FIRE_AFTER,<br>
+ RTEMS_RECORD_RTEMS_TIMER_SERVER_FIRE_WHEN,<br>
+ RTEMS_RECORD_SELECT,<br>
+ RTEMS_RECORD_SEND,<br>
+ RTEMS_RECORD_SENDMSG,<br>
+ RTEMS_RECORD_SENDTO,<br>
+ RTEMS_RECORD_SOCKET,<br>
+ RTEMS_RECORD_STATVFS,<br>
+ RTEMS_RECORD_SYMLINK,<br>
+ RTEMS_RECORD_TAIL,<br>
+ RTEMS_RECORD_THREAD_BEGIN,<br>
+ RTEMS_RECORD_THREAD_CREATE,<br>
+ RTEMS_RECORD_THREAD_DELETE,<br>
+ RTEMS_RECORD_THREAD_EXIT,<br>
+ RTEMS_RECORD_THREAD_EXITTED,<br>
+ RTEMS_RECORD_THREAD_PRIO_CURRENT_HIGH,<br>
+ RTEMS_RECORD_THREAD_PRIO_CURRENT_LOW,<br>
+ RTEMS_RECORD_THREAD_PRIO_REAL_HIGH,<br>
+ RTEMS_RECORD_THREAD_PRIO_REAL_LOW,<br>
+ RTEMS_RECORD_THREAD_RESTART,<br>
+ RTEMS_RECORD_THREAD_STACK_CURRENT,<br>
+ RTEMS_RECORD_THREAD_STACK_SIZE,<br>
+ RTEMS_RECORD_THREAD_STACK_USAGE,<br>
+ RTEMS_RECORD_THREAD_START,<br>
+ RTEMS_RECORD_THREAD_SWITCH_IN,<br>
+ RTEMS_RECORD_THREAD_SWITCH_OUT,<br>
+ RTEMS_RECORD_THREAD_TERMINATE,<br>
+ RTEMS_RECORD_UMA_ALLOC_PTR,<br>
+ RTEMS_RECORD_UMA_ALLOC_ZONE,<br>
+ RTEMS_RECORD_UMA_FREE_PTR,<br>
+ RTEMS_RECORD_UMA_FREE_ZONE,<br>
+ RTEMS_RECORD_UNLINK,<br>
+ RTEMS_RECORD_UNMOUNT,<br>
+ RTEMS_RECORD_UPTIME_HIGH,<br>
+ RTEMS_RECORD_UPTIME_LOW,<br>
+ RTEMS_RECORD_WORKSPACE_ALLOC,<br>
+ RTEMS_RECORD_WORKSPACE_FREE,<br>
+ RTEMS_RECORD_WORKSPACE_SIZE,<br>
+ RTEMS_RECORD_WORKSPACE_USAGE,<br>
+ RTEMS_RECORD_WRITE,<br>
+ RTEMS_RECORD_WRITEV,<br>
+<br>
+ /* There are 512 events reserved for the user */<br>
+ RTEMS_RECORD_USER = 512,<br>
+<br>
+ RTEMS_RECORD_LAST = 1023<br>
+} rtems_record_event;<br>
+<br>
+/**<br>
+ * @brief Bits in the record item event member reserved for the actual event.<br>
+ */<br>
+#define RTEMS_RECORD_EVENT_BITS 10<br>
+<br>
+/**<br>
+ * @brief Bits in the record item event member reserved for the time of the<br>
+ * event.<br>
+ */<br>
+#define RTEMS_RECORD_TIME_BITS 22<br>
+<br>
+/**<br>
+ * @brief Builds a time event for the specified time stamp and event.<br>
+ *<br>
+ * The events are stored in the record item with a time stamp. There are 22<br>
+ * bits allocated to the time stamp and 10 bits allocated to the event. The 22<br>
+ * bits are enough to get reliable time stamps on a system with a 4GHz CPU<br>
+ * counter and a 1000Hz clock tick.<br>
+ */<br>
+#define RTEMS_RECORD_TIME_EVENT( time, event ) \<br>
+ ( ( ( time ) << RTEMS_RECORD_EVENT_BITS ) | ( event ) )<br>
+<br>
+/**<br>
+ * @brief Gets the time of a time event.<br>
+ */<br>
+#define RTEMS_RECORD_GET_TIME( time_event ) \<br>
+ ( ( time_event ) >> RTEMS_RECORD_EVENT_BITS )<br>
+<br>
+/**<br>
+ * @brief Gets the event of a time event.<br>
+ */<br>
+#define RTEMS_RECORD_GET_EVENT( time_event ) \<br>
+ ( ( time_event ) & ( ( 1U << RTEMS_RECORD_EVENT_BITS ) - 1U ) )<br>
+<br>
+/**<br>
+ * @brief The record data integer type.<br>
+ *<br>
+ * It is big enough to store 32-bit integers and pointers.<br>
+ */<br>
+typedef unsigned long rtems_record_data;<br>
+<br>
+/**<br>
+ * @brief The native record item.<br>
+ */<br>
+typedef struct __attribute__((__packed__)) {<br>
+ uint32_t event;<br>
+ rtems_record_data data;<br>
+} rtems_record_item;<br>
+<br>
+/**<br>
+ * @brief The 32-bit format record item.<br>
+ */<br>
+typedef struct {<br>
+ uint32_t event;<br>
+ uint32_t data;<br>
+} rtems_record_item_32;<br>
+<br>
+/**<br>
+ * @brief The 64-bit format record item.<br>
+ */<br>
+typedef struct __attribute__((__packed__)) {<br>
+ uint32_t event;<br>
+ uint64_t data;<br>
+} rtems_record_item_64;<br>
+<br>
+const char *rtems_record_event_text( rtems_record_event event );<br>
+<br>
+/** @} */<br>
+<br>
+#ifdef __cplusplus<br>
+}<br>
+#endif /* __cplusplus */<br>
+<br>
+#endif /* _RTEMS_RECORDDATA_H */<br>
diff --git a/cpukit/include/rtems/score/percpu.h b/cpukit/include/rtems/score/percpu.h<br>
index 712d1cde36..22c5c30a00 100644<br>
--- a/cpukit/include/rtems/score/percpu.h<br>
+++ b/cpukit/include/rtems/score/percpu.h<br>
@@ -69,6 +69,8 @@ extern "C" {<br>
<br>
#if !defined( ASM )<br>
<br>
+struct Record_Control;<br>
+<br>
struct _Thread_Control;<br>
<br>
struct Scheduler_Context;<br>
@@ -513,6 +515,8 @@ typedef struct Per_CPU_Control {<br>
bool boot;<br>
#endif<br>
<br>
+ struct Record_Control *record;<br>
+<br>
Per_CPU_Stats Stats;<br>
} Per_CPU_Control;<br>
<br>
diff --git a/cpukit/include/rtems/sysinit.h b/cpukit/include/rtems/sysinit.h<br>
index 2c718af8de..60fd9ddf41 100644<br>
--- a/cpukit/include/rtems/sysinit.h<br>
+++ b/cpukit/include/rtems/sysinit.h<br>
@@ -33,6 +33,7 @@ extern "C" {<br>
#define RTEMS_SYSINIT_MP_EARLY 000500<br>
#define RTEMS_SYSINIT_DATA_STRUCTURES 000600<br>
#define RTEMS_SYSINIT_MP 000700<br>
+#define RTEMS_SYSINIT_RECORD 000800<br>
#define RTEMS_SYSINIT_USER_EXTENSIONS 000900<br>
#define RTEMS_SYSINIT_CLASSIC_TASKS 000a00<br>
#define RTEMS_SYSINIT_CLASSIC_TIMER 000b00<br>
diff --git a/cpukit/libmisc/record/record-client.c b/cpukit/libmisc/record/record-client.c<br>
new file mode 100644<br>
index 0000000000..6abda2b4c3<br>
--- /dev/null<br>
+++ b/cpukit/libmisc/record/record-client.c<br>
@@ -0,0 +1,429 @@<br>
+/*<br>
+ * SPDX-License-Identifier: BSD-2-Clause<br>
+ *<br>
+ * Copyright (C) 2018 embedded brains GmbH<br>
+ *<br>
+ * Redistribution and use in source and binary forms, with or without<br>
+ * modification, are permitted provided that the following conditions<br>
+ * are met:<br>
+ * 1. Redistributions of source code must retain the above copyright<br>
+ * notice, this list of conditions and the following disclaimer.<br>
+ * 2. Redistributions in binary form must reproduce the above copyright<br>
+ * notice, this list of conditions and the following disclaimer in the<br>
+ * documentation and/or other materials provided with the distribution.<br>
+ *<br>
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"<br>
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE<br>
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br>
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br>
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br>
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br>
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br>
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br>
+ * POSSIBILITY OF SUCH DAMAGE.<br>
+ */<br>
+<br>
+/*<br>
+ * This file must be compatible to general purpose POSIX system, e.g. Linux,<br>
+ * FreeBSD. It may be used for utility programs.<br>
+ */<br>
+<br>
+#if HAVE_CONFIG_H<br>
+#include "config.h"<br>
+#endif<br>
+<br>
+#include <rtems/recordclient.h><br>
+<br>
+#include <string.h><br>
+<br>
+static void set_to_bt_scaler(<br>
+ rtems_record_client_context *ctx,<br>
+ uint32_t frequency<br>
+)<br>
+{<br>
+ uint64_t bin_per_s;<br>
+<br>
+ bin_per_s = UINT64_C( 1 ) << 32;<br>
+ ctx->to_bt_scaler = ( ( bin_per_s << 31 ) + frequency - 1 ) / frequency;<br>
+}<br>
+<br>
+static void check_overflow(<br>
+ const rtems_record_client_context *ctx,<br>
+ const rtems_record_client_per_cpu *per_cpu,<br>
+ uint32_t new_head<br>
+)<br>
+{<br>
+ uint32_t last_tail;<br>
+ uint32_t last_head;<br>
+ uint32_t capacity;<br>
+ uint32_t new_content;<br>
+<br>
+ last_tail = per_cpu->tail[ per_cpu->index ];<br>
+ last_head = per_cpu->head[ per_cpu->index ];<br>
+<br>
+ if ( last_tail == last_head ) {<br>
+ return;<br>
+ }<br>
+<br>
+ capacity = ( last_tail - last_head - 1 ) & ( ctx->count - 1 );<br>
+ new_content = new_head - last_head;<br>
+<br>
+ if ( new_content <= capacity ) {<br>
+ return;<br>
+ }<br>
+<br>
+ ( *ctx->handler )(<br>
+ 0,<br>
+ 0,<br>
+ ctx->cpu,<br>
+ RTEMS_RECORD_OVERFLOW,<br>
+ new_content - capacity,<br>
+ ctx->handler_arg<br>
+ );<br>
+}<br>
+<br>
+static rtems_record_client_status visit( rtems_record_client_context *ctx )<br>
+{<br>
+ rtems_record_client_per_cpu *per_cpu;<br>
+ uint32_t time;<br>
+ rtems_record_event event;<br>
+ uint64_t data;<br>
+ uint64_t bt;<br>
+ uint32_t seconds;<br>
+ uint32_t nanosec;<br>
+<br>
+ per_cpu = &ctx->per_cpu[ ctx->cpu ];<br>
+ time = RTEMS_RECORD_GET_TIME( ctx->event );<br>
+ event = RTEMS_RECORD_GET_EVENT( ctx->event );<br>
+ data = ctx->data;<br>
+<br>
+ switch ( event ) {<br>
+ case RTEMS_RECORD_PROCESSOR:<br>
+ if ( data >= RTEMS_RECORD_CLIENT_MAXIMUM_CPU_COUNT ) {<br>
+ return RTEMS_RECORD_CLIENT_ERROR_UNSUPPORTED_CPU;<br>
+ }<br>
+<br>
+ ctx->cpu = (uint32_t) data;<br>
+ per_cpu = &ctx->per_cpu[ ctx->cpu ];<br>
+ break;<br>
+ case RTEMS_RECORD_UPTIME_LOW:<br>
+ per_cpu-><a href="http://uptime.bt" rel="noreferrer noreferrer" target="_blank">uptime.bt</a> = (uint32_t) data;<br>
+ per_cpu->uptime.time = time;<br>
+ time = 0;<br>
+ break;<br>
+ case RTEMS_RECORD_UPTIME_HIGH:<br>
+ per_cpu-><a href="http://uptime.bt" rel="noreferrer noreferrer" target="_blank">uptime.bt</a> += (int64_t) data << 32;<br>
+ time = 0;<br>
+ break;<br>
+ case RTEMS_RECORD_TAIL:<br>
+ per_cpu->tail[ per_cpu->index ] = (uint32_t) data;<br>
+ break;<br>
+ case RTEMS_RECORD_HEAD:<br>
+ per_cpu->head[ per_cpu->index ]= (uint32_t) data;<br>
+ per_cpu->index ^= 1;<br>
+ check_overflow( ctx, per_cpu, (uint32_t) data );<br>
+ break;<br>
+ case RTEMS_RECORD_COUNT:<br>
+ ctx->count = (uint32_t) data;<br>
+ break;<br>
+ case RTEMS_RECORD_FREQUENCY:<br>
+ set_to_bt_scaler( ctx, (uint32_t) data );<br>
+ break;<br>
+ case RTEMS_RECORD_VERSION:<br>
+ if ( data != RTEMS_RECORD_THE_VERSION ) {<br>
+ return RTEMS_RECORD_CLIENT_ERROR_UNSUPPORTED_VERSION;<br>
+ }<br>
+<br>
+ break;<br>
+ default:<br>
+ break;<br>
+ }<br>
+<br>
+ if ( time != 0 ) {<br>
+ time = ( time - per_cpu->uptime.time )<br>
+ & ( ( UINT32_C( 1 ) << RTEMS_RECORD_TIME_BITS ) - 1 );<br>
+ bt = ( time * ctx->to_bt_scaler ) >> 31;<br>
+ bt += per_cpu-><a href="http://uptime.bt" rel="noreferrer noreferrer" target="_blank">uptime.bt</a>;<br>
+ } else {<br>
+ bt = 0;<br>
+ }<br>
+<br>
+ seconds = (uint32_t) ( bt >> 32 );<br>
+ nanosec = (uint32_t) ( ( UINT64_C( 1000000000 ) * (uint32_t) bt ) >> 32 );<br>
+<br>
+ return ( *ctx->handler )(<br>
+ seconds,<br>
+ nanosec,<br>
+ ctx->cpu,<br>
+ event,<br>
+ data,<br>
+ ctx->handler_arg<br>
+ );<br>
+}<br>
+<br>
+static rtems_record_client_status consume_32(<br>
+ rtems_record_client_context *ctx,<br>
+ const void *buf,<br>
+ size_t n<br>
+)<br>
+{<br>
+ while ( n > 0 ) {<br>
+ size_t m;<br>
+ char *pos;<br>
+<br>
+ m = ctx->todo < n ? ctx->todo : n;<br>
+ pos = ctx->pos;<br>
+ pos = memcpy( pos, buf, m );<br>
+ n -= m;<br>
+ buf = (char *) buf + m;<br>
+<br>
+ if ( m == ctx->todo ) {<br>
+ rtems_record_client_status status;<br>
+<br>
+ ctx->todo = sizeof( ctx->item.format_32 );<br>
+ ctx->pos = &ctx->item.format_32;<br>
+ ctx->event = ctx->item.format_32.event;<br>
+ ctx->data = ctx->item.format_32.data;<br>
+<br>
+ status = visit( ctx );<br>
+<br>
+ if ( status != RTEMS_RECORD_CLIENT_SUCCESS ) {<br>
+ return status;<br>
+ }<br>
+ } else {<br>
+ ctx->todo -= m;<br>
+ ctx->pos = pos + m;<br>
+ }<br>
+ }<br>
+<br>
+ return RTEMS_RECORD_CLIENT_SUCCESS;<br>
+}<br>
+<br>
+static rtems_record_client_status consume_64(<br>
+ rtems_record_client_context *ctx,<br>
+ const void *buf,<br>
+ size_t n<br>
+)<br>
+{<br>
+ while ( n > 0 ) {<br>
+ size_t m;<br>
+ char *pos;<br>
+<br>
+ m = ctx->todo < n ? ctx->todo : n;<br>
+ pos = ctx->pos;<br>
+ pos = memcpy( pos, buf, m );<br>
+ n -= m;<br>
+ buf = (char *) buf + m;<br>
+<br>
+ if ( m == ctx->todo ) {<br>
+ rtems_record_client_status status;<br>
+<br>
+ ctx->todo = sizeof( ctx->item.format_64 );<br>
+ ctx->pos = &ctx->item.format_64;<br>
+ ctx->event = ctx->item.format_64.event;<br>
+ ctx->data = ctx->item.format_64.data;<br>
+<br>
+ status = visit( ctx );<br>
+<br>
+ if ( status != RTEMS_RECORD_CLIENT_SUCCESS ) {<br>
+ return status;<br>
+ }<br>
+ } else {<br>
+ ctx->todo -= m;<br>
+ ctx->pos = pos + m;<br>
+ }<br>
+ }<br>
+<br>
+ return RTEMS_RECORD_CLIENT_SUCCESS;<br>
+}<br>
+<br>
+static rtems_record_client_status consume_swap_32(<br>
+ rtems_record_client_context *ctx,<br>
+ const void *buf,<br>
+ size_t n<br>
+)<br>
+{<br>
+ while ( n > 0 ) {<br>
+ size_t m;<br>
+ char *pos;<br>
+<br>
+ m = ctx->todo < n ? ctx->todo : n;<br>
+ pos = ctx->pos;<br>
+ pos = memcpy( pos, buf, m );<br>
+ n -= m;<br>
+ buf = (char *) buf + m;<br>
+<br>
+ if ( m == ctx->todo ) {<br>
+ rtems_record_client_status status;<br>
+<br>
+ ctx->todo = sizeof( ctx->item.format_32 );<br>
+ ctx->pos = &ctx->item.format_32;<br>
+ ctx->event = __builtin_bswap32( ctx->item.format_32.event );<br>
+ ctx->data = __builtin_bswap32( ctx->item.format_32.data );<br>
+<br>
+ status = visit( ctx );<br>
+<br>
+ if ( status != RTEMS_RECORD_CLIENT_SUCCESS ) {<br>
+ return status;<br>
+ }<br>
+ } else {<br>
+ ctx->todo -= m;<br>
+ ctx->pos = pos + m;<br>
+ }<br>
+ }<br>
+<br>
+ return RTEMS_RECORD_CLIENT_SUCCESS;<br>
+}<br>
+<br>
+static rtems_record_client_status consume_swap_64(<br>
+ rtems_record_client_context *ctx,<br>
+ const void *buf,<br>
+ size_t n<br>
+)<br>
+{<br>
+ while ( n > 0 ) {<br>
+ size_t m;<br>
+ char *pos;<br>
+<br>
+ m = ctx->todo < n ? ctx->todo : n;<br>
+ pos = ctx->pos;<br>
+ pos = memcpy( pos, buf, m );<br>
+ n -= m;<br>
+ buf = (char *) buf + m;<br>
+<br>
+ if ( m == ctx->todo ) {<br>
+ rtems_record_client_status status;<br>
+<br>
+ ctx->todo = sizeof( ctx->item.format_64 );<br>
+ ctx->pos = &ctx->item.format_64;<br>
+ ctx->event = __builtin_bswap32( ctx->item.format_64.event );<br>
+ ctx->data = __builtin_bswap64( ctx->item.format_64.data );<br>
+<br>
+ status = visit( ctx );<br>
+<br>
+ if ( status != RTEMS_RECORD_CLIENT_SUCCESS ) {<br>
+ return status;<br>
+ }<br>
+ } else {<br>
+ ctx->todo -= m;<br>
+ ctx->pos = pos + m;<br>
+ }<br>
+ }<br>
+<br>
+ return RTEMS_RECORD_CLIENT_SUCCESS;<br>
+}<br>
+<br>
+static rtems_record_client_status consume_init(<br>
+ rtems_record_client_context *ctx,<br>
+ const void *buf,<br>
+ size_t n<br>
+)<br>
+{<br>
+ while ( n > 0 ) {<br>
+ size_t m;<br>
+ char *pos;<br>
+<br>
+ m = ctx->todo < n ? ctx->todo : n;<br>
+ pos = ctx->pos;<br>
+ pos = memcpy( pos, buf, m );<br>
+ n -= m;<br>
+ buf = (char *) buf + m;<br>
+<br>
+ if ( m == ctx->todo ) {<br>
+ uint32_t magic;<br>
+<br>
+ magic = ctx->header[ 1 ];<br>
+<br>
+ switch ( ctx->header[ 0 ] ) {<br>
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__<br>
+ case RTEMS_RECORD_FORMAT_LE_32:<br>
+ ctx->todo = sizeof( ctx->item.format_32 );<br>
+ ctx->pos = &ctx->item.format_32;<br>
+ ctx->consume = consume_32;<br>
+ break;<br>
+ case RTEMS_RECORD_FORMAT_LE_64:<br>
+ ctx->todo = sizeof( ctx->item.format_64 );<br>
+ ctx->pos = &ctx->item.format_64;<br>
+ ctx->consume = consume_64;<br>
+ break;<br>
+ case RTEMS_RECORD_FORMAT_BE_32:<br>
+ ctx->todo = sizeof( ctx->item.format_32 );<br>
+ ctx->pos = &ctx->item.format_32;<br>
+ ctx->consume = consume_swap_32;<br>
+ magic = __builtin_bswap32( magic );<br>
+ break;<br>
+ case RTEMS_RECORD_FORMAT_BE_64:<br>
+ ctx->todo = sizeof( ctx->item.format_64 );<br>
+ ctx->pos = &ctx->item.format_64;<br>
+ ctx->consume = consume_swap_64;<br>
+ magic = __builtin_bswap32( magic );<br>
+ break;<br>
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__<br>
+ case RTEMS_RECORD_FORMAT_LE_32:<br>
+ ctx->todo = sizeof( ctx->item.format_32 );<br>
+ ctx->pos = &ctx->item.format_32;<br>
+ ctx->consume = consume_swap_32;<br>
+ magic = __builtin_bswap32( magic );<br>
+ break;<br>
+ case RTEMS_RECORD_FORMAT_LE_64:<br>
+ ctx->todo = sizeof( ctx->item.format_64 );<br>
+ ctx->pos = &ctx->item.format_64;<br>
+ ctx->consume = consume_swap_64;<br>
+ magic = __builtin_bswap32( magic );<br>
+ break;<br>
+ case RTEMS_RECORD_FORMAT_BE_32:<br>
+ ctx->todo = sizeof( ctx->item.format_32 );<br>
+ ctx->pos = &ctx->item.format_32;<br>
+ ctx->consume = consume_32;<br>
+ break;<br>
+ case RTEMS_RECORD_FORMAT_BE_64:<br>
+ ctx->todo = sizeof( ctx->item.format_64 );<br>
+ ctx->pos = &ctx->item.format_64;<br>
+ ctx->consume = consume_64;<br>
+ break;<br>
+#else<br>
+#error "unexpected __BYTE_ORDER__"<br>
+#endif<br>
+ default:<br>
+ return RTEMS_RECORD_CLIENT_ERROR_UNKNOWN_FORMAT;<br>
+ }<br>
+<br>
+ if ( magic != RTEMS_RECORD_MAGIC ) {<br>
+ return RTEMS_RECORD_CLIENT_ERROR_INVALID_MAGIC;<br>
+ }<br>
+<br>
+ return rtems_record_client_run( ctx, buf, n );<br>
+ } else {<br>
+ ctx->todo -= m;<br>
+ ctx->pos = pos + m;<br>
+ }<br>
+ }<br>
+<br>
+ return RTEMS_RECORD_CLIENT_SUCCESS;<br>
+}<br>
+<br>
+void rtems_record_client_init(<br>
+ rtems_record_client_context *ctx,<br>
+ rtems_record_client_handler handler,<br>
+ void *arg<br>
+)<br>
+{<br>
+ ctx = memset( ctx, 0, sizeof( *ctx ) );<br>
+ ctx->to_bt_scaler = UINT64_C( 1 ) << 31;<br>
+ ctx->handler = handler;<br>
+ ctx->handler_arg = arg;<br>
+ ctx->todo = sizeof( ctx->header );<br>
+ ctx->pos = &ctx->header;<br>
+ ctx->consume = consume_init;<br>
+}<br>
+<br>
+rtems_record_client_status rtems_record_client_run(<br>
+ rtems_record_client_context *ctx,<br>
+ const void *buf,<br>
+ size_t n<br>
+)<br>
+{<br>
+ return ( *ctx->consume )( ctx, buf, n );<br>
+}<br>
diff --git a/cpukit/libmisc/record/record-server.c b/cpukit/libmisc/record/record-server.c<br>
new file mode 100644<br>
index 0000000000..7a1959cefc<br>
--- /dev/null<br>
+++ b/cpukit/libmisc/record/record-server.c<br>
@@ -0,0 +1,286 @@<br>
+/*<br>
+ * SPDX-License-Identifier: BSD-2-Clause<br>
+ *<br>
+ * Copyright (C) 2018 embedded brains GmbH<br>
+ *<br>
+ * Redistribution and use in source and binary forms, with or without<br>
+ * modification, are permitted provided that the following conditions<br>
+ * are met:<br>
+ * 1. Redistributions of source code must retain the above copyright<br>
+ * notice, this list of conditions and the following disclaimer.<br>
+ * 2. Redistributions in binary form must reproduce the above copyright<br>
+ * notice, this list of conditions and the following disclaimer in the<br>
+ * documentation and/or other materials provided with the distribution.<br>
+ *<br>
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"<br>
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE<br>
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br>
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br>
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br>
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br>
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br>
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br>
+ * POSSIBILITY OF SUCH DAMAGE.<br>
+ */<br>
+<br>
+#if HAVE_CONFIG_H<br>
+#include "config.h"<br>
+#endif<br>
+<br>
+#include <rtems/record.h><br>
+<br>
+#include <rtems.h><br>
+<br>
+#include <sys/endian.h><br>
+#include <sys/socket.h><br>
+#include <sys/uio.h><br>
+<br>
+#include <string.h><br>
+#include <unistd.h><br>
+<br>
+#include <netinet/in.h><br>
+<br>
+#ifdef RTEMS_SMP<br>
+#define CHUNKS (3 * CPU_MAXIMUM_PROCESSORS)<br>
+#else<br>
+#define CHUNKS 4<br>
+#endif<br>
+<br>
+typedef struct {<br>
+ int available;<br>
+ struct iovec *current;<br>
+ struct iovec iov[CHUNKS];<br>
+} writev_visitor_context;<br>
+<br>
+static void writev_visitor(<br>
+ const rtems_record_item *items,<br>
+ size_t count,<br>
+ void *arg<br>
+)<br>
+{<br>
+ writev_visitor_context *ctx;<br>
+<br>
+ ctx = arg;<br>
+<br>
+ if ( ctx->available > 0 ) {<br>
+ ctx->current->iov_base = RTEMS_DECONST( rtems_record_item *, items );<br>
+ ctx->current->iov_len = count * sizeof( *items );<br>
+ --ctx->available;<br>
+ ++ctx->current;<br>
+ }<br>
+}<br>
+<br>
+ssize_t rtems_record_writev( int fd, bool *written )<br>
+{<br>
+ writev_visitor_context ctx;<br>
+ int n;<br>
+<br>
+ ctx.available = CHUNKS;<br>
+ ctx.current = &ctx.iov[ 0 ];<br>
+ rtems_record_drain( writev_visitor, &ctx );<br>
+ n = CHUNKS - ctx.available;<br>
+<br>
+ if ( n > 0 ) {<br>
+ *written = true;<br>
+ return writev( fd, &ctx.iov[ 0 ], n );<br>
+ } else {<br>
+ *written = false;<br>
+ return 0;<br>
+ }<br>
+}<br>
+<br>
+#define WAKEUP_EVENT RTEMS_EVENT_0<br>
+<br>
+static void wakeup( rtems_id task )<br>
+{<br>
+ (void) rtems_event_send( task, WAKEUP_EVENT );<br>
+}<br>
+<br>
+static void wait( rtems_option options )<br>
+{<br>
+ rtems_event_set events;<br>
+<br>
+ (void) rtems_event_receive(<br>
+ WAKEUP_EVENT,<br>
+ RTEMS_EVENT_ANY | options,<br>
+ RTEMS_NO_TIMEOUT,<br>
+ &events<br>
+ );<br>
+}<br>
+<br>
+static void wakeup_timer( rtems_id timer, void *arg )<br>
+{<br>
+ rtems_id *server;<br>
+<br>
+ server = arg;<br>
+ wakeup( *server );<br>
+ (void) rtems_timer_reset( timer );<br>
+}<br>
+<br>
+void _Record_Stream_header_initialize( Record_Stream_header *header )<br>
+{<br>
+#if BYTE_ORDER == LITTLE_ENDIAN<br>
+#if __INTPTR_WIDTH__ == 32<br>
+ header->format = RTEMS_RECORD_FORMAT_LE_32,<br>
+#elif __INTPTR_WIDTH__ == 64<br>
+ header->format = RTEMS_RECORD_FORMAT_LE_64,<br>
+#error "unexpected __INTPTR_WIDTH__"<br>
+#endif<br>
+#elif BYTE_ORDER == BIG_ENDIAN<br>
+#if __INTPTR_WIDTH__ == 32<br>
+ header->format = RTEMS_RECORD_FORMAT_BE_32,<br>
+#elif __INTPTR_WIDTH__ == 64<br>
+ header->format = RTEMS_RECORD_FORMAT_BE_64,<br>
+#else<br>
+#error "unexpected __INTPTR_WIDTH__"<br>
+#endif<br>
+#else<br>
+#error "unexpected BYTE_ORDER"<br>
+#endif<br>
+<br>
+ header->magic = RTEMS_RECORD_MAGIC;<br>
+<br>
+ header->Version.event = RTEMS_RECORD_TIME_EVENT( 0, RTEMS_RECORD_VERSION );<br>
+ header->Version.data = RTEMS_RECORD_THE_VERSION;<br>
+<br>
+ header->Count.event = RTEMS_RECORD_TIME_EVENT( 0, RTEMS_RECORD_COUNT );<br>
+ header->Count.data = _Record_Item_count;<br>
+<br>
+ header->Frequency.event =<br>
+ RTEMS_RECORD_TIME_EVENT( 0, RTEMS_RECORD_FREQUENCY );<br>
+ header->Frequency.data = rtems_counter_frequency();<br>
+}<br>
+<br>
+static void send_header( int fd )<br>
+{<br>
+ Record_Stream_header header;<br>
+<br>
+ _Record_Stream_header_initialize( &header );<br>
+ (void) write( fd, &header, sizeof( header ) );<br>
+}<br>
+<br>
+void rtems_record_server( uint16_t port, rtems_interval period )<br>
+{<br>
+ rtems_status_code sc;<br>
+ rtems_id self;<br>
+ rtems_id timer;<br>
+ struct sockaddr_in addr;<br>
+ int sd;<br>
+ int rv;<br>
+<br>
+ sd = -1;<br>
+ self = rtems_task_self();<br>
+<br>
+ sc = rtems_timer_create( rtems_build_name( 'R', 'C', 'R', 'D' ), &timer );<br>
+ if ( sc != RTEMS_SUCCESSFUL ) {<br>
+ return;<br>
+ }<br>
+<br>
+ sd = socket( PF_INET, SOCK_STREAM, 0 );<br>
+ if (sd < 0) {<br>
+ goto error;<br>
+ }<br>
+<br>
+ memset( &addr, 0, sizeof( addr ) );<br>
+ addr.sin_family = AF_INET;<br>
+ addr.sin_port = htons( port );<br>
+ addr.sin_addr.s_addr = htonl( INADDR_ANY );<br>
+<br>
+ rv = bind( sd, (const struct sockaddr *) &addr, sizeof( addr ) );<br>
+ if (rv != 0) {<br>
+ goto error;<br>
+ }<br>
+<br>
+ rv = listen( sd, 0 );<br>
+ if (rv != 0) {<br>
+ goto error;<br>
+ }<br>
+<br>
+ while ( true ) {<br>
+ int cd;<br>
+ bool written;<br>
+ ssize_t n;<br>
+<br>
+ cd = accept( sd, NULL, NULL );<br>
+<br>
+ if ( cd < 0 ) {<br>
+ break;<br>
+ }<br>
+<br>
+ wait( RTEMS_NO_WAIT );<br>
+ (void) rtems_timer_fire_after( timer, period, wakeup_timer, &self );<br>
+ send_header( cd );<br>
+<br>
+ while ( true ) {<br>
+ n = rtems_record_writev( cd, &written );<br>
+<br>
+ if ( written && n <= 0 ) {<br>
+ break;<br>
+ }<br>
+<br>
+ wait( RTEMS_WAIT );<br>
+ }<br>
+<br>
+ (void) rtems_timer_cancel( timer );<br>
+ (void) close( cd );<br>
+ }<br>
+<br>
+error:<br>
+<br>
+ (void) close( sd );<br>
+ (void) rtems_timer_delete( timer );<br>
+}<br>
+<br>
+typedef struct {<br>
+ rtems_id task;<br>
+ uint16_t port;<br>
+ rtems_interval period;<br>
+} server_arg;<br>
+<br>
+static void server( rtems_task_argument arg )<br>
+{<br>
+ server_arg *sarg;<br>
+ uint16_t port;<br>
+ rtems_interval period;<br>
+<br>
+ sarg = (server_arg *) arg;<br>
+ port = sarg->port;<br>
+ period = sarg->period;<br>
+ wakeup(sarg->task);<br>
+ rtems_record_server( port, period );<br>
+ rtems_task_exit();<br>
+}<br>
+<br>
+rtems_status_code rtems_record_start_server(<br>
+ rtems_task_priority priority,<br>
+ uint16_t port,<br>
+ rtems_interval period<br>
+)<br>
+{<br>
+ rtems_status_code sc;<br>
+ rtems_id id;<br>
+ server_arg sarg;<br>
+<br>
+ sarg.port = port;<br>
+ sarg.period = period;<br>
+ sarg.task = rtems_task_self();<br>
+<br>
+ sc = rtems_task_create(<br>
+ rtems_build_name( 'R', 'C', 'R', 'D' ),<br>
+ priority,<br>
+ RTEMS_MINIMUM_STACK_SIZE,<br>
+ RTEMS_DEFAULT_MODES,<br>
+ RTEMS_DEFAULT_ATTRIBUTES,<br>
+ &id<br>
+ );<br>
+ if ( sc != RTEMS_SUCCESSFUL ) {<br>
+ return sc;<br>
+ }<br>
+<br>
+ (void) rtems_task_start( id, server, (rtems_task_argument) &sarg );<br>
+ wait( RTEMS_WAIT );<br>
+<br>
+ return RTEMS_SUCCESSFUL;<br>
+}<br>
diff --git a/cpukit/libmisc/record/record-static.c b/cpukit/libmisc/record/record-static.c<br>
new file mode 100644<br>
index 0000000000..b96ae6d0b1<br>
--- /dev/null<br>
+++ b/cpukit/libmisc/record/record-static.c<br>
@@ -0,0 +1,131 @@<br>
+/*<br>
+ * SPDX-License-Identifier: BSD-2-Clause<br>
+ *<br>
+ * Copyright (C) 2018 embedded brains GmbH<br>
+ *<br>
+ * Redistribution and use in source and binary forms, with or without<br>
+ * modification, are permitted provided that the following conditions<br>
+ * are met:<br>
+ * 1. Redistributions of source code must retain the above copyright<br>
+ * notice, this list of conditions and the following disclaimer.<br>
+ * 2. Redistributions in binary form must reproduce the above copyright<br>
+ * notice, this list of conditions and the following disclaimer in the<br>
+ * documentation and/or other materials provided with the distribution.<br>
+ *<br>
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"<br>
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE<br>
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br>
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br>
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br>
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br>
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br>
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br>
+ * POSSIBILITY OF SUCH DAMAGE.<br>
+ */<br>
+<br>
+#if HAVE_CONFIG_H<br>
+#include "config.h"<br>
+#endif<br>
+<br>
+#include <rtems/record.h><br>
+#include <rtems/config.h><br>
+#include <rtems/sysinit.h><br>
+#include <rtems/score/timecounter.h><br>
+#include <rtems/score/watchdogimpl.h><br>
+<br>
+static Watchdog_Interval _Record_Tick_interval;<br>
+<br>
+void _Record_Initialize( void )<br>
+{<br>
+ uint32_t cpu_max;<br>
+ uint32_t cpu_index;<br>
+ uintptr_t offset;<br>
+<br>
+ cpu_max = rtems_configuration_get_maximum_processors();<br>
+ offset = PER_CPU_DATA_OFFSET( _Record_Per_CPU );<br>
+<br>
+ for ( cpu_index = 0; cpu_index < cpu_max; ++cpu_index ) {<br>
+ Per_CPU_Control *cpu;<br>
+ Record_Control *control;<br>
+<br>
+ cpu = _Per_CPU_Get_by_index( cpu_index );<br>
+ control = PER_CPU_DATA_GET_BY_OFFSET( cpu, Record_Control, offset );<br>
+ control->mask = _Record_Item_count - 1U;<br>
+ cpu->record = control;<br>
+ }<br>
+}<br>
+<br>
+static void _Record_Watchdog(<br>
+ Watchdog_Control *watchdog,<br>
+ Per_CPU_Control *cpu<br>
+)<br>
+{<br>
+ ISR_Level level;<br>
+ sbintime_t now;<br>
+<br>
+ _ISR_Local_disable( level );<br>
+ _Watchdog_Per_CPU_reinsert_ticks(<br>
+ watchdog,<br>
+ cpu,<br>
+ _Record_Tick_interval<br>
+ );<br>
+ _ISR_Local_enable( level );<br>
+<br>
+ now = _Timecounter_Sbinuptime();<br>
+ rtems_record_produce_2(<br>
+ RTEMS_RECORD_UPTIME_LOW,<br>
+ (uint32_t) ( now >> 0 ),<br>
+ RTEMS_RECORD_UPTIME_HIGH,<br>
+ (uint32_t) ( now >> 32 )<br>
+ );<br>
+}<br>
+<br>
+static void _Record_Initialize_watchdogs( void )<br>
+{<br>
+ Watchdog_Interval interval;<br>
+ uint32_t cpu_max;<br>
+ uint32_t cpu_index;<br>
+ sbintime_t now;<br>
+<br>
+ interval = rtems_counter_frequency() / _Watchdog_Ticks_per_second;<br>
+ interval = ( UINT32_C( 1 ) << 22 ) / interval;<br>
+<br>
+ if ( interval == 0 ) {<br>
+ interval = 1;<br>
+ }<br>
+<br>
+ _Record_Tick_interval = interval;<br>
+<br>
+ cpu_max = rtems_configuration_get_maximum_processors();<br>
+<br>
+ for ( cpu_index = 0; cpu_index < cpu_max; ++cpu_index ) {<br>
+ Per_CPU_Control *cpu;<br>
+ Record_Control *control;<br>
+<br>
+ cpu = _Per_CPU_Get_by_index( cpu_index );<br>
+ control = cpu->record;<br>
+ _Watchdog_Preinitialize( &control->Watchdog, cpu );<br>
+ _Watchdog_Initialize( &control->Watchdog, _Record_Watchdog );<br>
+ _Watchdog_Per_CPU_reinsert_ticks(<br>
+ &control->Watchdog,<br>
+ cpu,<br>
+ _Record_Tick_interval<br>
+ );<br>
+ }<br>
+<br>
+ now = _Timecounter_Sbinuptime();<br>
+ rtems_record_produce_2(<br>
+ RTEMS_RECORD_UPTIME_LOW,<br>
+ (uint32_t) ( now >> 0 ),<br>
+ RTEMS_RECORD_UPTIME_HIGH,<br>
+ (uint32_t) ( now >> 32 )<br>
+ );<br>
+}<br>
+<br>
+RTEMS_SYSINIT_ITEM(<br>
+ _Record_Initialize_watchdogs,<br>
+ RTEMS_SYSINIT_DEVICE_DRIVERS,<br>
+ RTEMS_SYSINIT_ORDER_LAST<br>
+);<br>
diff --git a/cpukit/libmisc/record/record-text.c b/cpukit/libmisc/record/record-text.c<br>
new file mode 100644<br>
index 0000000000..cc41647a0d<br>
--- /dev/null<br>
+++ b/cpukit/libmisc/record/record-text.c<br>
@@ -0,0 +1,173 @@<br>
+/*<br>
+ * SPDX-License-Identifier: BSD-2-Clause<br>
+ *<br>
+ * Copyright (C) 2018 embedded brains GmbH<br>
+ *<br>
+ * Redistribution and use in source and binary forms, with or without<br>
+ * modification, are permitted provided that the following conditions<br>
+ * are met:<br>
+ * 1. Redistributions of source code must retain the above copyright<br>
+ * notice, this list of conditions and the following disclaimer.<br>
+ * 2. Redistributions in binary form must reproduce the above copyright<br>
+ * notice, this list of conditions and the following disclaimer in the<br>
+ * documentation and/or other materials provided with the distribution.<br>
+ *<br>
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"<br>
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE<br>
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br>
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br>
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br>
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br>
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br>
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br>
+ * POSSIBILITY OF SUCH DAMAGE.<br>
+ */<br>
+<br>
+/*<br>
+ * This file must be compatible to general purpose POSIX system, e.g. Linux,<br>
+ * FreeBSD. It may be used for utility programs.<br>
+ */<br>
+<br>
+#if HAVE_CONFIG_H<br>
+#include "config.h"<br>
+#endif<br>
+<br>
+#include <rtems/recorddata.h><br>
+<br>
+#include <stddef.h><br>
+<br>
+static const char * const event_text[] = {<br>
+ [ RTEMS_RECORD_EMPTY ] = "EMPTY",<br>
+ [ RTEMS_RECORD_VERSION ] = "VERSION",<br>
+ [ RTEMS_RECORD_ACCEPT ] = "ACCEPT",<br>
+ [ RTEMS_RECORD_BIND ] = "BIND",<br>
+ [ RTEMS_RECORD_CHOWN ] = "CHOWN",<br>
+ [ RTEMS_RECORD_CLOSE ] = "CLOSE",<br>
+ [ RTEMS_RECORD_CONNECT ] = "CONNECT",<br>
+ [ RTEMS_RECORD_COUNT ] = "COUNT",<br>
+ [ RTEMS_RECORD_FCHMOD ] = "FCHMOD",<br>
+ [ RTEMS_RECORD_FCNTL ] = "FCNTL",<br>
+ [ RTEMS_RECORD_FDATASYNC ] = "FDATASYNC",<br>
+ [ RTEMS_RECORD_FREQUENCY ] = "FREQUENCY",<br>
+ [ RTEMS_RECORD_FSTAT ] = "FSTAT",<br>
+ [ RTEMS_RECORD_FSYNC ] = "FSYNC",<br>
+ [ RTEMS_RECORD_FTRUNCATE ] = "FTRUNCATE",<br>
+ [ RTEMS_RECORD_HEAD ] = "HEAD",<br>
+ [ RTEMS_RECORD_HEAP_ALLOC ] = "HEAP_ALLOC",<br>
+ [ RTEMS_RECORD_HEAP_FREE ] = "HEAP_FREE",<br>
+ [ RTEMS_RECORD_HEAP_SIZE ] = "HEAP_SIZE",<br>
+ [ RTEMS_RECORD_HEAP_USAGE ] = "HEAP_USAGE",<br>
+ [ RTEMS_RECORD_INTERUPT_BEGIN ] = "INTERUPT_BEGIN",<br>
+ [ RTEMS_RECORD_INTERUPT_END ] = "INTERUPT_END",<br>
+ [ RTEMS_RECORD_INTERUPT_INSTALL ] = "INTERUPT_INSTALL",<br>
+ [ RTEMS_RECORD_INTERUPT_REMOVE ] = "INTERUPT_REMOVE",<br>
+ [ RTEMS_RECORD_IOCTL ] = "IOCTL",<br>
+ [ RTEMS_RECORD_KEVENT ] = "KEVENT",<br>
+ [ RTEMS_RECORD_KQUEUE ] = "KQUEUE",<br>
+ [ RTEMS_RECORD_LINK ] = "LINK",<br>
+ [ RTEMS_RECORD_LSEEK ] = "LSEEK",<br>
+ [ RTEMS_RECORD_MKNOD ] = "MKNOD",<br>
+ [ RTEMS_RECORD_MMAP ] = "MMAP",<br>
+ [ RTEMS_RECORD_MOUNT ] = "MOUNT",<br>
+ [ RTEMS_RECORD_OPEN ] = "OPEN",<br>
+ [ RTEMS_RECORD_OVERFLOW ] = "OVERFLOW",<br>
+ [ RTEMS_RECORD_POLL ] = "POLL",<br>
+ [ RTEMS_RECORD_PROCESSOR ] = "PROCESSOR",<br>
+ [ RTEMS_RECORD_READ ] = "READ",<br>
+ [ RTEMS_RECORD_READLINK ] = "READLINK",<br>
+ [ RTEMS_RECORD_READV ] = "READV",<br>
+ [ RTEMS_RECORD_RECV ] = "RECV",<br>
+ [ RTEMS_RECORD_RECVFROM ] = "RECVFROM",<br>
+ [ RTEMS_RECORD_RECVMSG ] = "RECVMSG",<br>
+ [ RTEMS_RECORD_RENAME ] = "RENAME",<br>
+ [ RTEMS_RECORD_RTEMS_BARRIER_CREATE ] = "RTEMS_BARRIER_CREATE",<br>
+ [ RTEMS_RECORD_RTEMS_BARRIER_DELETE ] = "RTEMS_BARRIER_DELETE",<br>
+ [ RTEMS_RECORD_RTEMS_BARRIER_RELEASE ] = "RTEMS_BARRIER_RELEASE",<br>
+ [ RTEMS_RECORD_RTEMS_BARRIER_WAIT ] = "RTEMS_BARRIER_WAIT",<br>
+ [ RTEMS_RECORD_RTEMS_EVENT_RECEIVE ] = "RTEMS_EVENT_RECEIVE",<br>
+ [ RTEMS_RECORD_RTEMS_EVENT_SEND ] = "RTEMS_EVENT_SEND",<br>
+ [ RTEMS_RECORD_RTEMS_EVENT_SYSTEM_RECEIVE ] = "RTEMS_EVENT_SYSTEM_RECEIVE",<br>
+ [ RTEMS_RECORD_RTEMS_EVENT_SYSTEM_SEND ] = "RTEMS_EVENT_SYSTEM_SEND",<br>
+ [ RTEMS_RECORD_RTEMS_MESSAGE_QUEUE_BROADCAST ] = "RTEMS_MESSAGE_QUEUE_BROADCAST",<br>
+ [ RTEMS_RECORD_RTEMS_MESSAGE_QUEUE_CREATE ] = "RTEMS_MESSAGE_QUEUE_CREATE",<br>
+ [ RTEMS_RECORD_RTEMS_MESSAGE_QUEUE_DELETE ] = "RTEMS_MESSAGE_QUEUE_DELETE",<br>
+ [ RTEMS_RECORD_RTEMS_MESSAGE_QUEUE_FLUSH ] = "RTEMS_MESSAGE_QUEUE_FLUSH",<br>
+ [ RTEMS_RECORD_RTEMS_MESSAGE_QUEUE_RECEIVE ] = "RTEMS_MESSAGE_QUEUE_RECEIVE",<br>
+ [ RTEMS_RECORD_RTEMS_MESSAGE_QUEUE_SEND ] = "RTEMS_MESSAGE_QUEUE_SEND",<br>
+ [ RTEMS_RECORD_RTEMS_MESSAGE_QUEUE_URGENT ] = "RTEMS_MESSAGE_QUEUE_URGENT",<br>
+ [ RTEMS_RECORD_RTEMS_PARTITION_CREATE ] = "RTEMS_PARTITION_CREATE",<br>
+ [ RTEMS_RECORD_RTEMS_PARTITION_DELETE ] = "RTEMS_PARTITION_DELETE",<br>
+ [ RTEMS_RECORD_RTEMS_PARTITION_GET_BUFFER ] = "RTEMS_PARTITION_GET_BUFFER",<br>
+ [ RTEMS_RECORD_RTEMS_PARTITION_RETURN_BUFFER ] = "RTEMS_PARTITION_RETURN_BUFFER",<br>
+ [ RTEMS_RECORD_RTEMS_RATE_MONOTONIC_CANCEL ] = "RTEMS_RATE_MONOTONIC_CANCEL",<br>
+ [ RTEMS_RECORD_RTEMS_RATE_MONOTONIC_CREATE ] = "RTEMS_RATE_MONOTONIC_CREATE",<br>
+ [ RTEMS_RECORD_RTEMS_RATE_MONOTONIC_DELETE ] = "RTEMS_RATE_MONOTONIC_DELETE",<br>
+ [ RTEMS_RECORD_RTEMS_RATE_MONOTONIC_PERIOD ] = "RTEMS_RATE_MONOTONIC_PERIOD",<br>
+ [ RTEMS_RECORD_RTEMS_SEMAPHORE_CREATE ] = "RTEMS_SEMAPHORE_CREATE",<br>
+ [ RTEMS_RECORD_RTEMS_SEMAPHORE_DELETE ] = "RTEMS_SEMAPHORE_DELETE",<br>
+ [ RTEMS_RECORD_RTEMS_SEMAPHORE_FLUSH ] = "RTEMS_SEMAPHORE_FLUSH",<br>
+ [ RTEMS_RECORD_RTEMS_SEMAPHORE_OBTAIN ] = "RTEMS_SEMAPHORE_OBTAIN",<br>
+ [ RTEMS_RECORD_RTEMS_SEMAPHORE_RELEASE ] = "RTEMS_SEMAPHORE_RELEASE",<br>
+ [ RTEMS_RECORD_RTEMS_TIMER_CANCEL ] = "RTEMS_TIMER_CANCEL",<br>
+ [ RTEMS_RECORD_RTEMS_TIMER_CREATE ] = "RTEMS_TIMER_CREATE",<br>
+ [ RTEMS_RECORD_RTEMS_TIMER_DELETE ] = "RTEMS_TIMER_DELETE",<br>
+ [ RTEMS_RECORD_RTEMS_TIMER_FIRE_AFTER ] = "RTEMS_TIMER_FIRE_AFTER",<br>
+ [ RTEMS_RECORD_RTEMS_TIMER_FIRE_WHEN ] = "RTEMS_TIMER_FIRE_WHEN",<br>
+ [ RTEMS_RECORD_RTEMS_TIMER_RESET ] = "RTEMS_TIMER_RESET",<br>
+ [ RTEMS_RECORD_RTEMS_TIMER_SERVER_FIRE_AFTER ] = "RTEMS_TIMER_SERVER_FIRE_AFTER",<br>
+ [ RTEMS_RECORD_RTEMS_TIMER_SERVER_FIRE_WHEN ] = "RTEMS_TIMER_SERVER_FIRE_WHEN",<br>
+ [ RTEMS_RECORD_SELECT ] = "SELECT",<br>
+ [ RTEMS_RECORD_SEND ] = "SEND",<br>
+ [ RTEMS_RECORD_SENDMSG ] = "SENDMSG",<br>
+ [ RTEMS_RECORD_SENDTO ] = "SENDTO",<br>
+ [ RTEMS_RECORD_SOCKET ] = "SOCKET",<br>
+ [ RTEMS_RECORD_STATVFS ] = "STATVFS",<br>
+ [ RTEMS_RECORD_SYMLINK ] = "SYMLINK",<br>
+ [ RTEMS_RECORD_TAIL ] = "TAIL",<br>
+ [ RTEMS_RECORD_THREAD_BEGIN ] = "THREAD_BEGIN",<br>
+ [ RTEMS_RECORD_THREAD_CREATE ] = "THREAD_CREATE",<br>
+ [ RTEMS_RECORD_THREAD_DELETE ] = "THREAD_DELETE",<br>
+ [ RTEMS_RECORD_THREAD_EXIT ] = "THREAD_EXIT",<br>
+ [ RTEMS_RECORD_THREAD_EXITTED ] = "THREAD_EXITTED",<br>
+ [ RTEMS_RECORD_THREAD_PRIO_CURRENT_HIGH ] = "THREAD_PRIO_CURRENT_HIGH",<br>
+ [ RTEMS_RECORD_THREAD_PRIO_CURRENT_LOW ] = "THREAD_PRIO_CURRENT_LOW",<br>
+ [ RTEMS_RECORD_THREAD_PRIO_REAL_HIGH ] = "THREAD_PRIO_REAL_HIGH",<br>
+ [ RTEMS_RECORD_THREAD_PRIO_REAL_LOW ] = "THREAD_PRIO_REAL_LOW",<br>
+ [ RTEMS_RECORD_THREAD_RESTART ] = "THREAD_RESTART",<br>
+ [ RTEMS_RECORD_THREAD_STACK_CURRENT ] = "THREAD_STACK_CURRENT",<br>
+ [ RTEMS_RECORD_THREAD_STACK_SIZE ] = "THREAD_STACK_SIZE",<br>
+ [ RTEMS_RECORD_THREAD_STACK_USAGE ] = "THREAD_STACK_USAGE",<br>
+ [ RTEMS_RECORD_THREAD_START ] = "THREAD_START",<br>
+ [ RTEMS_RECORD_THREAD_SWITCH_IN ] = "THREAD_SWITCH_IN",<br>
+ [ RTEMS_RECORD_THREAD_SWITCH_OUT ] = "THREAD_SWITCH_OUT",<br>
+ [ RTEMS_RECORD_THREAD_TERMINATE ] = "THREAD_TERMINATE",<br>
+ [ RTEMS_RECORD_UMA_ALLOC_PTR ] = "UMA_ALLOC_PTR",<br>
+ [ RTEMS_RECORD_UMA_ALLOC_ZONE ] = "UMA_ALLOC_ZONE",<br>
+ [ RTEMS_RECORD_UMA_FREE_PTR ] = "UMA_FREE_PTR",<br>
+ [ RTEMS_RECORD_UMA_FREE_ZONE ] = "UMA_FREE_ZONE",<br>
+ [ RTEMS_RECORD_UNLINK ] = "UNLINK",<br>
+ [ RTEMS_RECORD_UNMOUNT ] = "UNMOUNT",<br>
+ [ RTEMS_RECORD_UPTIME_HIGH ] = "UPTIME_HIGH",<br>
+ [ RTEMS_RECORD_UPTIME_LOW ] = "UPTIME_LOW",<br>
+ [ RTEMS_RECORD_WORKSPACE_ALLOC ] = "WORKSPACE_ALLOC",<br>
+ [ RTEMS_RECORD_WORKSPACE_FREE ] = "WORKSPACE_FREE",<br>
+ [ RTEMS_RECORD_WORKSPACE_SIZE ] = "WORKSPACE_SIZE",<br>
+ [ RTEMS_RECORD_WORKSPACE_USAGE ] = "WORKSPACE_USAGE",<br>
+ [ RTEMS_RECORD_WRITE ] = "WRITE",<br>
+ [ RTEMS_RECORD_WRITEV ] = "WRITEV"<br>
+};<br>
+<br>
+const char *rtems_record_event_text( rtems_record_event event )<br>
+{<br>
+ size_t n;<br>
+<br>
+ n = event;<br>
+<br>
+ if ( n < sizeof( event_text ) / sizeof( event_text[ 0 ] ) ) {<br>
+ return event_text[ n ];<br>
+ }<br>
+<br>
+ return NULL;<br>
+}<br>
diff --git a/cpukit/libmisc/record/record-userext.c b/cpukit/libmisc/record/record-userext.c<br>
new file mode 100644<br>
index 0000000000..3d30620e5c<br>
--- /dev/null<br>
+++ b/cpukit/libmisc/record/record-userext.c<br>
@@ -0,0 +1,125 @@<br>
+/*<br>
+ * SPDX-License-Identifier: BSD-2-Clause<br>
+ *<br>
+ * Copyright (C) 2018 embedded brains GmbH<br>
+ *<br>
+ * Redistribution and use in source and binary forms, with or without<br>
+ * modification, are permitted provided that the following conditions<br>
+ * are met:<br>
+ * 1. Redistributions of source code must retain the above copyright<br>
+ * notice, this list of conditions and the following disclaimer.<br>
+ * 2. Redistributions in binary form must reproduce the above copyright<br>
+ * notice, this list of conditions and the following disclaimer in the<br>
+ * documentation and/or other materials provided with the distribution.<br>
+ *<br>
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"<br>
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE<br>
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br>
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br>
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br>
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br>
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br>
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br>
+ * POSSIBILITY OF SUCH DAMAGE.<br>
+ */<br>
+<br>
+#if HAVE_CONFIG_H<br>
+#include "config.h"<br>
+#endif<br>
+<br>
+#include <rtems/record.h><br>
+#include <rtems/score/thread.h><br>
+<br>
+bool _Record_Thread_create(<br>
+ struct _Thread_Control *executing,<br>
+ struct _Thread_Control *created<br>
+)<br>
+{<br>
+ rtems_record_produce(<br>
+ RTEMS_RECORD_THREAD_CREATE,<br>
+ created->Object.id<br>
+ );<br>
+<br>
+ return true;<br>
+}<br>
+<br>
+void _Record_Thread_start(<br>
+ struct _Thread_Control *executing,<br>
+ struct _Thread_Control *started<br>
+)<br>
+{<br>
+ rtems_record_produce(<br>
+ RTEMS_RECORD_THREAD_START,<br>
+ started->Object.id<br>
+ );<br>
+}<br>
+<br>
+void _Record_Thread_restart(<br>
+ struct _Thread_Control *executing,<br>
+ struct _Thread_Control *restarted<br>
+)<br>
+{<br>
+ rtems_record_produce(<br>
+ RTEMS_RECORD_THREAD_RESTART,<br>
+ restarted->Object.id<br>
+ );<br>
+}<br>
+<br>
+void _Record_Thread_delete(<br>
+ struct _Thread_Control *executing,<br>
+ struct _Thread_Control *deleted<br>
+)<br>
+{<br>
+ rtems_record_produce(<br>
+ RTEMS_RECORD_THREAD_DELETE,<br>
+ deleted->Object.id<br>
+ );<br>
+}<br>
+<br>
+void _Record_Thread_switch(<br>
+ struct _Thread_Control *executing,<br>
+ struct _Thread_Control *heir<br>
+)<br>
+{<br>
+ rtems_record_item items[ 3 ];<br>
+<br>
+ items[ 0 ].event = RTEMS_RECORD_THREAD_SWITCH_OUT;<br>
+ items[ 0 ].data = executing->Object.id;<br>
+ items[ 1 ].event = RTEMS_RECORD_THREAD_STACK_CURRENT;<br>
+ items[ 1 ].data =<br>
+#if defined(__GNUC__)<br>
+ (uintptr_t) __builtin_frame_address( 0 )<br>
+ - (uintptr_t) executing->Start.Initial_stack.area;<br>
+#else<br>
+ 0;<br>
+#endif<br>
+ items[ 2 ].event = RTEMS_RECORD_THREAD_SWITCH_IN;<br>
+ items[ 2 ].data = heir->Object.id;<br>
+ rtems_record_produce_n( items, RTEMS_ARRAY_SIZE( items ) );<br>
+}<br>
+<br>
+void _Record_Thread_begin( struct _Thread_Control *executing )<br>
+{<br>
+ rtems_record_produce(<br>
+ RTEMS_RECORD_THREAD_BEGIN,<br>
+ executing->Object.id<br>
+ );<br>
+}<br>
+<br>
+void _Record_Thread_exitted( struct _Thread_Control *executing )<br>
+{<br>
+ rtems_record_produce(<br>
+ RTEMS_RECORD_THREAD_EXITTED,<br>
+ executing->Object.id<br>
+ );<br>
+}<br>
+<br>
+void _Record_Thread_terminate( struct _Thread_Control *executing )<br>
+{<br>
+ rtems_record_produce(<br>
+ RTEMS_RECORD_THREAD_TERMINATE,<br>
+ executing->Object.id<br>
+ );<br>
+}<br>
diff --git a/cpukit/libmisc/record/record.c b/cpukit/libmisc/record/record.c<br>
new file mode 100644<br>
index 0000000000..3f1751de1c<br>
--- /dev/null<br>
+++ b/cpukit/libmisc/record/record.c<br>
@@ -0,0 +1,132 @@<br>
+/*<br>
+ * SPDX-License-Identifier: BSD-2-Clause<br>
+ *<br>
+ * Copyright (C) 2018 embedded brains GmbH<br>
+ *<br>
+ * Redistribution and use in source and binary forms, with or without<br>
+ * modification, are permitted provided that the following conditions<br>
+ * are met:<br>
+ * 1. Redistributions of source code must retain the above copyright<br>
+ * notice, this list of conditions and the following disclaimer.<br>
+ * 2. Redistributions in binary form must reproduce the above copyright<br>
+ * notice, this list of conditions and the following disclaimer in the<br>
+ * documentation and/or other materials provided with the distribution.<br>
+ *<br>
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"<br>
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE<br>
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br>
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br>
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br>
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br>
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br>
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br>
+ * POSSIBILITY OF SUCH DAMAGE.<br>
+ */<br>
+<br>
+#if HAVE_CONFIG_H<br>
+#include "config.h"<br>
+#endif<br>
+<br>
+#include <rtems/record.h><br>
+#include <rtems/config.h><br>
+#include <rtems/score/assert.h><br>
+<br>
+#include <string.h><br>
+<br>
+void rtems_record_produce( rtems_record_event event, rtems_record_data data )<br>
+{<br>
+ rtems_record_context context;<br>
+<br>
+ rtems_record_prepare( &context );<br>
+ rtems_record_add( &context, event, data );<br>
+ rtems_record_commit( &context );<br>
+}<br>
+<br>
+void rtems_record_produce_2(<br>
+ rtems_record_event event_0,<br>
+ rtems_record_data data_0,<br>
+ rtems_record_event event_1,<br>
+ rtems_record_data data_1<br>
+)<br>
+{<br>
+ rtems_record_context context;<br>
+<br>
+ rtems_record_prepare( &context );<br>
+ rtems_record_add( &context, event_0, data_0 );<br>
+ rtems_record_add( &context, event_1, data_1 );<br>
+ rtems_record_commit( &context );<br>
+}<br>
+<br>
+void rtems_record_produce_n(<br>
+ const rtems_record_item *items,<br>
+ size_t n<br>
+)<br>
+{<br>
+ rtems_record_context context;<br>
+<br>
+ _Assert( n > 0 );<br>
+<br>
+ rtems_record_prepare( &context );<br>
+<br>
+ do {<br>
+ rtems_record_add( &context, items->event, items->data );<br>
+ ++items;<br>
+ --n;<br>
+ } while ( n > 0 );<br>
+<br>
+ rtems_record_commit( &context );<br>
+}<br>
+<br>
+void rtems_record_drain( rtems_record_drain_visitor visitor, void *arg )<br>
+{<br>
+ uint32_t cpu_max;<br>
+ uint32_t cpu_index;<br>
+<br>
+ cpu_max = rtems_configuration_get_maximum_processors();<br>
+<br>
+ for ( cpu_index = 0; cpu_index < cpu_max; ++cpu_index ) {<br>
+ Per_CPU_Control *cpu;<br>
+ Record_Control *control;<br>
+ unsigned int tail;<br>
+ unsigned int head;<br>
+<br>
+ cpu = _Per_CPU_Get_by_index( cpu_index );<br>
+ control = cpu->record;<br>
+<br>
+ tail = _Record_Tail( control );<br>
+ head = _Atomic_Load_uint( &control->head, ATOMIC_ORDER_ACQUIRE );<br>
+<br>
+ if ( tail == head ) {<br>
+ continue;<br>
+ }<br>
+<br>
+ control->tail = head;<br>
+<br>
+ control->Header[ 0 ].event = RTEMS_RECORD_PROCESSOR;<br>
+ control->Header[ 0 ].data = cpu_index;<br>
+ control->Header[ 1 ].event = RTEMS_RECORD_TAIL;<br>
+ control->Header[ 1 ].data = tail;<br>
+ control->Header[ 2 ].event = RTEMS_RECORD_HEAD;<br>
+ control->Header[ 2 ].data = head;<br>
+ ( *visitor )( control->Header, RTEMS_ARRAY_SIZE( control->Header ), arg );<br>
+<br>
+ if ( _Record_Is_overflow( control, tail, head ) ) {<br>
+ tail = head + 1;<br>
+ }<br>
+<br>
+ tail = _Record_Index( control, tail );<br>
+ head = _Record_Index( control, head );<br>
+<br>
+ if ( tail < head ) {<br>
+ ( *visitor )( &control->Items[ tail ], head - tail, arg );<br>
+ } else {<br>
+ ( *visitor )( &control->Items[ tail ], control->mask + 1 - tail, arg );<br>
+<br>
+ if ( head > 0 ) {<br>
+ ( *visitor )( &control->Items[ 0 ], head, arg );<br>
+ }<br>
+ }<br>
+ }<br>
+}<br>
diff --git a/testsuites/libtests/Makefile.am b/testsuites/libtests/Makefile.am<br>
index 810f65db8e..765096c443 100644<br>
--- a/testsuites/libtests/Makefile.am<br>
+++ b/testsuites/libtests/Makefile.am<br>
@@ -994,6 +994,24 @@ realloc_norun_SOURCES = POSIX/realloc.c<br>
realloc_norun_LDADD = $(RTEMS_ROOT)cpukit/librtemsdefaultconfig.a $(LDADD)<br>
endif<br>
<br>
+if TEST_record01<br>
+lib_tests += record01<br>
+lib_screens += record01/record01.scn<br>
+lib_docs += record01/record01.doc<br>
+record01_SOURCES = record01/init.c<br>
+record01_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_record01) \<br>
+ $(support_includes) -I$(RTEMS_SOURCE_ROOT)/cpukit/libnetworking<br>
+endif<br>
+<br>
+if TEST_record02<br>
+lib_tests += record02<br>
+lib_screens += record02/record02.scn<br>
+lib_docs += record02/record02.doc<br>
+record02_SOURCES = record02/init.c<br>
+record02_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_record02) \<br>
+ $(support_includes)<br>
+endif<br>
+<br>
if TEST_rtmonuse<br>
lib_tests += rtmonuse<br>
lib_screens += rtmonuse/rtmonuse.scn<br>
diff --git a/testsuites/libtests/<a href="http://configure.ac" rel="noreferrer noreferrer" target="_blank">configure.ac</a> b/testsuites/libtests/<a href="http://configure.ac" rel="noreferrer noreferrer" target="_blank">configure.ac</a><br>
index a2a0df01f1..c76fb799b4 100644<br>
--- a/testsuites/libtests/<a href="http://configure.ac" rel="noreferrer noreferrer" target="_blank">configure.ac</a><br>
+++ b/testsuites/libtests/<a href="http://configure.ac" rel="noreferrer noreferrer" target="_blank">configure.ac</a><br>
@@ -189,6 +189,8 @@ RTEMS_TEST_CHECK([rbheap01])<br>
RTEMS_TEST_CHECK([read])<br>
RTEMS_TEST_CHECK([readv])<br>
RTEMS_TEST_CHECK([realloc])<br>
+RTEMS_TEST_CHECK([record01])<br>
+RTEMS_TEST_CHECK([record02])<br>
RTEMS_TEST_CHECK([rtmonuse])<br>
RTEMS_TEST_CHECK([setjmp])<br>
RTEMS_TEST_CHECK([sha])<br>
diff --git a/testsuites/libtests/record01/init.c b/testsuites/libtests/record01/init.c<br>
new file mode 100644<br>
index 0000000000..f172332408<br>
--- /dev/null<br>
+++ b/testsuites/lib</blockquote></div>