Logo AND Algorithmique Numérique Distribuée

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