Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / src / mc / transition / Transition.hpp
1 /* Copyright (c) 2015-2023. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SIMGRID_MC_TRANSITION_HPP
7 #define SIMGRID_MC_TRANSITION_HPP
8
9 #include "simgrid/forward.h" // aid_t
10 #include "xbt/ex.h"
11 #include "xbt/utility.hpp"   // XBT_DECLARE_ENUM_CLASS
12
13 #include <sstream>
14 #include <string>
15
16 namespace simgrid::mc {
17
18 /** An element in the recorded path
19  *
20  *  At each decision point, we need to record which process transition
21  *  is triggered and potentially which value is associated with this
22  *  transition. The value is used to find which communication is triggered
23  *  in things like waitany and for associating a given value of MC_random()
24  *  calls.
25  */
26 class Transition {
27   /* Global statistics */
28   static unsigned long executed_transitions_;
29   static unsigned long replayed_transitions_;
30
31   friend State; // FIXME remove this once we have a proper class to handle the statistics
32
33 public:
34   /* Ordering is important here. depends() implementations only consider subsequent types in this ordering */
35   XBT_DECLARE_ENUM_CLASS(Type,
36                          /* First because indep with anybody including themselves */
37                          RANDOM, ACTOR_JOIN, ACTOR_SLEEP,
38                          /* high priority because indep with almost everybody */
39                          OBJECT_ACCESS,
40                          /* high priority because they can rewrite themselves to *_WAIT */
41                          TESTANY, WAITANY,
42                          /* BARRIER transitions sorted alphabetically */
43                          BARRIER_ASYNC_LOCK, BARRIER_WAIT,
44                          /* Alphabetical ordering of COMM_* */
45                          COMM_ASYNC_RECV, COMM_ASYNC_SEND, COMM_TEST, COMM_WAIT,
46                          /* alphabetical */
47                          MUTEX_ASYNC_LOCK, MUTEX_TEST, MUTEX_TRYLOCK, MUTEX_UNLOCK, MUTEX_WAIT,
48                          /* alphabetical ordering of SEM transitions */
49                          SEM_ASYNC_LOCK, SEM_UNLOCK, SEM_WAIT,
50                          /* UNKNOWN must be last */
51                          UNKNOWN);
52   Type type_ = Type::UNKNOWN;
53
54   aid_t aid_ = 0;
55
56   /** The user function call that caused this transition to exist. Format: >>filename:line:function()<< */
57   std::string call_location_ = "";
58
59   /* Which transition was executed for this simcall
60    *
61    * Some simcalls can lead to different transitions:
62    *
63    * * waitany/testany can trigger on different messages;
64    *
65    * * random can produce different values.
66    */
67   int times_considered_ = 0;
68
69   Transition() = default;
70   Transition(Type type, aid_t issuer, int times_considered)
71       : type_(type), aid_(issuer), times_considered_(times_considered)
72   {
73   }
74   virtual ~Transition();
75
76   /** Returns a textual representation of the transition. Pointer adresses are omitted if verbose=false */
77   virtual std::string to_string(bool verbose = false) const;
78   /** Returns something like >>label = "desc", color = c<< to describe the transition in dot format */
79   virtual std::string dot_string() const;
80
81   std::string const& get_call_location() const { return call_location_; }
82
83   /* Moves the application toward a path that was already explored, but don't change the current transition */
84   void replay(RemoteApp& app) const;
85
86   virtual bool depends(const Transition* other) const { return true; }
87
88   /**
89    The reversible race detector should only be used if we already have the assumption
90    this <* other (see Source set: a foundation for ODPOR). In particular this means that :
91    - this -->_E other
92    - proc(this) != proc(other)
93    - there is no event e s.t. this --> e --> other
94
95     @note: It is safe to assume that there is indeed a race between the two events in the execution;
96      indeed, the question the method answers is only sensible in the context of a race
97   */
98   virtual bool reversible_race(const Transition* other) const
99   {
100     xbt_die("%s unimplemented for %s", __func__, to_c_str(type_));
101   }
102
103   /* Returns the total amount of transitions executed so far (for statistics) */
104   static unsigned long get_executed_transitions() { return executed_transitions_; }
105   /* Returns the total amount of transitions replayed so far while backtracing (for statistics) */
106   static unsigned long get_replayed_transitions() { return replayed_transitions_; }
107 };
108
109 /** Make a new transition from serialized description */
110 Transition* deserialize_transition(aid_t issuer, int times_considered, std::stringstream& stream);
111
112 } // namespace simgrid::mc
113
114 #endif