Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Use std::equal_range in get_search_range()
[simgrid.git] / src / mc / mc_private.h
1 /* Copyright (c) 2007-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef SIMGRID_MC_PRIVATE_H
8 #define SIMGRID_MC_PRIVATE_H
9
10 #include "simgrid_config.h"
11
12 #include <sys/types.h>
13
14 #include <stdio.h>
15 #ifndef WIN32
16 #include <sys/mman.h>
17 #endif
18
19 #ifdef __cpluscplus
20 #include <algorithm>
21 #endif
22
23 #include <elfutils/libdw.h>
24
25 #include <simgrid/msg.h>
26 #include <xbt/fifo.h>
27 #include <xbt/config.h>
28 #include <xbt/base.h>
29
30 #include "mc/mc.h"
31 #include "mc/datatypes.h"
32 #include "src/mc/mc_base.h"
33
34 #include "src/simix/smx_private.h"
35 #include "src/xbt/mmalloc/mmprivate.h"
36
37 #ifdef __cplusplus
38 #include "src/mc/mc_forward.hpp"
39 #include "src/xbt/memory_map.hpp"
40 #endif
41
42 #include "src/mc/mc_protocol.h"
43
44 SG_BEGIN_DECL()
45
46 /********************************* MC Global **********************************/
47
48 XBT_PRIVATE void MC_init_dot_output();
49
50 XBT_PRIVATE extern FILE *dot_output;
51
52 XBT_PRIVATE extern int user_max_depth_reached;
53
54 XBT_PRIVATE void MC_replay(xbt_fifo_t stack);
55 XBT_PRIVATE void MC_show_deadlock(smx_simcall_t req);
56 XBT_PRIVATE void MC_show_stack_safety(xbt_fifo_t stack);
57 XBT_PRIVATE void MC_dump_stack_safety(xbt_fifo_t stack);
58 XBT_PRIVATE void MC_show_non_termination(void);
59
60 /** Stack (of `mc_state_t`) representing the current position of the
61  *  the MC in the exploration graph
62  *
63  *  It is managed by its head (`xbt_fifo_shift` and `xbt_fifo_unshift`).
64  */
65 XBT_PRIVATE extern xbt_fifo_t mc_stack;
66
67 #ifdef __cplusplus
68
69 SG_END_DECL()
70
71 namespace simgrid {
72 namespace mc {
73
74 struct DerefAndCompareByNbProcessesAndUsedHead {
75   template<class X, class Y>
76   bool operator()(X const& a, Y const& b)
77   {
78     return std::make_pair(a->nb_processes, a->heap_bytes_used) <
79       std::make_pair(b->nb_processes, b->heap_bytes_used);
80   }
81 };
82
83 /**
84  *  \brief Find a suitable subrange of candidate duplicates for a given state
85  *  \param list dynamic array of states/pairs with candidate duplicates of the current state;
86  *  \param ref current state/pair;
87  *  \param min (output) index of the beginning of the the subrange
88  *  \param max (output) index of the enf of the subrange
89  *
90  *  Given a suitably ordered array of states/pairs, this function extracts a subrange
91  *  (with index *min <= i <= *max) with candidate duplicates of the given state/pair.
92  *  This function uses only fast discriminating criterions and does not use the
93  *  full state/pair comparison algorithms.
94  *
95  *  The states/pairs in list MUST be ordered using a (given) weak order
96  *  (based on nb_processes and heap_bytes_used).
97  *  The subrange is the subrange of "equivalence" of the given state/pair.
98  */
99 // TODO, it would make sense to use std::set instead
100 // U = some pointer of T (T*, unique_ptr<T>, shared_ptr<T>)
101 template<class U, class T>
102 int get_search_interval(
103   U* list, std::size_t count, T *ref, int *min, int *max)
104 {
105   auto res = std::equal_range(
106     list, list + count, ref, DerefAndCompareByNbProcessesAndUsedHead());
107
108   // Not found, but we have the insertion point:
109   if (res.first == res.second)
110     return res.first - list;
111
112   // Found, we have the whole matching range:
113   else {
114     *min = res.first - list;
115     *max = (res.second - 1) - list;
116     return -1;
117   }
118 }
119
120 }
121 }
122
123 #endif
124
125 SG_BEGIN_DECL()
126
127 /****************************** Statistics ************************************/
128
129 typedef struct mc_stats {
130   unsigned long state_size;
131   unsigned long visited_states;
132   unsigned long visited_pairs;
133   unsigned long expanded_states;
134   unsigned long expanded_pairs;
135   unsigned long executed_transitions;
136 } s_mc_stats_t, *mc_stats_t;
137
138 XBT_PRIVATE extern mc_stats_t mc_stats;
139
140 XBT_PRIVATE void MC_print_statistics(mc_stats_t stats);
141
142 /********************************** Snapshot comparison **********************************/
143
144 //#define MC_DEBUG 1
145 #define MC_VERBOSE 1
146
147 /********************************** Miscellaneous **********************************/
148
149 XBT_PRIVATE void MC_report_assertion_error(void);
150 XBT_PRIVATE void MC_report_crash(int status);
151
152 SG_END_DECL()
153
154 #ifdef __cplusplus
155
156 namespace simgrid {
157 namespace mc {
158
159 XBT_PRIVATE void find_object_address(
160   std::vector<simgrid::xbt::VmMap> const& maps, simgrid::mc::ObjectInformation* result);
161
162 XBT_PRIVATE
163 int snapshot_compare(int num1, simgrid::mc::Snapshot* s1, int num2, simgrid::mc::Snapshot* s2);
164
165 }
166 }
167
168 #endif
169
170 #endif