1 /* Copyright (c) 2004-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 METASIMGRID_PRIVATE_H
8 #define METASIMGRID_PRIVATE_H
13 #include "simgrid/msg.h"
14 #include "simgrid/simix.h"
15 #include "src/include/surf/surf.h"
18 #include "xbt/dynar.h"
21 #include "xbt/config.h"
22 #include "src/instr/instr_private.h"
24 #include "src/kernel/activity/SynchroExec.hpp"
25 #include "src/kernel/activity/SynchroComm.hpp"
29 /**************** datatypes **********************************/
30 /********************************* Host **************************************/
31 typedef struct s_msg_host_priv {
33 std::vector<int> *file_descriptor_table;
35 /********************************* Task **************************************/
37 typedef struct simdata_task {
41 this->compute->unref();
43 /* parallel tasks only */
44 xbt_free(this->host_list);
52 simgrid::kernel::activity::Exec *compute = nullptr; /* SIMIX modeling of computation */
53 simgrid::kernel::activity::Comm *comm = nullptr; /* SIMIX modeling of communication */
54 double bytes_amount = 0.0; /* Data size */
55 double flops_amount = 0.0; /* Computation size */
56 msg_process_t sender = nullptr;
57 msg_process_t receiver = nullptr;
58 msg_host_t source = nullptr;
59 double priority = 0.0;
60 double bound = 0.0; /* Capping for CPU resource */
61 double rate = 0.0; /* Capping for network resource */
63 bool isused = false; /* Indicates whether the task is used in SIMIX currently */
64 int host_nb = 0; /* ==0 if sequential task; parallel task if not */
65 /******* Parallel Tasks Only !!!! *******/
66 sg_host_t *host_list = nullptr;
67 double *flops_parallel_amount = nullptr;
68 double *bytes_parallel_amount = nullptr;
71 void reportMultipleUse() const;
74 /********************************* File **************************************/
75 typedef struct simdata_file {
79 XBT_PRIVATE int __MSG_host_get_file_descriptor_id(msg_host_t host);
80 XBT_PRIVATE void __MSG_host_release_file_descriptor_id(msg_host_t host, int id);
82 /******************************* Process *************************************/
84 typedef struct simdata_process {
85 msg_host_t m_host; /* the host on which the process is running */
86 msg_host_t put_host; /* used for debugging purposes */
87 smx_activity_t waiting_action;
88 msg_task_t waiting_task;
89 msg_error_t last_errno; /* the last value returned by a MSG_function */
91 void* data; /* user data */
92 } s_simdata_process_t, *simdata_process_t;
94 typedef struct process_arg {
102 } s_process_arg_t, *process_arg_t;
104 typedef struct msg_comm {
105 smx_activity_t s_comm; /* SIMIX communication object encapsulated (the same for both processes) */
106 msg_task_t task_sent; /* task sent (NULL for the receiver) */
107 msg_task_t *task_received; /* where the task will be received (NULL for the sender) */
108 msg_error_t status; /* status of the communication once finished */
111 /******************************* VM *************************************/
112 typedef struct dirty_page {
114 double prev_remaining;
116 } s_dirty_page, *dirty_page_t;
118 /************************** Global variables ********************************/
119 typedef struct MSG_Global {
120 int debug_multiple_use; /* whether we want an error message when reusing the same Task for 2 things */
121 unsigned long int sent_msg; /* Total amount of messages sent during the simulation */
122 void (*task_copy_callback) (msg_task_t task, msg_process_t src, msg_process_t dst);
123 void_f_pvoid_t process_data_cleanup;
124 } s_MSG_Global_t, *MSG_Global_t;
126 /*extern MSG_Global_t msg_global;*/
127 XBT_PUBLIC_DATA(MSG_Global_t) msg_global;
129 /*************************************************************/
130 XBT_PRIVATE msg_host_t __MSG_host_create(sg_host_t host);
131 XBT_PRIVATE msg_storage_t __MSG_storage_create(smx_storage_t storage);
132 XBT_PRIVATE void __MSG_host_priv_free(msg_host_priv_t priv);
133 XBT_PRIVATE void __MSG_storage_destroy(msg_storage_priv_t host);
134 XBT_PRIVATE void __MSG_file_destroy(msg_file_priv_t host);
136 XBT_PRIVATE void MSG_process_cleanup_from_SIMIX(smx_actor_t smx_proc);
137 XBT_PRIVATE smx_actor_t MSG_process_create_from_SIMIX(const char *name,
138 std::function<void()> code, void *data,
139 sg_host_t host, double kill_time,
140 xbt_dict_t properties, int auto_restart,
141 smx_actor_t parent_process);
142 XBT_PRIVATE void MSG_comm_copy_data_from_SIMIX(smx_activity_t comm, void* buff, size_t buff_size);
144 XBT_PRIVATE void MSG_post_create_environment();
146 XBT_PRIVATE void MSG_host_add_task(msg_host_t host, msg_task_t task);
147 XBT_PRIVATE void MSG_host_del_task(msg_host_t host, msg_task_t task);
149 /********** Tracing **********/
150 /* declaration of instrumentation functions from msg_task_instr.c */
151 XBT_PRIVATE void TRACE_msg_set_task_category(msg_task_t task, const char *category);
152 XBT_PRIVATE void TRACE_msg_task_create(msg_task_t task);
153 XBT_PRIVATE void TRACE_msg_task_execute_start(msg_task_t task);
154 XBT_PRIVATE void TRACE_msg_task_execute_end(msg_task_t task);
155 XBT_PRIVATE void TRACE_msg_task_destroy(msg_task_t task);
156 XBT_PRIVATE void TRACE_msg_task_get_end(double start_time, msg_task_t task);
157 XBT_PRIVATE void TRACE_msg_task_get_start();
158 XBT_PRIVATE int TRACE_msg_task_put_start(msg_task_t task); //returns TRUE if the task_put_end must be called
159 XBT_PRIVATE void TRACE_msg_task_put_end();
161 /* declaration of instrumentation functions from msg_process_instr.c */
162 XBT_PRIVATE char *instr_process_id (msg_process_t proc, char *str, int len);
163 XBT_PRIVATE char *instr_process_id_2 (const char *process_name, int process_pid, char *str, int len);
164 XBT_PRIVATE void TRACE_msg_process_change_host(msg_process_t process, msg_host_t old_host, msg_host_t new_host);
165 XBT_PRIVATE void TRACE_msg_process_create (const char *process_name, int process_pid, msg_host_t host);
166 XBT_PRIVATE void TRACE_msg_process_destroy (const char *process_name, int process_pid);
167 XBT_PRIVATE void TRACE_msg_process_kill(smx_process_exit_status_t status, msg_process_t process);
168 XBT_PRIVATE void TRACE_msg_process_suspend(msg_process_t process);
169 XBT_PRIVATE void TRACE_msg_process_resume(msg_process_t process);
170 XBT_PRIVATE void TRACE_msg_process_sleep_in(msg_process_t process); //called from msg/gos.c
171 XBT_PRIVATE void TRACE_msg_process_sleep_out(msg_process_t process);
175 XBT_PUBLIC(msg_process_t) MSG_process_create_with_environment(
176 const char *name, std::function<void()> code, void *data,
177 msg_host_t host, xbt_dict_t properties);
179 inline void simdata_task::setUsed()
182 this->reportMultipleUse();
183 if (msg_global->debug_multiple_use) {