My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
main.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 */
24 #include "worker_thread.h"
25 #include "local_files.h"
26 #include "rt_stats.h"
27 #include "logging.h"
28 #include "runtime_dfg.h"
30 #include "output_thread.h"
31 #include "socket_monitor.h"
32 #include "profiler.h"
33 #include "runtime_dfg.h"
34 
35 #include <stdlib.h>
36 #include <unistd.h>
37 #include <stdbool.h>
38 #include <getopt.h>
39 #include <libgen.h>
40 #include <stdio.h>
41 
43 #define USAGE_ARGS \
44  " -j dfg.json -i runtime_id [-l statlog] [-p profiling_prob]"
45 
49 int main(int argc, char **argv) {
50 
51  char *dfg_json = NULL;
52  char *statlog = NULL;
53  int runtime_id = -1;
54  float prof_prob = 0;
55 
56  struct option long_options[] = {
57  {NULL, 0, 0, 0}
58  };
59 
60  while (1) {
61  int option_index = 0;
62  int c = getopt_long(argc, argv, "j:i:l:p:", long_options, &option_index);
63 
64  if (c == -1) {
65  break;
66  }
67  switch (c) {
68  case 'j':
69  dfg_json = optarg;
70  break;
71  case 'i':
72  runtime_id = atoi(optarg);
73  break;
74  case 'l':
75  statlog = optarg;
76  break;
77  case 'p':
78  prof_prob = atof(optarg);
79  break;
80  default:
81  printf("Unknown option provided: %c. Exiting\n", c);
82  exit(-1);
83  }
84  }
85 
86  if (dfg_json == NULL || runtime_id == -1) {
87  printf("%s " USAGE_ARGS "\n", argv[0]);
88  exit(-1);
89  }
90  set_local_directory(dirname(argv[0]));
91 
92  if (init_statistics() != 0) {
93  log_warn("Error initializing runtime statistics");
94  }
95  INIT_PROFILER(prof_prob);
96 
97  if (init_runtime_dfg(dfg_json, runtime_id) != 0) {
98  log_critical("Error initializing runtime %d from json file %s. Exiting",
99  runtime_id, dfg_json);
100  exit(-1);
101  }
102 
103  struct sockaddr_in ctrl_addr;
104  int rtn = controller_address(&ctrl_addr);
105  if (rtn < 0) {
106  log_critical("Could not get controller address from DFG");
107  exit(-1);
108  }
109 
110  struct dedos_thread *output_thread = start_output_monitor_thread();
111  if (output_thread == NULL) {
112  log_critical("Error starting output thread!");
113  exit(-1);
114  }
115 
116  // This will block until the socket monitor exits
117  rtn = run_socket_monitor(local_runtime_port(), &ctrl_addr);
118  if (rtn < 0) {
119  log_critical("Error running socket monitor. Runtime will exit");
120  }
121 
125 
126  finalize_statistics(statlog);
128  log_info("Exiting runtime...");
129  return 0;
130 }
int main(int argc, char **argv)
Entry point to start the runtime.
Definition: main.c:49
void finalize_statistics(char *statlog)
Writes the statistics to statlog if provided, and frees assocated structure.
Definition: rt_stats.c:822
int init_runtime_dfg(char *filename, int runtime_id)
Initializes the DFG as loaded from a JSON file, and sets the global variables such that the DFG and r...
Definition: runtime_dfg.c:41
Collecting statistics within the runtime.
int controller_address(struct sockaddr_in *addr)
Gets the sockaddr associated with the global controller.
Definition: runtime_dfg.c:77
#define log_info(fmt,...)
Definition: logging.h:88
#define log_critical(fmt,...)
Definition: logging.h:124
Monitors an incoming port for messages from runtime or controller.
void join_output_thread()
Joins the underlying pthread.
Definition: output_thread.c:90
Logging of status messages to the terminal.
Access local files within the repo.
Threads that hold MSUs.
Interactions with global dfg from individual runtime.
struct dedos_thread * start_output_monitor_thread(void)
Starts the thread monitoring the queue for messages to be sent to other endpoints.
For profiling the path of MSU messages through DeDOS.
#define USAGE_ARGS
The command-line arguments.
Definition: main.c:43
int set_local_directory(char *dir)
Sets the directory of the executable so we can get relaitve paths.
Definition: local_files.c:33
A dedos_thread which monitors a queue for output to be sent to other runtimes or the global controlle...
int init_statistics()
Initializes the entire stats module.
Definition: rt_stats.c:783
void stop_all_worker_threads()
Signals all worker threads to stop.
Definition: worker_thread.c:54
void stop_output_monitor()
Triggers the output thread to stop execution.
Definition: output_thread.c:86
int local_runtime_port()
Definition: runtime_dfg.c:99
static int runtime_id(int runtime_fd)
#define INIT_PROFILER(tprof)
Initializes the profiler with the provided probability of profiling.
Definition: profiler.h:69
int run_socket_monitor(int local_port, struct sockaddr_in *ctrl_addr)
Starts (blocking) the socket monitor, listening on the provided port.
#define log_warn(fmt,...)
Definition: logging.h:113
void free_runtime_dfg()
Frees the runtime's static instance of the DFG.
Definition: runtime_dfg.c:119
Structure representing any thread within DeDOS.
Definition: dedos_threads.h:35
Communication with global controller from runtime.