1 /* Copyright (c) 2007-2015. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #ifndef SIMGRID_MC_PRIVATE_H
8 #define SIMGRID_MC_PRIVATE_H
10 #include "simgrid_config.h"
12 #include <sys/types.h>
23 #include <elfutils/libdw.h>
25 #include <simgrid/msg.h>
27 #include <xbt/config.h>
31 #include "mc/datatypes.h"
32 #include "src/mc/mc_base.h"
34 #include "src/simix/smx_private.h"
35 #include "src/xbt/mmalloc/mmprivate.h"
38 #include "src/mc/mc_forward.hpp"
39 #include "src/xbt/memory_map.hpp"
42 #include "src/mc/mc_protocol.h"
46 /********************************* MC Global **********************************/
48 XBT_PRIVATE void MC_init_dot_output();
50 XBT_PRIVATE extern FILE *dot_output;
52 XBT_PRIVATE extern int user_max_depth_reached;
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);
60 /** Stack (of `mc_state_t`) representing the current position of the
61 * the MC in the exploration graph
63 * It is managed by its head (`xbt_fifo_shift` and `xbt_fifo_unshift`).
65 XBT_PRIVATE extern xbt_fifo_t mc_stack;
74 struct DerefAndCompareByNbProcessesAndUsedHead {
75 template<class X, class Y>
76 bool operator()(X const& a, Y const& b)
78 return std::make_pair(a->nb_processes, a->heap_bytes_used) <
79 std::make_pair(b->nb_processes, b->heap_bytes_used);
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
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.
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.
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)
105 auto res = std::equal_range(
106 list, list + count, ref, DerefAndCompareByNbProcessesAndUsedHead());
108 // Not found, but we have the insertion point:
109 if (res.first == res.second)
110 return res.first - list;
112 // Found, we have the whole matching range:
114 *min = res.first - list;
115 *max = (res.second - 1) - list;
127 /****************************** Statistics ************************************/
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;
138 XBT_PRIVATE extern mc_stats_t mc_stats;
140 XBT_PRIVATE void MC_print_statistics(mc_stats_t stats);
142 /********************************** Snapshot comparison **********************************/
147 /********************************** Miscellaneous **********************************/
149 XBT_PRIVATE void MC_report_assertion_error(void);
150 XBT_PRIVATE void MC_report_crash(int status);
159 XBT_PRIVATE void find_object_address(
160 std::vector<simgrid::xbt::VmMap> const& maps, simgrid::mc::ObjectInformation* result);
163 int snapshot_compare(int num1, simgrid::mc::Snapshot* s1, int num2, simgrid::mc::Snapshot* s2);