source: rtems/cpukit/libcsupport/src/resource_snapshot.c @ e67929c

5
Last change on this file since e67929c was e67929c, checked in by Sebastian Huber <sebastian.huber@…>, on 09/21/17 at 12:13:16

posix: Implement self-contained POSIX barriers

POSIX barriers are now available in all configurations and no longer
depend on --enable-posix.

Update #2514.
Update #3114.

  • Property mode set to 100644
File size: 4.5 KB
Line 
1/*
2 * Copyright (c) 2012-2014 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
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.org/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/rbtreeimpl.h>
26#include <rtems/score/protectedheap.h>
27#include <rtems/score/threadimpl.h>
28#include <rtems/score/wkspace.h>
29
30#include <rtems/posix/keyimpl.h>
31
32#include <rtems/rtems/barrierimpl.h>
33#include <rtems/extensionimpl.h>
34#include <rtems/rtems/dpmemimpl.h>
35#include <rtems/rtems/messageimpl.h>
36#include <rtems/rtems/partimpl.h>
37#include <rtems/rtems/ratemonimpl.h>
38#include <rtems/rtems/regionimpl.h>
39#include <rtems/rtems/semimpl.h>
40#include <rtems/rtems/tasksimpl.h>
41#include <rtems/rtems/timerimpl.h>
42
43#ifdef RTEMS_POSIX_API
44  #include <rtems/posix/barrierimpl.h>
45  #include <rtems/posix/condimpl.h>
46  #include <rtems/posix/mqueueimpl.h>
47  #include <rtems/posix/muteximpl.h>
48  #include <rtems/posix/psignal.h>
49  #include <rtems/posix/pthreadimpl.h>
50  #include <rtems/posix/rwlockimpl.h>
51  #include <rtems/posix/semaphoreimpl.h>
52  #include <rtems/posix/timerimpl.h>
53#endif
54
55static const struct {
56  Objects_APIs api;
57  uint16_t cls;
58} objects_info_table[] = {
59  { OBJECTS_POSIX_API, OBJECTS_POSIX_KEYS },
60  { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_BARRIERS },
61  { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_EXTENSIONS },
62  { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_MESSAGE_QUEUES },
63  { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_PARTITIONS },
64  { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_PERIODS },
65  { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_PORTS },
66  { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_REGIONS },
67  { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_SEMAPHORES },
68  { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TASKS },
69  { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TIMERS }
70  #ifdef RTEMS_POSIX_API
71    ,
72    { OBJECTS_POSIX_API, OBJECTS_POSIX_CONDITION_VARIABLES },
73    { OBJECTS_POSIX_API, OBJECTS_POSIX_MESSAGE_QUEUES },
74    { OBJECTS_POSIX_API, OBJECTS_POSIX_MUTEXES },
75    { OBJECTS_POSIX_API, OBJECTS_POSIX_RWLOCKS },
76    { OBJECTS_POSIX_API, OBJECTS_POSIX_SEMAPHORES },
77    { OBJECTS_POSIX_API, OBJECTS_POSIX_THREADS },
78    { OBJECTS_POSIX_API, OBJECTS_POSIX_TIMERS }
79  #endif
80};
81
82static int open_files(void)
83{
84  int free_count = 0;
85  rtems_libio_t *iop;
86
87  rtems_libio_lock();
88
89  iop = rtems_libio_iop_free_head;
90  while (iop != NULL) {
91    ++free_count;
92
93    iop = iop->data1;
94  }
95
96  rtems_libio_unlock();
97
98  return (int) rtems_libio_number_iops - free_count;
99}
100
101static void get_heap_info(Heap_Control *heap, Heap_Information_block *info)
102{
103  _Heap_Get_information(heap, info);
104  memset(&info->Stats, 0, sizeof(info->Stats));
105}
106
107static POSIX_Keys_Control *get_next_key(Objects_Id *id)
108{
109  return (POSIX_Keys_Control *)
110    _Objects_Get_next(*id, &_POSIX_Keys_Information, id);
111}
112
113static uint32_t get_active_posix_key_value_pairs(void)
114{
115  uint32_t count = 0;
116  Objects_Id id = OBJECTS_ID_INITIAL_INDEX;
117  POSIX_Keys_Control *the_key;
118
119  while ((the_key = get_next_key(&id)) != NULL ) {
120    count += _Chain_Node_count_unprotected(&the_key->Key_value_pairs);
121    _Objects_Allocator_unlock();
122  }
123
124  return count;
125}
126
127void rtems_resource_snapshot_take(rtems_resource_snapshot *snapshot)
128{
129  uint32_t *active;
130  size_t i;
131
132  memset(snapshot, 0, sizeof(*snapshot));
133
134  _RTEMS_Lock_allocator();
135
136  _Thread_Kill_zombies();
137
138  get_heap_info(RTEMS_Malloc_Heap, &snapshot->heap_info);
139  get_heap_info(&_Workspace_Area, &snapshot->workspace_info);
140
141  active = &snapshot->active_posix_keys;
142
143  for (i = 0; i < RTEMS_ARRAY_SIZE(objects_info_table); ++i) {
144    const Objects_Information *information;
145
146    information = _Objects_Get_information(
147      objects_info_table[i].api,
148      objects_info_table[i].cls
149    );
150
151    if (information != NULL) {
152      active[i] = _Objects_Active_count(information);
153    }
154  }
155
156  _RTEMS_Unlock_allocator();
157
158  snapshot->active_posix_key_value_pairs = get_active_posix_key_value_pairs();
159  snapshot->open_files = open_files();
160}
161
162bool rtems_resource_snapshot_equal(
163  const rtems_resource_snapshot *a,
164  const rtems_resource_snapshot *b
165)
166{
167  return memcmp(a, b, sizeof(*a)) == 0;
168}
169
170bool rtems_resource_snapshot_check(const rtems_resource_snapshot *snapshot)
171{
172  rtems_resource_snapshot now;
173
174  rtems_resource_snapshot_take(&now);
175
176  return rtems_resource_snapshot_equal(&now, snapshot);
177}
Note: See TracBrowser for help on using the repository browser.