record: Rework client

The ring buffer overflow handling is already performed by
rtems_record_fetch().
This commit is contained in:
Sebastian Huber
2024-10-11 02:36:27 +02:00
committed by Chris Johns
parent be764f7dec
commit 920f8d8897
3 changed files with 290 additions and 296 deletions

View File

@@ -1,7 +1,7 @@
/* /*
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
* *
* Copyright (C) 2018, 2019 embedded brains GmbH & Co. KG * Copyright (C) 2018, 2024 embedded brains GmbH & Co. KG
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@@ -72,43 +72,28 @@ typedef rtems_record_client_status ( *rtems_record_client_handler )(
void *arg void *arg
); );
typedef struct {
uint64_t uptime_bt;
uint32_t time_last;
uint64_t time_accumulated;
} rtems_record_client_uptime;
/**
* @brief This constant defines the maximum capacity of the hold back item
* storage in case a reallocation is necessary.
*/
#define RTEMS_RECORD_CLIENT_HOLD_BACK_REALLOCATION_LIMIT 0x100000
typedef struct { typedef struct {
/** /**
* @brief Event time to uptime maintenance. * @brief Event time to uptime maintenance.
*/ */
struct { rtems_record_client_uptime uptime;
uint64_t bt;
uint32_t time_at_bt;
uint32_t time_last;
uint32_t time_accumulated;
} uptime;
/** /**
* @brief The current or previous ring buffer tail. * @brief Last RTEMS_RECORD_UPTIME_LOW data.
*
* Indexed by the tail_head_index member.
*/ */
uint32_t tail[ 2 ]; uint32_t uptime_low;
/**
* @brief The current or previous ring buffer head.
*
* Indexed by the tail_head_index member.
*/
uint32_t head[ 2 ];
/**
* @brief The index of the tail and head members.
*
* This index is used to maintain the current and previous tail/head
* positions to detect ring buffer overflows.
*/
size_t tail_head_index;
/**
* @brief Count of lost items due to ring buffer overflows.
*/
uint32_t overflow;
/** /**
* @brief If true, then hold back items. * @brief If true, then hold back items.
@@ -123,6 +108,11 @@ typedef struct {
*/ */
rtems_record_item_64 *items; rtems_record_item_64 *items;
/**
* @brief The item capacity of the hold back storage.
*/
size_t item_capacity;
/** /**
* @brief The index for the next hold back item. * @brief The index for the next hold back item.
*/ */
@@ -134,7 +124,7 @@ typedef struct rtems_record_client_context {
rtems_record_client_per_cpu per_cpu[ RTEMS_RECORD_CLIENT_MAXIMUM_CPU_COUNT ]; rtems_record_client_per_cpu per_cpu[ RTEMS_RECORD_CLIENT_MAXIMUM_CPU_COUNT ];
uint32_t cpu; uint32_t cpu;
uint32_t cpu_count; uint32_t cpu_count;
uint32_t count; uint32_t per_cpu_items;
union { union {
rtems_record_item_32 format_32; rtems_record_item_32 format_32;
rtems_record_item_64 format_64; rtems_record_item_64 format_64;
@@ -163,7 +153,7 @@ typedef struct rtems_record_client_context {
* @param handler The handler is invoked for each received record item. * @param handler The handler is invoked for each received record item.
* @param arg The handler argument. * @param arg The handler argument.
*/ */
void rtems_record_client_init( rtems_record_client_status rtems_record_client_init(
rtems_record_client_context *ctx, rtems_record_client_context *ctx,
rtems_record_client_handler handler, rtems_record_client_handler handler,
void *arg void *arg

View File

@@ -1,7 +1,7 @@
/* /*
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
* *
* Copyright (C) 2018, 2019 embedded brains GmbH & Co. KG * Copyright (C) 2018, 2024 embedded brains GmbH & Co. KG
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@@ -38,7 +38,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <rtems/score/assert.h>
#define TIME_MASK ( ( UINT32_C( 1 ) << RTEMS_RECORD_TIME_BITS ) - 1 ) #define TIME_MASK ( ( UINT32_C( 1 ) << RTEMS_RECORD_TIME_BITS ) - 1 )
@@ -71,6 +70,50 @@ static rtems_record_client_status error(
return status; return status;
} }
static rtems_record_client_status process_per_cpu_count(
rtems_record_client_context *ctx,
uint64_t data
)
{
size_t item_capacity;
uint32_t cpu;
if ( ctx->per_cpu_items != 0 ) {
return error( ctx, RTEMS_RECORD_CLIENT_ERROR_DOUBLE_PER_CPU_COUNT );
}
if ( ctx->cpu_count == 0 ) {
return error( ctx, RTEMS_RECORD_CLIENT_ERROR_NO_CPU_MAX );
}
ctx->per_cpu_items = (uint32_t) data;
/*
* Use two times the ring buffer capacity so that it remains a power of two
* and can hold the RTEMS_RECORD_PROCESSOR and RTEMS_RECORD_PER_CPU_OVERFLOW
* items produced by rtems_record_fetch().
*/
item_capacity = 2 * ctx->per_cpu_items;
for ( cpu = 0; cpu < ctx->cpu_count; ++cpu ) {
rtems_record_client_per_cpu *per_cpu;
per_cpu = &ctx->per_cpu[ cpu ];
per_cpu->items = realloc(
per_cpu->items,
item_capacity * sizeof( *per_cpu->items )
);
if ( per_cpu->items == NULL ) {
return error( ctx, RTEMS_RECORD_CLIENT_ERROR_NO_MEMORY );
}
per_cpu->item_capacity = item_capacity;
}
return RTEMS_RECORD_CLIENT_SUCCESS;
}
static void set_to_bt_scaler( static void set_to_bt_scaler(
rtems_record_client_context *ctx, rtems_record_client_context *ctx,
uint32_t frequency uint32_t frequency
@@ -82,15 +125,62 @@ static void set_to_bt_scaler(
ctx->to_bt_scaler = ( ( bin_per_s << 31 ) + frequency - 1 ) / frequency; ctx->to_bt_scaler = ( ( bin_per_s << 31 ) + frequency - 1 ) / frequency;
} }
static bool has_time( rtems_record_event event )
{
switch ( event ) {
case RTEMS_RECORD_ARCH:
case RTEMS_RECORD_BSP:
case RTEMS_RECORD_FREQUENCY:
case RTEMS_RECORD_MULTILIB:
case RTEMS_RECORD_PER_CPU_COUNT:
case RTEMS_RECORD_PER_CPU_OVERFLOW:
case RTEMS_RECORD_PROCESSOR:
case RTEMS_RECORD_PROCESSOR_MAXIMUM:
case RTEMS_RECORD_THREAD_ID:
case RTEMS_RECORD_THREAD_NAME:
case RTEMS_RECORD_TOOLS:
case RTEMS_RECORD_VERSION:
case RTEMS_RECORD_VERSION_CONTROL_KEY:
return false;
default:
return true;
}
}
static uint64_t time_bt(
const rtems_record_client_context *ctx,
rtems_record_client_per_cpu *per_cpu,
uint32_t time,
rtems_record_event event
)
{
uint64_t bt;
uint64_t time_accumulated;
time_accumulated = per_cpu->uptime.time_accumulated;
if ( has_time( event) ) {
time_accumulated += ( time - per_cpu->uptime.time_last ) & TIME_MASK;
per_cpu->uptime.time_last = time;
per_cpu->uptime.time_accumulated = time_accumulated;
}
bt = per_cpu->uptime.uptime_bt;
bt += ( time_accumulated * ctx->to_bt_scaler ) >> 31;
return bt;
}
static rtems_record_client_status call_handler( static rtems_record_client_status call_handler(
const rtems_record_client_context *ctx, const rtems_record_client_context *ctx,
uint64_t bt, rtems_record_client_per_cpu *per_cpu,
uint32_t time,
rtems_record_event event, rtems_record_event event,
uint64_t data uint64_t data
) )
{ {
return ( *ctx->handler )( return ( *ctx->handler )(
bt, time_bt( ctx, per_cpu, time, event ),
ctx->cpu, ctx->cpu,
event, event,
data, data,
@@ -98,205 +188,61 @@ static rtems_record_client_status call_handler(
); );
} }
static void signal_overflow( static rtems_record_client_status resolve_hold_back(
rtems_record_client_per_cpu *per_cpu,
uint32_t data
)
{
per_cpu->hold_back = true;
per_cpu->item_index = 0;
per_cpu->overflow += data;
}
static void resolve_hold_back(
rtems_record_client_context *ctx, rtems_record_client_context *ctx,
rtems_record_client_per_cpu *per_cpu rtems_record_client_per_cpu *per_cpu
) )
{ {
if ( per_cpu->hold_back ) { rtems_record_item_64 *items;
uint32_t last_tail; uint32_t last;
uint32_t last_head; uint64_t accumulated;
uint32_t last_capacity; size_t index;
uint32_t new_head; rtems_record_client_uptime uptime;
uint32_t new_content;
uint32_t begin_index; items = per_cpu->items;
uint32_t index; last = per_cpu->uptime.time_last;
uint32_t first; accumulated = 0;
uint32_t last;
uint32_t delta; for ( index = per_cpu->item_index; index > 0; --index ) {
uint64_t uptime; uint32_t time_event;
time_event = items[ index - 1 ].event;
if ( has_time( RTEMS_RECORD_GET_EVENT( time_event ) ) ) {
uint32_t time;
time = RTEMS_RECORD_GET_TIME( time_event );
accumulated += ( last - time ) & TIME_MASK;
last = time;
}
}
uptime = per_cpu->uptime;
per_cpu->uptime.uptime_bt -= ( accumulated * ctx->to_bt_scaler ) >> 31;
per_cpu->uptime.time_last = last;
per_cpu->uptime.time_accumulated = 0;
for ( index = 0; index < per_cpu->item_index; ++index ) {
uint32_t time_event;
rtems_record_client_status status; rtems_record_client_status status;
last_head = per_cpu->head[ per_cpu->tail_head_index ]; time_event = items[ index ].event;
last_tail = per_cpu->tail[ per_cpu->tail_head_index ]; status = call_handler(
new_head = per_cpu->head[ per_cpu->tail_head_index ^ 1 ]; ctx,
last_capacity = ( last_tail - last_head - 1 ) & ( ctx->count - 1 ); per_cpu,
new_content = new_head - last_head; RTEMS_RECORD_GET_TIME( time_event ),
RTEMS_RECORD_GET_EVENT( time_event ),
items[ index ].data
);
if ( new_content > last_capacity ) { if ( status != RTEMS_RECORD_CLIENT_SUCCESS ) {
begin_index = new_content - last_capacity; return status;
per_cpu->overflow += begin_index;
} else {
begin_index = 0;
}
if ( begin_index >= per_cpu->item_index ) {
per_cpu->item_index = 0;
return;
}
per_cpu->hold_back = false;
first = RTEMS_RECORD_GET_TIME( per_cpu->items[ begin_index ].event );
last = first;
delta = 0;
uptime = 0;
for ( index = begin_index; index < per_cpu->item_index; ++index ) {
const rtems_record_item_64 *item;
rtems_record_event event;
uint32_t time;
item = &per_cpu->items[ index ];
event = RTEMS_RECORD_GET_EVENT( item->event );
time = RTEMS_RECORD_GET_TIME( item->event );
delta += ( time - last ) & TIME_MASK;
last = time;
if (
event == RTEMS_RECORD_UPTIME_LOW
&& index + 1 < per_cpu->item_index
&& RTEMS_RECORD_GET_EVENT( ( item + 1 )->event )
== RTEMS_RECORD_UPTIME_HIGH
) {
uptime = (uint32_t) item->data;
uptime += ( item + 1 )->data << 32;
break;
}
}
per_cpu->uptime.bt = uptime - ( ( delta * ctx->to_bt_scaler ) >> 31 );
per_cpu->uptime.time_at_bt = first;
per_cpu->uptime.time_last = first;
per_cpu->uptime.time_accumulated = 0;
if ( per_cpu->overflow > 0 ) {
call_handler(
ctx,
per_cpu->uptime.bt,
RTEMS_RECORD_PER_CPU_OVERFLOW,
per_cpu->overflow
);
per_cpu->overflow = 0;
}
for ( index = begin_index; index < per_cpu->item_index; ++index ) {
const rtems_record_item_64 *item;
item = &per_cpu->items[ index ];
status = visit( ctx, item->event, item->data );
_Assert_Unused_variable_equals(status, RTEMS_RECORD_CLIENT_SUCCESS);
} }
} }
}
static void process_per_cpu_head( per_cpu->uptime = uptime;
rtems_record_client_context *ctx, per_cpu->hold_back = false;
rtems_record_client_per_cpu *per_cpu, per_cpu->item_index = 0;
uint64_t data
)
{
uint32_t last_tail;
uint32_t last_head;
uint32_t last_capacity;
uint32_t new_tail;
uint32_t new_head;
uint32_t new_content;
uint32_t content;
new_tail = per_cpu->tail[ per_cpu->tail_head_index ];
new_head = (uint32_t) data;
content = new_head - new_tail;
per_cpu->head[ per_cpu->tail_head_index ] = new_head;
per_cpu->tail_head_index ^= 1;
if ( content >= ctx->count ) {
/*
* This is a complete ring buffer overflow, the server will detect this
* also. It sets the tail to the head plus one and sends us all the
* content. This reduces the ring buffer capacity to zero. So, during
* transfer, new events will overwrite items in transfer. This is handled
* by resolve_hold_back().
*/
per_cpu->tail[ per_cpu->tail_head_index ^ 1 ] = new_head + 1;
signal_overflow( per_cpu, content - ctx->count + 1 );
return;
}
last_tail = per_cpu->tail[ per_cpu->tail_head_index ];
last_head = per_cpu->head[ per_cpu->tail_head_index ];
if ( last_tail == last_head ) {
if ( per_cpu->uptime.bt == 0 ) {
/*
* This is a special case during initial ramp up. We hold back the items
* to deduce the uptime of the first item via resolve_hold_back().
*/
per_cpu->hold_back = true;
} else {
resolve_hold_back( ctx, per_cpu );
}
return;
}
last_capacity = ( last_tail - last_head - 1 ) & ( ctx->count - 1 );
new_content = new_head - last_head;
if ( new_content <= last_capacity || per_cpu->hold_back ) {
resolve_hold_back( ctx, per_cpu );
return;
}
signal_overflow( per_cpu, new_content - last_capacity );
}
static rtems_record_client_status process_per_cpu_count(
rtems_record_client_context *ctx,
uint64_t data
)
{
size_t per_cpu_items;
rtems_record_item_64 *items;
uint32_t cpu;
if ( ctx->count != 0 ) {
return error( ctx, RTEMS_RECORD_CLIENT_ERROR_DOUBLE_PER_CPU_COUNT );
}
if ( ctx->cpu_count == 0 ) {
return error( ctx, RTEMS_RECORD_CLIENT_ERROR_NO_CPU_MAX );
}
ctx->count = (uint32_t) data;
/*
* The ring buffer capacity plus two items for RTEMS_RECORD_PROCESSOR and
* RTEMS_RECORD_PER_CPU_TAIL.
*/
per_cpu_items = ctx->count + 1;
items = malloc( per_cpu_items * ctx->cpu_count * sizeof( *items ) );
if ( items == NULL ) {
return error( ctx, RTEMS_RECORD_CLIENT_ERROR_NO_MEMORY );
}
for ( cpu = 0; cpu < ctx->cpu_count; ++cpu ) {
ctx->per_cpu[ cpu ].items = items;
items += per_cpu_items;
}
return RTEMS_RECORD_CLIENT_SUCCESS; return RTEMS_RECORD_CLIENT_SUCCESS;
} }
@@ -305,52 +251,36 @@ static rtems_record_client_status hold_back(
rtems_record_client_context *ctx, rtems_record_client_context *ctx,
rtems_record_client_per_cpu *per_cpu, rtems_record_client_per_cpu *per_cpu,
uint32_t time_event, uint32_t time_event,
rtems_record_event event,
uint64_t data uint64_t data
) )
{ {
if ( event != RTEMS_RECORD_PER_CPU_HEAD ) { uint32_t item_index;
uint32_t item_index;
item_index = per_cpu->item_index; item_index = per_cpu->item_index;
if ( item_index <= ctx->count ) { if ( item_index >= per_cpu->item_capacity ) {
per_cpu->items[ item_index ].event = time_event; if ( item_index >= RTEMS_RECORD_CLIENT_HOLD_BACK_REALLOCATION_LIMIT ) {
per_cpu->items[ item_index ].data = data;
per_cpu->item_index = item_index + 1;
} else {
return error( ctx, RTEMS_RECORD_CLIENT_ERROR_PER_CPU_ITEMS_OVERFLOW ); return error( ctx, RTEMS_RECORD_CLIENT_ERROR_PER_CPU_ITEMS_OVERFLOW );
} }
} else {
return call_handler( ctx, 0, RTEMS_RECORD_GET_EVENT( time_event ), data ); per_cpu->item_capacity = 2 * item_index;
per_cpu->items = realloc(
per_cpu->items,
per_cpu->item_capacity * sizeof( *per_cpu->items )
);
if ( per_cpu->items == NULL ) {
return error( ctx, RTEMS_RECORD_CLIENT_ERROR_NO_MEMORY );
}
} }
per_cpu->items[ item_index ].event = time_event;
per_cpu->items[ item_index ].data = data;
per_cpu->item_index = item_index + 1;
return RTEMS_RECORD_CLIENT_SUCCESS; return RTEMS_RECORD_CLIENT_SUCCESS;
} }
static uint64_t time_bt(
const rtems_record_client_context *ctx,
rtems_record_client_per_cpu *per_cpu,
uint32_t time
)
{
uint64_t bt;
if ( time != 0 ) {
uint32_t delta;
delta = ( time - per_cpu->uptime.time_last ) & TIME_MASK;
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 bt;
}
static rtems_record_client_status visit( static rtems_record_client_status visit(
rtems_record_client_context *ctx, rtems_record_client_context *ctx,
uint32_t time_event, uint32_t time_event,
@@ -361,10 +291,12 @@ static rtems_record_client_status visit(
uint32_t time; uint32_t time;
rtems_record_event event; rtems_record_event event;
rtems_record_client_status status; rtems_record_client_status status;
bool do_hold_back;
per_cpu = &ctx->per_cpu[ ctx->cpu ]; per_cpu = &ctx->per_cpu[ ctx->cpu ];
time = RTEMS_RECORD_GET_TIME( time_event ); time = RTEMS_RECORD_GET_TIME( time_event );
event = RTEMS_RECORD_GET_EVENT( time_event ); event = RTEMS_RECORD_GET_EVENT( time_event );
do_hold_back = per_cpu->hold_back;
switch ( event ) { switch ( event ) {
case RTEMS_RECORD_PROCESSOR: case RTEMS_RECORD_PROCESSOR:
@@ -376,21 +308,21 @@ static rtems_record_client_status visit(
per_cpu = &ctx->per_cpu[ ctx->cpu ]; per_cpu = &ctx->per_cpu[ ctx->cpu ];
break; break;
case RTEMS_RECORD_UPTIME_LOW: case RTEMS_RECORD_UPTIME_LOW:
per_cpu->uptime.bt = (uint32_t) data; per_cpu->uptime_low = (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; break;
case RTEMS_RECORD_UPTIME_HIGH: case RTEMS_RECORD_UPTIME_HIGH:
per_cpu->uptime.bt += data << 32; per_cpu->uptime.uptime_bt = ( data << 32 ) | per_cpu->uptime_low;
time = 0; per_cpu->uptime.time_last = time;
break; per_cpu->uptime.time_accumulated = 0;
case RTEMS_RECORD_PER_CPU_TAIL:
per_cpu->tail[ per_cpu->tail_head_index ] = (uint32_t) data; if (do_hold_back) {
break; status = resolve_hold_back( ctx, per_cpu );
case RTEMS_RECORD_PER_CPU_HEAD:
process_per_cpu_head( ctx, per_cpu, data ); if ( status != RTEMS_RECORD_CLIENT_SUCCESS ) {
return status;
}
}
break; break;
case RTEMS_RECORD_PROCESSOR_MAXIMUM: case RTEMS_RECORD_PROCESSOR_MAXIMUM:
if ( data >= RTEMS_RECORD_CLIENT_MAXIMUM_CPU_COUNT ) { if ( data >= RTEMS_RECORD_CLIENT_MAXIMUM_CPU_COUNT ) {
@@ -402,6 +334,7 @@ static rtems_record_client_status visit(
} }
ctx->cpu_count = (uint32_t) data + 1; ctx->cpu_count = (uint32_t) data + 1;
do_hold_back = false;
break; break;
case RTEMS_RECORD_PER_CPU_COUNT: case RTEMS_RECORD_PER_CPU_COUNT:
status = process_per_cpu_count( ctx, data ); status = process_per_cpu_count( ctx, data );
@@ -410,6 +343,10 @@ static rtems_record_client_status visit(
return status; return status;
} }
break;
case RTEMS_RECORD_PER_CPU_OVERFLOW:
do_hold_back = true;
per_cpu->hold_back = true;
break; break;
case RTEMS_RECORD_FREQUENCY: case RTEMS_RECORD_FREQUENCY:
set_to_bt_scaler( ctx, (uint32_t) data ); set_to_bt_scaler( ctx, (uint32_t) data );
@@ -419,16 +356,17 @@ static rtems_record_client_status visit(
return error( ctx, RTEMS_RECORD_CLIENT_ERROR_UNSUPPORTED_VERSION ); return error( ctx, RTEMS_RECORD_CLIENT_ERROR_UNSUPPORTED_VERSION );
} }
do_hold_back = false;
break; break;
default: default:
break; break;
} }
if ( per_cpu->hold_back ) { if ( do_hold_back ) {
return hold_back( ctx, per_cpu, time_event, event, data ); return hold_back( ctx, per_cpu, time_event, data );
} }
return call_handler( ctx, time_bt( ctx, per_cpu, time ), event, data ); return call_handler( ctx, per_cpu, time, event, data );
} }
static rtems_record_client_status consume_32( static rtems_record_client_status consume_32(
@@ -688,12 +626,14 @@ static rtems_record_client_status consume_init(
return RTEMS_RECORD_CLIENT_SUCCESS; return RTEMS_RECORD_CLIENT_SUCCESS;
} }
void rtems_record_client_init( rtems_record_client_status rtems_record_client_init(
rtems_record_client_context *ctx, rtems_record_client_context *ctx,
rtems_record_client_handler handler, rtems_record_client_handler handler,
void *arg void *arg
) )
{ {
uint32_t cpu;
ctx = memset( ctx, 0, sizeof( *ctx ) ); ctx = memset( ctx, 0, sizeof( *ctx ) );
ctx->to_bt_scaler = UINT64_C( 1 ) << 31; ctx->to_bt_scaler = UINT64_C( 1 ) << 31;
ctx->handler = handler; ctx->handler = handler;
@@ -701,6 +641,12 @@ void rtems_record_client_init(
ctx->todo = sizeof( ctx->header ); ctx->todo = sizeof( ctx->header );
ctx->pos = &ctx->header; ctx->pos = &ctx->header;
ctx->consume = consume_init; ctx->consume = consume_init;
for ( cpu = 0; cpu < RTEMS_RECORD_CLIENT_MAXIMUM_CPU_COUNT; ++cpu ) {
ctx->per_cpu[ cpu ].hold_back = true;
}
return RTEMS_RECORD_CLIENT_SUCCESS;
} }
rtems_record_client_status rtems_record_client_run( rtems_record_client_status rtems_record_client_run(
@@ -712,6 +658,44 @@ rtems_record_client_status rtems_record_client_run(
return ( *ctx->consume )( ctx, buf, n ); return ( *ctx->consume )( ctx, buf, n );
} }
static void calculate_best_effort_uptime(
rtems_record_client_context *ctx,
rtems_record_client_per_cpu *per_cpu
)
{
rtems_record_item_64 *items;
uint32_t last;
uint64_t accumulated;
size_t index;
items = per_cpu->items;
accumulated = 0;
if ( per_cpu->uptime.uptime_bt != 0 ) {
last = per_cpu->uptime.time_last;
} else {
last = RTEMS_RECORD_GET_TIME( items[ 0 ].event );
}
for ( index = 0; index < per_cpu->item_index; ++index ) {
uint32_t time_event;
time_event = items[ index ].event;
if ( has_time( RTEMS_RECORD_GET_EVENT( time_event ) ) ) {
uint32_t time;
time = RTEMS_RECORD_GET_TIME( time_event );
accumulated += ( time - last ) & TIME_MASK;
last = time;
}
}
per_cpu->uptime.uptime_bt += ( accumulated * ctx->to_bt_scaler ) >> 31;
per_cpu->uptime.time_last = last;
per_cpu->uptime.time_accumulated = 0;
}
void rtems_record_client_destroy( void rtems_record_client_destroy(
rtems_record_client_context *ctx rtems_record_client_context *ctx
) )
@@ -723,10 +707,12 @@ void rtems_record_client_destroy(
ctx->cpu = cpu; ctx->cpu = cpu;
per_cpu = &ctx->per_cpu[ cpu ]; per_cpu = &ctx->per_cpu[ cpu ];
per_cpu->head[ per_cpu->tail_head_index ^ 1 ] =
per_cpu->head[ per_cpu->tail_head_index ];
resolve_hold_back( ctx, per_cpu );
}
free( ctx->per_cpu[ 0 ].items ); if ( per_cpu->hold_back && per_cpu->item_index > 0 ) {
calculate_best_effort_uptime( ctx, per_cpu );
(void) resolve_hold_back( ctx, per_cpu );
}
free( per_cpu->items );
}
} }

View File

@@ -53,25 +53,25 @@ static rtems_record_client_status client_handler(
void *arg void *arg
) )
{ {
uint32_t seconds;
uint32_t nanoseconds;
(void) arg; (void) arg;
if ( bt != 0 ) { if (event == RTEMS_RECORD_USER_5) {
uint32_t seconds; return RTEMS_RECORD_CLIENT_SUCCESS;
uint32_t nanoseconds;
rtems_record_client_bintime_to_seconds_and_nanoseconds(
bt,
&seconds,
&nanoseconds
);
printf( "%" PRIu32 ".%09" PRIu32 ":", seconds, nanoseconds );
} else {
printf( "*:" );
} }
rtems_record_client_bintime_to_seconds_and_nanoseconds(
bt,
&seconds,
&nanoseconds
);
printf( printf(
"%" PRIu32 ".%09" PRIu32 ":"
"%" PRIu32 ":%s:%" PRIx64 "\n", "%" PRIu32 ":%s:%" PRIx64 "\n",
seconds,
nanoseconds,
cpu, cpu,
rtems_record_event_text( event ), rtems_record_event_text( event ),
data data
@@ -163,7 +163,17 @@ static void fetch(test_context *ctx)
); );
rtems_test_assert(cs == RTEMS_RECORD_CLIENT_SUCCESS); rtems_test_assert(cs == RTEMS_RECORD_CLIENT_SUCCESS);
} while (fs == RTEMS_RECORD_FETCH_CONTINUE); } while (fs == RTEMS_RECORD_FETCH_CONTINUE);
}
static void overflow(void)
{
int i;
for (i = 0; i < 512; ++i) {
rtems_record_produce(RTEMS_RECORD_USER_5, 0);
}
rtems_record_produce(RTEMS_RECORD_USER_6, 0);
} }
static void Init(rtems_task_argument arg) static void Init(rtems_task_argument arg)
@@ -172,17 +182,25 @@ static void Init(rtems_task_argument arg)
Record_Stream_header header; Record_Stream_header header;
size_t size; size_t size;
rtems_record_client_status cs; rtems_record_client_status cs;
rtems_interrupt_level level;
TEST_BEGIN(); TEST_BEGIN();
ctx = &test_instance; ctx = &test_instance;
generate_events(); generate_events();
rtems_record_client_init(&ctx->client, client_handler, NULL); cs = rtems_record_client_init(&ctx->client, client_handler, NULL);
rtems_test_assert(cs == RTEMS_RECORD_CLIENT_SUCCESS);
size = _Record_Stream_header_initialize(&header); size = _Record_Stream_header_initialize(&header);
cs = rtems_record_client_run(&ctx->client, &header, size); cs = rtems_record_client_run(&ctx->client, &header, size);
rtems_test_assert(cs == RTEMS_RECORD_CLIENT_SUCCESS); rtems_test_assert(cs == RTEMS_RECORD_CLIENT_SUCCESS);
fetch(ctx); fetch(ctx);
rtems_interrupt_local_disable(level);
overflow();
fetch(ctx);
rtems_interrupt_local_enable(level);
rtems_record_client_destroy(&ctx->client); rtems_record_client_destroy(&ctx->client);
generate_events(); generate_events();