From 614466e7f4ba7116cf55955e2b2e5d556f896068 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 17 Dec 2018 06:40:05 +0100 Subject: record --- cpukit/include/rtems/record.h | 65 +++++++++++------------------ cpukit/include/rtems/recorddata.h | 2 +- cpukit/libmisc/capture/record-static.c | 13 ++---- cpukit/libmisc/capture/record-userext.c | 36 +++++----------- cpukit/libmisc/capture/record.c | 23 ++++++++--- testsuites/libtests/record01/init.c | 73 ++++++++++++++++----------------- 6 files changed, 90 insertions(+), 122 deletions(-) diff --git a/cpukit/include/rtems/record.h b/cpukit/include/rtems/record.h index 8535ce4d06..57b1eaeb8b 100644 --- a/cpukit/include/rtems/record.h +++ b/cpukit/include/rtems/record.h @@ -56,8 +56,6 @@ typedef struct Record_Configured_control Record_Configured_control; typedef struct { Record_Control *control; unsigned int head; - unsigned int increment; - unsigned int final_head; uint32_t now; rtems_interrupt_level level; } rtems_record_context; @@ -106,13 +104,12 @@ static inline unsigned int _Record_Capacity( return ( tail - head - 1U ) & control->mask; } -static inline unsigned int _Record_Increment( +static inline unsigned int _Record_Index( const Record_Control *control, - unsigned int index, - unsigned int increment + unsigned int index ) { - return ( index + increment ) & control->mask; + return index & control->mask; } static inline unsigned int _Record_Head( const Record_Control *control ) @@ -125,22 +122,25 @@ static inline unsigned int _Record_Tail( const Record_Control *control ) return _Atomic_Load_uint( &control->tail, ATOMIC_ORDER_RELAXED ); } +static inline bool _Record_Is_overflow( + const Record_Control *control, + unsigned int tail +) +{ + return _Record_Head( control ) - tail >= ( control->mask + 1U ); +} + static inline rtems_counter_ticks _Record_Now( void ) { return rtems_counter_read(); } -static inline void rtems_record_prepare_inline( - rtems_record_context *context, - unsigned int count -) +static inline void rtems_record_prepare_inline( rtems_record_context *context ) { rtems_interrupt_level level; const Per_CPU_Control *cpu_self; Record_Control *control; unsigned int head; - unsigned int tail; - unsigned int capacity; rtems_interrupt_local_disable( level ); context->now = RTEMS_RECORD_TIME_EVENT( _Record_Now(), 0 ); @@ -149,18 +149,7 @@ static inline void rtems_record_prepare_inline( control = cpu_self->record; context->control = control; head = _Record_Head( control ); - tail = _Record_Tail( control ); - capacity = _Record_Capacity( control, head, tail ); context->head = head; - - if ( RTEMS_PREDICT_TRUE( capacity > count ) ) { - context->increment = 1; - } else { - context->increment = 0; - count = capacity > 0 ? 1U : 0U; - } - - context->final_head = _Record_Increment( control, head, count ); } static inline void rtems_record_add_inline( @@ -175,13 +164,10 @@ static inline void rtems_record_add_inline( control = context->control; head = context->head; - item = &control->Items[ head ]; - context->head = _Record_Increment( control, head, context->increment ); + item = &control->Items[ _Record_Index( control, head ) ]; + context->head = head + 1; - item->event = RTEMS_RECORD_TIME_EVENT( - context->now, - event & -( (uint32_t) context->increment ) - ); + item->event = RTEMS_RECORD_TIME_EVENT( context->now, event ); item->data = data; } @@ -194,23 +180,13 @@ static inline void rtems_record_commit_inline( rtems_record_add_inline( context, event, data ); _Atomic_Store_uint( &context->control->head, - context->final_head, + context->head, ATOMIC_ORDER_RELEASE ); rtems_interrupt_local_enable( context->level ); } -static inline bool rtems_record_is_overflow( - const rtems_record_context *context -) -{ - return context->increment == 0; -} - -rtems_record_context *rtems_record_prepare( - rtems_record_context *context, - unsigned int count -); +rtems_record_context *rtems_record_prepare( rtems_record_context *context ); rtems_record_context *rtems_record_add( rtems_record_context *context, @@ -226,6 +202,13 @@ void rtems_record_commit( void rtems_record_produce( rtems_record_event event, rtems_record_data data ); +void rtems_record_produce_2( + rtems_record_event event_0, + rtems_record_data data_0, + rtems_record_event event_1, + rtems_record_data data_1 +); + typedef void ( *rtems_record_visitor )( const rtems_record_item *items, size_t count, diff --git a/cpukit/include/rtems/recorddata.h b/cpukit/include/rtems/recorddata.h index 39d465aa7b..4f14984c51 100644 --- a/cpukit/include/rtems/recorddata.h +++ b/cpukit/include/rtems/recorddata.h @@ -46,7 +46,7 @@ extern "C" { typedef enum { /* There are 512 events reserved for the system */ - RTEMS_RECORD_EVENT_OVERFLOW, + RTEMS_RECORD_EVENT_EMPTY, RTEMS_RECORD_EVENT_VERSION, /* Keep in lexicographical order */ diff --git a/cpukit/libmisc/capture/record-static.c b/cpukit/libmisc/capture/record-static.c index f6dfd8b000..825c4412b5 100644 --- a/cpukit/libmisc/capture/record-static.c +++ b/cpukit/libmisc/capture/record-static.c @@ -56,9 +56,7 @@ static void _Record_Watchdog( Per_CPU_Control *cpu ) { - rtems_record_context context_storage; - rtems_record_context *context; - sbintime_t now; + sbintime_t now; _Watchdog_Per_CPU_reinsert_ticks( watchdog, @@ -66,15 +64,10 @@ static void _Record_Watchdog( _Watchdog_Ticks_per_second ); - context = rtems_record_prepare( &context_storage, 2 ); now = _Timecounter_Sbinuptime(); - context = rtems_record_add( - context, + rtems_record_produce_2( RTEMS_RECORD_EVENT_UPTIME_LOW, - (uint32_t) ( now >> 0 ) - ); - rtems_record_commit( - context, + (uint32_t) ( now >> 0 ), RTEMS_RECORD_EVENT_UPTIME_HIGH, (uint32_t) ( now >> 32 ) ); diff --git a/cpukit/libmisc/capture/record-userext.c b/cpukit/libmisc/capture/record-userext.c index 39f61eace8..3a91f64693 100644 --- a/cpukit/libmisc/capture/record-userext.c +++ b/cpukit/libmisc/capture/record-userext.c @@ -33,28 +33,20 @@ bool _Record_Thread_create( struct _Thread_Control *created ) { - rtems_record_context context_storage; - rtems_record_context *context; - Objects_Id id; - - context = rtems_record_prepare( &context_storage, 2 ); - context = rtems_record_add( - context, - RTEMS_RECORD_EVENT_THREAD_CREATED, - created->Object.id - ); + Objects_Id created_by; /* The idle threads are created without an executing thread */ if ( executing != NULL ) { - id = executing->Object.id; + created_by = executing->Object.id; } else { - id = 0; + created_by = 0; } - rtems_record_commit( - context, + rtems_record_produce_2( + RTEMS_RECORD_EVENT_THREAD_CREATED, + created->Object.id, RTEMS_RECORD_EVENT_THREAD_CREATED_BY, - id + created_by ); return true; @@ -65,17 +57,9 @@ void _Record_Thread_delete( struct _Thread_Control *deleted ) { - rtems_record_context context_storage; - rtems_record_context *context; - - context = rtems_record_prepare( &context_storage, 2 ); - context = rtems_record_add( - context, + rtems_record_produce_2( RTEMS_RECORD_EVENT_THREAD_DELETED, - deleted->Object.id - ); - rtems_record_commit( - context, + deleted->Object.id, RTEMS_RECORD_EVENT_THREAD_DELETED_BY, executing->Object.id ); @@ -89,7 +73,7 @@ void _Record_Thread_switch( rtems_record_context context_storage; rtems_record_context *context; - context = rtems_record_prepare( &context_storage, 3 ); + context = rtems_record_prepare( &context_storage ); context = rtems_record_add( context, RTEMS_RECORD_EVENT_THREAD_SWITCH_OUT, diff --git a/cpukit/libmisc/capture/record.c b/cpukit/libmisc/capture/record.c index b87043fbbc..ed9185a300 100644 --- a/cpukit/libmisc/capture/record.c +++ b/cpukit/libmisc/capture/record.c @@ -30,12 +30,9 @@ #include -rtems_record_context *rtems_record_prepare( - rtems_record_context *context, - unsigned int count -) +rtems_record_context *rtems_record_prepare( rtems_record_context *context ) { - rtems_record_prepare_inline( context, count ); + rtems_record_prepare_inline( context ); return context; } @@ -62,10 +59,24 @@ void rtems_record_produce( rtems_record_event event, rtems_record_data data ) { rtems_record_context context; - rtems_record_prepare_inline( &context, 1 ); + rtems_record_prepare_inline( &context ); rtems_record_commit_inline( &context, event, data ); } +void rtems_record_produce_2( + rtems_record_event event_0, + rtems_record_data data_0, + rtems_record_event event_1, + rtems_record_data data_1 +) +{ + rtems_record_context context; + + rtems_record_prepare_inline( &context ); + rtems_record_add_inline( &context, event_0, data_0 ); + rtems_record_commit_inline( &context, event_1, data_1 ); +} + void rtems_record_drain( rtems_record_visitor visitor, void *arg ) { rtems_record_item item; diff --git a/testsuites/libtests/record01/init.c b/testsuites/libtests/record01/init.c index 8b71ed3c61..d5390dff49 100644 --- a/testsuites/libtests/record01/init.c +++ b/testsuites/libtests/record01/init.c @@ -75,40 +75,43 @@ static const rtems_record_item expected_items_1[ITEM_COUNT] = { static const rtems_record_item expected_items_2[ITEM_COUNT] = { { .event = TE(2, UE(1)), .data = 3 }, { .event = TE(6, UE(5)), .data = 7 }, - { .event = TE(10, RTEMS_RECORD_EVENT_OVERFLOW), .data = 11 } + { .event = TE(10, UE(9)), .data = 11 } }; static const rtems_record_item expected_items_3[ITEM_COUNT] = { { .event = TE(2, UE(1)), .data = 3 }, { .event = TE(6, UE(5)), .data = 7 }, - { .event = TE(10, RTEMS_RECORD_EVENT_OVERFLOW), .data = 11 }, - { .event = TE(14, RTEMS_RECORD_EVENT_OVERFLOW), .data = 15 } + { .event = TE(10, UE(9)), .data = 11 }, + { .event = TE(14, UE(13)), .data = 15 } }; static const rtems_record_item expected_items_4[ITEM_COUNT] = { - { .event = TE(2, UE(1)), .data = 3 }, + { .event = TE(18, UE(17)), .data = 19 }, { .event = TE(6, UE(5)), .data = 7 }, - { .event = TE(10, RTEMS_RECORD_EVENT_OVERFLOW), .data = 11 }, - { .event = TE(18, RTEMS_RECORD_EVENT_OVERFLOW), .data = 19 } + { .event = TE(10, UE(9)), .data = 11 }, + { .event = TE(14, UE(13)), .data = 15 } }; static const rtems_record_item expected_items_5[ITEM_COUNT] = { - { .event = TE(2, RTEMS_RECORD_EVENT_OVERFLOW), .data = 3 } + { .event = TE(2, UE(1)), .data = 3 } }; static const rtems_record_item expected_items_6[ITEM_COUNT] = { - { .event = TE(6, RTEMS_RECORD_EVENT_OVERFLOW), .data = 7 } + { .event = TE(2, UE(1)), .data = 3 }, + { .event = TE(6, UE(5)), .data = 7 } }; static const rtems_record_item expected_items_7[ITEM_COUNT] = { - { .event = TE(10, RTEMS_RECORD_EVENT_OVERFLOW), .data = 11 } + { .event = TE(2, UE(1)), .data = 3 }, + { .event = TE(6, UE(5)), .data = 7 }, + { .event = TE(10, UE(9)), .data = 11 } }; static const rtems_record_item expected_items_8[] = { { .event = TE(0, RTEMS_RECORD_EVENT_PROCESSOR), .data = 0 }, { .event = TE(2, UE(1)), .data = 3 }, { .event = TE(5, UE(4)), .data = 6 }, - { .event = TE(8, RTEMS_RECORD_EVENT_OVERFLOW), .data = 9 } + { .event = TE(8, UE(7)), .data = 9 } }; static const rtems_record_item expected_items_9[] = { @@ -121,7 +124,7 @@ static const rtems_record_item expected_items_10[] = { { .event = TE(0, RTEMS_RECORD_EVENT_PROCESSOR), .data = 0 }, { .event = TE(17, UE(16)), .data = 18 }, { .event = TE(20, UE(19)), .data = 21 }, - { .event = TE(23, RTEMS_RECORD_EVENT_OVERFLOW), .data = 24 } + { .event = TE(23, UE(22)), .data = 24 } }; static const rtems_record_item expected_items_11[] = { @@ -164,24 +167,24 @@ static void test_capacity(const Record_Control *control) rtems_test_assert(capacity == 0); } -static void test_increment(const Record_Control *control) +static void test_index(const Record_Control *control) { - unsigned int next; + unsigned int index; - next = _Record_Increment(control, 0, 1); - rtems_test_assert(next == 1); + index = _Record_Index(control, 0); + rtems_test_assert(index == 0); - next = _Record_Increment(control, 1, 1); - rtems_test_assert(next == 2); + index = _Record_Index(control, 1); + rtems_test_assert(index == 1); - next = _Record_Increment(control, 2, 1); - rtems_test_assert(next == 3); + index = _Record_Index(control, 2); + rtems_test_assert(index == 2); - next = _Record_Increment(control, 3, 1); - rtems_test_assert(next == 0); + index = _Record_Index(control, 3); + rtems_test_assert(index == 3); - next = _Record_Increment(control, 3, 0); - rtems_test_assert(next == 3); + index = _Record_Index(control, 4); + rtems_test_assert(index == 0); } static void test_prepare_2(test_context *ctx, Record_Control *control) @@ -190,12 +193,9 @@ static void test_prepare_2(test_context *ctx, Record_Control *control) init_context(ctx); - rtems_record_prepare(&rc, 2); - rtems_test_assert(!rtems_record_is_overflow(&rc)); + rtems_record_prepare(&rc); rtems_test_assert(rc.control == control); rtems_test_assert(rc.head == 0); - rtems_test_assert(rc.increment == 1); - rtems_test_assert(rc.final_head == 2); rtems_test_assert(_Record_Head(control) == 0); rtems_test_assert(_Record_Tail(control) == 0); @@ -220,34 +220,31 @@ static void test_prepare_3(test_context *ctx, Record_Control *control) init_context(ctx); - rtems_record_prepare(&rc, 3); - rtems_test_assert(rtems_record_is_overflow(&rc)); + rtems_record_prepare(&rc); rtems_test_assert(rc.control == control); rtems_test_assert(rc.head == 0); - rtems_test_assert(rc.increment == 0); - rtems_test_assert(rc.final_head == 1); rtems_test_assert(_Record_Head(control) == 0); rtems_test_assert(_Record_Tail(control) == 0); rc.now = 2; rtems_record_add(&rc, UE(1), 3); - rtems_test_assert(rc.head == 0); + rtems_test_assert(rc.head == 1); rtems_test_assert(memcmp(control->Items, expected_items_5, ITEM_SIZE) == 0); rtems_test_assert(_Record_Head(control) == 0); rtems_test_assert(_Record_Tail(control) == 0); rc.now = 6; rtems_record_add(&rc, UE(5), 7); - rtems_test_assert(rc.head == 0); + rtems_test_assert(rc.head == 2); rtems_test_assert(memcmp(control->Items, expected_items_6, ITEM_SIZE) == 0); rtems_test_assert(_Record_Head(control) == 0); rtems_test_assert(_Record_Tail(control) == 0); rc.now = 10; rtems_record_commit(&rc, UE(9), 11); - rtems_test_assert(rc.head == 0); + rtems_test_assert(rc.head == 3); rtems_test_assert(memcmp(control->Items, expected_items_7, ITEM_SIZE) == 0); - rtems_test_assert(_Record_Head(control) == 1); + rtems_test_assert(_Record_Head(control) == 3); rtems_test_assert(_Record_Tail(control) == 0); } @@ -286,13 +283,13 @@ static void test_produce(test_context *ctx, Record_Control *control) rtems_record_produce(UE(13), 15); set_time(&control->Items[3], 14); rtems_test_assert(memcmp(control->Items, expected_items_3, ITEM_SIZE) == 0); - rtems_test_assert(_Record_Head(control) == 3); + rtems_test_assert(_Record_Head(control) == 4); rtems_test_assert(_Record_Tail(control) == 0); rtems_record_produce(UE(17), 19); set_time(&control->Items[3], 18); rtems_test_assert(memcmp(control->Items, expected_items_4, ITEM_SIZE) == 0); - rtems_test_assert(_Record_Head(control) == 3); + rtems_test_assert(_Record_Head(control) == 5); rtems_test_assert(_Record_Tail(control) == 0); } @@ -540,7 +537,7 @@ static void Init(rtems_task_argument arg) init_context(ctx); test_capacity(&ctx->control); - test_increment(&ctx->control); + test_index(&ctx->control); test_prepare_2(ctx, &ctx->control); test_prepare_3(ctx, &ctx->control); test_produce(ctx, &ctx->control); -- cgit v1.2.3