46 #define SEARCH_FOR_ID(s, n, field, id_) \
49 for (int i=0; i<(n); ++i) { \
50 if (field[i]->id == id_) { \
140 if (strcasecmp(mode_str,
"pinned") == 0) {
142 }
else if (strcasecmp(mode_str,
"unpinned") == 0) {
145 log_warn(
"Unknown thread mode: %s", mode_str);
151 if (strcasecmp(mode_str,
"blocking") == 0) {
153 }
else if (strcasecmp(mode_str,
"nonblocking") == 0 ||
154 strcasecmp(mode_str,
"non-blocking") == 0) {
157 log_warn(
"Unknown blocking mode: %s", mode_str);
164 if (strstr(str_type,
"entry") != NULL) {
167 if (strstr(str_type,
"exit") != NULL) {
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);
183 target->
id =
template->id;
186 target->
type =
template->type;
191 struct dfg_msu *msu = calloc(1,
sizeof(*input));
205 log_error(
"MSU %u already exists and scheduled",
id);
209 msu = calloc(1,
sizeof(*msu));
219 .blocking_mode = mode
227 log_error(
"Cannot free MSU that is still assigned to thread or runtime");
240 log_error(
"Too many MSUs on thread %d", thread->
id);
274 log_error(
"Runtime id %u not instantiated", runtime_id);
278 if (thread == NULL) {
279 log_error(
"Thread id %u not instantiated on runtime %u", thread_id, runtime_id);
285 log_error(
"Error scheduling MSU on thread");
290 log(LOG_DFG,
"Scheduled DFG msu %d", msu->
id);
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);
307 for (di = 0; di < dfg->
n_msus && dfg->
msus[di] != msu; di++){}
319 for (
int i=ti; i < thread->
n_msus - 1; i++) {
320 thread->
msus[i] = thread->
msus[i+1];
324 for (
int i=di; i < dfg->
n_msus - 1; i++) {
352 for (
int j=0; j<rt->
n_routes; j++) {
355 log_error(
"MSU %d Cannot be unscheduled: referenced by route %d",
362 log(LOG_DFG,
"Unscheduled DFG msu %d", msu->
id);
370 log_error(
"DFG route %u already exists",
id);
375 log_error(
"Runtime %u does not exist in DFG", runtime_id);
379 log_error(
"Cannot fit more routes on runtime %u", runtime_id);
383 route = calloc(1,
sizeof(*route));
385 log_error(
"Could not allocate DFG route %u",
id);
400 for (
int i=0; i<dfg->
n_msus; i++) {
404 log_error(
"Cannot delete route %d while it is still attached to msu %d",
417 log_error(
"Could not find route in runtime");
430 log_error(
"Cannot add route on runtime %d to msu on runtime %d",
436 log_error(
"Route with type %d already exists in MSU %d",
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);
458 log_error(
"Cannot add more MSUs to route %d", route->
id);
462 log_error(
"Cannot add MSU of type %d to route of type %d",
469 log_perror(
"Error allocating route destination");
493 log_error(
"Could not find endpoint in route");
501 log(LOG_ROUTING_CHANGES,
"Route %d now has %d endpoints", route->
id, route->
n_endpoints);
513 log_error(
"Could not find endpoint in route");
521 int delta =
new > old ? 1 : -1;
528 for (
int i=old; delta * i < delta *
new; i += delta) {
542 log_error(
"Cannot add unspecified-thread-mode thread");
546 log_error(
"Cannot add more threads to runtime %d", rt->
id);
550 struct dfg_thread *thread = calloc(1,
sizeof(*thread));
551 if (thread == NULL) {
555 thread->
id = thread_id;
567 log_error(
"Unknown thread mode %d provided", mode);
586 for (
int i=0; i < rt->
n_routes; i++) {
600 for (
int i=0; i < dfg->
n_msus; i++) {
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.
int n_routes
The routes that an MSU can send to.
#define EXIT_VERTEX_TYPE
Bitmask representing an MSU through which messages exit DeDOS.
int n_msus
The number of MSUs in dedos_dfg::msus.
enum thread_mode mode
Pinned/unpinned mode for the thread.
int delete_dfg_route(struct dfg_route *route)
Deletes the provided route from the DFG.
struct dfg_msu * copy_dfg_msu(struct dfg_msu *input)
Allocates a new MSU with the same fields as the input MSU (though unscheduled)
uint8_t str_to_vertex_type(char *str_type)
Converts a string containing exit and/or entry to the correct bitmask.
thread_mode
Identifies if a thread is pinned to a core or able to be scheduled on any core.
int n_msus
Number of MSUs placed on the thread.
#define log_info(fmt,...)
int free_dfg_msu(struct dfg_msu *input)
Frees an MSU structure.
struct dfg_scheduling scheduling
Information about where an MSU is scheduled.
struct dfg_route * routes[64]
Routes located on this runtime.
#define MAX_THREADS
The maximum number of threads that may be present on a runtime.
struct dfg_msu * instances[512]
Each instance of this MSU type.
#define log_critical(fmt,...)
struct dfg_route * get_dfg_runtime_route(struct dfg_runtime *rt, unsigned int id)
void free_dfg(struct dedos_dfg *dfg)
Frees the entirety of the DFG structure.
struct dfg_route * get_dfg_route(unsigned int id)
Returns the route with the given ID.
uint8_t vertex_type
Whether the MSU is #ENTRY, #EXIT, or possible #ENTRY | #EXIT.
int del_dfg_route_endpoint(struct dfg_route *route, struct dfg_route_endpoint *ep)
Removes an MSU as a route endpoint.
int unschedule_dfg_msu(struct dfg_msu *msu)
Removes the given MSU from its runtime and thread.
struct dfg_msu * msus[8]
MSUs placed on that thread.
int n_msu_types
The number of elements in dedos_dfg::msu_types.
struct dfg_runtime * get_dfg_runtime(unsigned int runtime_id)
Returns the runtime with the given ID.
#define ENTRY_VERTEX_TYPE
Bitmask representing an MSU through which messages enter DeDOS.
Default – threads should not have this mode.
char name[32]
A name describing the function of the MSU.
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.
#define log_perror(fmt,...)
int id
Unique identifier for the runtime.
Logging of status messages to the terminal.
#define MAX_ROUTES
The total maximum number of routes that may be present in the DFG.
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 ...
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.
struct dfg_msu_type * type
The type of the MSU and meta-routing information.
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.
#define MAX_MSU_PER_THREAD
The maximum number of MSUs which can be placed on a single thread.
Representation of a runtime in the DFG.
struct dfg_dependency * dependencies[32]
These MSU types must be present in order for this MSU type to be cloned.
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.
struct dfg_route_endpoint * endpoints[256]
The endpoints of the route.
int n_endpoints
The number of endpoints in dfg_route::endpoints.
struct dfg_runtime * runtime
The runtime on which an MSU is running.
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...
int n_runtimes
The number of elements in dedos_dfg::runtimes.
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.
#define log_error(fmt,...)
struct dfg_msu * msu
The MSU at this endpoint to which a message would be delivered.
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. ...
struct dfg_msu_type * msu_types[32]
MSU types which may be present in the application.
int id
A unique identifier for the MSU.
blocking_mode
Whether an MSU is blocking or non-blocking.
Data with which an MSU is initialized, and the payload for messages of type CTRL_CREATE_MSU.
int n_unpinned_threads
Number of the above-threads which are unpinned.
struct dfg_thread * thread
The thread on which an MSU is running.
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.
struct db_info db
DB information.
int id
Unique identifier for the thread.
Representation of a single MSU in the dfg.
#define SEARCH_FOR_ID(s, n, field, id_)
Convenience macro to search a field within a structure for the element with an ID.
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...
struct db_info * get_db_info()
Returns DB info.
#define MAX_MSU
The maximum number of MSUs which can be present in the system at a time.
struct dfg_runtime * runtime
The runtime on which the route is located.
int n_pinned_threads
Number of the above-threads which are pinned.
int id
A unique identifier for the MSU type.
int id
A unique identifier for the route.
static void free_dfg_msu_type(struct dfg_msu_type *type)
Frees elements in the MSU type structure.
struct dfg_route * routes[32]
Top-level structure holding the data-flow graph.
A route through which MSU messages can be passed.
static struct dedos_dfg * dfg
Static local copy of the DFG, so each call doesn't have to pass a copy.
struct msu_init_data init_data
Initial data passed to the MSU.
int get_dfg_n_runtimes()
Returns the number of registered runtime.
static void free_dfg_runtime(struct dfg_runtime *rt)
Frees the runtime and all threads and routes associated with it.
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.
struct dfg_msu * get_dfg_msu(unsigned int id)
Returns the MSU with the given ID.
Info to connect and use database.
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.
struct dfg_runtime * runtimes[16]
The runtimes present in the application.
A single endpoint for an MSU route.
struct dfg_thread * threads[32]
Threads located on the runtime.
uint32_t key
The key associated with this endpoint.
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.
Representation of a thread on a runtime in the DFG.
int n_routes
Number of routes above.
static int runtime_id(int runtime_fd)
int n_instances
The number of instances of this MSU type.
#define log(level, fmt,...)
Log at a custom level.
enum blocking_mode str_to_blocking_mode(char *mode_str)
Converts a string of blocking/non-blocking to the correct enumerator.
int n_dependencies
The number of elements in dfg_msu_type::dependencies.
struct dfg_msu_type * get_dfg_msu_type(unsigned int id)
Returns the MSU type with the given ID.
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.
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.
#define log_warn(fmt,...)
int msu_has_route(struct dfg_msu *msu, struct dfg_route *route)
Returns 1 if the given MSU has the route as an endpoint.
#define MAX_ROUTE_ENDPOINTS
The maximum number of endpoints that a single route may have as destinations.
enum thread_mode str_to_thread_mode(char *mode_str)
Converts a string of pinned/unpinned to the corresponding enumerator.
Default value – used when unset, should never be specified.
enum blocking_mode blocking_mode
Whether the MSU is blocking or not.
struct dfg_msu_type * msu_type
The type of MSU to which this route delivers.
struct dfg_msu * msus[512]
The MSUs present in the application.