1 | /* |
---|
2 | * Copyright (c) 2012 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * embedded brains GmbH |
---|
5 | * Obere Lagerstr. 30 |
---|
6 | * 82178 Puchheim |
---|
7 | * Germany |
---|
8 | * <rtems@embedded-brains.de> |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.com/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #if HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include <rtems/libcsupport.h> |
---|
20 | |
---|
21 | #include <string.h> |
---|
22 | |
---|
23 | #include <rtems/libio_.h> |
---|
24 | #include <rtems/malloc.h> |
---|
25 | #include <rtems/score/wkspace.h> |
---|
26 | #include <rtems/score/protectedheap.h> |
---|
27 | |
---|
28 | #include <rtems/extensionimpl.h> |
---|
29 | |
---|
30 | #include <rtems/rtems/barrierimpl.h> |
---|
31 | #include <rtems/rtems/dpmemimpl.h> |
---|
32 | #include <rtems/rtems/messageimpl.h> |
---|
33 | #include <rtems/rtems/ratemonimpl.h> |
---|
34 | #include <rtems/rtems/semimpl.h> |
---|
35 | |
---|
36 | #ifdef RTEMS_POSIX_API |
---|
37 | #include <rtems/posix/barrierimpl.h> |
---|
38 | #include <rtems/posix/condimpl.h> |
---|
39 | #include <rtems/posix/mqueueimpl.h> |
---|
40 | #include <rtems/posix/muteximpl.h> |
---|
41 | #include <rtems/posix/key.h> |
---|
42 | #include <rtems/posix/psignal.h> |
---|
43 | #include <rtems/posix/pthreadimpl.h> |
---|
44 | #include <rtems/posix/rwlockimpl.h> |
---|
45 | #include <rtems/posix/semaphoreimpl.h> |
---|
46 | #include <rtems/posix/spinlockimpl.h> |
---|
47 | #include <rtems/posix/timerimpl.h> |
---|
48 | #endif |
---|
49 | |
---|
50 | static const Objects_Information *objects_info_table[] = { |
---|
51 | &_Barrier_Information, |
---|
52 | &_Extension_Information, |
---|
53 | &_Message_queue_Information, |
---|
54 | &_Partition_Information, |
---|
55 | &_Rate_monotonic_Information, |
---|
56 | &_Dual_ported_memory_Information, |
---|
57 | &_Region_Information, |
---|
58 | &_Semaphore_Information, |
---|
59 | &_RTEMS_tasks_Information, |
---|
60 | &_Timer_Information |
---|
61 | #ifdef RTEMS_POSIX_API |
---|
62 | , |
---|
63 | &_POSIX_Barrier_Information, |
---|
64 | &_POSIX_Condition_variables_Information, |
---|
65 | &_POSIX_Keys_Information, |
---|
66 | &_POSIX_Message_queue_Information, |
---|
67 | &_POSIX_Message_queue_Information_fds, |
---|
68 | &_POSIX_Mutex_Information, |
---|
69 | &_POSIX_RWLock_Information, |
---|
70 | &_POSIX_Semaphore_Information, |
---|
71 | &_POSIX_Spinlock_Information, |
---|
72 | &_POSIX_Threads_Information, |
---|
73 | &_POSIX_Timer_Information |
---|
74 | #endif |
---|
75 | }; |
---|
76 | |
---|
77 | static int open_files(void) |
---|
78 | { |
---|
79 | int free_count = 0; |
---|
80 | rtems_libio_t *iop; |
---|
81 | |
---|
82 | rtems_libio_lock(); |
---|
83 | |
---|
84 | iop = rtems_libio_iop_freelist; |
---|
85 | while (iop != NULL) { |
---|
86 | ++free_count; |
---|
87 | |
---|
88 | iop = iop->data1; |
---|
89 | } |
---|
90 | |
---|
91 | rtems_libio_unlock(); |
---|
92 | |
---|
93 | return (int) rtems_libio_number_iops - free_count; |
---|
94 | } |
---|
95 | |
---|
96 | static void free_all_delayed_blocks(void) |
---|
97 | { |
---|
98 | #ifdef HEAP_PROTECTION |
---|
99 | _RTEMS_Lock_allocator(); |
---|
100 | _Thread_Disable_dispatch(); |
---|
101 | _Heap_Protection_free_all_delayed_blocks( RTEMS_Malloc_Heap ); |
---|
102 | _Heap_Protection_free_all_delayed_blocks( &_Workspace_Area ); |
---|
103 | _Thread_Enable_dispatch(); |
---|
104 | _RTEMS_Unlock_allocator(); |
---|
105 | #endif |
---|
106 | } |
---|
107 | |
---|
108 | void rtems_resource_snapshot_take(rtems_resource_snapshot *snapshot) |
---|
109 | { |
---|
110 | uint32_t *active = &snapshot->rtems_api.active_barriers; |
---|
111 | size_t i; |
---|
112 | |
---|
113 | free_all_delayed_blocks(); |
---|
114 | |
---|
115 | _Protected_heap_Get_information(RTEMS_Malloc_Heap, &snapshot->heap_info); |
---|
116 | |
---|
117 | _Thread_Disable_dispatch(); |
---|
118 | |
---|
119 | _Heap_Get_information(&_Workspace_Area, &snapshot->workspace_info); |
---|
120 | |
---|
121 | for (i = 0; i < RTEMS_ARRAY_SIZE(objects_info_table); ++i) { |
---|
122 | active [i] = _Objects_Active_count(objects_info_table[i]); |
---|
123 | } |
---|
124 | |
---|
125 | _Thread_Enable_dispatch(); |
---|
126 | |
---|
127 | #ifndef RTEMS_POSIX_API |
---|
128 | memset(&snapshot->posix_api, 0, sizeof(snapshot->posix_api)); |
---|
129 | #endif |
---|
130 | |
---|
131 | snapshot->open_files = open_files(); |
---|
132 | } |
---|
133 | |
---|
134 | bool rtems_resource_snapshot_equal( |
---|
135 | const rtems_resource_snapshot *a, |
---|
136 | const rtems_resource_snapshot *b |
---|
137 | ) |
---|
138 | { |
---|
139 | return memcmp(a, b, sizeof(*a)) == 0; |
---|
140 | } |
---|
141 | |
---|
142 | bool rtems_resource_snapshot_check(const rtems_resource_snapshot *snapshot) |
---|
143 | { |
---|
144 | rtems_resource_snapshot now; |
---|
145 | |
---|
146 | rtems_resource_snapshot_take(&now); |
---|
147 | |
---|
148 | return rtems_resource_snapshot_equal(&now, snapshot); |
---|
149 | } |
---|