Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] mc_comm_pattern.c containing all communication pattern functions
[simgrid.git] / src / mc / mc_smx.h
1 /* Copyright (c) 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 MC_SMX_H
8 #define MC_SMX_H
9
10 #include <stddef.h>
11
12 #include <xbt/log.h>
13 #include <simgrid/simix.h>
14
15 #include "mc_process.h"
16 #include "mc_protocol.h"
17
18 /** @file
19  *  @brief (Cross-process, MCer/MCed) Access to SMX structures
20  *
21  *  We copy some C data structure from the MCed process in the MCer process.
22  *  This is implemented by:
23  *
24  *   - `model_checker->process.smx_process_infos`
25  *      (copy of `simix_global->process_list`);
26  *
27  *   - `model_checker->process.smx_old_process_infos`
28  *      (copy of `simix_global->process_to_destroy`);
29  *
30  *   - `model_checker->hostnames`.
31  *
32  * The process lists are currently refreshed each time MCed code is executed.
33  * We don't try to give a persistent MCer address for a given MCed process.
34  * For this reason, a MCer mc_process_t is currently not reusable after
35  * MCed code.
36  */
37
38 SG_BEGIN_DECL()
39
40 struct s_mc_smx_process_info {
41   /** MCed address of the process */
42   void* address;
43   /** (Flat) Copy of the process data structure */
44   struct s_smx_process copy;
45   /** Hostname (owned by `mc_modelchecker->hostnames`) */
46   char* hostname;
47   char* name;
48 };
49
50 xbt_dynar_t MC_smx_process_info_list_new(void);
51
52 void MC_process_smx_refresh(mc_process_t process);
53
54 /** Get the issuer of  a simcall (`req->issuer`)
55  *
56  *  In split-process mode, it does the black magic necessary to get an address
57  *  of a (shallow) copy of the data structure the issuer SIMIX process in the local
58  *  address space.
59  *
60  *  @param process the MCed process
61  *  @param req     the simcall (copied in the local process)
62  */
63 smx_process_t MC_smx_simcall_get_issuer(smx_simcall_t req);
64
65 const char* MC_smx_process_get_name(smx_process_t p);
66 const char* MC_smx_process_get_host_name(smx_process_t p);
67
68 #define MC_EACH_SIMIX_PROCESS(process, code) \
69   if (MC_process_is_self(&mc_model_checker->process)) { \
70     xbt_swag_foreach(process, simix_global->process_list) { \
71       code; \
72     } \
73   } else { \
74     MC_process_smx_refresh(&mc_model_checker->process); \
75     unsigned int _smx_process_index; \
76     mc_smx_process_info_t _smx_process_info; \
77     xbt_dynar_foreach_ptr(mc_model_checker->process.smx_process_infos, _smx_process_index, _smx_process_info) { \
78       smx_process_t process = &_smx_process_info->copy; \
79       code; \
80     } \
81   }
82
83 /** Execute a given simcall */
84 void MC_simcall_handle(smx_simcall_t req, int value);
85
86
87
88 /* ***** Resolve (local/MCer structure from remote/MCed addresses) ***** */
89
90 /** Get a local copy of the process from the process remote address */
91 smx_process_t MC_smx_resolve_process(smx_process_t process_remote_address);
92
93 /** Get the process info structure from the process remote address */
94 mc_smx_process_info_t MC_smx_resolve_process_info(smx_process_t process_remote_address);
95
96 SG_END_DECL()
97
98 #endif