summaryrefslogtreecommitdiffstats
path: root/cpukit
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2012-12-21 10:59:04 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2012-12-21 15:45:51 +0100
commitc5d27600f99a259430a73630255cbb01d397f96d (patch)
tree2f359ebd683beadb26ba5422f2084841c9c6562e /cpukit
parentscore: Add _Objects_Active_count() (diff)
downloadrtems-c5d27600f99a259430a73630255cbb01d397f96d.tar.bz2
libcsupport: Add rtems_resource_snapshot_take()
Add rtems_resource_rtems_api, rtems_resource_posix_api, rtems_resource_snapshot, rtems_resource_snapshot_equal(), and rtems_resource_snapshot_check().
Diffstat (limited to 'cpukit')
-rw-r--r--cpukit/libcsupport/Makefile.am1
-rw-r--r--cpukit/libcsupport/include/rtems/libcsupport.h87
-rw-r--r--cpukit/libcsupport/src/resource_snapshot.c127
3 files changed, 215 insertions, 0 deletions
diff --git a/cpukit/libcsupport/Makefile.am b/cpukit/libcsupport/Makefile.am
index 703ef60199..76147c9873 100644
--- a/cpukit/libcsupport/Makefile.am
+++ b/cpukit/libcsupport/Makefile.am
@@ -136,6 +136,7 @@ libcsupport_a_SOURCES = src/gxx_wrappers.c src/getchark.c src/printk.c \
src/sup_fs_deviceerrno.c \
src/clonenode.c \
src/freenode.c \
+ src/resource_snapshot.c \
$(BSD_LIBC_C_FILES) $(BASE_FS_C_FILES) $(MALLOC_C_FILES) \
$(ERROR_C_FILES) $(ASSOCIATION_C_FILES)
diff --git a/cpukit/libcsupport/include/rtems/libcsupport.h b/cpukit/libcsupport/include/rtems/libcsupport.h
index 81e2156ba4..2c498848b5 100644
--- a/cpukit/libcsupport/include/rtems/libcsupport.h
+++ b/cpukit/libcsupport/include/rtems/libcsupport.h
@@ -99,6 +99,93 @@ void newlib_delete_hook(
0 /* fatal */ \
}
+typedef struct {
+ uint32_t active_barriers;
+ uint32_t active_extensions;
+ uint32_t active_message_queues;
+ uint32_t active_partitions;
+ uint32_t active_periods;
+ uint32_t active_ports;
+ uint32_t active_regions;
+ uint32_t active_semaphores;
+ uint32_t active_tasks;
+ uint32_t active_timers;
+} rtems_resource_rtems_api;
+
+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;
+ uint32_t active_rwlocks;
+ uint32_t active_semaphores;
+ uint32_t active_spinlocks;
+ uint32_t active_threads;
+ uint32_t active_timers;
+} rtems_resource_posix_api;
+
+typedef struct {
+ Heap_Information_block workspace_info;
+ Heap_Information_block heap_info;
+ rtems_resource_rtems_api rtems_api;
+ rtems_resource_posix_api posix_api;
+ int open_files;
+} rtems_resource_snapshot;
+
+/**
+ * @brief Tasks a snapshot of the resource usage of the system.
+ *
+ * @param[out] snapshot The snapshot of used resources.
+ *
+ * @see rtems_resource_snapshot_equal() and rtems_resource_snapshot_check().
+ *
+ * @code
+ * #include <assert.h>
+ *
+ * #include <rtems/libcsupport.h>
+ *
+ * void example(void)
+ * {
+ * rtems_resource_snapshot before;
+ *
+ * test_setup();
+ * rtems_resource_snapshot_take(&before);
+ * test();
+ * assert(rtems_resource_snapshot_check(&before));
+ * test_cleanup();
+ * }
+ * @endcode
+ */
+void rtems_resource_snapshot_take(rtems_resource_snapshot *snapshot);
+
+/**
+ * @brief Compares two resource snapshots for equality.
+ *
+ * @return Returns true if the resource snapshots are equal, and false
+ * otherwise.
+ *
+ * @see rtems_resource_snapshot_take().
+ */
+bool rtems_resource_snapshot_equal(
+ const rtems_resource_snapshot *a,
+ const rtems_resource_snapshot *b
+);
+
+/**
+ * @brief Takes a new resource snapshot and checks that it is equal to the
+ * given snapshot.
+ *
+ * @param[in] snapshot The snapshot used for comparison with the new snapshot.
+ *
+ * @return Returns true if the resource snapshots are equal, and false
+ * otherwise.
+ *
+ * @see rtems_resource_snapshot_take().
+ */
+bool rtems_resource_snapshot_check(const rtems_resource_snapshot *snapshot);
+
#ifdef __cplusplus
}
#endif
diff --git a/cpukit/libcsupport/src/resource_snapshot.c b/cpukit/libcsupport/src/resource_snapshot.c
new file mode 100644
index 0000000000..e143fdf9ad
--- /dev/null
+++ b/cpukit/libcsupport/src/resource_snapshot.c
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2012 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include <rtems/libcsupport.h>
+
+#include <string.h>
+
+#include <rtems/libio_.h>
+#include <rtems/malloc.h>
+#include <rtems/score/wkspace.h>
+#include <rtems/score/protectedheap.h>
+
+#ifdef RTEMS_POSIX_API
+ #include <rtems/posix/barrier.h>
+ #include <rtems/posix/cond.h>
+ #include <rtems/posix/mqueue.h>
+ #include <rtems/posix/mutex.h>
+ #include <rtems/posix/key.h>
+ #include <rtems/posix/psignal.h>
+ #include <rtems/posix/pthread.h>
+ #include <rtems/posix/rwlock.h>
+ #include <rtems/posix/semaphore.h>
+ #include <rtems/posix/spinlock.h>
+ #include <rtems/posix/timer.h>
+#endif
+
+static const Objects_Information *objects_info_table[] = {
+ &_Barrier_Information,
+ &_Extension_Information,
+ &_Message_queue_Information,
+ &_Partition_Information,
+ &_Rate_monotonic_Information,
+ &_Dual_ported_memory_Information,
+ &_Region_Information,
+ &_Semaphore_Information,
+ &_RTEMS_tasks_Information,
+ &_Timer_Information
+ #ifdef RTEMS_POSIX_API
+ ,
+ &_POSIX_Barrier_Information,
+ &_POSIX_Condition_variables_Information,
+ &_POSIX_Keys_Information,
+ &_POSIX_Message_queue_Information,
+ &_POSIX_Message_queue_Information_fds,
+ &_POSIX_Mutex_Information,
+ &_POSIX_RWLock_Information,
+ &_POSIX_Semaphore_Information,
+ &_POSIX_Spinlock_Information,
+ &_POSIX_Threads_Information,
+ &_POSIX_Timer_Information
+ #endif
+};
+
+static int open_files(void)
+{
+ int free_count = 0;
+ rtems_libio_t *iop;
+
+ rtems_libio_lock();
+
+ iop = rtems_libio_iop_freelist;
+ while (iop != NULL) {
+ ++free_count;
+
+ iop = iop->data1;
+ }
+
+ rtems_libio_unlock();
+
+ return (int) rtems_libio_number_iops - free_count;
+}
+
+void rtems_resource_snapshot_take(rtems_resource_snapshot *snapshot)
+{
+ uint32_t *active = &snapshot->rtems_api.active_barriers;
+ size_t i;
+
+ _Protected_heap_Get_information(RTEMS_Malloc_Heap, &snapshot->heap_info);
+
+ _Thread_Disable_dispatch();
+
+ _Heap_Get_information(&_Workspace_Area, &snapshot->workspace_info);
+
+ for (i = 0; i < RTEMS_ARRAY_SIZE(objects_info_table); ++i) {
+ active [i] = _Objects_Active_count(objects_info_table[i]);
+ }
+
+ _Thread_Enable_dispatch();
+
+ #ifndef RTEMS_POSIX_API
+ memset(&snapshot->posix_api, 0, sizeof(snapshot->posix_api));
+ #endif
+
+ snapshot->open_files = open_files();
+}
+
+bool rtems_resource_snapshot_equal(
+ const rtems_resource_snapshot *a,
+ const rtems_resource_snapshot *b
+)
+{
+ return memcmp(a, b, sizeof(*a)) == 0;
+}
+
+bool rtems_resource_snapshot_check(const rtems_resource_snapshot *snapshot)
+{
+ rtems_resource_snapshot now;
+
+ rtems_resource_snapshot_take(&now);
+
+ return rtems_resource_snapshot_equal(&now, snapshot);
+}