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

5
Last change on this file since ef16a11 was 54f35888, checked in by Sebastian Huber <sebastian.huber@…>, on 10/25/18 at 08:54:12

posix: Provide threads by default

Update #2514.

  • Property mode set to 100644
File size: 3.6 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#include <rtems/posix/keyimpl.h>
30
31static const struct {
32  Objects_APIs api;
33  uint16_t cls;
34} objects_info_table[] = {
35  { OBJECTS_POSIX_API, OBJECTS_POSIX_KEYS },
36  { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_BARRIERS },
37  { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_EXTENSIONS },
38  { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_MESSAGE_QUEUES },
39  { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_PARTITIONS },
40  { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_PERIODS },
41  { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_PORTS },
42  { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_REGIONS },
43  { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_SEMAPHORES },
44  { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TASKS },
45  { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TIMERS },
46  { OBJECTS_POSIX_API, OBJECTS_POSIX_MESSAGE_QUEUES },
47  { OBJECTS_POSIX_API, OBJECTS_POSIX_SEMAPHORES },
48  { OBJECTS_POSIX_API, OBJECTS_POSIX_THREADS }
49  #ifdef RTEMS_POSIX_API
50    ,
51    { OBJECTS_POSIX_API, OBJECTS_POSIX_TIMERS }
52  #endif
53};
54
55static int open_files(void)
56{
57  int free_count = 0;
58  rtems_libio_t *iop;
59
60  rtems_libio_lock();
61
62  iop = rtems_libio_iop_free_head;
63  while (iop != NULL) {
64    ++free_count;
65
66    iop = iop->data1;
67  }
68
69  rtems_libio_unlock();
70
71  return (int) rtems_libio_number_iops - free_count;
72}
73
74static void get_heap_info(Heap_Control *heap, Heap_Information_block *info)
75{
76  _Heap_Get_information(heap, info);
77  memset(&info->Stats, 0, sizeof(info->Stats));
78}
79
80static POSIX_Keys_Control *get_next_key(Objects_Id *id)
81{
82  return (POSIX_Keys_Control *)
83    _Objects_Get_next(*id, &_POSIX_Keys_Information, id);
84}
85
86static uint32_t get_active_posix_key_value_pairs(void)
87{
88  uint32_t count = 0;
89  Objects_Id id = OBJECTS_ID_INITIAL_INDEX;
90  POSIX_Keys_Control *the_key;
91
92  while ((the_key = get_next_key(&id)) != NULL ) {
93    count += _Chain_Node_count_unprotected(&the_key->Key_value_pairs);
94    _Objects_Allocator_unlock();
95  }
96
97  return count;
98}
99
100void rtems_resource_snapshot_take(rtems_resource_snapshot *snapshot)
101{
102  uint32_t *active;
103  size_t i;
104
105  memset(snapshot, 0, sizeof(*snapshot));
106
107  _RTEMS_Lock_allocator();
108
109  _Thread_Kill_zombies();
110
111  get_heap_info(RTEMS_Malloc_Heap, &snapshot->heap_info);
112  get_heap_info(&_Workspace_Area, &snapshot->workspace_info);
113
114  active = &snapshot->active_posix_keys;
115
116  for (i = 0; i < RTEMS_ARRAY_SIZE(objects_info_table); ++i) {
117    const Objects_Information *information;
118
119    information = _Objects_Get_information(
120      objects_info_table[i].api,
121      objects_info_table[i].cls
122    );
123
124    if (information != NULL) {
125      active[i] = _Objects_Active_count(information);
126    }
127  }
128
129  _RTEMS_Unlock_allocator();
130
131  snapshot->active_posix_key_value_pairs = get_active_posix_key_value_pairs();
132  snapshot->open_files = open_files();
133}
134
135bool rtems_resource_snapshot_equal(
136  const rtems_resource_snapshot *a,
137  const rtems_resource_snapshot *b
138)
139{
140  return memcmp(a, b, sizeof(*a)) == 0;
141}
142
143bool rtems_resource_snapshot_check(const rtems_resource_snapshot *snapshot)
144{
145  rtems_resource_snapshot now;
146
147  rtems_resource_snapshot_take(&now);
148
149  return rtems_resource_snapshot_equal(&now, snapshot);
150}
Note: See TracBrowser for help on using the repository browser.