source: rtems/cpukit/sapi/src/profilingiterate.c @ 599d71f

Last change on this file since 599d71f was 48fed9a, checked in by Sebastian Huber <sebastian.huber@…>, on Jun 25, 2015 at 12:11:53 PM

score: Simplify <rtems/system.h>

Drop the <rtems/score/percpu.h> include since this file exposes a lot of
implementation details.

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 * Copyright (c) 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#ifdef HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include <rtems/profiling.h>
20#include <rtems/counter.h>
21#include <rtems/score/percpu.h>
22#include <rtems/score/smplock.h>
23#include <rtems.h>
24
25#include <string.h>
26
27static void per_cpu_stats_iterate(
28  rtems_profiling_visitor visitor,
29  void *visitor_arg,
30  rtems_profiling_data *data
31)
32{
33#ifdef RTEMS_PROFILING
34  uint32_t n = rtems_get_processor_count();
35  uint32_t i;
36
37  memset(data, 0, sizeof(*data));
38  data->header.type = RTEMS_PROFILING_PER_CPU;
39  for (i = 0; i < n; ++i) {
40    const Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index(i);
41    const Per_CPU_Stats *stats = &per_cpu->Stats;
42    rtems_profiling_per_cpu *per_cpu_data = &data->per_cpu;
43
44    per_cpu_data->processor_index = i;
45
46    per_cpu_data->max_thread_dispatch_disabled_time =
47      rtems_counter_ticks_to_nanoseconds(
48        stats->max_thread_dispatch_disabled_time
49      );
50
51    per_cpu_data->max_interrupt_time =
52      rtems_counter_ticks_to_nanoseconds(stats->max_interrupt_time);
53
54    per_cpu_data->max_interrupt_delay =
55      rtems_counter_ticks_to_nanoseconds(stats->max_interrupt_delay);
56
57    per_cpu_data->thread_dispatch_disabled_count =
58      stats->thread_dispatch_disabled_count;
59
60    per_cpu_data->total_thread_dispatch_disabled_time =
61      rtems_counter_ticks_to_nanoseconds(
62        stats->total_thread_dispatch_disabled_time
63      );
64
65    per_cpu_data->interrupt_count = stats->interrupt_count;
66
67    per_cpu_data->total_interrupt_time =
68      rtems_counter_ticks_to_nanoseconds(
69        stats->total_interrupt_time
70      );
71
72    (*visitor)(visitor_arg, data);
73  }
74#else
75  (void) visitor;
76  (void) visitor_arg;
77  (void) data;
78#endif
79}
80
81#if defined(RTEMS_PROFILING) && defined(RTEMS_SMP)
82RTEMS_STATIC_ASSERT(
83  RTEMS_PROFILING_SMP_LOCK_CONTENTION_COUNTS
84    == SMP_LOCK_STATS_CONTENTION_COUNTS,
85  smp_lock_contention_counts
86);
87#endif
88
89static void smp_lock_stats_iterate(
90  rtems_profiling_visitor visitor,
91  void *visitor_arg,
92  rtems_profiling_data *data
93)
94{
95#if defined(RTEMS_PROFILING) && defined(RTEMS_SMP)
96  SMP_lock_Stats_iteration_context iteration_context;
97  SMP_lock_Stats snapshot;
98  char name[64];
99
100  memset(data, 0, sizeof(*data));
101  data->header.type = RTEMS_PROFILING_SMP_LOCK;
102
103  _SMP_lock_Stats_iteration_start(&iteration_context);
104  while (
105    _SMP_lock_Stats_iteration_next(
106      &iteration_context,
107      &snapshot,
108      &name[0],
109      sizeof(name)
110    )
111  ) {
112    rtems_profiling_smp_lock *smp_lock_data = &data->smp_lock;
113
114    smp_lock_data->name = name;
115    smp_lock_data->max_acquire_time =
116      rtems_counter_ticks_to_nanoseconds(snapshot.max_acquire_time);
117    smp_lock_data->max_section_time =
118      rtems_counter_ticks_to_nanoseconds(snapshot.max_section_time);
119    smp_lock_data->usage_count = snapshot.usage_count;
120    smp_lock_data->total_acquire_time =
121      rtems_counter_ticks_to_nanoseconds(snapshot.total_acquire_time);
122    smp_lock_data->total_section_time =
123      rtems_counter_ticks_to_nanoseconds(snapshot.total_section_time);
124
125    memcpy(
126      &smp_lock_data->contention_counts[0],
127      &snapshot.contention_counts[0],
128      sizeof(smp_lock_data->contention_counts)
129    );
130
131    (*visitor)(visitor_arg, data);
132  }
133  _SMP_lock_Stats_iteration_stop(&iteration_context);
134#else
135  (void) visitor;
136  (void) visitor_arg;
137  (void) data;
138#endif
139}
140
141void rtems_profiling_iterate(
142  rtems_profiling_visitor visitor,
143  void *visitor_arg
144)
145{
146  rtems_profiling_data data;
147
148  per_cpu_stats_iterate(visitor, visitor_arg, &data);
149  smp_lock_stats_iterate(visitor, visitor_arg, &data);
150}
Note: See TracBrowser for help on using the repository browser.