My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
dfg_reader.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 */
26 #include "dfg_reader.h"
27 #include "dfg.h"
28 #include "jsmn_parser.h"
29 #include "jsmn.h"
30 #include "logging.h"
31 
32 #include <strings.h>
33 #include <stdbool.h>
34 #include <string.h>
35 
42 };
43 
52 static int fix_num_threads(struct dedos_dfg *dfg) {
53  for (int i=0; i<dfg->n_runtimes; i++) {
54  struct dfg_runtime *rt = dfg->runtimes[i];
55 
56  int n_pinned = rt->n_pinned_threads;
57  int n_unpinned = rt->n_unpinned_threads;
58  int total = n_pinned + n_unpinned;
59  for (int t=0; t < total; t++) {
60  struct dfg_thread *thread = rt->threads[t];
61  if (thread->mode == PINNED_THREAD) {
62  n_pinned--;
63  } else if (thread->mode == UNPINNED_THREAD) {
64  n_unpinned--;
65  } else {
66  if (n_pinned > 0) {
67  thread->mode = PINNED_THREAD;
68  log(LOG_DFG_READER, "Setting thread %d with no MSUs to pinned", t);
69  n_pinned--;
70  } else if (n_unpinned > 0) {
71  thread->mode = UNPINNED_THREAD;
72  log(LOG_DFG_READER, "Setting thread %d with no MSUs to unpinned", t);
73  n_unpinned--;
74  } else {
75  log_error("Cannot determine pinned/unpinned status of threads "
76  "based on number of blocking/nonblock MSUs");
77  return -1;
78  }
79  }
80  }
81  if (n_pinned < 0 || n_unpinned < 0) {
82  log_error("More pinned/unpinned threads specified by MSUs than by DFG on rt %d: "
83  "%d more pinned, %d more unpinned", rt->id, -1 * n_pinned, -1 * n_unpinned);
84  return -1;
85  }
86  }
87  return 0;
88 }
89 
94 static struct key_mapping key_map[];
95 
96 struct dedos_dfg *parse_dfg_json_file(const char *filename){
97 
98  struct dedos_dfg *dfg = calloc(1, sizeof(*dfg));
99 
100  set_dfg(dfg);
101 
102  int rtn = parse_file_into_obj(filename, dfg, key_map);
103 
104  if (rtn >= 0){
105  rtn = fix_num_threads(dfg);
106  if (rtn < 0) {
107  return NULL;
108  }
109  return dfg;
110  } else {
111  log_error("Failed to parse jsmn");
112  return NULL;
113  }
114 }
115 
118  struct dedos_dfg *dfg = GET_PARSE_OBJ();
119  char *name = GET_STR_TOK();
120  if (strlen(name) > MAX_APP_NAME_LENGTH) {
121  log_error("Application name '%s' is too long", name);
122  return -1;
123  }
124  strcpy(dfg->application_name, name);
125  return 0;
126 }
127 
130  struct dedos_dfg *dfg = GET_PARSE_OBJ();
131  char *ip = GET_STR_TOK();
132  struct in_addr addr;
133  int rtn = inet_pton(AF_INET, ip, &addr);
134  if (rtn <= 0) {
135  log_perror("Error converting '%s' to IP address", ip);
136  return -1;
137  }
138  dfg->global_ctl_ip = addr.s_addr;
139  return 0;
140 }
141 
144  struct dedos_dfg *dfg = GET_PARSE_OBJ();
145  dfg->global_ctl_port = GET_INT_TOK();
146  return 0;
147 }
148 
151  struct dedos_dfg *dfg = GET_PARSE_OBJ();
152  char *ip = GET_STR_TOK();
153  struct in_addr addr;
154  int rtn = inet_pton(AF_INET, ip, &addr);
155  if (rtn <= 0) {
156  log_perror("Error converting '%s' to IP address", ip);
157  return -1;
158  }
159  dfg->db.ip = addr.s_addr;
160 
161  return 0;
162 }
163 
166  struct dedos_dfg *dfg = GET_PARSE_OBJ();
167  dfg->db.port = GET_INT_TOK();
168 
169  return 0;
170 }
171 
174  struct dedos_dfg *dfg = GET_PARSE_OBJ();
175  char *str_db_user = GET_STR_TOK();
176  memcpy(dfg->db.user, str_db_user, strlen(str_db_user));
177 
178  return 0;
179 }
180 
183  struct dedos_dfg *dfg = GET_PARSE_OBJ();
184  char *str_db_pwd = GET_STR_TOK();
185  memcpy(dfg->db.pwd, str_db_pwd, strlen(str_db_pwd));
186 
187  return 0;
188 }
189 
192  struct dedos_dfg *dfg = GET_PARSE_OBJ();
193  char *str_db_name = GET_STR_TOK();
194  memcpy(dfg->db.name, str_db_name, strlen(str_db_name));
195 
196  return 0;
197 }
198 
201  struct dedos_dfg *dfg = GET_PARSE_OBJ();
202  int index = GET_OBJ_INDEX();
203 
204  dfg->n_runtimes++;
205  dfg->runtimes[index] = calloc(1, sizeof(*dfg->runtimes[index]));
206 
207  RETURN_OBJ(dfg->runtimes[index], RUNTIMES);
208 }
209 
212 
215  struct dedos_dfg *dfg = GET_PARSE_OBJ();
216  int index = GET_OBJ_INDEX();
217 
218  dfg->n_msus++;
219  dfg->msus[index] = calloc(1, sizeof(struct dfg_msu));
220 
221  RETURN_OBJ(dfg->msus[index], MSUS);
222 }
223 
226 
229  struct dedos_dfg *dfg = GET_PARSE_OBJ();
230 
231  int index = GET_OBJ_INDEX();
232 
233  dfg->n_msu_types++;
234  dfg->msu_types[index] = calloc(1, sizeof(**dfg->msu_types));
235 
236  RETURN_OBJ(dfg->msu_types[index], MSU_TYPES);
237 }
238 
241 
244  struct dfg_msu_type *type = GET_PARSE_OBJ();
245  type->id = GET_INT_TOK();
246  return 0;
247 }
248 
251  struct dfg_msu_type *type = GET_PARSE_OBJ();
252  char *name = GET_STR_TOK();
253 
254  if (strlen(name) > MAX_MSU_NAME_LEN) {
255  log_error("MSU name %s too long", name);
256  return -1;
257  }
258  strcpy(type->name, name);
259  return 0;
260 }
261 
264 
267  struct dfg_msu_type *type = GET_PARSE_OBJ();
268  int index = GET_OBJ_INDEX();
269 
270  type->n_dependencies++;
271  type->dependencies[index] = calloc(1, sizeof(*type->dependencies[index]));
272 
273  RETURN_OBJ(type->dependencies[index], DEPENDENCIES);
274 }
275 
278 
281  struct dfg_msu_type *type = GET_PARSE_OBJ();
282  type->cloneable = GET_INT_TOK();
283  return 0;
284 }
285 
288  struct dfg_msu_type *type = GET_PARSE_OBJ();
289  type->colocation_group = GET_INT_TOK();
290  return 0;
291 }
292 
295  struct dfg_msu *vertex = GET_PARSE_OBJ();
296 
297  char *init_data = GET_STR_TOK();
298  if (strlen(init_data) > MAX_INIT_DATA_LEN) {
299  log_error("Init data '%s' too long", init_data);
300  return -1;
301  }
302  strcpy(vertex->init_data.init_data, init_data);
303  return 0;
304 }
305 
308  struct dfg_msu *msu = GET_PARSE_OBJ();
309  msu->id = GET_INT_TOK();
310  return 0;
311 }
312 
315  struct dfg_msu *msu = GET_PARSE_OBJ();
316  char *str_type = GET_STR_TOK();
317  msu->vertex_type = str_to_vertex_type(str_type);
318  return 0;
319 }
320 
323  struct dfg_msu *vertex = GET_PARSE_OBJ();
324 
325  struct dfg_msu_type *type = get_dfg_msu_type(GET_INT_TOK());
326  if (type == NULL) {
327  // Return once type has been instantiated
328  return 1;
329  }
330  vertex->type = type;
331 
332  type->instances[type->n_instances] = vertex;
333  type->n_instances++;
334  return 0;
335 }
336 
339  struct dfg_msu *vertex = GET_PARSE_OBJ();
340 
341  char *str_mode = GET_STR_TOK();
342 
343  vertex->blocking_mode = str_to_blocking_mode(str_mode);
344  if (vertex->blocking_mode == UNKNOWN_BLOCKING_MODE) {
345  log_error("Unknown blocking mode specified: %s", str_mode);
346  return -1;
347  }
348 
349  struct dfg_runtime *rt = vertex->scheduling.runtime;
350  if (rt == NULL) {
351  return 1;
352  }
353 
354  struct dfg_thread *thread = vertex->scheduling.thread;
355  if (thread == NULL) {
356  log(LOG_DFG_READER, "Waiting for thread instantiation");
357  return 1;
358  }
359 
360  if (thread->mode == UNSPECIFIED_THREAD_MODE) {
361  thread->mode = (vertex->blocking_mode == NONBLOCK_MSU) ? PINNED_THREAD : UNPINNED_THREAD;
362  }
363 
364  if ((thread->mode == PINNED_THREAD) ^ (vertex->blocking_mode == NONBLOCK_MSU)) {
365  log_error("Can only put blocking MSUs on pinned threads, and nonblock MSUs on unpinned");
366  return -1;
367  }
368  return 0;
369 }
370 
373 
376  struct dfg_runtime *rt = GET_PARSE_OBJ();
377  rt->id = GET_INT_TOK();
378  return 0;
379 }
380 
383  struct dfg_runtime *rt = GET_PARSE_OBJ();
384  char *ip = GET_STR_TOK();
385  struct in_addr addr;
386  int rtn = inet_pton(AF_INET, ip, &addr);
387  if (rtn <= 0) {
388  log_perror("Error converting '%s' to IP address", ip);
389  return -1;
390  }
391  rt->ip = addr.s_addr;
392  return 0;
393 }
394 
397  struct dfg_runtime *rt = GET_PARSE_OBJ();
398  rt->port = GET_INT_TOK();
399  return 0;
400 }
401 
404  struct dfg_runtime *rt = GET_PARSE_OBJ();
405  rt->n_cores = GET_INT_TOK();
406  return 0;
407 }
408 
411  struct dfg_runtime *rt = GET_PARSE_OBJ();
412 
413  int n_existing = rt->n_unpinned_threads;
414  int n_new = GET_INT_TOK();
415 
416  for (int i=n_existing; i<n_existing+n_new; i++) {
417  rt->threads[i] = calloc(1, sizeof(**rt->threads));
418  rt->threads[i]->id = i+1;
419  }
420  rt->n_pinned_threads = n_new;
421  return 0;
422 }
423 
426  struct dfg_runtime *rt = GET_PARSE_OBJ();
427 
428  int n_existing = rt->n_pinned_threads;
429  int n_new = GET_INT_TOK();
430 
431  for (int i=n_existing; i < n_existing + n_new; i++) {
432  rt->threads[i] = calloc(1, sizeof(**rt->threads));
433  rt->threads[i]->id = i+1;
434  }
435  rt->n_unpinned_threads = n_new;
436  return 0;
437 }
438 
441  struct dfg_runtime *rt = GET_PARSE_OBJ();
442  int index = GET_OBJ_INDEX();
443  rt->n_routes++;
444  rt->routes[index] = calloc(1, sizeof(**rt->routes));
445  rt->routes[index]->runtime = rt;
446 
447  RETURN_OBJ(rt->routes[index], ROUTES);
448 }
449 
452 
455  struct dfg_route *route = GET_PARSE_OBJ();
456  int id = GET_INT_TOK();
457  struct dfg_route *existing = get_dfg_route(id);
458  if (existing != NULL) {
459  log_error("Route with ID %d exists twice in DFG", id);
460  return -1;
461  }
462  route->id = id;
463  log(LOG_DFG_PARSING, "Created route with id: %d", id);
464  return 0;
465 }
466 
469  struct dfg_route *route = GET_PARSE_OBJ();
470  int type_id = GET_INT_TOK();
471  struct dfg_msu_type *type = get_dfg_msu_type(type_id);
472  if (type == NULL) {
473  // Return once type is instantiated
474  return -1;
475  }
476  route->msu_type = type;
477  return 0;
478 }
479 
482  struct dfg_route *route = GET_PARSE_OBJ();
483 
484  int index = GET_OBJ_INDEX();
485  route->n_endpoints++;
486  route->endpoints[index] = calloc(1, sizeof(**route->endpoints));
487 
488  RETURN_OBJ(route->endpoints[index], DESTINATIONS);
489 }
490 
493 
496  struct dfg_route_endpoint *dest = GET_PARSE_OBJ();
497  dest->key = GET_INT_TOK();
498  return 0;
499 }
500 
503  struct dfg_route_endpoint *dest = GET_PARSE_OBJ();
504  int msu_id = GET_INT_TOK();
505 
506  struct dfg_msu *msu = get_dfg_msu(msu_id);
507  if (msu == NULL) {
508  // Wait for MSU to be instantiated
509  log(LOG_DFG_PARSING, "MSU %d is not yet instantiated", msu_id);
510  return 1;
511  }
512  dest->msu = msu;
513  return 0;
514 }
515 
518  struct dfg_meta_routing *meta = GET_PARSE_OBJ();
519  int i;
520  bool found_types = true;
522  int str_type = GET_INT_TOK();
523  struct dfg_msu_type *type = get_dfg_msu_type(str_type);
524  if (type == NULL) {
525  // Wait for type to be instantiated
526  log(LOG_DFG_PARSING, "Type %d is not yet instantiated", str_type);
527  found_types = false;
528  } else {
529  meta->src_types[i] = type;
530  }
531  } END_ITER_TOK_LIST(i)
532  meta->n_src_types = i;
533  if (found_types == false)
534  return 1;
535  return 0;
536 }
537 
540  struct dfg_meta_routing *meta = GET_PARSE_OBJ();
541  bool found_types = true;
542  int i;
544  int str_type = GET_INT_TOK();
545  struct dfg_msu_type *type = get_dfg_msu_type(str_type);
546  if (type == NULL) {
547  log(LOG_DFG_PARSING, "Type %d is not yet instantiated", str_type);
548  found_types = false;
549  } else {
550  meta->dst_types[i] = type;
551  }
552  } END_ITER_TOK_LIST(i)
553 
554  meta->n_dst_types = i;
555  if (found_types == false) {
556  return 1;
557  }
558  return 0;
559 }
560 
563  struct dfg_dependency *dep = GET_PARSE_OBJ();
564 
565  int type_id = GET_INT_TOK();
566  struct dfg_msu_type *type = get_dfg_msu_type(type_id);
567 
568  if (type == NULL) {
569  // Return once type has been instantiated
570  log(LOG_DFG_PARSING, "Type %d is not yet instantiated", type_id);
571  return 1;
572  }
573  dep->type = type;
574  return 0;
575 }
576 
579  struct dfg_dependency *dep = GET_PARSE_OBJ();
580 
581  char *str_loc = GET_STR_TOK();
582  if (strcasecmp(str_loc, "local") == 0) {
583  dep->locality = MSU_IS_LOCAL;
584  } else if (strcasecmp(str_loc, "remote") == 0) {
585  dep->locality = MSU_IS_REMOTE;
586  } else {
587  log_error("Unknown locality %s specified. Must be 'local' or 'remote'", str_loc);
588  }
589  return 0;
590 }
591 
594  struct dfg_scheduling *sched = GET_PARSE_OBJ();
595 
596  int id = GET_INT_TOK();
597  struct dfg_runtime *rt = get_dfg_runtime(id);
598  if (rt == NULL) {
599  log(LOG_DFG_PARSING, "Runtime %d is not yet instantiated", id);
600  return 1;
601  }
602  sched->runtime = rt;
603  return 0;
604 }
605 
608  struct dfg_scheduling *sched = GET_PARSE_OBJ();
609 
610  if (sched->runtime == NULL) {
611  // Runtime must be instantiated before thread
612  log(LOG_DFG_PARSING, "MSU runtime not yet instantiated");
613  return 1;
614  }
615  int id = GET_INT_TOK();
616  struct dfg_thread *thread = get_dfg_thread(sched->runtime, id);
617  if (thread == NULL) {
618  // Thread must be instantiated too
619  log(LOG_DFG_PARSING, "Thread %d not yet instantiated", id);
620  return 1;
621  }
622  sched->thread = thread;
623 
624  // This is frustrating...
625  // Have to iterate through all MSUs to find the one this scheduling object refers to
626  // Should perhaps provide parse object as a linked list so you can traverse upwards?
627  struct dedos_dfg *dfg = get_root_jsmn_obj();
628  struct dfg_msu *msu = NULL;
629  for (int i=0; i<dfg->n_msus; i++) {
630  if (&dfg->msus[i]->scheduling == sched) {
631  msu = dfg->msus[i];
632  break;
633  }
634  }
635  // Shouldn't happen, really...
636  if (msu == NULL) {
637  log(LOG_DFG_PARSING, "Msu for thead %d not yet instantiated", id);
638  return 1;
639  }
640  thread->msus[thread->n_msus] = msu;
641  thread->n_msus++;
642 
643  return 0;
644 }
645 
648  struct dfg_scheduling *sched = GET_PARSE_OBJ();
649 
650  bool set_routes = true;
651  int i;
652  log(LOG_DFG_PARSING, "MSU_ROUTE pre TOK: %s", GET_STR_TOK());
654  log(LOG_DFG_PARSING, "MSU_ROUTE TOK: %s", GET_STR_TOK());
655  int route_id = GET_INT_TOK();
656  struct dfg_route *route = get_dfg_route(route_id);
657  if (route == NULL) {
658  log(LOG_DFG_PARSING, "Route %d not yet instantiated for msu", route_id);
659  set_routes = false;
660  } else {
661  sched->routes[i] = route;
662  }
663  } END_ITER_TOK_LIST(i)
664 
665  sched->n_routes = i;
666  if (!set_routes) {
667  return 1;
668  }
669  return 0;
670 }
671 
673 static int not_implemented(jsmntok_t **tok, char *j, struct json_state *in, struct json_state **saved) {
674  log_warn("JSON key %s is not implemented in DFG reader", tok_to_str((*tok)-1, j));
675  return 0;
676 }
677 
681 static struct key_mapping key_map[] = {
682  { "application_name", ROOT, set_app_name },
683  { "global_ctl_ip", ROOT, set_ctl_ip },
684  { "global_ctl_port", ROOT, set_ctl_port },
685  { "db_ip", ROOT, set_db_ip },
686  { "db_port", ROOT, set_db_port },
687  { "db_user", ROOT, set_db_user },
688  { "db_pwd", ROOT, set_db_pwd },
689  { "db_name", ROOT, set_db_name },
690 
691  { "MSU_types", ROOT, set_msu_types },
692  { "MSUs", ROOT, set_msus },
693  { "runtimes", ROOT, set_runtimes },
694 
695  { "id", MSU_TYPES, set_msu_type_id},
696  { "name", MSU_TYPES, set_msu_type_name },
697  { "meta_routing", MSU_TYPES, set_meta_routing },
698  { "dependencies", MSU_TYPES, set_dependencies },
699  { "cloneable", MSU_TYPES, set_cloneable },
700  { "colocation_group", MSU_TYPES, set_colocation_group },
701 
702  { "id", MSUS, set_msu_id },
703  { "vertex_type", MSUS, set_msu_vertex_type },
704  { "init_data", MSUS, set_msu_init_data },
705  { "type", MSUS, set_msu_type },
706  { "blocking_mode", MSUS, set_blocking_mode },
707  { "scheduling", MSUS, set_scheduling },
708 
709  { "id", RUNTIMES, set_rt_id },
710  { "ip", RUNTIMES, set_rt_ip },
711  { "port", RUNTIMES, set_rt_port },
712  { "num_cores", RUNTIMES, set_rt_n_cores },
713  { "num_pinned_threads", RUNTIMES, set_num_pinned_threads },
714  { "num_unpinned_threads", RUNTIMES, set_num_unpinned_threads },
715  { "routes", RUNTIMES, set_rt_routes },
716 
717  { "id", ROUTES, set_route_id },
718  { "type", ROUTES, set_route_type },
719  { "endpoints", ROUTES, set_route_endpoints },
720 
721  { "key", DESTINATIONS, set_dest_key },
722  { "msu", DESTINATIONS, set_dest_msu },
723 
724  { "source_types", META_ROUTING, set_source_types },
725  { "dst_types", META_ROUTING, set_dst_types },
726 
727  { "type", DEPENDENCIES, set_dep_type },
728  { "locality", DEPENDENCIES, set_dep_locality },
729 
730  { "runtime", SCHEDULING, set_msu_runtime },
731  { "thread_id", SCHEDULING, set_msu_thread },
732  { "routes", SCHEDULING, set_msu_routes },
733 
734  { "load_mode", ROOT, not_implemented },
735  { "application_deadline", ROOT, not_implemented },
736  { "profiling", MSUS, not_implemented },
737  { "statistics", MSUS, not_implemented },
738  { "dram", RUNTIMES, not_implemented },
739  { "io_network_bw", RUNTIMES, not_implemented},
740  { "deadline", SCHEDULING, not_implemented},
741  { NULL, 0, NULL }
742 };
743 
static int set_dep_type(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
key: "type", object DEPENDENCIES
Definition: dfg_reader.c:562
static int set_scheduling(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "scheduling", Object MSUS.
Definition: dfg_reader.c:372
JSON token description.
Definition: jsmn.h:61
int n_routes
The routes that an MSU can send to.
Definition: dfg.h:120
MSUs which must be present for another MSU to be cloned.
Definition: dfg.h:203
#define START_ITER_TOK_LIST(i)
Macro to iterate over a list of tokens.
Definition: jsmn_parser.h:164
char * tok_to_str(jsmntok_t *tok, char *j)
Destructively extracts a c-string from a jsmn token.
Definition: jsmn_parser.c:69
static int set_route_type(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "type", object ROUTES.
Definition: dfg_reader.c:468
int n_msus
The number of MSUs in dedos_dfg::msus.
Definition: dfg.h:255
static int set_msu_vertex_type(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "vertex_type", Object MSUS.
Definition: dfg_reader.c:314
enum thread_mode mode
Pinned/unpinned mode for the thread.
Definition: dfg.h:106
uint32_t ip
IP of the node on which the runtime is running.
Definition: dfg.h:75
#define MAX_APP_NAME_LENGTH
The maximum length for the name of the application.
Definition: dfg.h:59
static struct json_state init_dfg_msu_type(struct json_state *in__, int index__)
Key: element in "MSU_types", Object ROOT.
Definition: dfg_reader.c:228
struct dfg_msu_type * type
The MSU type which must be present.
Definition: dfg.h:204
static int set_msu_thread(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "thread_id", object: SCHEDULING.
Definition: dfg_reader.c:607
static int set_db_user(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "db_user", Object ROOT.
Definition: dfg_reader.c:173
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
int global_ctl_port
Port of the global controller.
Definition: dfg.h:242
int n_msus
Number of MSUs placed on the thread.
Definition: dfg.h:108
static int set_app_name(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "application_name", Object: ROOT.
Definition: dfg_reader.c:117
static int fix_num_threads(struct dedos_dfg *dfg)
Fixes the thread assignment within the DFG such that the pinned and unpinned threads are accurate...
Definition: dfg_reader.c:52
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
struct dfg_msu * instances[512]
Each instance of this MSU type.
Definition: dfg.h:186
uint32_t global_ctl_ip
IP address of the global controller.
Definition: dfg.h:241
#define GET_STR_TOK()
Within a PARSE_FN, gets the token being read as a string.
Definition: jsmn_parser.h:85
int n_cores
Number of cores on the runtime node.
Definition: dfg.h:77
static int set_colocation_group(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "colocation_group", object MSU_TYPES.
Definition: dfg_reader.c:287
static int set_db_ip(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "db_ip", Object: ROOT.
Definition: dfg_reader.c:150
struct dfg_route * get_dfg_route(unsigned int id)
Returns the route with the given ID.
Definition: dfg.c:76
static struct json_state init_dependencies(struct json_state *in__, int index__)
Key: Element in "dependencies", Object: MSU_TYPES.
Definition: dfg_reader.c:266
uint8_t vertex_type
Whether the MSU is #ENTRY, #EXIT, or possible #ENTRY | #EXIT.
Definition: dfg.h:218
static int set_cloneable(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "cloneable", Object MSU_TYPES.
Definition: dfg_reader.c:280
static int set_dest_key(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "key", object DESTINATIONS.
Definition: dfg_reader.c:495
int n_src_types
The number of types that should route to this MSU.
Definition: dfg.h:131
uint32_t ip
Definition: dfg.h:231
struct dfg_msu * msus[8]
MSUs placed on that thread.
Definition: dfg.h:107
static struct json_state init_endpoint(struct json_state *in__, int index__)
Key: Element in "endpoints", object ROUTES.
Definition: dfg_reader.c:481
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
int n_dst_types
The number of types that this msu should route to.
Definition: dfg.h:133
static struct json_state init_runtime(struct json_state *in__, int index__)
Key: element in "runtimes", Object ROOT.
Definition: dfg_reader.c:200
static int set_msu_types(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "MSU_types", Object: ROOT.
Definition: dfg_reader.c:240
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
#define log_perror(fmt,...)
Definition: logging.h:102
int id
Unique identifier for the runtime.
Definition: dfg.h:74
static int set_msu_type_id(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "id", Object: MSU_TYPES.
Definition: dfg_reader.c:243
Logging of status messages to the terminal.
static int set_msu_id(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "id", Object MSUS.
Definition: dfg_reader.c:307
static int set_rt_port(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: port, object RUNTIMES.
Definition: dfg_reader.c:396
Structure to hold state while parsing JSON.
Definition: jsmn_parser.h:49
static int set_route_id(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "id", object ROUTES.
Definition: dfg_reader.c:454
object_type
The objects types which can be located in the json DFG See key_map for usage.
Definition: dfg_reader.c:39
static int set_msu_type(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key "type", Object MSUS.
Definition: dfg_reader.c:322
static int set_dest_msu(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "msu", object DESTINATIONS.
Definition: dfg_reader.c:502
#define MAX_MSU_NAME_LEN
The maximum length of the name for an MSU type.
Definition: dfg.h:55
int colocation_group
Definition: dfg.h:191
struct dfg_msu_type * type
The type of the MSU and meta-routing information.
Definition: dfg.h:221
char application_name[64]
Description of the whole application.
Definition: dfg.h:240
Structure to map a key + state to a function.
Definition: jsmn_parser.h:178
char pwd[16]
Definition: dfg.h:235
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
static int set_source_types(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "source_types", object META_ROUTING.
Definition: dfg_reader.c:517
struct dfg_route_endpoint * endpoints[256]
The endpoints of the route.
Definition: dfg.h:156
char name[16]
Definition: dfg.h:233
int n_endpoints
The number of endpoints in dfg_route::endpoints.
Definition: dfg.h:157
#define PARSE_FN(fn_name)
Macro for defining a jsmn_parsing_fn.
Definition: jsmn_parser.h:76
const char * name
Definition: http_parser.c:485
struct dfg_runtime * runtime
The runtime on which an MSU is running.
Definition: dfg.h:117
int n_runtimes
The number of elements in dedos_dfg::runtimes.
Definition: dfg.h:260
static int set_db_port(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "global_ctl_port", Object: ROOT.
Definition: dfg_reader.c:165
#define log_error(fmt,...)
Definition: logging.h:101
static int set_dst_types(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "dst_types", object META_ROUTING.
Definition: dfg_reader.c:539
static int set_route_endpoints(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "endpoints", object ROUTES.
Definition: dfg_reader.c:492
struct dfg_msu * msu
The MSU at this endpoint to which a message would be delivered.
Definition: dfg.h:143
#define MAX_INIT_DATA_LEN
The maximum length of the initial data that may be passed to an MSU.
Definition: dfg.h:53
#define GET_OBJ_INDEX()
In an INIT_OBJ_FN, returns the index of the currently parsed object list.
Definition: jsmn_parser.h:120
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
struct dfg_msu_type * src_types[512]
The types that should route to this MSU.
Definition: dfg.h:130
A type of MSU.
Definition: dfg.h:176
Declares function for converting JSON to dedos_dfg.
struct dfg_msu_type * msu_types[32]
MSU types which may be present in the application.
Definition: dfg.h:248
#define PARSE_OBJ_LIST_FN(fn_name, init_fn)
Macro for parsing a list of objects in a json file.
Definition: jsmn_parser.h:103
int id
A unique identifier for the MSU.
Definition: dfg.h:217
int cloneable
If cloneable == N, this MSU can be cloned on runtimes numbered up to and including N...
Definition: dfg.h:189
int n_unpinned_threads
Number of the above-threads which are unpinned.
Definition: dfg.h:81
Describes which MSU types a given MSU type should route to if it is cloned.
Definition: dfg.h:129
int port
Definition: dfg.h:232
static int not_implemented(jsmntok_t **tok, char *j, struct json_state *in, struct json_state **saved)
To be used to raise an error when a JSON key is deprecated.
Definition: dfg_reader.c:673
static struct json_state init_dfg_msu_from_json(struct json_state *in__, int index__)
Key: element in "MSUs", Object ROOT.
Definition: dfg_reader.c:214
struct dfg_thread * thread
The thread on which an MSU is running.
Definition: dfg.h:118
General-purpose function to interact with JSMN library, and create objects (potentially with circular...
static int set_ctl_ip(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "global_ctl_ip", Object: ROOT.
Definition: dfg_reader.c:129
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
static int set_msu_init_data(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "init_data", Object: MSUS.
Definition: dfg_reader.c:294
static int set_blocking_mode(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
key: "blocking_mode", object: MSUS
Definition: dfg_reader.c:338
void * get_root_jsmn_obj()
Returns the initial object passed into the JSON parser.
Definition: jsmn_parser.c:92
#define PARSE_OBJ_FN(fn_name, parent_obj_type, parent_obj_field, new_type)
Macro to descend into a JSON object and the corresponding C struct for parsing.
Definition: jsmn_parser.h:143
static int set_meta_routing(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "meta_routing", Object: MSU_TYPES.
Definition: dfg_reader.c:263
struct dfg_msu_type * dst_types[512]
The types that this msu should route to.
Definition: dfg.h:132
struct dfg_runtime * runtime
The runtime on which the route is located.
Definition: dfg.h:154
int parse_file_into_obj(const char *filename, void *obj, struct key_mapping *km)
Using the provided functions, parses the JSON present in 'filename' and stores the resulting object i...
Definition: jsmn_parser.c:135
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
char user[16]
Definition: dfg.h:234
int id
A unique identifier for the route.
Definition: dfg.h:153
static int set_msus(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "MSUs", Object ROOT.
Definition: dfg_reader.c:225
static int set_msu_type_name(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "name", Object: MSU_TYPES.
Definition: dfg_reader.c:250
static int set_rt_n_cores(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: num_cores, object RUNTIMES.
Definition: dfg_reader.c:403
static int set_dep_locality(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "locality", object: DEPENDENCIES.
Definition: dfg_reader.c:578
enum msu_locality locality
Whether it must be present on the same machine.
Definition: dfg.h:205
struct dfg_route * routes[32]
Definition: dfg.h:119
Top-level structure holding the data-flow graph.
Definition: dfg.h:239
#define RETURN_OBJ(data__, type__)
Should be the last line in an INIT_OBJ_FN.
Definition: jsmn_parser.h:128
A route through which MSU messages can be passed.
Definition: dfg.h:152
struct dedos_dfg * parse_dfg_json_file(const char *filename)
Converts a json file to a dfg structure.
Definition: dfg_reader.c:96
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
#define GET_PARSE_OBJ()
Within a PARSE_FN, gets the object currently being constructed.
Definition: jsmn_parser.h:81
Interfaces for the creation and modification of the data-flow-graph and and general description of th...
static int set_msu_routes(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
key: "routes", object SCHEDULING
Definition: dfg_reader.c:647
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
#define GET_INT_TOK()
Within a PARSE_FN, gets the token being read as an integer.
Definition: jsmn_parser.h:89
static int set_db_pwd(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "db_pwd", Object ROOT.
Definition: dfg_reader.c:182
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
static int set_rt_routes(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "routes", object RUNTIMES.
Definition: dfg_reader.c:451
static int set_ctl_port(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "global_ctl_port", Object: ROOT.
Definition: dfg_reader.c:143
static int set_msu_runtime(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "runtime", object: SCHEDULING.
Definition: dfg_reader.c:593
Structure representing the scheduling of an MSU on a runtime.
Definition: dfg.h:116
static int set_db_name(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "db_name", Object ROOT.
Definition: dfg_reader.c:191
Representation of a thread on a runtime in the DFG.
Definition: dfg.h:104
static struct key_mapping key_map[]
Provides the mapping between the keys in the JSON and the functions which are called when those keys ...
Definition: dfg_reader.c:94
int n_routes
Number of routes above.
Definition: dfg.h:84
char init_data[64]
Definition: dfg.h:67
int n_instances
The number of instances of this MSU type.
Definition: dfg.h:187
static int set_runtimes(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "runtimes", Object ROOT.
Definition: dfg_reader.c:211
#define log(level, fmt,...)
Log at a custom level.
Definition: logging.h:147
static struct json_state init_route(struct json_state *in__, int index__)
Key: Element in "routes", object RUNTIMES.
Definition: dfg_reader.c:440
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
#define INIT_OBJ_FN(fn_name)
Macro for instantiating a new struct based on the appearance of a new JSON object.
Definition: jsmn_parser.h:114
static int set_dependencies(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: "dependencies", Object MSU_TYPES.
Definition: dfg_reader.c:277
static int set_rt_id(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: id, Object RUNTIMES.
Definition: dfg_reader.c:375
struct dfg_msu_type * get_dfg_msu_type(unsigned int id)
Returns the MSU type with the given ID.
Definition: dfg.c:68
#define END_ITER_TOK_LIST(i)
Macro that should appear at the end of the iteration of a list of tokens.
Definition: jsmn_parser.h:172
static int set_num_unpinned_threads(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: num_unpinned_threads, object RUNTIMES.
Definition: dfg_reader.c:425
int port
Port on which the runtime is listening for controller/inter-runtime.
Definition: dfg.h:76
struct dfg_meta_routing meta_routing
Which types of msus route to/from this MSU.
Definition: dfg.h:180
static int set_num_pinned_threads(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: num_pinned_threads, object RUNTIMES.
Definition: dfg_reader.c:410
#define log_warn(fmt,...)
Definition: logging.h:113
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
static int set_rt_ip(jsmntok_t **tok__, char *j__, struct json_state *in__, struct json_state **saved__)
Key: ip, Object RUNTIMES.
Definition: dfg_reader.c:382