From 7bdb765a67812750b9454d2940512da9fec16d38 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Fri, 12 Dec 2014 08:46:30 +0100 Subject: Add POSIX key value pairs to resource snapshot --- cpukit/libcsupport/include/rtems/libcsupport.h | 3 +- cpukit/libcsupport/src/resource_snapshot.c | 54 ++++++++++++++++++++------ testsuites/psxtests/psxconfig01/init.c | 44 ++++++++++++++------- 3 files changed, 74 insertions(+), 27 deletions(-) diff --git a/cpukit/libcsupport/include/rtems/libcsupport.h b/cpukit/libcsupport/include/rtems/libcsupport.h index c1bb9a191c..e4ae0aea63 100644 --- a/cpukit/libcsupport/include/rtems/libcsupport.h +++ b/cpukit/libcsupport/include/rtems/libcsupport.h @@ -118,7 +118,6 @@ typedef struct { typedef struct { uint32_t active_barriers; uint32_t active_condition_variables; - uint32_t active_keys; uint32_t active_message_queues; uint32_t active_message_queue_descriptors; uint32_t active_mutexes; @@ -132,6 +131,8 @@ typedef struct { typedef struct { Heap_Information_block workspace_info; Heap_Information_block heap_info; + uint32_t active_posix_key_value_pairs; + uint32_t active_posix_keys; rtems_resource_rtems_api rtems_api; rtems_resource_posix_api posix_api; int open_files; diff --git a/cpukit/libcsupport/src/resource_snapshot.c b/cpukit/libcsupport/src/resource_snapshot.c index 6e4c4ca86f..6bba22671b 100644 --- a/cpukit/libcsupport/src/resource_snapshot.c +++ b/cpukit/libcsupport/src/resource_snapshot.c @@ -1,8 +1,8 @@ /* - * Copyright (c) 2012 embedded brains GmbH. All rights reserved. + * Copyright (c) 2012-2014 embedded brains GmbH. All rights reserved. * * embedded brains GmbH - * Obere Lagerstr. 30 + * Dornierstr. 4 * 82178 Puchheim * Germany * @@ -22,13 +22,15 @@ #include #include +#include #include #include #include -#include +#include #include +#include #include #include #include @@ -43,7 +45,6 @@ #include #include #include - #include #include #include #include @@ -52,7 +53,8 @@ #include #endif -static const Objects_Information *objects_info_table[] = { +static const Objects_Information *const objects_info_table[] = { + &_POSIX_Keys_Information, &_Barrier_Information, &_Extension_Information, &_Message_queue_Information, @@ -67,7 +69,6 @@ static const Objects_Information *objects_info_table[] = { , &_POSIX_Barrier_Information, &_POSIX_Condition_variables_Information, - &_POSIX_Keys_Information, &_POSIX_Message_queue_Information, &_POSIX_Message_queue_Information_fds, &_POSIX_Mutex_Information, @@ -104,11 +105,45 @@ static void get_heap_info(Heap_Control *heap, Heap_Information_block *info) memset(&info->Stats, 0, sizeof(info->Stats)); } +static bool count_posix_key_value_pairs( + const RBTree_Node *node, + RBTree_Direction dir, + void *visitor_arg +) +{ + uint32_t *count = visitor_arg; + + (void) node; + (void) dir; + + ++(*count); + + return false; +} + +static uint32_t get_active_posix_key_value_pairs(void) +{ + uint32_t count = 0; + + _Thread_Disable_dispatch(); + _RBTree_Iterate( + &_POSIX_Keys_Key_value_lookup_tree, + RBT_LEFT, + count_posix_key_value_pairs, + &count + ); + _Thread_Enable_dispatch(); + + return count; +} + void rtems_resource_snapshot_take(rtems_resource_snapshot *snapshot) { - uint32_t *active = &snapshot->rtems_api.active_barriers; + uint32_t *active = &snapshot->active_posix_keys; size_t i; + memset(snapshot, 0, sizeof(*snapshot)); + _RTEMS_Lock_allocator(); _Thread_Kill_zombies(); @@ -122,10 +157,7 @@ void rtems_resource_snapshot_take(rtems_resource_snapshot *snapshot) _RTEMS_Unlock_allocator(); - #ifndef RTEMS_POSIX_API - memset(&snapshot->posix_api, 0, sizeof(snapshot->posix_api)); - #endif - + snapshot->active_posix_key_value_pairs = get_active_posix_key_value_pairs(); snapshot->open_files = open_files(); } diff --git a/testsuites/psxtests/psxconfig01/init.c b/testsuites/psxtests/psxconfig01/init.c index afce9f6c5f..61beec3495 100644 --- a/testsuites/psxtests/psxconfig01/init.c +++ b/testsuites/psxtests/psxconfig01/init.c @@ -8,10 +8,10 @@ /* * Copyright (c) 2014. On-Line Applications Research Corporation (OAR). - * Copyright (c) 2011-2012 embedded brains GmbH. All rights reserved. + * Copyright (c) 2011-2014 embedded brains GmbH. All rights reserved. * * embedded brains GmbH - * Obere Lagerstr. 30 + * Dornierstr. 4 * 82178 Puchheim * Germany * @@ -45,6 +45,11 @@ const char rtems_test_name[] = "PSXCONFIG 1"; #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5 +#define CONFIGURE_MAXIMUM_POSIX_KEYS 23 +#ifdef CONFIGURE_MAXIMUM_POSIX_KEYS + #define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS CONFIGURE_MAXIMUM_POSIX_KEYS +#endif + #define CONFIGURE_MAXIMUM_BARRIERS 2 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 7 #define CONFIGURE_MAXIMUM_PARTITIONS 37 @@ -60,7 +65,6 @@ const char rtems_test_name[] = "PSXCONFIG 1"; #define CONFIGURE_MAXIMUM_POSIX_BARRIERS 31 #define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 29 -#define CONFIGURE_MAXIMUM_POSIX_KEYS 23 #define POSIX_MQ_COUNT 5 #define CONFIGURE_MAXIMUM_POSIX_MUTEXES 19 #define CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS 7 @@ -262,6 +266,7 @@ static rtems_task Init(rtems_task_argument argument) rtems_extensions_table table; rtems_resource_snapshot snapshot; int i = 0; + pthread_key_t key; TEST_BEGIN(); @@ -299,6 +304,27 @@ static rtems_task Init(rtems_task_argument argument) ); #endif +#ifdef CONFIGURE_MAXIMUM_POSIX_KEYS + for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_KEYS; ++i) { + eno = pthread_key_create(&key, posix_key_dtor); + rtems_test_assert(eno == 0); + + eno = pthread_setspecific(key, (void *) (i + 1)); + rtems_test_assert(eno == 0); + } + eno = pthread_key_create(&key, posix_key_dtor); + rtems_test_assert(eno == EAGAIN); + rtems_resource_snapshot_take(&snapshot); + rtems_test_assert( + snapshot.active_posix_keys == CONFIGURE_POSIX_KEYS + ); + rtems_test_assert( + snapshot.active_posix_key_value_pairs == CONFIGURE_MAXIMUM_POSIX_KEYS + ); +#else + (void) key; +#endif + #ifdef CONFIGURE_MAXIMUM_BARRIERS for (i = 0; i < CONFIGURE_MAXIMUM_BARRIERS; ++i) { sc = rtems_barrier_create(name, RTEMS_DEFAULT_ATTRIBUTES, 1, &id); @@ -455,18 +481,6 @@ static rtems_task Init(rtems_task_argument argument) ); #endif -#ifdef CONFIGURE_MAXIMUM_POSIX_KEYS - for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_KEYS; ++i) { - pthread_key_t key; - eno = pthread_key_create(&key, posix_key_dtor); - rtems_test_assert(eno == 0); - } - rtems_resource_snapshot_take(&snapshot); - rtems_test_assert( - snapshot.posix_api.active_keys == CONFIGURE_POSIX_KEYS - ); -#endif - #ifdef POSIX_MQ_COUNT for (i = 0; i < POSIX_MQ_COUNT; ++i) { int oflag = O_RDWR | O_CREAT | O_EXCL; -- cgit v1.2.3