My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
runtime_messages.c
Go to the documentation of this file.
1 /*
2 START OF LICENSE STUB
3  DeDOS: Declarative Dispersion-Oriented Software
4  Copyright (C) 2017 University of Pennsylvania, Georgetown University
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 END OF LICENSE STUB
19 */
20 #include "runtime_messages.h"
21 #include "dfg.h"
22 #include "logging.h"
23 #include "ctrl_runtime_messages.h"
24 #include "runtime_communication.h"
25 
26 int send_create_msu_msg(struct dfg_msu *msu) {
27 
28  if (msu->scheduling.runtime == NULL || msu->scheduling.thread == NULL) {
29  log_error("Cannot send message for unscheduled MSU");
30  return -1;
31  }
32 
33  struct ctrl_create_msu_msg msg = {
34  .msu_id = msu->id,
35  .type_id = msu->type->id,
36  .init_data = msu->init_data
37  };
38 
39  struct ctrl_runtime_msg_hdr hdr = {
41  .thread_id = msu->scheduling.thread->id,
42  .payload_size = sizeof(msg)
43  };
44 
45  int rtn = send_to_runtime(msu->scheduling.runtime->id, &hdr, &msg);
46 
47  if (rtn < 0) {
48  log_error("Error sending create-msu msg to runtime %d",
49  msu->scheduling.runtime->id);
50  return -1;
51  }
52  log(LOG_RUNTIME_MESSAGES, "Sent CREATE_MSU message");
53  return 0;
54 }
55 
56 int send_delete_msu_msg(struct dfg_msu *msu) {
57 
58  if (msu->scheduling.runtime == NULL || msu->scheduling.thread == NULL) {
59  log_error("Cannot send message for unscheduled MSU");
60  return -1;
61  }
62 
63  struct ctrl_delete_msu_msg msg = {
64  .msu_id = msu->id,
65  .force = 1
66  };
67 
68  struct ctrl_runtime_msg_hdr hdr = {
70  .thread_id = msu->scheduling.thread->id,
71  .payload_size = sizeof(msg)
72  };
73 
74  int rtn = send_to_runtime(msu->scheduling.runtime->id, &hdr, &msg);
75 
76  if (rtn < 0) {
77  log_error("Error sending delete-msu-msg to runtime %d",
78  msu->scheduling.runtime->id);
79  return -1;
80  }
81  log(LOG_RUNTIME_MESSAGES, "Sent DELETE_MSU message");
82  return 0;
83 }
84 
86  struct ctrl_route_msg msg = {
87  .type = CREATE_ROUTE,
88  .route_id = route->id,
89  .type_id = route->msu_type->id
90  };
91  struct ctrl_runtime_msg_hdr hdr = {
93  .thread_id = MAIN_THREAD_ID,
94  .payload_size = sizeof(msg)
95  };
96 
97  int rtn = send_to_runtime(route->runtime->id, &hdr, &msg);
98  if (rtn < 0) {
99  log_error("Error sending add-route msg to runtime %d", route->runtime->id);
100  return -1;
101  }
102  log(LOG_RUNTIME_MESSAGES, "Sent CREATE_ROUTE message");
103  return 0;
104 }
105 
106 int send_delete_route_msg(struct dfg_route *route) {
107  struct ctrl_route_msg msg = {
108  .type = DELETE_ROUTE,
109  .route_id = route->id
110  };
111 
112  struct ctrl_runtime_msg_hdr hdr = {
114  .thread_id = MAIN_THREAD_ID,
115  .payload_size = sizeof(msg)
116  };
117 
118  int rtn = send_to_runtime(route->runtime->id, &hdr, &msg);
119  if (rtn < 0) {
120  log_error("Error sending del-route msg to runtime %d", route->runtime->id);
121  return -1;
122  }
123  log(LOG_RUNTIME_MESSAGES, "Sent DELETE_ROUTE message");
124  return 0;
125 }
126 
127 int send_add_route_to_msu_msg(struct dfg_route *route, struct dfg_msu *msu) {
128  struct ctrl_msu_route_msg msg = {
129  .type = ADD_ROUTE,
130  .route_id = route->id,
131  .msu_id = msu->id
132  };
133 
134  struct ctrl_runtime_msg_hdr hdr = {
136  .thread_id = msu->scheduling.thread->id,
137  .payload_size = sizeof(msg)
138  };
139 
140  int rtn = send_to_runtime(msu->scheduling.runtime->id, &hdr, &msg);
141  if (rtn < 0) {
142  log_error("Error sending add-route-to-msu msg to runtime %d",
143  msu->scheduling.runtime->id);
144  return -1;
145  }
146  log(LOG_RUNTIME_MESSAGES, "Sent ADD_ROUTE_TO_MSU message");
147  return 0;
148 }
149 
150 int send_add_endpoint_msg(struct dfg_route *route, struct dfg_route_endpoint *endpoint) {
151  struct ctrl_route_msg msg = {
152  .type = ADD_ENDPOINT,
153  .route_id = route->id,
154  .msu_id = endpoint->msu->id,
155  .key = endpoint->key,
156  .runtime_id = endpoint->msu->scheduling.runtime->id
157  };
158 
159  struct ctrl_runtime_msg_hdr hdr = {
161  .thread_id = MAIN_THREAD_ID,
162  .payload_size = sizeof(msg)
163  };
164 
165  int rtn = send_to_runtime(route->runtime->id, &hdr, &msg);
166  if (rtn < 0) {
167  log_error("Error sending add-endpoint-to-route msg to runtime %d",
168  route->runtime->id);
169  return -1;
170  }
171  log(LOG_RUNTIME_MESSAGES, "Sent ADD_ENDPOINT message");
172  return 0;
173 }
174 
175 int send_del_endpoint_msg(struct dfg_route *route, struct dfg_route_endpoint *endpoint) {
176  struct ctrl_route_msg msg = {
177  .type = DEL_ENDPOINT,
178  .route_id = route->id,
179  .msu_id = endpoint->msu->id
180  };
181 
182  struct ctrl_runtime_msg_hdr hdr = {
184  .thread_id = MAIN_THREAD_ID,
185  .payload_size = sizeof(msg)
186  };
187 
188  int rtn = send_to_runtime(route->runtime->id, &hdr, &msg);
189  if (rtn < 0) {
190  log_error("Error sending del-endpoint msg to runtime %d", route->runtime->id);
191  return -1;
192  }
193  log(LOG_RUNTIME_MESSAGES, "Sent ADD_ENDPOINT message");
194  return 0;
195 }
196 
197 int send_mod_endpoint_msg(struct dfg_route *route, struct dfg_route_endpoint *endpoint) {
198  struct ctrl_route_msg msg = {
199  .type = MOD_ENDPOINT,
200  .route_id = route->id,
201  .msu_id = endpoint->msu->id,
202  .key = endpoint->key
203  };
204 
205  struct ctrl_runtime_msg_hdr hdr = {
207  .thread_id = MAIN_THREAD_ID,
208  .payload_size = sizeof(msg)
209  };
210 
211  int rtn = send_to_runtime(route->runtime->id, &hdr, &msg);
212  if (rtn < 0) {
213  log_error("Error sending mod-endpoint msg to runtime %d", route->runtime->id);
214  return -1;
215  }
216  return 0;
217 }
218 
219 int send_create_thread_msg(struct dfg_thread *thread, struct dfg_runtime *rt) {
220  struct ctrl_create_thread_msg msg = {
221  .thread_id = thread->id,
222  .mode = thread->mode
223  };
224 
225  struct ctrl_runtime_msg_hdr hdr = {
227  .thread_id = MAIN_THREAD_ID,
228  .payload_size = sizeof(msg)
229  };
230 
231  int rtn = send_to_runtime(rt->id, &hdr, &msg);
232  if (rtn < 0) {
233  log_error("Error sending create-thread msg to runtime %d", rt->id);
234  return -1;
235  }
236  log(LOG_RUNTIME_MESSAGES, "Sent CREATE_THREAD message");
237  return 0;
238 }
payload: ctrl_create_thread_msg
int send_to_runtime(unsigned int runtime_id, struct ctrl_runtime_msg_hdr *hdr, void *payload)
enum thread_mode mode
Pinned/unpinned mode for the thread.
Definition: dfg.h:106
#define MAIN_THREAD_ID
The ID to which messages should be addressed when delivered to the main runtime thread.
Definition: dfg.h:42
struct dfg_scheduling scheduling
Information about where an MSU is scheduled.
Definition: dfg.h:225
payload: ctrl_msu_route_msg
All messages sent from controller to runtime are prefixed with this header.
Payload for messages of type CTRL_DELETE_MSU.
Adds a route to an MSU.
int send_delete_msu_msg(struct dfg_msu *msu)
enum ctrl_msu_route_type type
Sub-type of message.
int send_add_endpoint_msg(struct dfg_route *route, struct dfg_route_endpoint *endpoint)
Deletes a route.
int send_mod_endpoint_msg(struct dfg_route *route, struct dfg_route_endpoint *endpoint)
Payload for messages of type CTRL_MODIFY_ROUTE.
static int route(struct msu_type *type, struct local_msu *sender, struct msu_msg *msg, struct msu_endpoint *output)
Definition: baremetal_msu.c:30
int id
Unique identifier for the runtime.
Definition: dfg.h:74
payload: ctrl_create_msu_msg
Logging of status messages to the terminal.
struct dfg_msu_type * type
The type of the MSU and meta-routing information.
Definition: dfg.h:221
Payload for messages of type CTRL_CREATE_MSU.
Representation of a runtime in the DFG.
Definition: dfg.h:73
int send_create_msu_msg(struct dfg_msu *msu)
struct dfg_runtime * runtime
The runtime on which an MSU is running.
Definition: dfg.h:117
#define log_error(fmt,...)
Definition: logging.h:101
int thread_id
The ID to give to the created thread.
struct dfg_msu * msu
The MSU at this endpoint to which a message would be delivered.
Definition: dfg.h:143
int send_add_route_to_msu_msg(struct dfg_route *route, struct dfg_msu *msu)
Payload for messages of type CTRL_CREATE_THREAD.
int id
A unique identifier for the MSU.
Definition: dfg.h:217
struct dfg_thread * thread
The thread on which an MSU is running.
Definition: dfg.h:118
Definitions of structures for sending messages from the global controller to runtimes.
int msu_id
ID of the MSU to be deleted.
int id
Unique identifier for the thread.
Definition: dfg.h:105
Representation of a single MSU in the dfg.
Definition: dfg.h:216
payload: ctrl_route_msg
Payload for messages of type CTRL_MSU_ROUTES.
struct dfg_runtime * runtime
The runtime on which the route is located.
Definition: dfg.h:154
int id
A unique identifier for the MSU type.
Definition: dfg.h:177
int id
A unique identifier for the route.
Definition: dfg.h:153
Adds an endpoint to a route.
A route through which MSU messages can be passed.
Definition: dfg.h:152
struct msu_init_data init_data
Initial data passed to the MSU.
Definition: dfg.h:219
int msu_id
ID of the MSU to create.
Interfaces for the creation and modification of the data-flow-graph and and general description of th...
A single endpoint for an MSU route.
Definition: dfg.h:139
Deletes an endpoint from a route.
uint32_t key
The key associated with this endpoint.
Definition: dfg.h:140
enum ctrl_runtime_msg_type type
Identifies the type of payload that follows.
enum ctrl_route_msg_type type
sub-type of message
Modifies the key corresponding to a route endpoint.
Representation of a thread on a runtime in the DFG.
Definition: dfg.h:104
Creates a new route.
#define log(level, fmt,...)
Log at a custom level.
Definition: logging.h:147
int send_delete_route_msg(struct dfg_route *route)
int send_create_route_msg(struct dfg_route *route)
int send_del_endpoint_msg(struct dfg_route *route, struct dfg_route_endpoint *endpoint)
int send_create_thread_msg(struct dfg_thread *thread, struct dfg_runtime *rt)
payload: ctrl_delete_msu_msg
struct dfg_msu_type * msu_type
The type of MSU to which this route delivers.
Definition: dfg.h:155