Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Allow multicore VMs, and take this into account in the sharing
[simgrid.git] / src / msg / msg_private.h
1 /* Copyright (c) 2004-2017. 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 METASIMGRID_PRIVATE_H
7 #define METASIMGRID_PRIVATE_H
8
9 #include "simgrid/msg.h"
10
11 #include "src/kernel/activity/CommImpl.hpp"
12 #include "src/kernel/activity/ExecImpl.hpp"
13 #include "xbt/Extendable.hpp"
14
15 /**************** datatypes **********************************/
16 /**************************** Host Extension *********************************/
17 namespace simgrid {
18 class MsgHostExt {
19 public:
20   static simgrid::xbt::Extension<s4u::Host, MsgHostExt> EXTENSION_ID;
21
22   ~MsgHostExt() {
23     delete file_descriptor_table;
24   }
25   std::vector<int>* file_descriptor_table = nullptr; // Created lazily on need
26 };
27 }
28 /********************************* Task **************************************/
29
30 typedef struct simdata_task {
31   ~simdata_task()
32   {
33     if (this->compute)
34       this->compute->unref();
35
36     /* parallel tasks only */
37     xbt_free(this->host_list);
38   }
39   void setUsed();
40   void setNotUsed()
41   {
42     this->isused = false;
43   }
44
45   simgrid::kernel::activity::ExecImpl* compute = nullptr; /* SIMIX modeling of computation */
46   simgrid::kernel::activity::CommImpl* comm = nullptr; /* SIMIX modeling of communication */
47   double bytes_amount = 0.0; /* Data size */
48   double flops_amount = 0.0; /* Computation size */
49   msg_process_t sender = nullptr;
50   msg_process_t receiver = nullptr;
51   msg_host_t source = nullptr;
52
53   double priority = 1.0;
54   double bound    = 0.0; /* Capping for CPU resource, or 0 for no capping */
55   double rate     = -1;  /* Capping for network resource, or -1 for no capping*/
56
57   bool isused = false;  /* Indicates whether the task is used in SIMIX currently */
58   int host_nb = 0;      /* ==0 if sequential task; parallel task if not */
59   /*******  Parallel Tasks Only !!!! *******/
60   sg_host_t *host_list = nullptr;
61   double *flops_parallel_amount = nullptr;
62   double *bytes_parallel_amount = nullptr;
63
64 private:
65   void reportMultipleUse() const;
66 } s_simdata_task_t;
67
68 /********************************* File **************************************/
69 typedef struct simdata_file {
70   smx_file_t smx_file;
71 } s_simdata_file_t;
72
73 /******************************* Process *************************************/
74
75 namespace simgrid {
76 class MsgActorExt {
77 public:
78   explicit MsgActorExt(void* d) : data(d) {}
79   msg_error_t errno_ = MSG_OK;  /* the last value returned by a MSG_function */
80   void* data = nullptr; /* user data */
81 };
82 }
83
84 typedef struct msg_comm {
85   smx_activity_t s_comm;          /* SIMIX communication object encapsulated (the same for both processes) */
86   msg_task_t task_sent;           /* task sent (NULL for the receiver) */
87   msg_task_t *task_received;      /* where the task will be received (NULL for the sender) */
88   msg_error_t status;           /* status of the communication once finished */
89 } s_msg_comm_t;
90
91 /************************** Global variables ********************************/
92 typedef struct MSG_Global {
93   int debug_multiple_use;       /* whether we want an error message when reusing the same Task for 2 things */
94   unsigned long int sent_msg;   /* Total amount of messages sent during the simulation */
95   void (*task_copy_callback) (msg_task_t task, msg_process_t src, msg_process_t dst);
96   void_f_pvoid_t process_data_cleanup;
97 } s_MSG_Global_t;
98 typedef s_MSG_Global_t* MSG_Global_t;
99
100 SG_BEGIN_DECL()
101
102 XBT_PUBLIC_DATA(MSG_Global_t) msg_global;
103
104 /*************************************************************/
105
106 XBT_PRIVATE msg_host_t __MSG_host_create(sg_host_t host);
107 XBT_PRIVATE msg_storage_t __MSG_storage_create(smx_storage_t storage);
108 XBT_PRIVATE void __MSG_storage_destroy(msg_storage_priv_t host);
109 XBT_PRIVATE void __MSG_file_destroy(msg_file_t file);
110
111 XBT_PRIVATE void MSG_process_cleanup_from_SIMIX(smx_actor_t smx_proc);
112 XBT_PRIVATE smx_actor_t MSG_process_create_from_SIMIX(const char* name, std::function<void()> code, void* data,
113                                                       sg_host_t host, xbt_dict_t properties,
114                                                       smx_actor_t parent_process);
115 XBT_PRIVATE void MSG_comm_copy_data_from_SIMIX(smx_activity_t comm, void* buff, size_t buff_size);
116
117 XBT_PRIVATE void MSG_post_create_environment();
118
119 XBT_PRIVATE void MSG_host_add_task(msg_host_t host, msg_task_t task);
120 XBT_PRIVATE void MSG_host_del_task(msg_host_t host, msg_task_t task);
121
122 /********** Tracing **********/
123 /* declaration of instrumentation functions from msg_task_instr.c */
124 XBT_PRIVATE void TRACE_msg_set_task_category(msg_task_t task, const char *category);
125 XBT_PRIVATE void TRACE_msg_task_create(msg_task_t task);
126 XBT_PRIVATE void TRACE_msg_task_execute_start(msg_task_t task);
127 XBT_PRIVATE void TRACE_msg_task_execute_end(msg_task_t task);
128 XBT_PRIVATE void TRACE_msg_task_destroy(msg_task_t task);
129 XBT_PRIVATE void TRACE_msg_task_get_end(double start_time, msg_task_t task);
130 XBT_PRIVATE void TRACE_msg_task_get_start();
131 XBT_PRIVATE int TRACE_msg_task_put_start(msg_task_t task);    //returns TRUE if the task_put_end must be called
132 XBT_PRIVATE void TRACE_msg_task_put_end();
133
134 /* declaration of instrumentation functions from msg_process_instr.c */
135 XBT_PRIVATE char *instr_process_id (msg_process_t proc, char *str, int len);
136 XBT_PRIVATE char *instr_process_id_2 (const char *process_name, int process_pid, char *str, int len);
137 XBT_PRIVATE void TRACE_msg_process_change_host(msg_process_t process, msg_host_t old_host, msg_host_t new_host);
138 XBT_PRIVATE void TRACE_msg_process_create (const char *process_name, int process_pid, msg_host_t host);
139 XBT_PRIVATE void TRACE_msg_process_destroy (const char *process_name, int process_pid);
140 XBT_PRIVATE void TRACE_msg_process_kill(smx_process_exit_status_t status, msg_process_t process);
141 XBT_PRIVATE void TRACE_msg_process_suspend(msg_process_t process);
142 XBT_PRIVATE void TRACE_msg_process_resume(msg_process_t process);
143 XBT_PRIVATE void TRACE_msg_process_sleep_in(msg_process_t process);   //called from msg/gos.c
144 XBT_PRIVATE void TRACE_msg_process_sleep_out(msg_process_t process);
145
146 SG_END_DECL()
147
148 inline void simdata_task::setUsed()
149 {
150   if (this->isused)
151     this->reportMultipleUse();
152   if (msg_global->debug_multiple_use) {
153     // TODO, backtrace
154   }
155   this->isused = true;
156 }
157
158 #endif