My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
dfg.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 */
25 #include "dfg.h"
26 #include "logging.h"
27 
28 #include <stdbool.h>
29 #include <stdlib.h>
30 
32 static struct dedos_dfg *dfg;
33 
34 void set_dfg(struct dedos_dfg *dfg_in) {
35  dfg = dfg_in;
36 }
37 
46 #define SEARCH_FOR_ID(s, n, field, id_) \
47  if (dfg == NULL) \
48  return NULL; \
49  for (int i=0; i<(n); ++i) { \
50  if (field[i]->id == id_) { \
51  return field[i]; \
52  } \
53  } \
54  return NULL;
55 
56 struct db_info *get_db_info() {
57  return &dfg->db;
58 }
59 
61  return dfg->n_runtimes;
62 }
63 
64 struct dfg_runtime *get_dfg_runtime(unsigned int runtime_id) {
65  SEARCH_FOR_ID(dfg, dfg->n_runtimes, dfg->runtimes, runtime_id);
66 }
67 
68 struct dfg_msu_type *get_dfg_msu_type(unsigned int id){
69  SEARCH_FOR_ID(dfg, dfg->n_msu_types, dfg->msu_types, id)
70 }
71 
72 struct dfg_route *get_dfg_runtime_route(struct dfg_runtime *rt, unsigned int id) {
73  SEARCH_FOR_ID(rt, rt->n_routes, rt->routes, id);
74 }
75 
76 struct dfg_route *get_dfg_route(unsigned int id) {
77  for (int i=0; i<dfg->n_runtimes; i++) {
78  struct dfg_route *route = get_dfg_runtime_route(dfg->runtimes[i], id);
79  if (route != NULL) {
80  return route;
81  }
82  }
83  return NULL;
84 }
85 
86 struct dfg_msu *get_dfg_msu(unsigned int id){
87  SEARCH_FOR_ID(dfg, dfg->n_msus, dfg->msus, id)
88 }
89 
90 struct dfg_route *get_dfg_rt_route_by_type(struct dfg_runtime *rt, struct dfg_msu_type *type) {
91  for (int i=0; i<rt->n_routes; i++) {
92  if (rt->routes[i]->msu_type == type) {
93  return rt->routes[i];
94  }
95  }
96  return NULL;
97 }
98 
99 struct dfg_route *get_dfg_msu_route_by_type(struct dfg_msu *msu, struct dfg_msu_type *route_type) {
100  for (int i=0; i<msu->scheduling.n_routes; i++) {
101  if (msu->scheduling.routes[i]->msu_type == route_type) {
102  return msu->scheduling.routes[i];
103  }
104  }
105  return NULL;
106 }
107 
108 struct dfg_thread *get_dfg_thread(struct dfg_runtime *rt, unsigned int id){
110 }
111 
112 struct dfg_route_endpoint *get_dfg_route_endpoint(struct dfg_route *route, unsigned int msu_id) {
113  for (int i=0; i<route->n_endpoints; i++) {
114  if (route->endpoints[i]->msu->id == msu_id) {
115  return route->endpoints[i];
116  }
117  }
118  return NULL;
119 }
120 
121 int msu_has_route(struct dfg_msu *msu, struct dfg_route *route) {
122  for (int i=0; i<msu->scheduling.n_routes; i++) {
123  if (msu->scheduling.routes[i] == route) {
124  return 1;
125  }
126  }
127  return 0;
128 }
129 
131  for (int i=0; i<type->n_instances; i++) {
132  if (type->instances[i]->scheduling.runtime == rt) {
133  return type->instances[i];
134  }
135  }
136  return NULL;
137 }
138 
139 enum thread_mode str_to_thread_mode(char *mode_str) {
140  if (strcasecmp(mode_str, "pinned") == 0) {
141  return PINNED_THREAD;
142  } else if (strcasecmp(mode_str, "unpinned") == 0) {
143  return UNPINNED_THREAD;
144  } else {
145  log_warn("Unknown thread mode: %s", mode_str);
147  }
148 }
149 
150 enum blocking_mode str_to_blocking_mode(char *mode_str) {
151  if (strcasecmp(mode_str, "blocking") == 0) {
152  return BLOCKING_MSU;
153  } else if (strcasecmp(mode_str, "nonblocking") == 0 ||
154  strcasecmp(mode_str, "non-blocking") == 0) {
155  return NONBLOCK_MSU;
156  } else {
157  log_warn("Unknown blocking mode: %s", mode_str);
158  return UNKNOWN_BLOCKING_MODE;
159  }
160 }
161 
162 uint8_t str_to_vertex_type(char *str_type) {
163  uint8_t vertex_type = 0;
164  if (strstr(str_type, "entry") != NULL) {
165  vertex_type |= ENTRY_VERTEX_TYPE;
166  }
167  if (strstr(str_type, "exit") != NULL) {
168  vertex_type |= EXIT_VERTEX_TYPE;
169  }
170  if (vertex_type == 0 && strstr(str_type, "nop") == NULL) {
171  log_warn("Unknown vertex type %s specified (neither exit, entry, nop found)", str_type);
172  return 0;
173  }
174  return vertex_type;
175 }
176 
182 static void set_msu_properties(struct dfg_msu *template, struct dfg_msu *target) {
183  target->id = template->id;
184  target->vertex_type = template->vertex_type;
185  target->init_data = template->init_data;
186  target->type = template->type;
187  target->blocking_mode = template->blocking_mode;
188 }
189 
190 struct dfg_msu *copy_dfg_msu(struct dfg_msu *input) {
191  struct dfg_msu *msu = calloc(1, sizeof(*input));
192  if (msu == NULL) {
193  log_error("Error allocating dfg MSU");
194  return NULL;
195  }
196  set_msu_properties(input, msu);
197  return msu;
198 }
199 
200 struct dfg_msu *init_dfg_msu(unsigned int id, struct dfg_msu_type *type, uint8_t vertex_type,
201  enum blocking_mode mode, struct msu_init_data *init_data) {
202 
203  struct dfg_msu *msu = get_dfg_msu(id);
204  if (msu != NULL) {
205  log_error("MSU %u already exists and scheduled", id);
206  return NULL;
207  }
208 
209  msu = calloc(1, sizeof(*msu));
210  if (msu == NULL) {
211  log_error("Error allocating dfg MSU");
212  return NULL;
213  }
214  struct dfg_msu template = {
215  .id = id,
216  .vertex_type = vertex_type,
217  .init_data = *init_data,
218  .type = type,
219  .blocking_mode = mode
220  };
221  set_msu_properties(&template, msu);
222  return msu;
223 }
224 
225 int free_dfg_msu(struct dfg_msu *input) {
226  if (input->scheduling.runtime != NULL || input->scheduling.thread != NULL) {
227  log_error("Cannot free MSU that is still assigned to thread or runtime");
228  return -1;
229  }
230  free(input);
231  return 0;
232 }
233 
237 static int schedule_msu_on_thread(struct dfg_msu *msu, struct dfg_thread *thread,
238  struct dfg_runtime *rt) {
239  if (thread->n_msus == MAX_MSU_PER_THREAD) {
240  log_error("Too many MSUs on thread %d", thread->id);
241  return -1;
242  }
243  if (dfg->n_msus == MAX_MSU) {
244  log_error("Too many MSUs in DFG");
245  return -1;
246  }
247  dfg->msus[dfg->n_msus] = msu;
248  dfg->n_msus++;
249 
250  thread->msus[thread->n_msus] = msu;
251  thread->n_msus++;
252 
253  msu->type->instances[msu->type->n_instances] = msu;
254  msu->type->n_instances++;
255 
256  msu->scheduling.thread = thread;
257  msu->scheduling.runtime = rt;
258  return 0;
259 }
260 
261 int schedule_dfg_msu(struct dfg_msu *msu, unsigned int runtime_id, unsigned int thread_id) {
262  if (dfg == NULL) {
263  log_error("DFG not instantiated");
264  return -1;
265  }
266 
267  if (msu->scheduling.runtime != NULL || msu->scheduling.thread != NULL) {
268  log_error("MSU already scheduled");
269  return -1;
270  }
271 
272  struct dfg_runtime *rt = get_dfg_runtime(runtime_id);
273  if (rt == NULL) {
274  log_error("Runtime id %u not instantiated", runtime_id);
275  return -1;
276  }
277  struct dfg_thread *thread = get_dfg_thread(rt, thread_id);
278  if (thread == NULL) {
279  log_error("Thread id %u not instantiated on runtime %u", thread_id, runtime_id);
280  return -1;
281  }
282 
283  int rtn = schedule_msu_on_thread(msu, thread, rt);
284  if (rtn < 0) {
285  log_error("Error scheduling MSU on thread");
286  return -1;
287  }
288 
289  log_info("TEST");
290  log(LOG_DFG, "Scheduled DFG msu %d", msu->id);
291  return 0;
292 }
293 
298 static int remove_msu_from_thread(struct dfg_msu *msu) {
299  struct dfg_thread *thread = msu->scheduling.thread;
300  int ti;
301  for (ti=0; ti<thread->n_msus && thread->msus[ti] != msu; ti++){}
302  if (ti == thread->n_msus) {
303  log_error("MSU %d does not exist on thread %d", msu->id, thread->id);
304  return -1;
305  }
306  int di;
307  for (di = 0; di < dfg->n_msus && dfg->msus[di] != msu; di++){}
308  if (di == dfg->n_msus) {
309  log_critical("Cannot find MSU %d in DFG!", msu->id);
310  return -1;
311  }
312  int ii;
313  for (ii = 0; ii < msu->type->n_instances && msu->type->instances[ii] != msu; ii++) {}
314  if (ii == msu->type->n_instances) {
315  log_error("Cannot find MSU %d in list of instances of %s", msu->id, msu->type->name);
316  return -1;
317  }
318 
319  for (int i=ti; i < thread->n_msus - 1; i++) {
320  thread->msus[i] = thread->msus[i+1];
321  }
322  thread->n_msus--;
323 
324  for (int i=di; i < dfg->n_msus - 1; i++) {
325  dfg->msus[i] = dfg->msus[i+1];
326  }
327  dfg->n_msus--;
328 
329  for (int i=ii; i < msu->type->n_instances - 1; i++) {
330  msu->type->instances[i] = msu->type->instances[i+1];
331  }
332  msu->type->n_instances--;
333 
334  msu->scheduling.runtime = NULL;
335  msu->scheduling.thread = NULL;
336  return 0;
337 }
338 
339 int unschedule_dfg_msu(struct dfg_msu *msu) {
340  if (dfg == NULL) {
341  log_error("DFG not instantiated");
342  return -1;
343  }
344 
345  if (msu->scheduling.runtime == NULL || msu->scheduling.thread == NULL) {
346  log_error("MSU not scheduled");
347  return -1;
348  }
349 
350  for (int i=0; i<dfg->n_runtimes; i++) {
351  struct dfg_runtime *rt = dfg->runtimes[i];
352  for (int j=0; j<rt->n_routes; j++) {
353  struct dfg_route *route = rt->routes[j];
354  if (get_dfg_route_endpoint(route, msu->id) != NULL) {
355  log_error("MSU %d Cannot be unscheduled: referenced by route %d",
356  msu->id, route->id);
357  return -1;
358  }
359  }
360  }
361 
362  log(LOG_DFG, "Unscheduled DFG msu %d", msu->id);
363  return remove_msu_from_thread(msu);
364 }
365 
366 struct dfg_route *create_dfg_route(unsigned int id, struct dfg_msu_type *type,
367  unsigned int runtime_id) {
368  struct dfg_route *route = get_dfg_route(id);
369  if (route != NULL) {
370  log_error("DFG route %u already exists", id);
371  return NULL;
372  }
373  struct dfg_runtime *rt = get_dfg_runtime(runtime_id);
374  if (rt == NULL) {
375  log_error("Runtime %u does not exist in DFG", runtime_id);
376  return NULL;
377  }
378  if (rt->n_routes == MAX_ROUTES) {
379  log_error("Cannot fit more routes on runtime %u", runtime_id);
380  return NULL;
381  }
382 
383  route = calloc(1, sizeof(*route));
384  if (route == NULL) {
385  log_error("Could not allocate DFG route %u", id);
386  return NULL;
387  }
388 
389  route->id = id;
390  route->msu_type = type;
391  route->runtime = rt;
392  // TODO: Add runtime to route in dfg_reader
393 
394  rt->routes[rt->n_routes] = route;
395  rt->n_routes++;
396  return route;
397 }
398 
400  for (int i=0; i<dfg->n_msus; i++) {
401  struct dfg_msu *msu = dfg->msus[i];
402  for (int j=0; j<msu->scheduling.n_routes; j++) {
403  if (msu->scheduling.routes[i] == route) {
404  log_error("Cannot delete route %d while it is still attached to msu %d",
405  route->id, msu->id);
406  return -1;
407  }
408  }
409  }
410 
411  struct dfg_runtime *rt = route->runtime;
412 
413  int i;
414  // Find the index of the route in the runtime
415  for (i=0; i<rt->n_routes && rt->routes[i] != route; i++);
416  if (i == rt->n_routes) {
417  log_error("Could not find route in runtime");
418  return -1;
419  }
420  for (; i<rt->n_routes-1; i++) {
421  rt->routes[i] = rt->routes[i+1];
422  }
423  rt->n_routes--;
424  return 0;
425 }
426 
427 
428 int add_dfg_route_to_msu(struct dfg_route *route, struct dfg_msu *msu) {
429  if (msu->scheduling.runtime != route->runtime) {
430  log_error("Cannot add route on runtime %d to msu on runtime %d",
431  route->runtime->id, msu->scheduling.runtime->id);
432  return -1;
433  }
434  for (int i=0; i<msu->scheduling.n_routes; i++) {
435  if (msu->scheduling.routes[i]->msu_type == route->msu_type) {
436  log_error("Route with type %d already exists in MSU %d",
437  route->msu_type->id, msu->id);
438  return -1;
439  }
440  }
441 
442  if (route->n_endpoints == 0) {
443  log_warn("Route with no destinations added to an MSU! "
444  "(Route: %d, msu: %d) "
445  "This could have unfortunate results!",
446  (int)route->id, (int)msu->id);
447  }
448 
450  msu->scheduling.n_routes++;
451  return 0;
452 }
453 
454 
456  struct dfg_route *route) {
457  if (route->n_endpoints == MAX_ROUTE_ENDPOINTS) {
458  log_error("Cannot add more MSUs to route %d", route->id);
459  return NULL;
460  }
461  if (route->msu_type != msu->type) {
462  log_error("Cannot add MSU of type %d to route of type %d",
463  msu->type->id, route->msu_type->id);
464  return NULL;
465  }
466 
467  struct dfg_route_endpoint *dest = malloc(sizeof(*dest));
468  if (dest == NULL) {
469  log_perror("Error allocating route destination");
470  return NULL;
471  }
472  dest->msu = msu;
473  dest->key = key;
474 
475  int i;
476  // Insert the endpoint in the correct place (ascending keys)
477  for (i=0; i<route->n_endpoints && route->endpoints[i]->key < key; i++);
478  for (int j=route->n_endpoints; j>i; j--) {
479  route->endpoints[j] = route->endpoints[j-1];
480  }
481  route->endpoints[i] = dest;
482  route->n_endpoints++;
483 
484  return dest;
485 }
486 
488  int i;
489  // Search for endpoint index
490  for (i=0; i<route->n_endpoints && route->endpoints[i] != ep; i++);
491 
492  if (i == route->n_endpoints) {
493  log_error("Could not find endpoint in route");
494  return -1;
495  }
496 
497  for (; i<route->n_endpoints-1; i++) {
498  route->endpoints[i] = route->endpoints[i+1];
499  }
500  route->n_endpoints--;
501  log(LOG_ROUTING_CHANGES, "Route %d now has %d endpoints", route->id, route->n_endpoints);
502  return 0;
503 }
504 
506  uint32_t new_key) {
507  // This is all so the keys remain in ascending order
508 
509  // Find where the endpoint used to be
510  int old;
511  for (old=0; old<route->n_endpoints && route->endpoints[old] != ep; old++);
512  if (old == route->n_endpoints) {
513  log_error("Could not find endpoint in route");
514  return -1;
515  }
516  // Find where it should now be
517  int new;
518  for (new=0; new<route->n_endpoints && route->endpoints[new]->key < new_key; new++);
519 
520  // Which direction are we moving the in-between endpoints
521  int delta = new > old ? 1 : -1;
522  // If we're deleting from below the new location, subtract one to the new location
523  if (delta == 1) {
524  new -= 1;
525  }
526 
527  // Iterate from the old to the new location, moving the endpoints in the other direction
528  for (int i=old; delta * i < delta * new; i += delta) {
529  route->endpoints[i] = route->endpoints[i + delta];
530  }
531 
532 
533  // Replace the new endpoint
534  ep->key = new_key;
535  route->endpoints[new] = ep;
536  return 0;
537 }
538 
539 struct dfg_thread * create_dfg_thread(struct dfg_runtime *rt, int thread_id,
540  enum thread_mode mode) {
541  if (mode == UNSPECIFIED_THREAD_MODE) {
542  log_error("Cannot add unspecified-thread-mode thread");
543  return NULL;
544  }
546  log_error("Cannot add more threads to runtime %d", rt->id);
547  return NULL;
548  }
549 
550  struct dfg_thread *thread = calloc(1, sizeof(*thread));
551  if (thread == NULL) {
552  log_error("Could not allocate thread");
553  return NULL;
554  }
555  thread->id = thread_id;
556  thread->mode = mode;
557 
558  rt->threads[rt->n_pinned_threads + rt->n_unpinned_threads] = thread;
559  switch(mode) {
560  case PINNED_THREAD:
561  rt->n_pinned_threads++;
562  break;
563  case UNPINNED_THREAD:
564  rt->n_unpinned_threads++;
565  break;
566  default:
567  log_error("Unknown thread mode %d provided", mode);
568  return NULL;
569  }
570  return thread;
571 }
572 
574 static void free_dfg_msu_type(struct dfg_msu_type *type) {
575  for (int i=0; i<type->n_dependencies; i++) {
576  free(type->dependencies[i]);
577  }
578  free(type);
579 }
580 
582 static void free_dfg_runtime(struct dfg_runtime *rt) {
583  for (int i=0; i < rt->n_pinned_threads + rt->n_unpinned_threads; i++) {
584  free(rt->threads[i]);
585  }
586  for (int i=0; i < rt->n_routes; i++) {
587  for (int j=0; j < rt->routes[i]->n_endpoints; j++) {
588  free(rt->routes[i]->endpoints[j]);
589  }
590  free(rt->routes[i]);
591  }
592  free(rt);
593 }
594 
595 
596 void free_dfg(struct dedos_dfg *dfg) {
597  for (int i=0; i < dfg->n_msu_types; i++) {
598  free_dfg_msu_type(dfg->msu_types[i]);
599  }
600  for (int i=0; i < dfg->n_msus; i++) {
601  free(dfg->msus[i]);
602  }
603  for (int i=0; i < dfg->n_runtimes; i++) {
604  free_dfg_runtime(dfg->runtimes[i]);
605  }
606  free(dfg);
607 }
struct dfg_route * get_dfg_msu_route_by_type(struct dfg_msu *msu, struct dfg_msu_type *route_type)
Returns the route which the given MSU sends to of the specified MSU type.
Definition: dfg.c:99
int n_routes
The routes that an MSU can send to.
Definition: dfg.h:120
#define EXIT_VERTEX_TYPE
Bitmask representing an MSU through which messages exit DeDOS.
Definition: dfg.h:211
int n_msus
The number of MSUs in dedos_dfg::msus.
Definition: dfg.h:255
enum thread_mode mode
Pinned/unpinned mode for the thread.
Definition: dfg.h:106
int delete_dfg_route(struct dfg_route *route)
Deletes the provided route from the DFG.
Definition: dfg.c:399
struct dfg_msu * copy_dfg_msu(struct dfg_msu *input)
Allocates a new MSU with the same fields as the input MSU (though unscheduled)
Definition: dfg.c:190
uint8_t str_to_vertex_type(char *str_type)
Converts a string containing exit and/or entry to the correct bitmask.
Definition: dfg.c:162
thread_mode
Identifies if a thread is pinned to a core or able to be scheduled on any core.
Definition: dfg.h:91
int n_msus
Number of MSUs placed on the thread.
Definition: dfg.h:108
#define log_info(fmt,...)
Definition: logging.h:88
int free_dfg_msu(struct dfg_msu *input)
Frees an MSU structure.
Definition: dfg.c:225
struct dfg_scheduling scheduling
Information about where an MSU is scheduled.
Definition: dfg.h:225
struct dfg_route * routes[64]
Routes located on this runtime.
Definition: dfg.h:83
#define MAX_THREADS
The maximum number of threads that may be present on a runtime.
Definition: dfg.h:47
struct dfg_msu * instances[512]
Each instance of this MSU type.
Definition: dfg.h:186
#define log_critical(fmt,...)
Definition: logging.h:124
struct dfg_route * get_dfg_runtime_route(struct dfg_runtime *rt, unsigned int id)
Definition: dfg.c:72
void free_dfg(struct dedos_dfg *dfg)
Frees the entirety of the DFG structure.
Definition: dfg.c:596
struct dfg_route * get_dfg_route(unsigned int id)
Returns the route with the given ID.
Definition: dfg.c:76
uint8_t vertex_type
Whether the MSU is #ENTRY, #EXIT, or possible #ENTRY | #EXIT.
Definition: dfg.h:218
int del_dfg_route_endpoint(struct dfg_route *route, struct dfg_route_endpoint *ep)
Removes an MSU as a route endpoint.
Definition: dfg.c:487
int unschedule_dfg_msu(struct dfg_msu *msu)
Removes the given MSU from its runtime and thread.
Definition: dfg.c:339
struct dfg_msu * msus[8]
MSUs placed on that thread.
Definition: dfg.h:107
int n_msu_types
The number of elements in dedos_dfg::msu_types.
Definition: dfg.h:250
static int route(struct msu_type *type, struct local_msu *sender, struct msu_msg *msg, struct msu_endpoint *output)
Definition: baremetal_msu.c:30
struct dfg_runtime * get_dfg_runtime(unsigned int runtime_id)
Returns the runtime with the given ID.
Definition: dfg.c:64
unsigned char uint8_t
Definition: uthash.h:97
#define ENTRY_VERTEX_TYPE
Bitmask representing an MSU through which messages enter DeDOS.
Definition: dfg.h:209
Default – threads should not have this mode.
Definition: dfg.h:92
char name[32]
A name describing the function of the MSU.
Definition: dfg.h:179
struct dfg_route_endpoint * add_dfg_route_endpoint(struct dfg_msu *msu, uint32_t key, struct dfg_route *route)
Adds an MSU as an endpoint to a route.
Definition: dfg.c:455
#define log_perror(fmt,...)
Definition: logging.h:102
int id
Unique identifier for the runtime.
Definition: dfg.h:74
Logging of status messages to the terminal.
#define MAX_ROUTES
The total maximum number of routes that may be present in the DFG.
Definition: dfg.h:49
static int remove_msu_from_thread(struct dfg_msu *msu)
Removes the msu from it's thread, runtime, and instance, and removes the thread and runtime from the ...
Definition: dfg.c:298
struct dfg_route * create_dfg_route(unsigned int id, struct dfg_msu_type *type, unsigned int runtime_id)
Creates a route with the specified parameters.
Definition: dfg.c:366
struct dfg_msu_type * type
The type of the MSU and meta-routing information.
Definition: dfg.h:221
struct dfg_thread * create_dfg_thread(struct dfg_runtime *rt, int thread_id, enum thread_mode mode)
Creates a new thread on the given runtime.
Definition: dfg.c:539
#define MAX_MSU_PER_THREAD
The maximum number of MSUs which can be placed on a single thread.
Definition: dfg.h:61
Representation of a runtime in the DFG.
Definition: dfg.h:73
struct dfg_dependency * dependencies[32]
These MSU types must be present in order for this MSU type to be cloned.
Definition: dfg.h:183
struct dfg_msu * init_dfg_msu(unsigned int id, struct dfg_msu_type *type, uint8_t vertex_type, enum blocking_mode mode, struct msu_init_data *init_data)
Allocates a new MSU with the given parameters.
Definition: dfg.c:200
struct dfg_route_endpoint * endpoints[256]
The endpoints of the route.
Definition: dfg.h:156
int n_endpoints
The number of endpoints in dfg_route::endpoints.
Definition: dfg.h:157
struct dfg_runtime * runtime
The runtime on which an MSU is running.
Definition: dfg.h:117
static void set_msu_properties(struct dfg_msu *template, struct dfg_msu *target)
Sets the non-scheduling properties of the MSU to be equal to those of the passed in target...
Definition: dfg.c:182
int n_runtimes
The number of elements in dedos_dfg::runtimes.
Definition: dfg.h:260
struct dfg_route * get_dfg_rt_route_by_type(struct dfg_runtime *rt, struct dfg_msu_type *type)
Returns the route on the given runtime with the specified MSU type.
Definition: dfg.c:90
#define log_error(fmt,...)
Definition: logging.h:101
struct dfg_msu * msu
The MSU at this endpoint to which a message would be delivered.
Definition: dfg.h:143
void set_dfg(struct dedos_dfg *dfg_in)
Sets the local copy of the DFG, so it doesn't have to be passed in for each call. ...
Definition: dfg.c:34
A type of MSU.
Definition: dfg.h:176
struct dfg_msu_type * msu_types[32]
MSU types which may be present in the application.
Definition: dfg.h:248
int id
A unique identifier for the MSU.
Definition: dfg.h:217
blocking_mode
Whether an MSU is blocking or non-blocking.
Definition: dfg.h:161
Data with which an MSU is initialized, and the payload for messages of type CTRL_CREATE_MSU.
Definition: dfg.h:66
int n_unpinned_threads
Number of the above-threads which are unpinned.
Definition: dfg.h:81
struct dfg_thread * thread
The thread on which an MSU is running.
Definition: dfg.h:118
struct dfg_msu * msu_type_on_runtime(struct dfg_runtime *rt, struct dfg_msu_type *type)
Returns 1 if the given MSU type is present on the provided runtime.
Definition: dfg.c:130
struct db_info db
DB information.
Definition: dfg.h:245
int id
Unique identifier for the thread.
Definition: dfg.h:105
Representation of a single MSU in the dfg.
Definition: dfg.h:216
#define SEARCH_FOR_ID(s, n, field, id_)
Convenience macro to search a field within a structure for the element with an ID.
Definition: dfg.c:46
static int schedule_msu_on_thread(struct dfg_msu *msu, struct dfg_thread *thread, struct dfg_runtime *rt)
Adds the MSU to the thread, runtime, and instance, and adds the thread and runtime to the MSU...
Definition: dfg.c:237
struct db_info * get_db_info()
Returns DB info.
Definition: dfg.c:56
#define MAX_MSU
The maximum number of MSUs which can be present in the system at a time.
Definition: dfg.h:39
struct dfg_runtime * runtime
The runtime on which the route is located.
Definition: dfg.h:154
int n_pinned_threads
Number of the above-threads which are pinned.
Definition: dfg.h:80
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
static void free_dfg_msu_type(struct dfg_msu_type *type)
Frees elements in the MSU type structure.
Definition: dfg.c:574
struct dfg_route * routes[32]
Definition: dfg.h:119
Top-level structure holding the data-flow graph.
Definition: dfg.h:239
A route through which MSU messages can be passed.
Definition: dfg.h:152
static struct dedos_dfg * dfg
Static local copy of the DFG, so each call doesn't have to pass a copy.
Definition: dfg.c:32
struct msu_init_data init_data
Initial data passed to the MSU.
Definition: dfg.h:219
int get_dfg_n_runtimes()
Returns the number of registered runtime.
Definition: dfg.c:60
static void free_dfg_runtime(struct dfg_runtime *rt)
Frees the runtime and all threads and routes associated with it.
Definition: dfg.c:582
Interfaces for the creation and modification of the data-flow-graph and and general description of th...
struct dfg_thread * get_dfg_thread(struct dfg_runtime *rt, unsigned int id)
Returns the thread on the given runtime with the specified ID.
Definition: dfg.c:108
struct dfg_msu * get_dfg_msu(unsigned int id)
Returns the MSU with the given ID.
Definition: dfg.c:86
Info to connect and use database.
Definition: dfg.h:230
int schedule_dfg_msu(struct dfg_msu *msu, unsigned int runtime_id, unsigned int thread_id)
Places the given MSU on the correct runtime and thread.
Definition: dfg.c:261
struct dfg_runtime * runtimes[16]
The runtimes present in the application.
Definition: dfg.h:258
A single endpoint for an MSU route.
Definition: dfg.h:139
struct dfg_thread * threads[32]
Threads located on the runtime.
Definition: dfg.h:79
uint32_t key
The key associated with this endpoint.
Definition: dfg.h:140
struct dfg_route_endpoint * get_dfg_route_endpoint(struct dfg_route *route, unsigned int msu_id)
Returns the endpoint within the given route which has the specified MSU ID.
Definition: dfg.c:112
Representation of a thread on a runtime in the DFG.
Definition: dfg.h:104
int n_routes
Number of routes above.
Definition: dfg.h:84
char init_data[64]
Definition: dfg.h:67
static int runtime_id(int runtime_fd)
unsigned int uint32_t
Definition: uthash.h:96
int n_instances
The number of instances of this MSU type.
Definition: dfg.h:187
#define log(level, fmt,...)
Log at a custom level.
Definition: logging.h:147
enum blocking_mode str_to_blocking_mode(char *mode_str)
Converts a string of blocking/non-blocking to the correct enumerator.
Definition: dfg.c:150
int n_dependencies
The number of elements in dfg_msu_type::dependencies.
Definition: dfg.h:184
struct dfg_msu_type * get_dfg_msu_type(unsigned int id)
Returns the MSU type with the given ID.
Definition: dfg.c:68
int add_dfg_route_to_msu(struct dfg_route *route, struct dfg_msu *msu)
Subscribes an MSU to a route, so it can send to the route's endpoints.
Definition: dfg.c:428
int mod_dfg_route_endpoint(struct dfg_route *route, struct dfg_route_endpoint *ep, uint32_t new_key)
Modifies the key associated with an MSU endpoint.
Definition: dfg.c:505
#define log_warn(fmt,...)
Definition: logging.h:113
int msu_has_route(struct dfg_msu *msu, struct dfg_route *route)
Returns 1 if the given MSU has the route as an endpoint.
Definition: dfg.c:121
#define MAX_ROUTE_ENDPOINTS
The maximum number of endpoints that a single route may have as destinations.
Definition: dfg.h:51
enum thread_mode str_to_thread_mode(char *mode_str)
Converts a string of pinned/unpinned to the corresponding enumerator.
Definition: dfg.c:139
Default value – used when unset, should never be specified.
Definition: dfg.h:162
enum blocking_mode blocking_mode
Whether the MSU is blocking or not.
Definition: dfg.h:223
struct dfg_msu_type * msu_type
The type of MSU to which this route delivers.
Definition: dfg.h:155
struct dfg_msu * msus[512]
The MSUs present in the application.
Definition: dfg.h:253