The ROme OpTimistic Simulator  2.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
control.c
Go to the documentation of this file.
1 
29 #include <stdbool.h>
30 
31 #include <scheduler/scheduler.h>
32 #include <scheduler/process.h>
33 #include <core/core.h>
35 #include <mm/mm.h>
36 #include <mm/ecs.h>
37 #include <datatypes/list.h>
38 #include <gvt/gvt.h>
39 
40 // Questa funzione serve a mandare in rollback qualcuno che mi
41 // aveva mandato un RENDEZVOUS_START. Viene invocata da rollback()
42 // e simtime è il tempo del bound, quindi il tempo dell'ultimo evento
43 // correttamente processato nella traiettoria speculativa.
44 // Ogni volta che ricevo un RENDEZVOUS_START da un altro processo
45 // copio il messaggio nella rendezvous_queue.
46 void rollback_control_message(struct lp_struct *lp, simtime_t simtime)
47 {
48  msg_t *control_antimessage;
49  msg_t *msg, *msg_prev;
50 
51  if (list_empty(lp->rendezvous_queue)) {
52  return;
53  }
54 
55  msg = list_tail(lp->rendezvous_queue);
56  while (msg != NULL && msg->timestamp > simtime) {
57 
58  // Control antimessage
59  pack_msg(&control_antimessage, msg->receiver, msg->sender,
60  RENDEZVOUS_ROLLBACK, msg->timestamp, msg->send_time, 0,
61  NULL);
62  control_antimessage->rendezvous_mark = msg->rendezvous_mark;
63  control_antimessage->message_kind = control;
64  Send(control_antimessage);
65  msg_prev = list_prev(msg);
66  list_delete_by_content(lp->rendezvous_queue, msg);
67  msg = msg_prev;
68  }
69 }
70 
71 // return false if the antimessage is recognized (and processed) as a control antimessage
72 bool anti_control_message(msg_t * msg)
73 {
74 #ifndef HAVE_CROSS_STATE
75  (void)msg;
76 #else
77  msg_t *old_rendezvous;
78 
79  if (msg->type == RENDEZVOUS_ROLLBACK) {
80 
81  struct lp_struct *receiver = find_lp_by_gid(msg->receiver);
82  //Check if a relative message exists
83  //TODO non serve andare indietro più del tempo di rendezvous_rollback (VERO!!! Ma in quel caso devo uscire dal ciclo con old_rendezvous == NULL per cadere nell'if successivo)
84  old_rendezvous = list_tail(receiver->queue_in);
85  while (old_rendezvous != NULL
86  && old_rendezvous->rendezvous_mark !=
87  msg->rendezvous_mark) {
88  old_rendezvous = list_prev(old_rendezvous);
89  }
90 
91  if (old_rendezvous == NULL) {
92  return false;
93  }
94  //If this event is in the past
95  if (old_rendezvous->timestamp <= lvt(lid_receiver)) {
96 
97  // Set LP->bound to the message that caused ECS
98  receiver->bound = list_prev(old_rendezvous);
99  while (receiver->bound != NULL
100  && receiver->bound->timestamp >=
101  old_rendezvous->timestamp) {
102  // if(list_prev(receiver->bound) == NULL) {
103  // break;
104  // }
105  receiver->bound = list_prev(receiver->bound);
106  }
107 
108  receiver->state = LP_STATE_ROLLBACK;
109  }
110 
111  old_rendezvous->rendezvous_mark = 0;
112 
113  //Reset ECS information
114  if (receiver->wait_on_rendezvous == msg->rendezvous_mark) {
115  receiver->ECS_index = 0;
116  receiver->wait_on_rendezvous = 0;
117  }
118 
119  return false;
120  }
121 #endif
122 
123  return true;
124 }
125 
126 // return true if the control message should be reprocessed during silent exceution
127 bool reprocess_control_msg(msg_t * msg)
128 {
129 
130  if (msg->type < MIN_VALUE_CONTROL) {
131  return true;
132  }
133 
134  return false;
135 }
136 
137 // return true if the event must not be filtered here
138 bool receive_control_msg(msg_t * msg)
139 {
140 
141  if (msg->type < MIN_VALUE_CONTROL || msg->type > MAX_VALUE_CONTROL) {
142  return true;
143  }
144 #ifdef HAVE_CROSS_STATE
145  struct lp_struct *receiver = find_lp_by_gid(msg->receiver);
146  switch (msg->type) {
147 
148  case RENDEZVOUS_START:
149  return true;
150 
151  case RENDEZVOUS_GET_PAGE:
152  ecs_send_pages(msg);
153  break;
154 
157  if (receiver->state == LP_STATE_ROLLBACK ||
158  receiver->state == LP_STATE_SILENT_EXEC) {
159  break;
160  }
161  if (receiver->wait_on_rendezvous == msg->rendezvous_mark) {
162  ecs_install_pages(msg);
163  receiver->state = LP_STATE_READY_FOR_SYNCH;
164  }
165  break;
166 
167  case RENDEZVOUS_ACK:
168  if (receiver->state == LP_STATE_ROLLBACK ||
169  receiver->state == LP_STATE_SILENT_EXEC) {
170  break;
171  }
172  if (receiver->wait_on_rendezvous == msg->rendezvous_mark) {
173  setup_ecs_on_segment(msg);
174  receiver->state = LP_STATE_READY_FOR_SYNCH;
175  }
176 
177  break;
178 
179  case RENDEZVOUS_UNBLOCK:
180  if (receiver->state == LP_STATE_ROLLBACK ||
181  receiver->state == LP_STATE_SILENT_EXEC) {
182  break;
183  }
184 
185  if (receiver->wait_on_rendezvous == msg->rendezvous_mark) {
186  receiver->wait_on_rendezvous = 0;
187  receiver->state = LP_STATE_READY;
188  }
189 
190  current = find_lp_by_gid(msg->receiver);
191  current_lvt = msg->timestamp;
193  LogState(current);
194  current_lvt = INFTY;
195  current = NULL;
196 
197  break;
198 
199  case RENDEZVOUS_ROLLBACK:
200  return true;
201 
202  default:
203  rootsim_error(true,
204  "Trying to handle a control message which is meaningless at receive time: %d\n",
205  msg->type);
206 
207  }
208 #endif
209 
210  return false;
211 }
212 
213 // return true if must be passed to the LP
214 bool process_control_msg(msg_t * msg)
215 {
216 
217 #ifdef HAVE_CROSS_STATE
218  msg_t *control_msg;
219 #endif
220 
221  if (msg->type < MIN_VALUE_CONTROL || msg->type > MAX_VALUE_CONTROL) {
222  return true;
223  }
224 #ifdef HAVE_CROSS_STATE
225  struct lp_struct *receiver = find_lp_by_gid(msg->receiver);
226  msg_t *copy;
227  switch (msg->type) {
228 
229  case RENDEZVOUS_START:
230  copy = rsalloc(sizeof(msg_t));
231  *copy = *msg;
232  list_insert(receiver->rendezvous_queue, timestamp, copy);
233  // Place this into input queue
234  receiver->wait_on_rendezvous = msg->rendezvous_mark;
235 
236  receiver->state = LP_STATE_WAIT_FOR_UNBLOCK;
237 
238  pack_msg(&control_msg, msg->receiver, msg->sender,
239  RENDEZVOUS_ACK, msg->timestamp, msg->timestamp, 0,
240  NULL);
241  control_msg->message_kind = positive;
242  control_msg->rendezvous_mark = msg->rendezvous_mark;
243  Send(control_msg);
244 
245  break;
246 
247  default:
248  rootsim_error(true,
249  "Trying to handle a control message which is meaningless at schedule time: %d\n",
250  msg->type);
251 
252  }
253 #endif
254 
255  return false;
256 }
ECS protocol: a remote LP is asked for a certain set of pages.
Definition: communication.h:69
Communication Routines.
#define lvt(lp)
Definition: process.h:168
msg_t * bound
Pointer to the last correctly processed event.
Definition: process.h:106
ECS protocol: the sender LP has been synchronized and is now blocked.
Definition: communication.h:66
void force_LP_checkpoint(struct lp_struct *lp)
Definition: state.c:364
Core ROOT-Sim functionalities.
Anything after this value is considered as an impossible message.
Definition: communication.h:72
#define list_empty(list)
Definition: list.h:110
The ROOT-Sim scheduler main module header.
#define list_prev(ptr)
Definition: list.h:95
Separation value between model and platform messages.
Definition: communication.h:64
__thread struct lp_struct * current
This is a per-thread variable pointing to the block state of the LP currently scheduled.
Definition: scheduler.c:72
ECS protocol: start synchronizing two LPs for a page fault.
Definition: communication.h:65
#define list_insert(li, key_name, data)
Insert a new node in the list.
Definition: list.h:163
#define INFTY
Infinite timestamp: this is the highest timestamp in a simulation run.
Definition: ROOT-Sim.h:58
double simtime_t
This defines the type with whom timestamps are represented.
Definition: ROOT-Sim.h:55
Memory Manager main header.
Generic Lists.
Message Type definition.
Definition: core.h:164
ECS protocol: the destination LP can resume its normal execution.
Definition: communication.h:67
void Send(msg_t *msg)
Send a message.
LP control blocks.
unsigned long long rendezvous_mark
Unique identifier of the message, used for antimessages.
Definition: core.h:186
void pack_msg(msg_t **msg, GID_t sender, GID_t receiver, int type, simtime_t timestamp, simtime_t send_time, size_t size, void *payload)
Pack a message in a platform-level data structure.
short unsigned int state
Current execution state of the LP.
Definition: process.h:88
ECS protocol: modified pages are sent back to the owner LP.
Definition: communication.h:71
ECS protocol: an ECS synchronization should be rolled back.
Definition: communication.h:68
Global Virtual Time.
ECS protocol: the sender LP is giving a lease on a set of pages.
Definition: communication.h:70
#define list_tail(list)
Definition: list.h:81
Event & Cross State Synchornization.
bool LogState(struct lp_struct *lp)
Definition: state.c:55